From 948ac44f63eaef8a5742cce63ebacb3c06e816eb Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Sat, 11 Nov 2023 11:11:58 -0500 Subject: [PATCH 1/2] Update winit. --- surfman/Cargo.toml | 6 +-- surfman/src/platform/macos/cgl/connection.rs | 12 +++-- .../src/platform/macos/system/connection.rs | 45 ++++++++++++------- surfman/src/platform/macos/system/surface.rs | 2 +- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/surfman/Cargo.toml b/surfman/Cargo.toml index f6f2b16f..5b52f934 100644 --- a/surfman/Cargo.toml +++ b/surfman/Cargo.toml @@ -38,8 +38,8 @@ libc = "0.2" log = "0.4" sparkle = { version = "0.1", optional = true } osmesa-sys = { version = "0.1", optional = true } -winit = { version = "0.28.1", optional = true } -raw-window-handle = { version = "0.5", optional = true } +winit = { version = "0.29", optional = true } +raw-window-handle = { version = "0.6", optional = true } [dev-dependencies] clap = "2" @@ -79,4 +79,4 @@ winapi = { version = "0.3", features = ["d3d11", "libloaderapi", "winbase", "win [target.'cfg(target_os = "android")'.dependencies] raw-window-handle = "0.5" -winit = { version = "0.28.1", features = [ "android-native-activity" ] } +winit = { version = "0.29", features = [ "android-native-activity" ] } diff --git a/surfman/src/platform/macos/cgl/connection.rs b/surfman/src/platform/macos/cgl/connection.rs index 420bce49..3b8ff725 100644 --- a/surfman/src/platform/macos/cgl/connection.rs +++ b/surfman/src/platform/macos/cgl/connection.rs @@ -147,10 +147,14 @@ impl Connection { use raw_window_handle::RawWindowHandle::AppKit; match raw_handle { - AppKit(handle) => Ok(NativeWidget { - view: NSView(unsafe { msg_send![handle.ns_view as id, retain] }), - opaque: unsafe { msg_send![handle.ns_window as id, isOpaque] }, - }), + AppKit(handle) => { + let view = NSView(unsafe { msg_send![handle.ns_view.as_ptr() as id, retain] }); + let window: id = unsafe { msg_send![view.0, window] }; + Ok(NativeWidget { + view: view, + opaque: unsafe { msg_send![window, isOpaque] }, + }) + } _ => Err(Error::IncompatibleNativeWidget), } } diff --git a/surfman/src/platform/macos/system/connection.rs b/surfman/src/platform/macos/system/connection.rs index 8e7c305f..85229399 100644 --- a/surfman/src/platform/macos/system/connection.rs +++ b/surfman/src/platform/macos/system/connection.rs @@ -22,10 +22,10 @@ use euclid::default::Size2D; use std::os::raw::c_void; use std::str::FromStr; -#[cfg(feature = "sm-winit")] -use winit::platform::macos::WindowExtMacOS; #[cfg(feature = "sm-winit")] use winit::window::Window; +#[cfg(feature = "sm-winit")] +use raw_window_handle::HasWindowHandle; /// A no-op connection. /// @@ -145,16 +145,25 @@ impl Connection { &self, window: &Window, ) -> Result { - let ns_view = window.ns_view() as id; - let ns_window = window.ns_window() as id; - if ns_view.is_null() { - return Err(Error::IncompatibleNativeWidget); - } - unsafe { - Ok(NativeWidget { - view: NSView(msg_send![ns_view, retain]), - opaque: msg_send![ns_window as id, isOpaque], - }) + use raw_window_handle::RawWindowHandle::AppKit; + + let handle = window.window_handle().map_err(|_| Error::IncompatibleNativeWidget)?; + let raw_handle = handle.as_raw(); + match raw_handle { + AppKit(handle) => { + let ns_view = handle.ns_view.as_ptr() as id; + if ns_view.is_null() { + return Err(Error::IncompatibleNativeWidget); + } + let ns_window: id = unsafe { msg_send![ns_view, window] }; + unsafe { + Ok(NativeWidget { + view: NSView(msg_send![ns_view, retain]), + opaque: msg_send![ns_window, isOpaque], + }) + } + } + _ => Err(Error::IncompatibleNativeWidget), } } @@ -180,10 +189,14 @@ impl Connection { use raw_window_handle::RawWindowHandle::AppKit; match raw_handle { - AppKit(handle) => Ok(NativeWidget { - view: NSView(unsafe { msg_send![handle.ns_view as id, retain] }), - opaque: unsafe { msg_send![handle.ns_window as id, isOpaque] }, - }), + AppKit(handle) => { + let view = NSView(unsafe { msg_send![handle.ns_view.as_ptr() as id, retain] }); + let window: id = unsafe { msg_send![view.0, window] }; + Ok(NativeWidget { + view: view, + opaque: unsafe { msg_send![window, isOpaque] }, + }) + } _ => Err(Error::IncompatibleNativeWidget), } } diff --git a/surfman/src/platform/macos/system/surface.rs b/surfman/src/platform/macos/system/surface.rs index ab44487a..cca2d9f4 100644 --- a/surfman/src/platform/macos/system/surface.rs +++ b/surfman/src/platform/macos/system/surface.rs @@ -473,7 +473,7 @@ impl Drop for ViewInfo { self.display_link.stop(); // Drop the reference that the callback was holding onto. - mem::transmute_copy::, Arc>(&self.next_vblank); + let _ = mem::transmute_copy::, Arc>(&self.next_vblank); } } } From cde8ca2cec5291690fa4eca4150bc55deda0ee57 Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Fri, 19 Jan 2024 14:52:19 +0100 Subject: [PATCH 2/2] Try to fix the build for Wayland --- surfman/Cargo.toml | 2 +- .../src/platform/unix/wayland/connection.rs | 28 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/surfman/Cargo.toml b/surfman/Cargo.toml index 5b52f934..73e5f69c 100644 --- a/surfman/Cargo.toml +++ b/surfman/Cargo.toml @@ -25,7 +25,7 @@ sm-angle-default = ["sm-angle"] sm-no-wgl = ["sm-angle-default"] sm-test = [] sm-wayland-default = [] -sm-winit = ["winit"] +sm-winit = ["winit", "sm-raw-window-handle"] sm-x11 = ["x11"] sm-raw-window-handle = ["raw-window-handle"] diff --git a/surfman/src/platform/unix/wayland/connection.rs b/surfman/src/platform/unix/wayland/connection.rs index 2a272c34..15e19b54 100644 --- a/surfman/src/platform/unix/wayland/connection.rs +++ b/surfman/src/platform/unix/wayland/connection.rs @@ -17,8 +17,6 @@ use std::ptr; use std::sync::Arc; use wayland_sys::client::{wl_display, wl_proxy, WAYLAND_CLIENT_HANDLE}; -#[cfg(feature = "sm-winit")] -use winit::platform::wayland::WindowExtWayland; #[cfg(feature = "sm-winit")] use winit::window::Window; @@ -164,13 +162,12 @@ impl Connection { /// Opens the display connection corresponding to the given `winit` window. #[cfg(feature = "sm-winit")] pub fn from_winit_window(window: &Window) -> Result { - unsafe { - let wayland_display = match window.wayland_display() { - Some(wayland_display) => wayland_display as *mut wl_display, - None => return Err(Error::IncompatibleWinitWindow), - }; - Connection::from_wayland_display(wayland_display, false) - } + use raw_window_handle::HasRawDisplayHandle; + let raw_display_handle = match window.raw_display_handle() { + Ok(raw_display_handle) => raw_display_handle, + _ => return Err(Error::ConnectionFailed), + }; + Connection::from_raw_display_handle(raw_display_handle) } /// Opens the display connection corresponding to the given raw display handle. @@ -182,7 +179,7 @@ impl Connection { use raw_window_handle::WaylandDisplayHandle; unsafe { let wayland_display = match raw_handle { - Wayland(WaylandDisplayHandle { display, .. }) => display as *mut wl_display, + Wayland(WaylandDisplayHandle { display, .. }) => display.as_ptr() as *mut wl_display, _ => return Err(Error::IncompatibleRawDisplayHandle), }; @@ -198,11 +195,14 @@ impl Connection { &self, window: &Window, ) -> Result { - let wayland_surface = match window.wayland_surface() { - Some(wayland_surface) => wayland_surface as *mut wl_proxy, - None => return Err(Error::IncompatibleNativeWidget), + use raw_window_handle::RawWindowHandle; + use raw_window_handle::HasRawWindowHandle; + let wayland_surface = match window.raw_window_handle() { + Ok(RawWindowHandle::Wayland(handle)) => handle.surface.as_ptr() as *mut wl_proxy, + _ => return Err(Error::IncompatibleNativeWidget), }; + // The window's DPI factor is 1.0 when nothing has been rendered to it yet. So use the DPI // factor of the primary monitor instead, since that's where the window will presumably go // when actually displayed. (The user might move it somewhere else later, of course.) @@ -239,7 +239,7 @@ impl Connection { use raw_window_handle::RawWindowHandle::Wayland; let wayland_surface = match raw_handle { - Wayland(handle) => handle.surface as *mut wl_proxy, + Wayland(handle) => handle.surface.as_ptr() as *mut wl_proxy, _ => return Err(Error::IncompatibleNativeWidget), };