Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@ 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",
"CGDataProvider",
"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",
Expand All @@ -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",
Expand Down
17 changes: 14 additions & 3 deletions src/backends/cg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -223,7 +224,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> 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`).
Expand Down Expand Up @@ -308,6 +309,17 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> 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,
Comment on lines +317 to +320
Copy link
Member Author

@madsmtm madsmtm Nov 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously CGBitmapInfo::ByteOrder32Little | CGBitmapInfo(CGImageAlphaInfo::NoneSkipFirst.0).

I've added CGImageComponentInfo::Integer and CGImagePixelFormatInfo::Packed for clarity here, though these are both 0 so they shouldn't affect this functionally.

);

let image = unsafe {
CGImage::new(
self.imp.width,
Expand All @@ -316,8 +328,7 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> 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,
Expand Down