-
Notifications
You must be signed in to change notification settings - Fork 86
Use objc2-*
family of crates
#334
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
Conversation
fn surface_bind_to_gl_texture(surface: &IOSurfaceRef, width: i32, height: i32, has_alpha: bool) { | ||
const BGRA: GLenum = 0x80E1; | ||
const RGBA: GLenum = 0x1908; | ||
const RGB: GLenum = 0x1907; | ||
const TEXTURE_RECTANGLE_ARB: GLenum = 0x84F5; | ||
const UNSIGNED_INT_8_8_8_8_REV: GLenum = 0x8367; | ||
|
||
unsafe { | ||
let context = CGLGetCurrentContext(); | ||
let gl_error = CGLTexImageIOSurface2D( | ||
context, | ||
TEXTURE_RECTANGLE_ARB, | ||
if has_alpha { | ||
RGBA as GLenum | ||
} else { | ||
RGB as GLenum | ||
}, | ||
width, | ||
height, | ||
BGRA as GLenum, | ||
UNSIGNED_INT_8_8_8_8_REV, | ||
surface as *const IOSurfaceRef as cgl::IOSurfaceRef, | ||
0, | ||
); | ||
|
||
if gl_error != kCGLNoError { | ||
let error_msg = CStr::from_ptr(CGLErrorString(gl_error)); | ||
panic!("{}", error_msg.to_string_lossy()); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was previously provided in io_surface::IOSurface::bind_to_gl_texture
, but it really mixes two domains (IOSurface and CGL), and requires that we link both of those, so I didn't want to expose it in objc2-io-surface
.
pub(crate) const kIODefaultCache: i32 = 0; | ||
pub(crate) const kIOWriteCombineCache: i32 = 4; | ||
pub(crate) const kIOMapCacheShift: i32 = 8; | ||
pub(crate) const kIOMapDefaultCache: i32 = kIODefaultCache << kIOMapCacheShift; | ||
pub(crate) const kIOMapWriteCombineCache: i32 = kIOWriteCombineCache << kIOMapCacheShift; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided in objc2-io-kit
, but felt like too little benefit to take on the dependency.
let () = msg_send![self.view.0, release]; | ||
self.surface | ||
.io_surface | ||
.unlock(IOSurfaceLockOptions::empty(), &mut seed); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kind of manual memory management is now unnecessary, the Retained<NSView>
in NativeWidget
will do it for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a couple questions here:
I've marked this as ready now, since servo/core-foundation-rs#729 seems to be settling on deprecating the Unsure why CI failed, maybe spurious? |
The
objc2-*
family of crates provide many benefits over thecore-foundation-rs
crates, most notably here is that the bindings are auto-generated and thus much more complete (meaning that we can avoid the error-pronemsg_send!
in almost all cases).See servo/core-foundation-rs#729 for additional motivation.