Skip to content
Permalink
Browse files

Make XRViewerPose inherit from XRPose

  • Loading branch information...
Manishearth committed Apr 3, 2019
1 parent f9c25c6 commit f7745edcbb1d980d32834af3b059310b41635a2b
@@ -5,8 +5,7 @@
// https://immersive-web.github.io/webxr/#xrviewerpose-interface

[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRViewerPose {
// readonly attribute XRRigidTransform transform;
interface XRViewerPose : XRPose {
// readonly attribute FrozenArray<XRView> views;
// workaround until we have FrozenArray
// see https://github.com/servo/servo/issues/10427#issuecomment-449593626
@@ -4,13 +4,11 @@

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;
@@ -54,20 +52,11 @@ impl XRFrameMethods for XRFrame {
/// https://immersive-web.github.io/webxr/#dom-xrframe-getviewerpose
fn GetViewerPose(&self, reference: &XRReferenceSpace) -> Option<DomRoot<XRViewerPose>> {
let pose = reference.get_viewer_pose(&self.data);
let left = XRView::new(
Some(XRViewerPose::new(
&self.global(),
&self.session,
XREye::Left,
&pose,
pose,
&self.data,
);
let right = XRView::new(
&self.global(),
&self.session,
XREye::Right,
&pose,
&self.data,
);
Some(XRViewerPose::new(&self.global(), &left, &right))
))
}
}
@@ -6,7 +6,7 @@ use crate::dom::bindings::codegen::Bindings::XRPoseBinding;
use crate::dom::bindings::codegen::Bindings::XRPoseBinding::XRPoseMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::window::Window;
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrrigidtransform::XRRigidTransform;
use dom_struct::dom_struct;
use euclid::RigidTransform3D;
@@ -26,8 +26,8 @@ impl XRPose {
}

#[allow(unused)]
pub fn new(global: &Window, transform: RigidTransform3D<f64>) -> DomRoot<XRPose> {
let transform = XRRigidTransform::new(global, transform);
pub fn new(global: &GlobalScope, transform: RigidTransform3D<f64>) -> DomRoot<XRPose> {
let transform = XRRigidTransform::new(&global.as_window(), transform);
reflect_dom_object(
Box::new(XRPose::new_inherited(&transform)),
global,
@@ -2,43 +2,57 @@
* 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::XRViewBinding::XREye;
use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding;
use crate::dom::bindings::codegen::Bindings::XRViewerPoseBinding::XRViewerPoseMethods;
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot;
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrpose::XRPose;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession;
use crate::dom::xrview::XRView;
use dom_struct::dom_struct;
use euclid::RigidTransform3D;
use js::conversions::ToJSValConvertible;
use js::jsapi::{Heap, JSContext};
use js::jsval::{JSVal, UndefinedValue};
use webvr_traits::WebVRFrameData;

#[dom_struct]
pub struct XRViewerPose {
reflector_: Reflector,
pose: XRPose,
views: Heap<JSVal>,
}

impl XRViewerPose {
fn new_inherited() -> XRViewerPose {
fn new_inherited(transform: &XRRigidTransform) -> XRViewerPose {
XRViewerPose {
reflector_: Reflector::new(),
pose: XRPose::new_inherited(transform),
views: Heap::default(),
}
}

#[allow(unsafe_code)]
pub fn new(global: &GlobalScope, left: &XRView, right: &XRView) -> DomRoot<XRViewerPose> {
pub fn new(
global: &GlobalScope,
session: &XRSession,
pose: RigidTransform3D<f64>,
data: &WebVRFrameData,
) -> DomRoot<XRViewerPose> {
let left = XRView::new(global, session, XREye::Left, &pose, &data);
let right = XRView::new(global, session, XREye::Right, &pose, &data);
let transform = XRRigidTransform::new(&global.as_window(), pose);
let pose = reflect_dom_object(
Box::new(XRViewerPose::new_inherited()),
Box::new(XRViewerPose::new_inherited(&transform)),
global,
XRViewerPoseBinding::Wrap,
);

unsafe {
let cx = global.get_cx();
rooted!(in(cx) let mut jsval = UndefinedValue());
let vec = vec![DomRoot::from_ref(left), DomRoot::from_ref(right)];
let vec = vec![left, right];
vec.to_jsval(cx, jsval.handle_mut());
pose.views.set(jsval.get());
}

0 comments on commit f7745ed

Please sign in to comment.
You can’t perform that action at this time.