Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make views a per-frame deal
  • Loading branch information
Manishearth committed May 18, 2020
1 parent bdfa6b0 commit 7088247
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 32 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion components/script/dom/bindings/trace.rs
Expand Up @@ -162,7 +162,7 @@ use webgpu::{
};
use webrender_api::{DocumentId, ImageKey};
use webxr_api::SwapChainId as WebXRSwapChainId;
use webxr_api::{Finger, Hand, Ray};
use webxr_api::{Finger, Hand, Ray, View};

unsafe_no_jsmanaged_fields!(Tm);

Expand Down Expand Up @@ -775,6 +775,13 @@ unsafe impl<Space> JSTraceable for Ray<Space> {
}
}

unsafe impl<Eye> JSTraceable for View<Eye> {
#[inline]
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing
}
}

unsafe impl JSTraceable for StyleLocked<FontFaceRule> {
unsafe fn trace(&self, _trc: *mut JSTracer) {
// Do nothing.
Expand Down
7 changes: 6 additions & 1 deletion components/script/dom/xrframe.rs
Expand Up @@ -85,7 +85,12 @@ impl XRFrameMethods for XRFrame {
} else {
return Ok(None);
};
Ok(Some(XRViewerPose::new(&self.global(), &self.session, pose)))
Ok(Some(XRViewerPose::new(
&self.global(),
&self.session,
pose,
&self.data.views,
)))
}

/// https://immersive-web.github.io/webxr/#dom-xrframe-getpose
Expand Down
14 changes: 10 additions & 4 deletions components/script/dom/xrview.rs
Expand Up @@ -14,7 +14,7 @@ use crate::script_runtime::JSContext;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use std::ptr::NonNull;
use webxr_api::View;
use webxr_api::{ApiSpace, View};

#[dom_struct]
pub struct XRView {
Expand All @@ -23,8 +23,8 @@ pub struct XRView {
eye: XREye,
#[ignore_malloc_size_of = "mozjs"]
proj: Heap<*mut JSObject>,
#[ignore_malloc_size_of = "mozjs"]
view: Heap<*mut JSObject>,
#[ignore_malloc_size_of = "defined in rust-webxr"]
view: View<ApiSpace>,
proj_array: Vec<f32>,
transform: Dom<XRRigidTransform>,
}
Expand All @@ -35,18 +35,23 @@ impl XRView {
transform: &XRRigidTransform,
eye: XREye,
proj_array: Vec<f32>,
view: View<ApiSpace>,
) -> XRView {
XRView {
reflector_: Reflector::new(),
session: Dom::from_ref(session),
eye,
proj: Heap::default(),
view: Heap::default(),
proj_array,
view,
transform: Dom::from_ref(transform),
}
}

pub fn view(&self) -> &View<ApiSpace> {
&self.view
}

pub fn new<V: Copy>(
global: &GlobalScope,
session: &XRSession,
Expand All @@ -71,6 +76,7 @@ impl XRView {
&transform,
eye,
(&proj).to_vec(),
view.cast_unit(),
)),
global,
);
Expand Down
5 changes: 3 additions & 2 deletions components/script/dom/xrviewerpose.rs
Expand Up @@ -39,10 +39,11 @@ impl XRViewerPose {
global: &GlobalScope,
session: &XRSession,
pose: ApiViewerPose,
frame_views: &Views,
) -> DomRoot<XRViewerPose> {
let _ac = enter_realm(&*global);
rooted_vec!(let mut views);
session.with_session(|s| match s.views() {
match frame_views {
Views::Inline => views.push(XRView::new(
global,
session,
Expand All @@ -62,7 +63,7 @@ impl XRViewerPose {
views.push(XRView::new(global, session, &right, XREye::Right, &pose));
views.push(XRView::new(global, session, &third_eye, XREye::None, &pose));
},
});
};
let transform = XRRigidTransform::new(global, cast_transform(pose));
let pose = reflect_dom_object(Box::new(XRViewerPose::new_inherited(&transform)), global);

Expand Down
23 changes: 3 additions & 20 deletions components/script/dom/xrwebgllayer.rs
Expand Up @@ -4,7 +4,6 @@

use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextMethods;
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextBinding::WebGL2RenderingContextMethods;
use crate::dom::bindings::codegen::Bindings::XRViewBinding::{XREye, XRViewMethods};
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerInit;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLLayerMethods;
use crate::dom::bindings::codegen::Bindings::XRWebGLLayerBinding::XRWebGLRenderingContext;
Expand All @@ -22,10 +21,10 @@ use crate::dom::xrview::XRView;
use crate::dom::xrviewport::XRViewport;
use canvas_traits::webgl::WebGLFramebufferId;
use dom_struct::dom_struct;
use euclid::{Point2D, Rect, Size2D};
use euclid::Size2D;
use std::convert::TryInto;
use webxr_api::SwapChainId as WebXRSwapChainId;
use webxr_api::{Viewport, Views};
use webxr_api::Viewport;

#[derive(JSTraceable, MallocSizeOf)]
#[unrooted_must_root_lint::must_root]
Expand Down Expand Up @@ -241,22 +240,6 @@ impl XRWebGLLayerMethods for XRWebGLLayer {
return None;
}

let views = self.session.with_session(|s| s.views().clone());

let viewport = match (view.Eye(), views) {
(XREye::None, Views::Inline) => {
let origin = Point2D::new(0, 0);
Rect::new(origin, self.size().cast())
},
(XREye::None, Views::Mono(view)) => view.viewport,
(XREye::None, Views::StereoCapture(_, _, view)) => view.viewport,
(XREye::Left, Views::Stereo(view, _)) => view.viewport,
(XREye::Left, Views::StereoCapture(view, _, _)) => view.viewport,
(XREye::Right, Views::Stereo(_, view)) => view.viewport,
(XREye::Right, Views::StereoCapture(_, view, _)) => view.viewport,
_ => return None,
};

Some(XRViewport::new(&self.global(), viewport))
Some(XRViewport::new(&self.global(), view.view().viewport))
}
}
@@ -1,5 +1,4 @@
[xrSession_input_events_end.https.html]
expected: TIMEOUT
[Calling end during an input callback stops processing at the right time]
expected: TIMEOUT
expected: FAIL

0 comments on commit 7088247

Please sign in to comment.