From 9fdaf9bf0c6958356b8e3b4f5d03f838c13c6307 Mon Sep 17 00:00:00 2001 From: Daniel Adams <70986246+msub2@users.noreply.github.com> Date: Sun, 1 Sep 2024 11:58:32 +0000 Subject: [PATCH] Update FakeXRDevice to support updating bounds (#33271) * Update FakeXRDevice to support updating bounds Signed-off-by: Daniel Adams * Add missing spec link Signed-off-by: Daniel Adams * Mark secondaryViews as optional in FakeXRDevice.setViews Signed-off-by: Daniel Adams --------- Signed-off-by: Daniel Adams --- Cargo.lock | 4 +-- components/script/dom/fakexrdevice.rs | 30 ++++++++++++++-- .../script/dom/webidls/FakeXRDevice.webidl | 34 +++++++++--------- .../script/dom/xrboundedreferencespace.rs | 36 ++++--------------- components/script/dom/xrreferencespace.rs | 4 +-- ...undedReferenceSpace_updates.https.html.ini | 7 ---- ...undedReferenceSpace_updates.https.html.ini | 7 ---- 7 files changed, 56 insertions(+), 66 deletions(-) delete mode 100644 tests/wpt/meta-legacy-layout/webxr/xrBoundedReferenceSpace_updates.https.html.ini delete mode 100644 tests/wpt/meta/webxr/xrBoundedReferenceSpace_updates.https.html.ini diff --git a/Cargo.lock b/Cargo.lock index 9d1674359e4..41cca2187a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7783,7 +7783,7 @@ dependencies = [ [[package]] name = "webxr" version = "0.0.1" -source = "git+https://github.com/servo/webxr#7656508fdcda194997cdaa751f2b98797d963867" +source = "git+https://github.com/servo/webxr#1a2186a5b33ae9e2e0b4fc15e9dc6095ae2e5fd0" dependencies = [ "crossbeam-channel", "euclid", @@ -7800,7 +7800,7 @@ dependencies = [ [[package]] name = "webxr-api" version = "0.0.1" -source = "git+https://github.com/servo/webxr#7656508fdcda194997cdaa751f2b98797d963867" +source = "git+https://github.com/servo/webxr#1a2186a5b33ae9e2e0b4fc15e9dc6095ae2e5fd0" dependencies = [ "euclid", "ipc-channel", diff --git a/components/script/dom/fakexrdevice.rs b/components/script/dom/fakexrdevice.rs index d4799d2b10a..f1c7f4180c6 100644 --- a/components/script/dom/fakexrdevice.rs +++ b/components/script/dom/fakexrdevice.rs @@ -17,8 +17,8 @@ use webxr_api::{ use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; use crate::dom::bindings::codegen::Bindings::FakeXRDeviceBinding::{ - FakeXRDeviceMethods, FakeXRRegionType, FakeXRRigidTransformInit, FakeXRViewInit, - FakeXRWorldInit, + FakeXRBoundsPoint, FakeXRDeviceMethods, FakeXRRegionType, FakeXRRigidTransformInit, + FakeXRViewInit, FakeXRWorldInit, }; use crate::dom::bindings::codegen::Bindings::FakeXRInputControllerBinding::FakeXRInputSourceInit; use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{ @@ -183,10 +183,15 @@ impl From for EntityType { impl FakeXRDeviceMethods for FakeXRDevice { /// - fn SetViews(&self, views: Vec) -> Fallible<()> { + fn SetViews( + &self, + views: Vec, + _secondary_views: Option>, + ) -> Fallible<()> { let _ = self .sender .send(MockDeviceMsg::SetViews(get_views(&views)?)); + // TODO: Support setting secondary views for mock backend Ok(()) } @@ -309,6 +314,25 @@ impl FakeXRDeviceMethods for FakeXRDevice { self.disconnect(sender); p } + + /// + fn SetBoundsGeometry(&self, bounds_coodinates: Vec) -> Fallible<()> { + if bounds_coodinates.len() < 3 { + return Err(Error::Type( + "Bounds geometry must contain at least 3 points".into(), + )); + } + let coords = bounds_coodinates + .iter() + .map(|coord| { + let x = *coord.x.unwrap() as f32; + let y = *coord.z.unwrap() as f32; + Point2D::new(x, y) + }) + .collect(); + let _ = self.sender.send(MockDeviceMsg::SetBoundsGeometry(coords)); + Ok(()) + } } impl From for Handedness { diff --git a/components/script/dom/webidls/FakeXRDevice.webidl b/components/script/dom/webidls/FakeXRDevice.webidl index 617b18d12f3..00665ceadbd 100644 --- a/components/script/dom/webidls/FakeXRDevice.webidl +++ b/components/script/dom/webidls/FakeXRDevice.webidl @@ -6,29 +6,31 @@ [Exposed=Window, Pref="dom.webxr.test"] interface FakeXRDevice { - // Sets the values to be used for subsequent - // requestAnimationFrame() callbacks. - [Throws] undefined setViews(sequence views); - - [Throws] undefined setViewerOrigin(FakeXRRigidTransformInit origin, optional boolean emulatedPosition = false); - undefined clearViewerOrigin(); - - [Throws] undefined setFloorOrigin(FakeXRRigidTransformInit origin); - undefined clearFloorOrigin(); - - // // Simulates devices focusing and blurring sessions. - undefined simulateVisibilityChange(XRVisibilityState state); - - // void setBoundsGeometry(sequence boundsCoodinates); - - [Throws] FakeXRInputController simulateInputSourceConnection(FakeXRInputSourceInit init); + // Sets the values to be used for subsequent requestAnimationFrame() callbacks. + [Throws] undefined setViews(sequence views, optional sequence secondaryViews); // behaves as if device was disconnected Promise disconnect(); + [Throws] undefined setViewerOrigin(FakeXRRigidTransformInit origin, optional boolean emulatedPosition = false); + undefined clearViewerOrigin(); + [Throws] undefined setFloorOrigin(FakeXRRigidTransformInit origin); + undefined clearFloorOrigin(); + [Throws] undefined setBoundsGeometry(sequence boundsCoodinates); + // undefined simulateResetPose(); + + // Simulates devices focusing and blurring sessions. + undefined simulateVisibilityChange(XRVisibilityState state); + + [Throws] FakeXRInputController simulateInputSourceConnection(FakeXRInputSourceInit init); + // Hit test extensions: [Throws] undefined setWorld(FakeXRWorldInit world); undefined clearWorld(); + + // Depth sensing extensions: + // undefined setDepthSensingData(FakeXRDepthSensingDataInit depthSensingData); + // undefined clearDepthSensingData(); }; // https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport diff --git a/components/script/dom/xrboundedreferencespace.rs b/components/script/dom/xrboundedreferencespace.rs index 41bb2052694..591e3fad124 100644 --- a/components/script/dom/xrboundedreferencespace.rs +++ b/components/script/dom/xrboundedreferencespace.rs @@ -61,36 +61,14 @@ impl XRBoundedReferenceSpaceMethods for XRBoundedReferenceSpace { /// 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, - ); + let points: Vec> = bounds + .into_iter() + .map(|point| { + DOMPointReadOnly::new(&self.global(), point.x.into(), 0.0, point.y.into(), 1.0) + }) + .collect(); - to_frozen_array(&[point1, point2, point3, point4], cx) + to_frozen_array(&points, cx) } else { to_frozen_array::>(&[], cx) } diff --git a/components/script/dom/xrreferencespace.rs b/components/script/dom/xrreferencespace.rs index 402d9d584e8..20f299292e8 100644 --- a/components/script/dom/xrreferencespace.rs +++ b/components/script/dom/xrreferencespace.rs @@ -3,7 +3,7 @@ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ use dom_struct::dom_struct; -use euclid::{Box2D, RigidTransform3D}; +use euclid::{Point2D, RigidTransform3D}; use webxr_api::{self, Floor, Frame, Space}; use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::{ @@ -136,7 +136,7 @@ impl XRReferenceSpace { } } - pub fn get_bounds(&self) -> Option> { + pub fn get_bounds(&self) -> Option>> { self.upcast::() .session() .with_session(|s| s.reference_space_bounds()) diff --git a/tests/wpt/meta-legacy-layout/webxr/xrBoundedReferenceSpace_updates.https.html.ini b/tests/wpt/meta-legacy-layout/webxr/xrBoundedReferenceSpace_updates.https.html.ini deleted file mode 100644 index 53da0ae9b17..00000000000 --- a/tests/wpt/meta-legacy-layout/webxr/xrBoundedReferenceSpace_updates.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[xrBoundedReferenceSpace_updates.https.html] - expected: ERROR - ['XRBoundedReferenceSpace updates properly when the changes are applied - webgl2] - expected: NOTRUN - - ['XRBoundedReferenceSpace updates properly when the changes are applied - webgl] - expected: TIMEOUT diff --git a/tests/wpt/meta/webxr/xrBoundedReferenceSpace_updates.https.html.ini b/tests/wpt/meta/webxr/xrBoundedReferenceSpace_updates.https.html.ini deleted file mode 100644 index 53da0ae9b17..00000000000 --- a/tests/wpt/meta/webxr/xrBoundedReferenceSpace_updates.https.html.ini +++ /dev/null @@ -1,7 +0,0 @@ -[xrBoundedReferenceSpace_updates.https.html] - expected: ERROR - ['XRBoundedReferenceSpace updates properly when the changes are applied - webgl2] - expected: NOTRUN - - ['XRBoundedReferenceSpace updates properly when the changes are applied - webgl] - expected: TIMEOUT