raw_window_handle_ffi/handles/
web_offscreen_canvas.rs

1use crate::{RawWindowHandle, RawWindowHandleData};
2use std::{ffi::c_void, ptr::NonNull};
3
4/// raw_window_handle_ffi:
5///         This type is ABI-stable and FFI-compatible analogue for [`raw_window_handle::WebOffscreenCanvasWindowHandle`].
6///         Can be converted to and from the referenced type.
7#[repr(C)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub struct WebOffscreenCanvasWindowHandle {
10    /// A pointer to the [`JsValue`] of an [`OffscreenCanvas`].
11    ///
12    /// Note: This uses [`c_void`] to avoid depending on `wasm-bindgen`
13    /// directly.
14    ///
15    /// [`JsValue`]: https://docs.rs/wasm-bindgen/latest/wasm_bindgen/struct.JsValue.html
16    /// [`OffscreenCanvas`]: https://docs.rs/web-sys/latest/web_sys/struct.OffscreenCanvas.html
17    //
18    // SAFETY: See WebCanvasWindowHandle.
19    pub obj: NonNull<c_void>,
20}
21
22unsafe impl Send for WebOffscreenCanvasWindowHandle {}
23unsafe impl Sync for WebOffscreenCanvasWindowHandle {}
24
25impl From<raw_window_handle::WebOffscreenCanvasWindowHandle> for WebOffscreenCanvasWindowHandle {
26    fn from(value: raw_window_handle::WebOffscreenCanvasWindowHandle) -> Self {
27        Self { obj: value.obj }
28    }
29}
30
31impl WebOffscreenCanvasWindowHandle {
32    /// Converts FFI type back to the original [`raw_window_handle::AppKitWindowHandle`].
33    ///
34    /// # Safety
35    /// Original type [`raw_window_handle::AppKitWindowHandle`] is marked as `non_exaustive`,
36    /// and therefore it is impossible to convert to it completely safely.
37    pub unsafe fn into(self) -> raw_window_handle::WebOffscreenCanvasWindowHandle {
38        raw_window_handle::WebOffscreenCanvasWindowHandle::new(self.obj)
39    }
40}
41
42impl From<WebOffscreenCanvasWindowHandle> for RawWindowHandle {
43    fn from(val: WebOffscreenCanvasWindowHandle) -> RawWindowHandle {
44        RawWindowHandle {
45            kind: crate::RawWindowHandleKind::WebOffscreenCanvasWindowHandle,
46            data: RawWindowHandleData {
47                web_offscreen_canvas: val,
48            },
49        }
50    }
51}