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:
Daniel Adams 2024-09-17 02:22:15 +00:00 committed by GitHub
parent b0cae28c83
commit f8e0fde044
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 210 additions and 90 deletions

View file

@ -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);
}
},