From 1de162f1c1ef0ea9a2b653bc29cd0e3e00386abd Mon Sep 17 00:00:00 2001 From: chirsz Date: Thu, 25 Apr 2024 12:28:16 +0800 Subject: feat(ext/webgpu): support `UnsafeWindowSurface` on wayland (#23423) --- ext/webgpu/byow.rs | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'ext/webgpu') diff --git a/ext/webgpu/byow.rs b/ext/webgpu/byow.rs index 984eaae1b..30824c52b 100644 --- a/ext/webgpu/byow.rs +++ b/ext/webgpu/byow.rs @@ -105,23 +105,38 @@ fn raw_window( window: *const c_void, display: *const c_void, ) -> Result { - if system != "x11" { + let (win_handle, display_handle); + if system == "x11" { + win_handle = { + let mut handle = raw_window_handle::XlibWindowHandle::empty(); + handle.window = window as *mut c_void as _; + + raw_window_handle::RawWindowHandle::Xlib(handle) + }; + + display_handle = { + let mut handle = raw_window_handle::XlibDisplayHandle::empty(); + handle.display = display as *mut c_void; + + raw_window_handle::RawDisplayHandle::Xlib(handle) + }; + } else if system == "wayland" { + win_handle = { + let mut handle = raw_window_handle::WaylandWindowHandle::empty(); + handle.surface = window as _; + + raw_window_handle::RawWindowHandle::Wayland(handle) + }; + + display_handle = { + let mut handle = raw_window_handle::WaylandDisplayHandle::empty(); + handle.display = display as _; + + raw_window_handle::RawDisplayHandle::Wayland(handle) + }; + } else { return Err(type_error("Invalid system on Linux")); } - let win_handle = { - let mut handle = raw_window_handle::XlibWindowHandle::empty(); - handle.window = window as *mut c_void as _; - - raw_window_handle::RawWindowHandle::Xlib(handle) - }; - - let display_handle = { - let mut handle = raw_window_handle::XlibDisplayHandle::empty(); - handle.display = display as *mut c_void; - - raw_window_handle::RawDisplayHandle::Xlib(handle) - }; - Ok((win_handle, display_handle)) } -- cgit v1.2.3