diff options
15 files changed, 146 insertions, 72 deletions
diff --git a/Cargo.lock b/Cargo.lock index 53ccb12a0cd..2543db9bb74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7778,7 +7778,7 @@ dependencies = [ [[package]] name = "webxr" version = "0.0.1" -source = "git+https://github.com/servo/webxr#13a0b240d10479180a9e100d7b4e25cfc142db8d" +source = "git+https://github.com/servo/webxr#06cf8102e1ee7954e4ea1e5a08a905dda60e35cd" dependencies = [ "crossbeam-channel", "euclid", @@ -7795,7 +7795,7 @@ dependencies = [ [[package]] name = "webxr-api" version = "0.0.1" -source = "git+https://github.com/servo/webxr#13a0b240d10479180a9e100d7b4e25cfc142db8d" +source = "git+https://github.com/servo/webxr#06cf8102e1ee7954e4ea1e5a08a905dda60e35cd" dependencies = [ "euclid", "ipc-channel", diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 2f74d04f8b3..ae275631e95 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -623,6 +623,7 @@ pub mod xmlhttprequest; pub mod xmlhttprequesteventtarget; pub mod xmlhttprequestupload; pub mod xmlserializer; +pub mod xrboundedreferencespace; pub mod xrcompositionlayer; pub mod xrcubelayer; pub mod xrcylinderlayer; diff --git a/components/script/dom/webidls/XRBoundedReferenceSpace.webidl b/components/script/dom/webidls/XRBoundedReferenceSpace.webidl new file mode 100644 index 00000000000..ee7f59085ba --- /dev/null +++ b/components/script/dom/webidls/XRBoundedReferenceSpace.webidl @@ -0,0 +1,10 @@ +/* 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/#xrboundedreferencespace-interface + +[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] +interface XRBoundedReferenceSpace : XRReferenceSpace { + readonly attribute /*FrozenArray<DOMPointReadOnly>*/ any boundsGeometry; +}; diff --git a/components/script/dom/webidls/XRReferenceSpace.webidl b/components/script/dom/webidls/XRReferenceSpace.webidl index 0479bd12beb..f8a1638ef8d 100644 --- a/components/script/dom/webidls/XRReferenceSpace.webidl +++ b/components/script/dom/webidls/XRReferenceSpace.webidl @@ -14,6 +14,7 @@ enum XRReferenceSpaceType { [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRReferenceSpace : XRSpace { - XRReferenceSpace getOffsetReferenceSpace(XRRigidTransform originOffset); + [NewObject] XRReferenceSpace getOffsetReferenceSpace(XRRigidTransform originOffset); + // attribute EventHandler onreset; }; diff --git a/components/script/dom/xrboundedreferencespace.rs b/components/script/dom/xrboundedreferencespace.rs new file mode 100644 index 00000000000..41bb2052694 --- /dev/null +++ b/components/script/dom/xrboundedreferencespace.rs @@ -0,0 +1,98 @@ +/* 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::jsval::JSVal; + +use crate::dom::bindings::codegen::Bindings::XRBoundedReferenceSpaceBinding::XRBoundedReferenceSpaceMethods; +use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::XRReferenceSpaceType; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject}; +use crate::dom::bindings::root::{Dom, DomRoot}; +use crate::dom::bindings::utils::to_frozen_array; +use crate::dom::dompointreadonly::DOMPointReadOnly; +use crate::dom::globalscope::GlobalScope; +use crate::dom::xrreferencespace::XRReferenceSpace; +use crate::dom::xrrigidtransform::XRRigidTransform; +use crate::dom::xrsession::XRSession; +use crate::script_runtime::JSContext; + +#[dom_struct] +pub struct XRBoundedReferenceSpace { + xrspace: XRReferenceSpace, + offset: Dom<XRRigidTransform>, +} + +impl XRBoundedReferenceSpace { + pub fn new_inherited( + session: &XRSession, + offset: &XRRigidTransform, + ) -> XRBoundedReferenceSpace { + XRBoundedReferenceSpace { + xrspace: XRReferenceSpace::new_inherited( + session, + offset, + XRReferenceSpaceType::Bounded_floor, + ), + offset: Dom::from_ref(offset), + } + } + + #[allow(unused)] + pub fn new(global: &GlobalScope, session: &XRSession) -> DomRoot<XRBoundedReferenceSpace> { + let offset = XRRigidTransform::identity(global); + Self::new_offset(global, session, &offset) + } + + #[allow(unused)] + pub fn new_offset( + global: &GlobalScope, + session: &XRSession, + offset: &XRRigidTransform, + ) -> DomRoot<XRBoundedReferenceSpace> { + reflect_dom_object( + Box::new(XRBoundedReferenceSpace::new_inherited(session, offset)), + global, + ) + } +} + +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() { + let point1 = DOMPointReadOnly::new( + &self.global(), + bounds.min.x.into(), + 0.0, + bounds.min.y.into(), + 1.0, + ); + let point2 = DOMPointReadOnly::new( + &self.global(), + bounds.min.x.into(), + 0.0, + bounds.max.y.into(), + 1.0, + ); + let point3 = DOMPointReadOnly::new( + &self.global(), + bounds.max.x.into(), + 0.0, + bounds.max.y.into(), + 1.0, + ); + let point4 = DOMPointReadOnly::new( + &self.global(), + bounds.max.x.into(), + 0.0, + bounds.min.y.into(), + 1.0, + ); + + to_frozen_array(&[point1, point2, point3, point4], cx) + } else { + to_frozen_array::<DomRoot<DOMPointReadOnly>>(&[], cx) + } + } +} diff --git a/components/script/dom/xrreferencespace.rs b/components/script/dom/xrreferencespace.rs index e7bf33cddd9..402d9d584e8 100644 --- a/components/script/dom/xrreferencespace.rs +++ b/components/script/dom/xrreferencespace.rs @@ -3,8 +3,8 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; -use euclid::RigidTransform3D; -use webxr_api::{self, Frame, Space}; +use euclid::{Box2D, RigidTransform3D}; +use webxr_api::{self, Floor, Frame, Space}; use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::{ XRReferenceSpaceMethods, XRReferenceSpaceType, @@ -65,6 +65,7 @@ impl XRReferenceSpace { 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"), }; let offset = self.offset.transform(); @@ -121,7 +122,7 @@ impl XRReferenceSpace { // for most devices is (0, 0, 0) Some(RigidTransform3D::identity()) }, - XRReferenceSpaceType::Local_floor => { + XRReferenceSpaceType::Local_floor | XRReferenceSpaceType::Bounded_floor => { let native_to_floor = self .upcast::<XRSpace>() .session() @@ -134,4 +135,10 @@ impl XRReferenceSpace { _ => unimplemented!(), } } + + pub fn get_bounds(&self) -> Option<Box2D<f32, Floor>> { + self.upcast::<XRSpace>() + .session() + .with_session(|s| s.reference_space_bounds()) + } } diff --git a/components/script/dom/xrsession.rs b/components/script/dom/xrsession.rs index 6cfd8fda59e..f79ebed7fce 100644 --- a/components/script/dom/xrsession.rs +++ b/components/script/dom/xrsession.rs @@ -54,6 +54,7 @@ use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::performance::reduce_timing_resolution; use crate::dom::promise::Promise; +use crate::dom::xrboundedreferencespace::XRBoundedReferenceSpace; use crate::dom::xrframe::XRFrame; use crate::dom::xrhittestsource::XRHitTestSource; use crate::dom::xrinputsourcearray::XRInputSourceArray; @@ -793,9 +794,16 @@ impl XRSessionMethods for XRSession { // XXXManishearth reject based on session type // https://github.com/immersive-web/webxr/blob/master/spatial-tracking-explainer.md#practical-usage-guidelines + if !self.is_immersive() && + (ty == XRReferenceSpaceType::Bounded_floor || ty == XRReferenceSpaceType::Unbounded) + { + p.reject_error(Error::NotSupported); + return p; + } + match ty { - XRReferenceSpaceType::Bounded_floor | XRReferenceSpaceType::Unbounded => { - // XXXManishearth eventually support these + XRReferenceSpaceType::Unbounded => { + // XXXmsub2 figure out how to support this p.reject_error(Error::NotSupported) }, ty => { @@ -814,7 +822,13 @@ impl XRSessionMethods for XRSession { return p; } } - p.resolve_native(&XRReferenceSpace::new(&self.global(), self, ty)); + if ty == XRReferenceSpaceType::Bounded_floor { + let space = XRBoundedReferenceSpace::new(&self.global(), self); + p.resolve_native(&space); + } else { + let space = XRReferenceSpace::new(&self.global(), self, ty); + p.resolve_native(&space); + } }, } p diff --git a/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini b/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini index f7d261b8002..167b94c38ff 100644 --- a/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/meta-legacy-layout/webxr/idlharness.https.window.js.ini @@ -17,27 +17,18 @@ [XRRay interface object length] expected: FAIL - [XRBoundedReferenceSpace interface object length] - expected: FAIL - [XRRay interface: attribute matrix] expected: FAIL [XRReferenceSpaceEvent interface object length] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface object] expected: FAIL [XRReferenceSpaceEvent interface: attribute transform] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface object] - expected: FAIL - [XRRay interface: attribute direction] expected: FAIL @@ -50,12 +41,6 @@ [XRRay interface: existence and properties of interface object] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - - [XRBoundedReferenceSpace interface: attribute boundsGeometry] - expected: FAIL - [XRReferenceSpaceEvent interface object name] expected: FAIL @@ -86,12 +71,6 @@ [XR interface: operation supportsSession(XRSessionMode)] expected: FAIL - [XRBoundedReferenceSpace interface object name] - expected: FAIL - - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object] - expected: FAIL - [XR interface: calling requestSession(XRSessionMode, XRSessionInit) on navigator.xr with too few arguments must throw TypeError] expected: FAIL diff --git a/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini b/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini index 7bd61021eb7..64b97680787 100644 --- a/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini +++ b/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini @@ -1,7 +1,6 @@ [xrReferenceSpace_originOffsetBounded.https.html] - expected: ERROR [Updating XRBoundedReferenceSpace origin offset updates view, input matrices, and bounds geometry. - webgl] - expected: TIMEOUT + expected: FAIL [Updating XRBoundedReferenceSpace origin offset updates view, input matrices, and bounds geometry. - webgl2] - expected: NOTRUN + expected: FAIL diff --git a/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_relationships.https.html.ini b/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_relationships.https.html.ini deleted file mode 100644 index db66d43bc56..00000000000 --- a/tests/wpt/meta-legacy-layout/webxr/xrReferenceSpace_relationships.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[xrReferenceSpace_relationships.https.html] - expected: ERROR - [Bounded space, viewer space, local and local-floor space have correct poses w.r.t. each other - webgl2] - expected: NOTRUN - - [Bounded space, viewer space, local and local-floor space have correct poses w.r.t. each other - webgl] - expected: TIMEOUT diff --git a/tests/wpt/meta/webxr/idlharness.https.window.js.ini b/tests/wpt/meta/webxr/idlharness.https.window.js.ini index 15162e81c1c..21af20bb1f0 100644 --- a/tests/wpt/meta/webxr/idlharness.https.window.js.ini +++ b/tests/wpt/meta/webxr/idlharness.https.window.js.ini @@ -53,9 +53,6 @@ [Stringification of xrReferenceSpace] expected: FAIL - [XRBoundedReferenceSpace interface object length] - expected: FAIL - [XRWebGLLayer interface: xrWebGLLayer must inherit property "framebuffer" with the proper type] expected: FAIL @@ -89,9 +86,6 @@ [XRReferenceSpace must be primary interface of xrReferenceSpace] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object's "constructor" property] - expected: FAIL - [XRReferenceSpaceEvent interface: existence and properties of interface object] expected: FAIL @@ -119,9 +113,6 @@ [XRReferenceSpaceEvent interface: attribute transform] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface object] - expected: FAIL - [XRInputSourcesChangeEvent interface: xrInputSourcesChangeEvent must inherit property "added" with the proper type] expected: FAIL @@ -161,18 +152,12 @@ [XRSession interface: xrSession must inherit property "onsqueezeend" with the proper type] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object's @@unscopables property] - expected: FAIL - [XRPermissionStatus interface object name] expected: FAIL [XRRenderState interface: xrRenderState must inherit property "inlineVerticalFieldOfView" with the proper type] expected: FAIL - [XRBoundedReferenceSpace interface: attribute boundsGeometry] - expected: FAIL - [XRSession interface: calling cancelAnimationFrame(long) on xrSession with too few arguments must throw TypeError] expected: FAIL @@ -227,9 +212,6 @@ [XRSessionEvent must be primary interface of xrSessionEvent] expected: FAIL - [XRBoundedReferenceSpace interface object name] - expected: FAIL - [XRRenderState interface: xrRenderState must inherit property "depthFar" with the proper type] expected: FAIL @@ -242,9 +224,6 @@ [XRSession interface: calling updateRenderState(optional XRRenderStateInit) on xrSession with too few arguments must throw TypeError] expected: FAIL - [XRBoundedReferenceSpace interface: existence and properties of interface prototype object] - expected: FAIL - [Stringification of xrInputSourceArray] expected: FAIL diff --git a/tests/wpt/meta/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini b/tests/wpt/meta/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini index 7bd61021eb7..64b97680787 100644 --- a/tests/wpt/meta/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini +++ b/tests/wpt/meta/webxr/xrReferenceSpace_originOffsetBounded.https.html.ini @@ -1,7 +1,6 @@ [xrReferenceSpace_originOffsetBounded.https.html] - expected: ERROR [Updating XRBoundedReferenceSpace origin offset updates view, input matrices, and bounds geometry. - webgl] - expected: TIMEOUT + expected: FAIL [Updating XRBoundedReferenceSpace origin offset updates view, input matrices, and bounds geometry. - webgl2] - expected: NOTRUN + expected: FAIL diff --git a/tests/wpt/meta/webxr/xrReferenceSpace_relationships.https.html.ini b/tests/wpt/meta/webxr/xrReferenceSpace_relationships.https.html.ini deleted file mode 100644 index db66d43bc56..00000000000 --- a/tests/wpt/meta/webxr/xrReferenceSpace_relationships.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[xrReferenceSpace_relationships.https.html] - expected: ERROR - [Bounded space, viewer space, local and local-floor space have correct poses w.r.t. each other - webgl2] - expected: NOTRUN - - [Bounded space, viewer space, local and local-floor space have correct poses w.r.t. each other - webgl] - expected: TIMEOUT diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 159822ee27d..44edde285c0 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -13473,7 +13473,7 @@ ] ], "interfaces.html": [ - "7a7d6c0a467ab2006d5edd9ef3a3b4a07f99cd64", + "dd0f564f708a2a0e8cf1ed571bd2bd45977fa469", [ null, {} diff --git a/tests/wpt/mozilla/tests/mozilla/interfaces.html b/tests/wpt/mozilla/tests/mozilla/interfaces.html index 7a7d6c0a467..dd0f564f708 100644 --- a/tests/wpt/mozilla/tests/mozilla/interfaces.html +++ b/tests/wpt/mozilla/tests/mozilla/interfaces.html @@ -278,6 +278,7 @@ test_interfaces([ "XMLHttpRequestEventTarget", "XMLHttpRequestUpload", "XMLSerializer", + "XRBoundedReferenceSpace", "XRFrame", "XRHand", "XRHitTestResult", |