Skip to content
Closed
Changes from 2 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
11 changes: 8 additions & 3 deletions winit-uikit/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ use dpi::{
Position, Size,
};
use objc2::rc::Retained;
use objc2::runtime::AnyObject;
use objc2::{MainThreadMarker, available, class, define_class, msg_send};
use objc2_core_foundation::{CGFloat, CGPoint, CGRect, CGSize};
use objc2_foundation::{NSObject, NSObjectProtocol};
use objc2_foundation::NSObject;
use objc2_ui_kit::{
UIApplication, UICoordinateSpace, UIEdgeInsets, UIResponder, UIScreen,
UIScreenOverscanCompensation, UIViewController, UIWindow,
Expand Down Expand Up @@ -535,8 +536,12 @@ impl Window {

let view = WinitView::new(mtm, ios_attributes.scale_factor, frame);

let gl_or_metal_backed =
view.isKindOfClass(class!(CAMetalLayer)) || view.isKindOfClass(class!(CAEAGLLayer));
let gl_or_metal_backed = unsafe {
let view_layer: *mut AnyObject = msg_send![&*view, layer];
let metal_backed: bool = msg_send![view_layer, isKindOfClass: class!(CAMetalLayer)];
let gl_backed: bool = msg_send![view_layer, isKindOfClass: class!(CAEAGLLayer)];

@tronical tronical Jul 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I must be missing something, but ... isn't this new code doing the same as the old code? (except that it introduces the use of unsafe)

Edit: nevermind, I see now that it performs the check on the layer, not the view.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of this unsafe, block, would it be possible to use https://docs.rs/objc2-ui-kit/latest/objc2_ui_kit/struct.UIView.html#method.layerClass to obtain the class and then perform the check?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good suggestion to avoid the handwritten unsafe block. A direct UIView::layerClass call would inspect the base UIView class, while subclasses may override it, so it is not equivalent to checking the actual backing-layer instance. I enabled the objc2-quartz-core bindings and now use the safe typed view.layer() result followed by isKindOfClass checks. This removes the raw pointer and the entire unsafe block.

Verification: cargo check -p winit-uikit --target aarch64-apple-ios passes on macOS. I also tested the same typed access pattern through our 0.30 patch lineage on a physical iPad: signed install and launch passed, rendering looked correct, and the app remained alive through a controlled suspend/resume.

metal_backed || gl_backed
};

let view_controller = WinitViewController::new(mtm, &ios_attributes, &view);
let window = WinitUIWindow::new(mtm, &window_attributes, frame, &view_controller);
Expand Down
Loading