diff options
author | Martin Robinson <mrobinson@igalia.com> | 2025-01-30 20:07:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-30 19:07:35 +0000 |
commit | 534e78db5331fbfbad7e60d72a88e9aacdc11ee4 (patch) | |
tree | 3bcd217e0e7b7fd0c91d5406a81ea241ffc4ce06 /components/shared/webxr/lib.rs | |
parent | 64b40ea70065f949d1e281bd046c56d50312f2a7 (diff) | |
download | servo-534e78db5331fbfbad7e60d72a88e9aacdc11ee4.tar.gz servo-534e78db5331fbfbad7e60d72a88e9aacdc11ee4.zip |
Merge webxr repository (#35228)
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Diffstat (limited to 'components/shared/webxr/lib.rs')
-rw-r--r-- | components/shared/webxr/lib.rs | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/components/shared/webxr/lib.rs b/components/shared/webxr/lib.rs new file mode 100644 index 00000000000..9acad34e0e5 --- /dev/null +++ b/components/shared/webxr/lib.rs @@ -0,0 +1,175 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ + +//! This crate defines the Rust API for WebXR. It is implemented by the `webxr` crate. + +mod device; +mod error; +mod events; +mod frame; +mod hand; +mod hittest; +mod input; +mod layer; +mod mock; +mod registry; +mod session; +mod space; +pub mod util; +mod view; + +pub use device::DeviceAPI; +pub use device::DiscoveryAPI; + +pub use error::Error; + +pub use events::Event; +pub use events::EventBuffer; +pub use events::Visibility; + +pub use frame::Frame; +pub use frame::FrameUpdateEvent; +pub use frame::ViewerPose; + +pub use hand::Finger; +pub use hand::FingerJoint; +pub use hand::Hand; +pub use hand::HandSpace; +pub use hand::Joint; +pub use hand::JointFrame; + +pub use hittest::EntityType; +pub use hittest::EntityTypes; +pub use hittest::HitTestId; +pub use hittest::HitTestResult; +pub use hittest::HitTestSource; +pub use hittest::HitTestSpace; +pub use hittest::Ray; +pub use hittest::Triangle; + +pub use input::Handedness; +pub use input::InputFrame; +pub use input::InputId; +pub use input::InputSource; +pub use input::SelectEvent; +pub use input::SelectKind; +pub use input::TargetRayMode; + +pub use layer::ContextId; +pub use layer::GLContexts; +pub use layer::GLTypes; +pub use layer::LayerGrandManager; +pub use layer::LayerGrandManagerAPI; +pub use layer::LayerId; +pub use layer::LayerInit; +pub use layer::LayerLayout; +pub use layer::LayerManager; +pub use layer::LayerManagerAPI; +pub use layer::LayerManagerFactory; +pub use layer::SubImage; +pub use layer::SubImages; + +pub use mock::MockButton; +pub use mock::MockButtonType; +pub use mock::MockDeviceInit; +pub use mock::MockDeviceMsg; +pub use mock::MockDiscoveryAPI; +pub use mock::MockInputInit; +pub use mock::MockInputMsg; +pub use mock::MockRegion; +pub use mock::MockViewInit; +pub use mock::MockViewsInit; +pub use mock::MockWorld; + +pub use registry::MainThreadRegistry; +pub use registry::MainThreadWaker; +pub use registry::Registry; + +pub use session::EnvironmentBlendMode; +pub use session::MainThreadSession; +pub use session::Quitter; +pub use session::Session; +pub use session::SessionBuilder; +pub use session::SessionId; +pub use session::SessionInit; +pub use session::SessionMode; +pub use session::SessionThread; + +pub use space::ApiSpace; +pub use space::BaseSpace; +pub use space::Space; + +pub use view::Capture; +pub use view::CubeBack; +pub use view::CubeBottom; +pub use view::CubeLeft; +pub use view::CubeRight; +pub use view::CubeTop; +pub use view::Display; +pub use view::Floor; +pub use view::Input; +pub use view::LeftEye; +pub use view::Native; +pub use view::RightEye; +pub use view::SomeEye; +pub use view::View; +pub use view::Viewer; +pub use view::Viewport; +pub use view::Viewports; +pub use view::Views; +pub use view::CUBE_BACK; +pub use view::CUBE_BOTTOM; +pub use view::CUBE_LEFT; +pub use view::CUBE_RIGHT; +pub use view::CUBE_TOP; +pub use view::LEFT_EYE; +pub use view::RIGHT_EYE; +pub use view::VIEWER; + +#[cfg(feature = "ipc")] +use std::thread; + +use std::time::Duration; + +#[cfg(feature = "ipc")] +pub use ipc_channel::ipc::IpcSender as Sender; + +#[cfg(feature = "ipc")] +pub use ipc_channel::ipc::IpcReceiver as Receiver; + +#[cfg(feature = "ipc")] +pub use ipc_channel::ipc::channel; + +#[cfg(not(feature = "ipc"))] +pub use std::sync::mpsc::{Receiver, RecvTimeoutError, Sender}; + +#[cfg(not(feature = "ipc"))] +pub fn channel<T>() -> Result<(Sender<T>, Receiver<T>), ()> { + Ok(std::sync::mpsc::channel()) +} + +#[cfg(not(feature = "ipc"))] +pub fn recv_timeout<T>(receiver: &Receiver<T>, timeout: Duration) -> Result<T, RecvTimeoutError> { + receiver.recv_timeout(timeout) +} + +#[cfg(feature = "ipc")] +pub fn recv_timeout<T>( + receiver: &Receiver<T>, + timeout: Duration, +) -> Result<T, ipc_channel::ipc::TryRecvError> +where + T: serde::Serialize + for<'a> serde::Deserialize<'a>, +{ + // Sigh, polling, sigh. + let mut delay = timeout / 1000; + while delay < timeout { + if let Ok(msg) = receiver.try_recv() { + return Ok(msg); + } + thread::sleep(delay); + delay = delay * 2; + } + receiver.try_recv() +} |