diff --git a/Cargo.toml b/Cargo.toml index d866e24..0a175b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,7 +81,7 @@ features = [ ] [target.'cfg(target_vendor = "apple")'.dependencies] -objc2-core-graphics = { version = "0.3.1", default-features = false, features = [ +objc2-core-graphics = { version = "0.3.2", default-features = false, features = [ "std", "objc2", "CGColorSpace", @@ -89,11 +89,11 @@ objc2-core-graphics = { version = "0.3.1", default-features = false, features = "CGImage", ] } objc2 = "0.6.0" -objc2-core-foundation = { version = "0.3.1", default-features = false, features = [ +objc2-core-foundation = { version = "0.3.2", default-features = false, features = [ "std", "CFCGTypes", ] } -objc2-foundation = { version = "0.3.1", default-features = false, features = [ +objc2-foundation = { version = "0.3.2", default-features = false, features = [ "std", "objc2-core-foundation", "NSDictionary", @@ -103,7 +103,7 @@ objc2-foundation = { version = "0.3.1", default-features = false, features = [ "NSThread", "NSValue", ] } -objc2-quartz-core = { version = "0.3.1", default-features = false, features = [ +objc2-quartz-core = { version = "0.3.2", default-features = false, features = [ "std", "objc2-core-foundation", "CALayer", diff --git a/src/backends/cg.rs b/src/backends/cg.rs index ba6c17a..a724128 100644 --- a/src/backends/cg.rs +++ b/src/backends/cg.rs @@ -8,6 +8,7 @@ use objc2::{define_class, msg_send, AllocAnyThread, DefinedClass, MainThreadMark use objc2_core_foundation::{CFRetained, CGPoint}; use objc2_core_graphics::{ CGBitmapInfo, CGColorRenderingIntent, CGColorSpace, CGDataProvider, CGImage, CGImageAlphaInfo, + CGImageByteOrderInfo, CGImageComponentInfo, CGImagePixelFormatInfo, }; use objc2_foundation::{ ns_string, NSDictionary, NSKeyValueChangeKey, NSKeyValueChangeNewKey, @@ -223,7 +224,7 @@ impl SurfaceInterface for CGImpl< layer.setContentsGravity(unsafe { kCAGravityTopLeft }); // Initialize color space here, to reduce work later on. - let color_space = unsafe { CGColorSpace::new_device_rgb() }.unwrap(); + let color_space = CGColorSpace::new_device_rgb().unwrap(); // Grab initial width and height from the layer (whose properties have just been initialized // by the observer using `NSKeyValueObservingOptionInitial`). @@ -308,6 +309,17 @@ impl BufferInterface for BufferImpl<'_, } }; + // `CGBitmapInfo` consists of a combination of `CGImageAlphaInfo`, `CGImageComponentInfo` + // `CGImageByteOrderInfo` and `CGImagePixelFormatInfo` (see e.g. `CGBitmapInfoMake`). + // + // TODO: Use `CGBitmapInfo::new` once the next version of objc2-core-graphics is released. + let bitmap_info = CGBitmapInfo( + CGImageAlphaInfo::NoneSkipFirst.0 + | CGImageComponentInfo::Integer.0 + | CGImageByteOrderInfo::Order32Little.0 + | CGImagePixelFormatInfo::Packed.0, + ); + let image = unsafe { CGImage::new( self.imp.width, @@ -316,8 +328,7 @@ impl BufferInterface for BufferImpl<'_, 32, self.imp.width * 4, Some(&self.imp.color_space), - // TODO: This looks incorrect! - CGBitmapInfo::ByteOrder32Little | CGBitmapInfo(CGImageAlphaInfo::NoneSkipFirst.0), + bitmap_info, Some(&data_provider), ptr::null(), false,