1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 08:33:43 -05:00

feat(ext/webgpu): support UnsafeWindowSurface on wayland (#23423)

This commit is contained in:
chirsz 2024-04-25 12:28:16 +08:00 committed by GitHub
parent f3284529f1
commit 1de162f1c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 16 deletions

View file

@ -776,12 +776,13 @@ declare namespace Deno {
* | "cocoa" (macOS) | `NSView*` | - |
* | "win32" (Windows) | `HWND` | `HINSTANCE` |
* | "x11" (Linux) | Xlib `Window` | Xlib `Display*` |
* | "wayland" (Linux) | `wl_surface*` | `wl_display*` |
*
* @category WebGPU
*/
export class UnsafeWindowSurface {
constructor(
system: "cocoa" | "win32" | "x11",
system: "cocoa" | "win32" | "x11" | "wayland",
windowHandle: Deno.PointerValue<unknown>,
displayHandle: Deno.PointerValue<unknown>,
);

View file

@ -105,23 +105,38 @@ fn raw_window(
window: *const c_void,
display: *const c_void,
) -> Result<RawHandles, AnyError> {
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))
}