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

4
Cargo.lock generated
View file

@ -7960,7 +7960,7 @@ dependencies = [
[[package]]
name = "webxr"
version = "0.0.1"
source = "git+https://github.com/servo/webxr#5587c9236bac0a8b7b87b3a95b22882400461b46"
source = "git+https://github.com/servo/webxr#845ae9c22c3eeb7b2ac3fcf9ed791879628256b3"
dependencies = [
"crossbeam-channel",
"euclid",
@ -7977,7 +7977,7 @@ dependencies = [
[[package]]
name = "webxr-api"
version = "0.0.1"
source = "git+https://github.com/servo/webxr#5587c9236bac0a8b7b87b3a95b22882400461b46"
source = "git+https://github.com/servo/webxr#845ae9c22c3eeb7b2ac3fcf9ed791879628256b3"
dependencies = [
"euclid",
"ipc-channel",

View file

@ -337,6 +337,11 @@ impl FakeXRDeviceMethods for FakeXRDevice {
let _ = self.sender.send(MockDeviceMsg::SetBoundsGeometry(coords));
Ok(())
}
/// <https://immersive-web.github.io/webxr-test-api/#dom-fakexrdevice-simulateresetpose>
fn SimulateResetPose(&self) {
let _ = self.sender.send(MockDeviceMsg::SimulateResetPose);
}
}
impl From<XRHandedness> for Handedness {

View file

@ -646,6 +646,7 @@ pub mod xrprojectionlayer;
pub mod xrquadlayer;
pub mod xrray;
pub mod xrreferencespace;
pub mod xrreferencespaceevent;
pub mod xrrenderstate;
pub mod xrrigidtransform;
pub mod xrsession;

View file

@ -17,7 +17,7 @@ interface FakeXRDevice {
[Throws] undefined setFloorOrigin(FakeXRRigidTransformInit origin);
undefined clearFloorOrigin();
[Throws] undefined setBoundsGeometry(sequence<FakeXRBoundsPoint> boundsCoodinates);
// undefined simulateResetPose();
undefined simulateResetPose();
// Simulates devices focusing and blurring sessions.
undefined simulateVisibilityChange(XRVisibilityState state);

View file

@ -16,5 +16,5 @@ enum XRReferenceSpaceType {
interface XRReferenceSpace : XRSpace {
[NewObject] XRReferenceSpace getOffsetReferenceSpace(XRRigidTransform originOffset);
// attribute EventHandler onreset;
attribute EventHandler onreset;
};

View file

@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
// https://immersive-web.github.io/webxr/#xrreferencespaceevent-interface
[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRReferenceSpaceEvent : Event {
[Throws] constructor(DOMString type, XRReferenceSpaceEventInit eventInitDict);
[SameObject] readonly attribute XRReferenceSpace referenceSpace;
[SameObject] readonly attribute XRRigidTransform? transform;
};
dictionary XRReferenceSpaceEventInit : EventInit {
required XRReferenceSpace referenceSpace;
XRRigidTransform? transform = null;
};

View file

@ -19,7 +19,7 @@ use crate::script_runtime::JSContext;
#[dom_struct]
pub struct XRBoundedReferenceSpace {
xrspace: XRReferenceSpace,
reference_space: XRReferenceSpace,
offset: Dom<XRRigidTransform>,
}
@ -29,7 +29,7 @@ impl XRBoundedReferenceSpace {
offset: &XRRigidTransform,
) -> XRBoundedReferenceSpace {
XRBoundedReferenceSpace {
xrspace: XRReferenceSpace::new_inherited(
reference_space: XRReferenceSpace::new_inherited(
session,
offset,
XRReferenceSpaceType::Bounded_floor,
@ -55,12 +55,16 @@ impl XRBoundedReferenceSpace {
global,
)
}
pub fn reference_space(&self) -> &XRReferenceSpace {
&self.reference_space
}
}
impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace {
/// <https://www.w3.org/TR/webxr/#dom-xrboundedreferencespace-boundsgeometry>
fn BoundsGeometry(&self, cx: JSContext) -> JSVal {
if let Some(bounds) = self.xrspace.get_bounds() {
if let Some(bounds) = self.reference_space.get_bounds() {
let points: Vec<DomRoot<DOMPointReadOnly>> = bounds
.into_iter()
.map(|point| {

View file

@ -71,6 +71,10 @@ impl XRReferenceSpace {
let offset = self.offset.transform();
Space { base, offset }
}
pub fn ty(&self) -> XRReferenceSpaceType {
self.ty
}
}
impl XRReferenceSpaceMethods for XRReferenceSpace {
@ -85,6 +89,9 @@ impl XRReferenceSpaceMethods for XRReferenceSpace {
&offset,
)
}
// https://www.w3.org/TR/webxr/#dom-xrreferencespace-onreset
event_handler!(reset, GetOnreset, SetOnreset);
}
impl XRReferenceSpace {

View file

@ -0,0 +1,128 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 dom_struct::dom_struct;
use js::rust::HandleObject;
use servo_atoms::Atom;
use crate::dom::bindings::codegen::Bindings::EventBinding::Event_Binding::EventMethods;
use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceEventBinding::{
XRReferenceSpaceEventInit, XRReferenceSpaceEventMethods,
};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::script_runtime::CanGc;
#[dom_struct]
pub struct XRReferenceSpaceEvent {
event: Event,
space: Dom<XRReferenceSpace>,
transform: Option<Dom<XRRigidTransform>>,
}
impl XRReferenceSpaceEvent {
#[allow(crown::unrooted_must_root)]
fn new_inherited(
space: &XRReferenceSpace,
transform: Option<&XRRigidTransform>,
) -> XRReferenceSpaceEvent {
XRReferenceSpaceEvent {
event: Event::new_inherited(),
space: Dom::from_ref(space),
transform: transform.map(Dom::from_ref),
}
}
pub fn new(
global: &GlobalScope,
type_: Atom,
bubbles: bool,
cancelable: bool,
space: &XRReferenceSpace,
transform: Option<&XRRigidTransform>,
) -> DomRoot<XRReferenceSpaceEvent> {
Self::new_with_proto(
global,
None,
type_,
bubbles,
cancelable,
space,
transform,
CanGc::note(),
)
}
fn new_with_proto(
global: &GlobalScope,
proto: Option<HandleObject>,
type_: Atom,
bubbles: bool,
cancelable: bool,
space: &XRReferenceSpace,
transform: Option<&XRRigidTransform>,
can_gc: CanGc,
) -> DomRoot<XRReferenceSpaceEvent> {
let trackevent = reflect_dom_object_with_proto(
Box::new(XRReferenceSpaceEvent::new_inherited(space, transform)),
global,
proto,
can_gc,
);
{
let event = trackevent.upcast::<Event>();
event.init_event(type_, bubbles, cancelable);
}
trackevent
}
#[allow(non_snake_case)]
pub fn Constructor(
window: &Window,
proto: Option<HandleObject>,
can_gc: CanGc,
type_: DOMString,
init: &XRReferenceSpaceEventInit,
) -> Fallible<DomRoot<XRReferenceSpaceEvent>> {
Ok(XRReferenceSpaceEvent::new_with_proto(
&window.global(),
proto,
Atom::from(type_),
init.parent.bubbles,
init.parent.cancelable,
&init.referenceSpace,
init.transform.as_deref(),
can_gc,
))
}
}
impl XRReferenceSpaceEventMethods for XRReferenceSpaceEvent {
/// <https://www.w3.org/TR/webxr/#dom-xrreferencespaceeventinit-session>
fn ReferenceSpace(&self) -> DomRoot<XRReferenceSpace> {
DomRoot::from_ref(&*self.space)
}
/// <https://www.w3.org/TR/webxr/#dom-xrreferencespaceevent-transform>
fn GetTransform(&self) -> Option<DomRoot<XRRigidTransform>> {
if let Some(ref transform) = self.transform {
Some(DomRoot::from_ref(&**transform))
} else {
None
}
}
/// <https://dom.spec.whatwg.org/#dom-event-istrusted>
fn IsTrusted(&self) -> bool {
self.event.IsTrusted()
}
}

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

View file

@ -1,7 +0,0 @@
[events_referenceSpace_reset_immersive.https.html]
[XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl2]
expected: FAIL
[XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl]
expected: FAIL

View file

@ -1,7 +0,0 @@
[events_referenceSpace_reset_inline.https.html]
[XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl2]
expected: FAIL
[XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl]
expected: FAIL

View file

@ -5,30 +5,15 @@
[XR interface: calling supportsSession(XRSessionMode) on navigator.xr with too few arguments must throw TypeError]
expected: FAIL
[XRReferenceSpaceEvent interface: attribute referenceSpace]
expected: FAIL
[XR interface: navigator.xr must inherit property "ondevicechange" with the proper type]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object]
expected: FAIL
[XRRay interface object length]
expected: FAIL
[XRRay interface: attribute matrix]
expected: FAIL
[XRReferenceSpaceEvent interface object length]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface object]
expected: FAIL
[XRReferenceSpaceEvent interface: attribute transform]
expected: FAIL
[XRRay interface: attribute direction]
expected: FAIL
@ -41,18 +26,9 @@
[XRRay interface: existence and properties of interface object]
expected: FAIL
[XRReferenceSpaceEvent interface object name]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[XRInputSource interface: attribute gamepad]
expected: FAIL
[XRReferenceSpace interface: attribute onreset]
expected: FAIL
[XRRay interface: attribute origin]
expected: FAIL
@ -62,9 +38,6 @@
[XRRay interface: existence and properties of interface prototype object]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[XR interface: operation requestSession(XRSessionMode, XRSessionInit)]
expected: FAIL

View file

@ -1,7 +0,0 @@
[events_referenceSpace_reset_immersive.https.html]
[XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl2]
expected: FAIL
[XRSession resetpose from a device properly fires off the right events for immersive sessions - webgl]
expected: FAIL

View file

@ -1,7 +0,0 @@
[events_referenceSpace_reset_inline.https.html]
[XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl2]
expected: FAIL
[XRSession resetpose from a device properly fires off the right events for non-immersive sessions - webgl]
expected: FAIL

View file

@ -5,9 +5,6 @@
[XRSession interface: calling requestReferenceSpace(XRReferenceSpaceType) on xrSession with too few arguments must throw TypeError]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's @@unscopables property]
expected: FAIL
[XRSession interface: xrSession must inherit property "visibilityState" with the proper type]
expected: FAIL
@ -20,15 +17,9 @@
[XRWebGLLayer interface: calling getNativeFramebufferScaleFactor(XRSession) on xrWebGLLayer with too few arguments must throw TypeError]
expected: FAIL
[XRReferenceSpaceEvent interface: attribute referenceSpace]
expected: FAIL
[XRWebGLLayer interface: xrWebGLLayer must inherit property "antialias" with the proper type]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object]
expected: FAIL
[XRSession interface: xrSession must inherit property "requestAnimationFrame(XRFrameRequestCallback)" with the proper type]
expected: FAIL
@ -62,12 +53,6 @@
[WebGLRenderingContext includes WebGLRenderingContextOverloads: member names are unique]
expected: FAIL
[XRReferenceSpaceEvent interface object name]
expected: FAIL
[XRReferenceSpaceEvent interface object length]
expected: FAIL
[XRRenderState must be primary interface of xrRenderState]
expected: FAIL
@ -86,9 +71,6 @@
[XRReferenceSpace must be primary interface of xrReferenceSpace]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface object]
expected: FAIL
[XRPermissionStatus interface: attribute granted]
expected: FAIL
@ -110,9 +92,6 @@
[idl_test setup]
expected: FAIL
[XRReferenceSpaceEvent interface: attribute transform]
expected: FAIL
[XRInputSourcesChangeEvent interface: xrInputSourcesChangeEvent must inherit property "added" with the proper type]
expected: FAIL
@ -176,9 +155,6 @@
[XRInputSourcesChangeEvent interface: xrInputSourcesChangeEvent must inherit property "removed" with the proper type]
expected: FAIL
[XRReferenceSpace interface: attribute onreset]
expected: FAIL
[XRSession interface: xrSession must inherit property "onsqueeze" with the proper type]
expected: FAIL
@ -194,9 +170,6 @@
[Stringification of xrWebGLLayer]
expected: FAIL
[XRReferenceSpaceEvent interface: existence and properties of interface prototype object's "constructor" property]
expected: FAIL
[Stringification of xrRenderState]
expected: FAIL

View file

@ -13495,7 +13495,7 @@
]
],
"interfaces.html": [
"dd0f564f708a2a0e8cf1ed571bd2bd45977fa469",
"086bc095b078efdcac4f51ef314f7851793dbb53",
[
null,
{}

View file

@ -291,6 +291,7 @@ test_interfaces([
"XRLayer",
"XRPose",
"XRReferenceSpace",
"XRReferenceSpaceEvent",
"XRRay",
"XRRenderState",
"XRRigidTransform",