aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/xrframe.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/xrframe.rs')
-rw-r--r--components/script/dom/xrframe.rs67
1 files changed, 67 insertions, 0 deletions
diff --git a/components/script/dom/xrframe.rs b/components/script/dom/xrframe.rs
new file mode 100644
index 00000000000..8343bb76420
--- /dev/null
+++ b/components/script/dom/xrframe.rs
@@ -0,0 +1,67 @@
+/* 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/. */
+
+use crate::dom::bindings::codegen::Bindings::XRFrameBinding;
+use crate::dom::bindings::codegen::Bindings::XRFrameBinding::XRFrameMethods;
+use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
+use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
+use crate::dom::bindings::root::{Dom, DomRoot};
+use crate::dom::globalscope::GlobalScope;
+use crate::dom::xrreferencespace::XRReferenceSpace;
+use crate::dom::xrsession::XRSession;
+use crate::dom::xrview::XRView;
+use crate::dom::xrviewerpose::XRViewerPose;
+use dom_struct::dom_struct;
+use webvr_traits::WebVRFrameData;
+
+#[dom_struct]
+pub struct XRFrame {
+ reflector_: Reflector,
+ session: Dom<XRSession>,
+ #[ignore_malloc_size_of = "defined in rust-webvr"]
+ data: WebVRFrameData,
+}
+
+impl XRFrame {
+ fn new_inherited(session: &XRSession, data: WebVRFrameData) -> XRFrame {
+ XRFrame {
+ reflector_: Reflector::new(),
+ session: Dom::from_ref(session),
+ data,
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ session: &XRSession,
+ data: WebVRFrameData,
+ ) -> DomRoot<XRFrame> {
+ reflect_dom_object(
+ Box::new(XRFrame::new_inherited(session, data)),
+ global,
+ XRFrameBinding::Wrap,
+ )
+ }
+}
+
+impl XRFrameMethods for XRFrame {
+ /// https://immersive-web.github.io/webxr/#dom-xrframe-session
+ fn Session(&self) -> DomRoot<XRSession> {
+ DomRoot::from_ref(&self.session)
+ }
+
+ /// https://immersive-web.github.io/webxr/#dom-xrframe-getviewerpose
+ fn GetViewerPose(&self, reference: Option<&XRReferenceSpace>) -> Option<DomRoot<XRViewerPose>> {
+ // We assume the reference space is eye level for now
+ // since it's the only one 3DOF devices support
+ if reference.is_some() {
+ // it's not possible to obtain a reference
+ // space at all yet
+ return None;
+ }
+ let left = XRView::new(&self.global(), &self.session, XREye::Left, &self.data);
+ let right = XRView::new(&self.global(), &self.session, XREye::Right, &self.data);
+ Some(XRViewerPose::new(&self.global(), &left, &right))
+ }
+}