Skip to content

Make {ttf, image, mixer, gfx}::ffi public #746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
In this file will be listed the changes, especially the breaking ones that one should be careful of
when upgrading from a version of rust-sdl2 to another.

[PR #746](https://github.com/Rust-SDL2/rust-sdl2/pull/746)
* Make `{ttf, image, mixer, gfx}::ffi` public.

### v0.31.1

[PR #737](https://github.com/Rust-SDL2/rust-sdl2/pull/737)
Expand Down
610 changes: 610 additions & 0 deletions src/sdl2/gfx/ffi.rs

Large diffs are not rendered by default.

39 changes: 9 additions & 30 deletions src/sdl2/gfx/framerate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,27 @@ use libc;
use libc::{c_void, uint32_t, size_t};
use std::mem;
use ::get_error;


mod ll {
/* automatically generated by rust-bindgen */

use libc::*;
#[repr(C)]
pub struct FPSmanager {
pub framecount: uint32_t,
pub rateticks: c_float,
pub baseticks: uint32_t,
pub lastticks: uint32_t,
pub rate: uint32_t,
}
extern "C" {
pub fn SDL_initFramerate(manager: *mut FPSmanager);
pub fn SDL_setFramerate(manager: *mut FPSmanager, rate: uint32_t) -> c_int;
pub fn SDL_getFramerate(manager: *mut FPSmanager) -> c_int;
pub fn SDL_getFramecount(manager: *mut FPSmanager) -> c_int;
pub fn SDL_framerateDelay(manager: *mut FPSmanager) -> uint32_t;
}
}
use super::ffi;

/// Structure holding the state and timing information of the framerate controller.
pub struct FPSManager {
raw: *mut ll::FPSmanager,
raw: *mut ffi::FPSmanager,
}

impl FPSManager {
/// Create the framerate manager.
pub fn new() -> FPSManager {
unsafe {
let size = mem::size_of::<ll::FPSmanager>() as size_t;
let raw = libc::malloc(size) as *mut ll::FPSmanager;
ll::SDL_initFramerate(raw);
let size = mem::size_of::<ffi::FPSmanager>() as size_t;
let raw = libc::malloc(size) as *mut ffi::FPSmanager;
ffi::SDL_initFramerate(raw);
FPSManager { raw: raw }
}
}

/// Set the framerate in Hz.
pub fn set_framerate(&mut self, rate: u32) -> Result<(), String> {
let ret = unsafe { ll::SDL_setFramerate(self.raw, rate as uint32_t) };
let ret = unsafe { ffi::SDL_setFramerate(self.raw, rate as uint32_t) };
match ret {
0 => Ok(()),
_ => Err(get_error())
Expand All @@ -55,18 +34,18 @@ impl FPSManager {
/// Return the current target framerate in Hz.
pub fn get_framerate(&self) -> i32 {
// will not get an error
unsafe { ll::SDL_getFramerate(self.raw) as i32 }
unsafe { ffi::SDL_getFramerate(self.raw) as i32 }
}

/// Return the current framecount.
pub fn get_frame_count(&self) -> i32 {
// will not get an error
unsafe { ll::SDL_getFramecount(self.raw) as i32 }
unsafe { ffi::SDL_getFramecount(self.raw) as i32 }
}

/// Delay execution to maintain a constant framerate and calculate fps.
pub fn delay(&mut self) -> u32 {
unsafe { ll::SDL_framerateDelay(self.raw) as u32 }
unsafe { ffi::SDL_framerateDelay(self.raw) as u32 }
}
}

Expand Down
81 changes: 1 addition & 80 deletions src/sdl2/gfx/imagefilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,86 +4,7 @@ use std::mem;
use libc::{self,size_t, c_void, c_uint, c_int};
use ::get_error;
use c_vec::CVec;

mod ll {
/* automatically generated by rust-bindgen */

use libc::*;
extern "C" {
pub fn SDL_imageFilterMMXdetect() -> c_int;
pub fn SDL_imageFilterMMXoff();
pub fn SDL_imageFilterMMXon();
pub fn SDL_imageFilterAdd(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterMean(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterSub(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterAbsDiff(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) ->
c_int;
pub fn SDL_imageFilterMult(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterMultNor(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) ->
c_int;
pub fn SDL_imageFilterMultDivby2(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) ->
c_int;
pub fn SDL_imageFilterMultDivby4(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) ->
c_int;
pub fn SDL_imageFilterBitAnd(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterBitOr(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterDiv(Src1: *mut u8, Src2: *mut u8,
Dest: *mut u8, length: c_uint) -> c_int;
pub fn SDL_imageFilterBitNegation(Src1: *mut u8, Dest: *mut u8,
length: c_uint) -> c_int;
pub fn SDL_imageFilterAddByte(Src1: *mut u8, Dest: *mut u8,
length: c_uint, C: u8) -> c_int;
pub fn SDL_imageFilterAddUint(Src1: *mut u8, Dest: *mut u8,
length: c_uint, C: c_uint) -> c_int;
pub fn SDL_imageFilterAddByteToHalf(Src1: *mut u8,
Dest: *mut u8, length: c_uint,
C: u8) -> c_int;
pub fn SDL_imageFilterSubByte(Src1: *mut u8, Dest: *mut u8,
length: c_uint, C: u8) -> c_int;
pub fn SDL_imageFilterSubUint(Src1: *mut u8, Dest: *mut u8,
length: c_uint, C: c_uint) -> c_int;
pub fn SDL_imageFilterShiftRight(Src1: *mut u8, Dest: *mut u8,
length: c_uint, N: u8) -> c_int;
pub fn SDL_imageFilterShiftRightUint(Src1: *mut u8,
Dest: *mut u8, length: c_uint,
N: u8) -> c_int;
pub fn SDL_imageFilterMultByByte(Src1: *mut u8, Dest: *mut u8,
length: c_uint, C: u8) -> c_int;
pub fn SDL_imageFilterShiftRightAndMultByByte(Src1: *mut u8,
Dest: *mut u8,
length: c_uint, N: u8,
C: u8) -> c_int;
pub fn SDL_imageFilterShiftLeftByte(Src1: *mut u8,
Dest: *mut u8, length: c_uint,
N: u8) -> c_int;
pub fn SDL_imageFilterShiftLeftUint(Src1: *mut u8,
Dest: *mut u8, length: c_uint,
N: u8) -> c_int;
pub fn SDL_imageFilterShiftLeft(Src1: *mut u8, Dest: *mut u8,
length: c_uint, N: u8) -> c_int;
pub fn SDL_imageFilterBinarizeUsingThreshold(Src1: *mut u8,
Dest: *mut u8,
length: c_uint, T: u8)
-> c_int;
pub fn SDL_imageFilterClipToRange(Src1: *mut u8, Dest: *mut u8,
length: c_uint, Tmin: u8,
Tmax: u8) -> c_int;
pub fn SDL_imageFilterNormalizeLinear(Src: *mut u8,
Dest: *mut u8, length: c_uint,
Cmin: c_int, Cmax: c_int,
Nmin: c_int, Nmax: c_int) -> c_int;
}
}
use super::ffi as ll;

/// MMX detection routine (with override flag).
pub fn mmx_detect() -> bool {
Expand Down
3 changes: 3 additions & 0 deletions src/sdl2/gfx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#[link(name="SDL2_gfx")]
extern {}

#[allow(non_camel_case_types, dead_code)]
pub mod ffi;

pub mod primitives;
pub mod rotozoom;
pub mod framerate;
Expand Down
Loading