Skip to content

Commit

Permalink
metal: handle views without the main layer
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Dec 25, 2024
1 parent 28f0ebe commit 98300ac
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions blade-graphics/src/metal/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ impl super::Context {
raw_window_handle::RawWindowHandle::AppKit(handle) => unsafe {
let view = Retained::retain(handle.ns_view.as_ptr() as *mut objc2_app_kit::NSView)
.unwrap();
let main_layer = view.layer().unwrap();
let render_layer = if main_layer.is_kind_of::<CAMetalLayer>() {
Retained::cast(main_layer)
let main_layer = view.layer();
let render_layer = if main_layer
.as_ref()
.map_or(false, |layer| layer.is_kind_of::<CAMetalLayer>())
{
Retained::cast(main_layer.unwrap())
} else {
let new_layer = CAMetalLayer::new();
new_layer.setFrame(main_layer.frame());
if let Some(layer) = main_layer {
new_layer.setFrame(layer.frame());
}
view.setLayer(Some(&new_layer));
view.setWantsLayer(true);
new_layer.setContentsGravity(objc2_quartz_core::kCAGravityTopLeft);
Expand Down

0 comments on commit 98300ac

Please sign in to comment.