Skip to content
Open
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
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ mint = ["dpi/mint"]
rwh_04 = ["dep:rwh_04", "ndk/rwh_04"]
rwh_05 = ["dep:rwh_05", "ndk/rwh_05"]
rwh_06 = ["dep:rwh_06", "ndk/rwh_06"]
# Only works on iOS/macOS, will create a UIView/NSView with CAMetalLayer and sets gl_or_metal_backed (iOS) true
metal = []

[build-dependencies]
cfg_aliases = "0.2.1"
Expand Down
5 changes: 5 additions & 0 deletions src/platform_impl/ios/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ declare_class!(
}

unsafe impl WinitView {
#[allow(non_snake_case)]
#[cfg(feature="metal")]
#[method(layerClass)]
fn layerClass() -> &'static objc2::runtime::AnyClass{ objc2::class!(CAMetalLayer) }

#[method(drawRect:)]
fn draw_rect(&self, rect: CGRect) {
let mtm = MainThreadMarker::new().unwrap();
Expand Down
5 changes: 3 additions & 2 deletions src/platform_impl/ios/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,9 @@ impl Window {

let view = WinitView::new(mtm, &window_attributes, frame);

let gl_or_metal_backed =
view.isKindOfClass(class!(CAMetalLayer)) || view.isKindOfClass(class!(CAEAGLLayer));
let gl_or_metal_backed = cfg!(feature = "metal")
|| view.isKindOfClass(class!(CAMetalLayer))
|| view.isKindOfClass(class!(CAEAGLLayer));

let view_controller = WinitViewController::new(mtm, &window_attributes, &view);
let window = WinitUIWindow::new(mtm, &window_attributes, frame, &view_controller);
Expand Down
10 changes: 10 additions & 0 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,16 @@ impl WinitView {
});
let this: Retained<Self> = unsafe { msg_send_id![super(this), init] };

if cfg!(feature = "metal") {
unsafe {
let _: () = objc2::msg_send![&this, setWantsLayer: objc2::ffi::YES];
let metal_layer_cls = objc2::class!(CAMetalLayer);
let metal_layer: *mut objc2::runtime::AnyObject =
objc2::msg_send![metal_layer_cls, new];
let _: () = objc2::msg_send![&this, setLayer: metal_layer];
}
}

this.setPostsFrameChangedNotifications(true);
let notification_center = unsafe { NSNotificationCenter::defaultCenter() };
unsafe {
Expand Down
Loading