mirror of
https://github.com/servo/servo.git
synced 2025-08-11 16:35:33 +01:00
webxr: Implement reference space reset events (#33460)
* Initial interface implementation Signed-off-by: Daniel Adams <msub2official@gmail.com> * Add event handler Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update FakeXRDevice interface Signed-off-by: Daniel Adams <msub2official@gmail.com> * Implement reset event Signed-off-by: Daniel Adams <msub2official@gmail.com> * Downcast bounded spaces Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update expectations Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update webxr commit Signed-off-by: Daniel Adams <msub2official@gmail.com> * fmt Signed-off-by: Daniel Adams <msub2official@gmail.com> * Adjust DomRoot usage Signed-off-by: Daniel Adams <msub2official@gmail.com> * fmt Signed-off-by: Daniel Adams <msub2official@gmail.com> * Update manifest Signed-off-by: Daniel Adams <msub2official@gmail.com> --------- Signed-off-by: Daniel Adams <msub2official@gmail.com>
This commit is contained in:
parent
b0cae28c83
commit
f8e0fde044
18 changed files with 210 additions and 90 deletions
|
@ -60,7 +60,9 @@ use crate::dom::xrhittestsource::XRHitTestSource;
|
|||
use crate::dom::xrinputsourcearray::XRInputSourceArray;
|
||||
use crate::dom::xrinputsourceevent::XRInputSourceEvent;
|
||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||
use crate::dom::xrreferencespaceevent::XRReferenceSpaceEvent;
|
||||
use crate::dom::xrrenderstate::XRRenderState;
|
||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||
use crate::dom::xrsessionevent::XRSessionEvent;
|
||||
use crate::dom::xrspace::XRSpace;
|
||||
use crate::realms::InRealm;
|
||||
|
@ -109,6 +111,7 @@ pub struct XRSession {
|
|||
framerate: Cell<f32>,
|
||||
#[ignore_malloc_size_of = "promises are hard"]
|
||||
update_framerate_promise: DomRefCell<Option<Rc<Promise>>>,
|
||||
reference_spaces: DomRefCell<Vec<Dom<XRReferenceSpace>>>,
|
||||
}
|
||||
|
||||
impl XRSession {
|
||||
|
@ -142,6 +145,7 @@ impl XRSession {
|
|||
input_frames: DomRefCell::new(HashMap::new()),
|
||||
framerate: Cell::new(0.0),
|
||||
update_framerate_promise: DomRefCell::new(None),
|
||||
reference_spaces: DomRefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,6 +377,35 @@ impl XRSession {
|
|||
XREvent::InputChanged(id, frame) => {
|
||||
self.input_frames.borrow_mut().insert(id, frame);
|
||||
},
|
||||
XREvent::ReferenceSpaceChanged(base_space, transform) => {
|
||||
self.reference_spaces
|
||||
.borrow()
|
||||
.iter()
|
||||
.filter(|space| {
|
||||
let base = match space.ty() {
|
||||
XRReferenceSpaceType::Local => webxr_api::BaseSpace::Local,
|
||||
XRReferenceSpaceType::Viewer => webxr_api::BaseSpace::Viewer,
|
||||
XRReferenceSpaceType::Local_floor => webxr_api::BaseSpace::Floor,
|
||||
XRReferenceSpaceType::Bounded_floor => {
|
||||
webxr_api::BaseSpace::BoundedFloor
|
||||
},
|
||||
_ => panic!("unsupported reference space found"),
|
||||
};
|
||||
base == base_space
|
||||
})
|
||||
.for_each(|space| {
|
||||
let offset = XRRigidTransform::new(&self.global(), transform);
|
||||
let event = XRReferenceSpaceEvent::new(
|
||||
&self.global(),
|
||||
atom!("reset"),
|
||||
false,
|
||||
false,
|
||||
space,
|
||||
Some(&*offset),
|
||||
);
|
||||
event.upcast::<Event>().fire(space.upcast());
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -829,9 +862,15 @@ impl XRSessionMethods for XRSession {
|
|||
}
|
||||
if ty == XRReferenceSpaceType::Bounded_floor {
|
||||
let space = XRBoundedReferenceSpace::new(&self.global(), self);
|
||||
self.reference_spaces
|
||||
.borrow_mut()
|
||||
.push(Dom::from_ref(space.reference_space()));
|
||||
p.resolve_native(&space);
|
||||
} else {
|
||||
let space = XRReferenceSpace::new(&self.global(), self, ty);
|
||||
self.reference_spaces
|
||||
.borrow_mut()
|
||||
.push(Dom::from_ref(&*space));
|
||||
p.resolve_native(&space);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue