diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/raw-window-handle/src | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/raw-window-handle/src')
-rw-r--r-- | third_party/rust/raw-window-handle/src/android.rs | 31 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/ios.rs | 34 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/lib.rs | 194 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/macos.rs | 33 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/unix.rs | 98 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/web.rs | 33 | ||||
-rw-r--r-- | third_party/rust/raw-window-handle/src/windows.rs | 34 |
7 files changed, 457 insertions, 0 deletions
diff --git a/third_party/rust/raw-window-handle/src/android.rs b/third_party/rust/raw-window-handle/src/android.rs new file mode 100644 index 0000000000..abf65dda5f --- /dev/null +++ b/third_party/rust/raw-window-handle/src/android.rs @@ -0,0 +1,31 @@ +use core::ptr; +use libc::c_void; + +/// Raw window handle for Android. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::android::AndroidHandle; +/// let handle = AndroidHandle { +/// /* fields */ +/// ..AndroidHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct AndroidHandle { + /// A pointer to an ANativeWindow. + pub a_native_window: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl AndroidHandle { + pub fn empty() -> AndroidHandle { + #[allow(deprecated)] + AndroidHandle { + a_native_window: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} diff --git a/third_party/rust/raw-window-handle/src/ios.rs b/third_party/rust/raw-window-handle/src/ios.rs new file mode 100644 index 0000000000..03820c2119 --- /dev/null +++ b/third_party/rust/raw-window-handle/src/ios.rs @@ -0,0 +1,34 @@ +use core::ptr; +use libc::c_void; + +/// Raw window handle for iOS. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::ios::IOSHandle; +/// let handle = IOSHandle { +/// /* fields */ +/// ..IOSHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct IOSHandle { + pub ui_window: *mut c_void, + pub ui_view: *mut c_void, + pub ui_view_controller: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl IOSHandle { + pub fn empty() -> IOSHandle { + #[allow(deprecated)] + IOSHandle { + ui_window: ptr::null_mut(), + ui_view: ptr::null_mut(), + ui_view_controller: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} diff --git a/third_party/rust/raw-window-handle/src/lib.rs b/third_party/rust/raw-window-handle/src/lib.rs new file mode 100644 index 0000000000..6bd8072d64 --- /dev/null +++ b/third_party/rust/raw-window-handle/src/lib.rs @@ -0,0 +1,194 @@ +//! Interoperability library for Rust Windowing applications. +//! +//! This library provides standard types for accessing a window's platform-specific raw window +//! handle. This does not provide any utilities for creating and managing windows; instead, it +//! provides a common interface that window creation libraries (e.g. Winit, SDL) can use to easily +//! talk with graphics libraries (e.g. gfx-hal). +//! +//! ## Platform handle initialization +//! +//! Each platform handle struct is purposefully non-exhaustive, so that additional fields may be +//! added without breaking backwards compatibility. Each struct provides an `empty` method that may +//! be used along with the struct update syntax to construct it. See each specific struct for +//! examples. +//! +#![cfg_attr(feature = "nightly-docs", feature(doc_cfg))] +#![no_std] + +#[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "android")))] +#[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "android"))] +pub mod android; +#[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "ios")))] +#[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "ios"))] +pub mod ios; +#[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "macos")))] +#[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "macos"))] +pub mod macos; +#[cfg_attr( + feature = "nightly-docs", + doc(cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))) +)] +#[cfg_attr( + not(feature = "nightly-docs"), + cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )) +)] +pub mod unix; +#[cfg_attr(feature = "nightly-docs", doc(cfg(target_arch = "wasm32")))] +#[cfg_attr(not(feature = "nightly-docs"), cfg(target_arch = "wasm32"))] +pub mod web; +#[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "windows")))] +#[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "windows"))] +pub mod windows; + +mod platform { + #[cfg(target_os = "android")] + pub use crate::android::*; + #[cfg(target_os = "macos")] + pub use crate::macos::*; + #[cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))] + pub use crate::unix::*; + #[cfg(target_os = "windows")] + pub use crate::windows::*; + // mod platform; + #[cfg(target_os = "ios")] + pub use crate::ios::*; + #[cfg(target_arch = "wasm32")] + pub use crate::web::*; +} + +/// Window that wraps around a raw window handle. +/// +/// # Safety guarantees +/// +/// Users can safely assume that non-`null`/`0` fields are valid handles, and it is up to the +/// implementer of this trait to ensure that condition is upheld. However, It is entirely valid +/// behavior for fields within each platform-specific `RawWindowHandle` variant to be `null` or +/// `0`, and appropriate checking should be done before the handle is used. +/// +/// Despite that qualification, implementers should still make a best-effort attempt to fill in all +/// available fields. If an implementation doesn't, and a downstream user needs the field, it should +/// try to derive the field from other fields the implementer *does* provide via whatever methods the +/// platform provides. +/// +/// The exact handles returned by `raw_window_handle` must remain consistent between multiple calls +/// to `raw_window_handle`, and must be valid for at least the lifetime of the `HasRawWindowHandle` +/// implementer. +pub unsafe trait HasRawWindowHandle { + fn raw_window_handle(&self) -> RawWindowHandle; +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum RawWindowHandle { + #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "ios")))] + #[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "ios"))] + IOS(ios::IOSHandle), + + #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "macos")))] + #[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "macos"))] + MacOS(macos::MacOSHandle), + + #[cfg_attr( + feature = "nightly-docs", + doc(cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))) + )] + #[cfg_attr( + not(feature = "nightly-docs"), + cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )) + )] + Xlib(unix::XlibHandle), + + #[cfg_attr( + feature = "nightly-docs", + doc(cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))) + )] + #[cfg_attr( + not(feature = "nightly-docs"), + cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )) + )] + Xcb(unix::XcbHandle), + + #[cfg_attr( + feature = "nightly-docs", + doc(cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + ))) + )] + #[cfg_attr( + not(feature = "nightly-docs"), + cfg(any( + target_os = "linux", + target_os = "dragonfly", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" + )) + )] + Wayland(unix::WaylandHandle), + + #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "windows")))] + #[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "windows"))] + Windows(windows::WindowsHandle), + + #[cfg_attr(feature = "nightly-docs", doc(cfg(target_arch = "wasm32")))] + #[cfg_attr(not(feature = "nightly-docs"), cfg(target_arch = "wasm32"))] + Web(web::WebHandle), + + #[cfg_attr(feature = "nightly-docs", doc(cfg(target_os = "android")))] + #[cfg_attr(not(feature = "nightly-docs"), cfg(target_os = "android"))] + Android(android::AndroidHandle), + + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + __NonExhaustiveDoNotUse(seal::Seal), +} + +mod seal { + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] + pub struct Seal; +} diff --git a/third_party/rust/raw-window-handle/src/macos.rs b/third_party/rust/raw-window-handle/src/macos.rs new file mode 100644 index 0000000000..9e167c805c --- /dev/null +++ b/third_party/rust/raw-window-handle/src/macos.rs @@ -0,0 +1,33 @@ +use core::ptr; +use libc::c_void; + +/// Raw window handle for macOS. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::macos::MacOSHandle; +/// let handle = MacOSHandle { +/// /* fields */ +/// ..MacOSHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct MacOSHandle { + pub ns_window: *mut c_void, + pub ns_view: *mut c_void, + // TODO: WHAT ABOUT ns_window_controller and ns_view_controller? + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl MacOSHandle { + pub fn empty() -> MacOSHandle { + #[allow(deprecated)] + MacOSHandle { + ns_window: ptr::null_mut(), + ns_view: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} diff --git a/third_party/rust/raw-window-handle/src/unix.rs b/third_party/rust/raw-window-handle/src/unix.rs new file mode 100644 index 0000000000..be8d6f8cca --- /dev/null +++ b/third_party/rust/raw-window-handle/src/unix.rs @@ -0,0 +1,98 @@ +use core::ptr; +use libc::{c_ulong, c_void}; + +/// Raw window handle for Xlib. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::unix::XlibHandle; +/// let handle = XlibHandle { +/// /* fields */ +/// ..XlibHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct XlibHandle { + /// An Xlib `Window`. + pub window: c_ulong, + /// A pointer to an Xlib `Display`. + pub display: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +/// Raw window handle for Xcb. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::unix::XcbHandle; +/// let handle = XcbHandle { +/// /* fields */ +/// ..XcbHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct XcbHandle { + /// An X11 `xcb_window_t`. + pub window: u32, // Based on xproto.h + /// A pointer to an X server `xcb_connection_t`. + pub connection: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +/// Raw window handle for Wayland. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::unix::WaylandHandle; +/// let handle = WaylandHandle { +/// /* fields */ +/// ..WaylandHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct WaylandHandle { + /// A pointer to a `wl_surface`. + pub surface: *mut c_void, + /// A pointer to a `wl_display`. + pub display: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl XlibHandle { + pub fn empty() -> XlibHandle { + #[allow(deprecated)] + XlibHandle { + window: 0, + display: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} + +impl XcbHandle { + pub fn empty() -> XcbHandle { + #[allow(deprecated)] + XcbHandle { + window: 0, + connection: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} + +impl WaylandHandle { + pub fn empty() -> WaylandHandle { + #[allow(deprecated)] + WaylandHandle { + surface: ptr::null_mut(), + display: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} diff --git a/third_party/rust/raw-window-handle/src/web.rs b/third_party/rust/raw-window-handle/src/web.rs new file mode 100644 index 0000000000..846d78c1e6 --- /dev/null +++ b/third_party/rust/raw-window-handle/src/web.rs @@ -0,0 +1,33 @@ +/// Raw window handle for the web +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::web::WebHandle; +/// let handle = WebHandle { +/// /* fields */ +/// ..WebHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct WebHandle { + /// An ID value inserted into the data attributes of the canvas element as 'raw-handle' + /// + /// When accessing from JS, the attribute will automatically be called rawHandle + /// + /// Each canvas created by the windowing system should be assigned their own unique ID. + /// 0 should be reserved for invalid / null IDs. + pub id: u32, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl WebHandle { + pub fn empty() -> WebHandle { + #[allow(deprecated)] + WebHandle { + id: 0, + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} diff --git a/third_party/rust/raw-window-handle/src/windows.rs b/third_party/rust/raw-window-handle/src/windows.rs new file mode 100644 index 0000000000..365886eed2 --- /dev/null +++ b/third_party/rust/raw-window-handle/src/windows.rs @@ -0,0 +1,34 @@ +use core::ptr; +use libc::c_void; + +/// Raw window handle for Windows. +/// +/// ## Construction +/// ``` +/// # use raw_window_handle::windows::WindowsHandle; +/// let handle = WindowsHandle { +/// /* fields */ +/// ..WindowsHandle::empty() +/// }; +/// ``` +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub struct WindowsHandle { + /// A Win32 HWND handle. + pub hwnd: *mut c_void, + /// The HINSTANCE associated with this type's HWND. + pub hinstance: *mut c_void, + #[doc(hidden)] + #[deprecated = "This field is used to ensure that this struct is non-exhaustive, so that it may be extended in the future. Do not refer to this field."] + pub _non_exhaustive_do_not_use: crate::seal::Seal, +} + +impl WindowsHandle { + pub fn empty() -> WindowsHandle { + #[allow(deprecated)] + WindowsHandle { + hwnd: ptr::null_mut(), + hinstance: ptr::null_mut(), + _non_exhaustive_do_not_use: crate::seal::Seal, + } + } +} |