1212
1313extern crate libc;
1414extern crate core_foundation;
15+ extern crate core_foundation_sys;
1516extern crate cgl;
1617extern crate leaky_cow;
1718
@@ -20,6 +21,7 @@ extern crate leaky_cow;
2021use core_foundation:: base:: { CFRelease , CFRetain , CFTypeID , CFTypeRef , CFType , TCFType } ;
2122use core_foundation:: dictionary:: { CFDictionary , CFDictionaryRef } ;
2223use core_foundation:: string:: { CFString , CFStringRef } ;
24+ use core_foundation_sys:: base:: mach_port_t;
2325use cgl:: { kCGLNoError, CGLGetCurrentContext , CGLTexImageIOSurface2D , CGLErrorString , GLenum } ;
2426use libc:: { c_int, size_t} ;
2527use std:: os:: raw:: c_void;
@@ -33,8 +35,12 @@ const RGB: GLenum = 0x1907;
3335const TEXTURE_RECTANGLE_ARB : GLenum = 0x84F5 ;
3436const UNSIGNED_INT_8_8_8_8_REV : GLenum = 0x8367 ;
3537
36- //static kIOSurfaceLockReadOnly: u32 = 0x1;
37- //static kIOSurfaceLockAvoidSync: u32 = 0x2;
38+ #[ allow( non_snake_case) ]
39+ pub mod IOSurfaceLockOptions {
40+ #![ allow( non_upper_case_globals) ]
41+ pub const kIOSurfaceLockReadOnly: u32 = 0x00000001 ;
42+ pub const kIOSurfaceLockAvoidSync: u32 = 0x00000002 ;
43+ }
3844
3945type IOReturn = c_int ;
4046
@@ -143,7 +149,7 @@ impl IOSurface {
143149 let error_msg = error_msg. to_string_lossy ( ) ;
144150 // This will only actually leak memory if error_msg is a `Cow::Owned`, which
145151 // will only happen if the platform gives us invalid unicode.
146- panic ! ( error_msg. leak( ) ) ;
152+ panic ! ( "{}" , error_msg. leak( ) ) ;
147153 }
148154 }
149155 }
@@ -195,16 +201,47 @@ extern {
195201 pub static kIOSurfaceIsGlobal: CFStringRef ;
196202 pub static kIOSurfacePixelFormat: CFStringRef ;
197203
198- fn IOSurfaceCreate ( properties : CFDictionaryRef ) -> IOSurfaceRef ;
199- fn IOSurfaceLookup ( csid : IOSurfaceID ) -> IOSurfaceRef ;
200- fn IOSurfaceGetID ( buffer : IOSurfaceRef ) -> IOSurfaceID ;
201-
202- fn IOSurfaceGetTypeID ( ) -> CFTypeID ;
203-
204- fn IOSurfaceLock ( buffer : IOSurfaceRef , options : u32 , seed : * mut u32 ) -> IOReturn ;
205- fn IOSurfaceUnlock ( buffer : IOSurfaceRef , options : u32 , seed : * mut u32 ) -> IOReturn ;
206-
207- fn IOSurfaceGetHeight ( buffer : IOSurfaceRef ) -> size_t ;
208- fn IOSurfaceGetBytesPerRow ( buffer : IOSurfaceRef ) -> size_t ;
209- fn IOSurfaceGetBaseAddress ( buffer : IOSurfaceRef ) -> * mut c_void ;
204+ pub fn IOSurfaceCreate ( properties : CFDictionaryRef ) -> IOSurfaceRef ;
205+ pub fn IOSurfaceLookup ( csid : IOSurfaceID ) -> IOSurfaceRef ;
206+ pub fn IOSurfaceGetID ( buffer : IOSurfaceRef ) -> IOSurfaceID ;
207+
208+ pub fn IOSurfaceGetTypeID ( ) -> CFTypeID ;
209+
210+ pub fn IOSurfaceLock ( buffer : IOSurfaceRef , options : u32 , seed : * mut u32 ) -> IOReturn ;
211+ pub fn IOSurfaceUnlock ( buffer : IOSurfaceRef , options : u32 , seed : * mut u32 ) -> IOReturn ;
212+ pub fn IOSurfaceGetSeed ( buffer : IOSurfaceRef ) -> u32 ;
213+
214+ pub fn IOSurfaceGetHeight ( buffer : IOSurfaceRef ) -> size_t ;
215+ pub fn IOSurfaceGetWidth ( buffer : IOSurfaceRef ) -> usize ;
216+ pub fn IOSurfaceGetBytesPerRow ( buffer : IOSurfaceRef ) -> size_t ;
217+ pub fn IOSurfaceGetBaseAddress ( buffer : IOSurfaceRef ) -> * mut c_void ;
218+ pub fn IOSurfaceGetElementHeight ( buffer : IOSurfaceRef ) -> usize ;
219+ pub fn IOSurfaceGetElementWidth ( buffer : IOSurfaceRef ) -> usize ;
220+ pub fn IOSurfaceGetBytesPerElement ( buffer : IOSurfaceRef ) -> usize ;
221+ pub fn IOSurfaceGetAllocSize ( buffer : IOSurfaceRef ) -> usize ;
222+
223+ pub fn IOSurfaceGetPixelFormat ( buffer : IOSurfaceRef ) -> i32 ;
224+
225+ pub fn IOSurfaceGetUseCount ( buffer : IOSurfaceRef ) -> i32 ;
226+ pub fn IOSurfaceIncrementUseCount ( buffer : IOSurfaceRef ) ;
227+ pub fn IOSurfaceDecrementUseCount ( buffer : IOSurfaceRef ) ;
228+ pub fn IOSurfaceIsInUse ( buffer : IOSurfaceRef ) -> bool ;
229+
230+ pub fn IOSurfaceCreateMachPort ( buffer : IOSurfaceRef ) -> mach_port_t ;
231+ pub fn IOSurfaceLookupFromMachPort ( port : mach_port_t ) -> IOSurfaceRef ;
232+
233+ pub fn IOSurfaceGetPropertyAlignment ( property : CFStringRef ) -> usize ;
234+ pub fn IOSurfaceGetPropertyMaximum ( property : CFStringRef ) -> usize ;
235+
236+ pub fn IOSurfaceCopyValue ( buffer : IOSurfaceRef , key : CFStringRef ) -> CFTypeRef ;
237+ pub fn IOSurfaceRemoveValue ( buffer : IOSurfaceRef , key : CFStringRef ) ;
238+ pub fn IOSurfaceSetValue ( buffer : IOSurfaceRef , key : CFStringRef , value : CFTypeRef ) ;
239+
240+ pub fn IOSurfaceGetBaseAddressOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> * mut c_void ;
241+ pub fn IOSurfaceGetBytesPerElementOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
242+ pub fn IOSurfaceGetBytesPerRowOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
243+ pub fn IOSurfaceGetElementHeightOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
244+ pub fn IOSurfaceGetElementWidthOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
245+ pub fn IOSurfaceGetHeightOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
246+ pub fn IOSurfaceGetWidthOfPlane ( buffer : IOSurfaceRef , plane_index : usize ) -> usize ;
210247}
0 commit comments