From 215c12f1fabbfb89f6f920322d2a8084b0e8cc61 Mon Sep 17 00:00:00 2001 From: Jinlei Li Date: Tue, 8 Feb 2022 03:56:09 +0800 Subject: [PATCH] Angle support on macOS (#2461) --- wgpu-hal/src/gles/egl.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index f1c7695355..a8fdf21ee9 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -948,7 +948,19 @@ impl crate::Surface for Surface { window } (WindowKind::Unknown, Rwh::Win32(handle)) => handle.hwnd, - (WindowKind::Unknown, Rwh::AppKit(handle)) => handle.ns_view, + (WindowKind::Unknown, Rwh::AppKit(handle)) => { + #[cfg(not(target_os = "macos"))] + let window_ptr = handle.ns_view; + #[cfg(target_os = "macos")] + let window_ptr = { + use objc::{msg_send, runtime::Object, sel, sel_impl}; + // ns_view always have a layer and don't need to verify that it exists. + let layer: *mut Object = + msg_send![handle.ns_view as *mut Object, layer]; + layer as *mut std::ffi::c_void + }; + window_ptr + } _ => { log::warn!( "Initialized platform {:?} doesn't work with window {:?}", @@ -964,7 +976,7 @@ impl crate::Surface for Surface { // We don't want any of the buffering done by the driver, because we // manage a swapchain on our side. // Some drivers just fail on surface creation seeing `EGL_SINGLE_BUFFER`. - if cfg!(target_os = "android") + if cfg!(any(target_os = "android", target_os = "macos")) || cfg!(windows) || self.wsi.kind == WindowKind::AngleX11 {