mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Make views a per-frame deal
This commit is contained in:
parent
bdfa6b0751
commit
708824700f
7 changed files with 33 additions and 32 deletions
|
@ -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);
|
||||
|
||||
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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>,
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -71,6 +76,7 @@ impl XRView {
|
|||
&transform,
|
||||
eye,
|
||||
(&proj).to_vec(),
|
||||
view.cast_unit(),
|
||||
)),
|
||||
global,
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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]
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue