diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-07-02 15:10:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-02 15:10:14 -0400 |
commit | b4ed3b6f3c6f8dedde41ac28ec3afdb117f5a44a (patch) | |
tree | 7ee03fc0af42890fe8ac8d2909331608e25506fe /components/script | |
parent | f4ff9e2eeb254a81f7b4ec9a43fe01fed2777b1a (diff) | |
parent | 480a9988d1b3c728113ad7f981ccb7b3035d2022 (diff) | |
download | servo-b4ed3b6f3c6f8dedde41ac28ec3afdb117f5a44a.tar.gz servo-b4ed3b6f3c6f8dedde41ac28ec3afdb117f5a44a.zip |
Auto merge of #23641 - Manishearth:newtest, r=asajeffrey
Update to newest XRTest API
requires https://github.com/servo/rust-webvr/pull/88 and https://github.com/servo/servo/pull/23575
Incorporates changes from https://github.com/immersive-web/webxr-test-api/pull/10 (and various minor improvements on that, like https://github.com/immersive-web/webxr-test-api/pull/20). Test no longer relies on racy state setting functions.
We're nearing consensus on what the test API should look like, thought I'd implement the updated model so I can start poking at the tests.
Fixes https://github.com/servo/servo/issues/23634 by setting everything at initialization.
This is based on https://github.com/servo/servo/pull/23575, so we can't merge it yet.
r? @asajeffrey (only the last commit)
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23641)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/fakexrdevice.rs | 121 | ||||
-rw-r--r-- | components/script/dom/fakexrdevicecontroller.rs | 104 | ||||
-rw-r--r-- | components/script/dom/mod.rs | 2 | ||||
-rw-r--r-- | components/script/dom/webidls/FakeXRDevice.webidl | 57 | ||||
-rw-r--r-- | components/script/dom/webidls/FakeXRDeviceController.webidl | 49 | ||||
-rw-r--r-- | components/script/dom/webidls/XRTest.webidl | 20 | ||||
-rw-r--r-- | components/script/dom/xrtest.rs | 34 |
7 files changed, 224 insertions, 163 deletions
diff --git a/components/script/dom/fakexrdevice.rs b/components/script/dom/fakexrdevice.rs new file mode 100644 index 00000000000..070ba5fa89c --- /dev/null +++ b/components/script/dom/fakexrdevice.rs @@ -0,0 +1,121 @@ +/* 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 crate::dom::bindings::codegen::Bindings::FakeXRDeviceBinding::{ + self, FakeXRDeviceMethods, FakeXRRigidTransformInit, FakeXRViewInit, +}; +use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye; +use crate::dom::bindings::error::{Error, Fallible}; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; +use crate::dom::bindings::root::DomRoot; +use crate::dom::globalscope::GlobalScope; +use dom_struct::dom_struct; +use webvr_traits::{MockVRControlMsg, MockVRView, WebVRMsg}; + +#[dom_struct] +pub struct FakeXRDevice { + reflector: Reflector, +} + +impl FakeXRDevice { + pub fn new_inherited() -> FakeXRDevice { + FakeXRDevice { + reflector: Reflector::new(), + } + } + + pub fn new(global: &GlobalScope) -> DomRoot<FakeXRDevice> { + reflect_dom_object( + Box::new(FakeXRDevice::new_inherited()), + global, + FakeXRDeviceBinding::Wrap, + ) + } + + fn send_msg(&self, msg: MockVRControlMsg) { + self.global() + .as_window() + .webvr_thread() + .unwrap() + .send(WebVRMsg::MessageMockDisplay(msg)) + .unwrap(); + } +} + +pub fn get_views(views: &[FakeXRViewInit]) -> Fallible<(MockVRView, MockVRView)> { + if views.len() != 2 { + return Err(Error::NotSupported); + } + + let (left, right) = match (views[0].eye, views[1].eye) { + (XREye::Left, XREye::Right) => (&views[0], &views[1]), + (XREye::Right, XREye::Left) => (&views[1], &views[0]), + _ => return Err(Error::NotSupported), + }; + + if left.projectionMatrix.len() != 16 || + right.projectionMatrix.len() != 16 || + left.viewOffset.position.len() != 3 || + right.viewOffset.position.len() != 3 + { + return Err(Error::Type("Incorrectly sized array".into())); + } + + let mut proj_l = [0.; 16]; + let mut proj_r = [0.; 16]; + let v: Vec<_> = left.projectionMatrix.iter().map(|x| **x).collect(); + proj_l.copy_from_slice(&v); + let v: Vec<_> = right.projectionMatrix.iter().map(|x| **x).collect(); + proj_r.copy_from_slice(&v); + + let mut offset_l = [0.; 3]; + let mut offset_r = [0.; 3]; + let v: Vec<_> = left.viewOffset.position.iter().map(|x| **x).collect(); + offset_l.copy_from_slice(&v); + let v: Vec<_> = right.viewOffset.position.iter().map(|x| **x).collect(); + offset_r.copy_from_slice(&v); + let left = MockVRView { + projection: proj_l, + offset: offset_l, + }; + let right = MockVRView { + projection: proj_r, + offset: offset_r, + }; + Ok((left, right)) +} + +pub fn get_origin(origin: &FakeXRRigidTransformInit) -> Fallible<([f32; 3], [f32; 4])> { + if origin.position.len() != 3 || origin.orientation.len() != 4 { + return Err(Error::Type("Incorrectly sized array".into())); + } + let mut p = [0.; 3]; + let mut o = [0.; 4]; + let v: Vec<_> = origin.position.iter().map(|x| **x).collect(); + p.copy_from_slice(&v[0..3]); + let v: Vec<_> = origin.orientation.iter().map(|x| **x).collect(); + o.copy_from_slice(&v); + + Ok((p, o)) +} + +impl FakeXRDeviceMethods for FakeXRDevice { + /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md + fn SetViews(&self, views: Vec<FakeXRViewInit>) -> Fallible<()> { + let (left, right) = get_views(&views)?; + self.send_msg(MockVRControlMsg::SetViews(left, right)); + Ok(()) + } + + /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md + fn SetViewerOrigin( + &self, + origin: &FakeXRRigidTransformInit, + _emulated_position: bool, + ) -> Fallible<()> { + let (position, orientation) = get_origin(origin)?; + self.send_msg(MockVRControlMsg::SetViewerPose(position, orientation)); + Ok(()) + } +} diff --git a/components/script/dom/fakexrdevicecontroller.rs b/components/script/dom/fakexrdevicecontroller.rs deleted file mode 100644 index a7ed2833716..00000000000 --- a/components/script/dom/fakexrdevicecontroller.rs +++ /dev/null @@ -1,104 +0,0 @@ -/* 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/. */ - -/* 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 crate::dom::bindings::codegen::Bindings::FakeXRDeviceControllerBinding::{ - self, FakeXRDeviceControllerMethods, FakeXRRigidTransform, FakeXRViewInit, -}; -use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye; -use crate::dom::bindings::error::{Error, Fallible}; -use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; -use crate::dom::bindings::root::DomRoot; -use crate::dom::globalscope::GlobalScope; -use dom_struct::dom_struct; -use webvr_traits::{MockVRControlMsg, WebVREyeParameters, WebVRMsg}; - -#[dom_struct] -pub struct FakeXRDeviceController { - reflector: Reflector, -} - -impl FakeXRDeviceController { - pub fn new_inherited() -> FakeXRDeviceController { - FakeXRDeviceController { - reflector: Reflector::new(), - } - } - - pub fn new(global: &GlobalScope) -> DomRoot<FakeXRDeviceController> { - reflect_dom_object( - Box::new(FakeXRDeviceController::new_inherited()), - global, - FakeXRDeviceControllerBinding::Wrap, - ) - } - - pub fn send_msg(&self, msg: MockVRControlMsg) { - self.global() - .as_window() - .webvr_thread() - .unwrap() - .send(WebVRMsg::MessageMockDisplay(msg)) - .unwrap(); - } -} - -impl FakeXRDeviceControllerMethods for FakeXRDeviceController { - /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md - fn SetViews(&self, views: Vec<FakeXRViewInit>) -> Fallible<()> { - if views.len() != 2 { - return Err(Error::NotSupported); - } - - let (left, right) = match (views[0].eye, views[1].eye) { - (XREye::Left, XREye::Right) => (&views[0], &views[1]), - (XREye::Right, XREye::Left) => (&views[1], &views[0]), - _ => return Err(Error::NotSupported), - }; - - if left.projectionMatrix.len() != 16 || - right.projectionMatrix.len() != 16 || - left.viewOffset.position.len() != 3 || - right.viewOffset.position.len() != 3 - { - return Err(Error::Type("Incorrectly sized array".into())); - } - - let mut proj_l = [0.; 16]; - let mut proj_r = [0.; 16]; - let v: Vec<_> = left.projectionMatrix.iter().map(|x| **x).collect(); - proj_l.copy_from_slice(&v); - let v: Vec<_> = right.projectionMatrix.iter().map(|x| **x).collect(); - proj_r.copy_from_slice(&v); - - let mut params_l = WebVREyeParameters::default(); - let mut params_r = WebVREyeParameters::default(); - let v: Vec<_> = left.viewOffset.position.iter().map(|x| **x).collect(); - params_l.offset.copy_from_slice(&v); - let v: Vec<_> = right.viewOffset.position.iter().map(|x| **x).collect(); - params_r.offset.copy_from_slice(&v); - - self.send_msg(MockVRControlMsg::SetProjectionMatrices(proj_l, proj_r)); - self.send_msg(MockVRControlMsg::SetEyeParameters(params_l, params_r)); - Ok(()) - } - - /// https://github.com/immersive-web/webxr-test-api/blob/master/explainer.md - fn SetViewerOrigin(&self, origin: &FakeXRRigidTransform) -> Fallible<()> { - if origin.position.len() != 4 || origin.orientation.len() != 4 { - return Err(Error::Type("Incorrectly sized array".into())); - } - let mut position = [0.; 3]; - let mut orientation = [0.; 4]; - let v: Vec<_> = origin.position.iter().map(|x| **x).collect(); - position.copy_from_slice(&v[0..3]); - let v: Vec<_> = origin.orientation.iter().map(|x| **x).collect(); - orientation.copy_from_slice(&v); - self.send_msg(MockVRControlMsg::SetViewerPose(position, orientation)); - Ok(()) - } -} diff --git a/components/script/dom/mod.rs b/components/script/dom/mod.rs index 77729567558..d20b68c92b7 100644 --- a/components/script/dom/mod.rs +++ b/components/script/dom/mod.rs @@ -301,7 +301,7 @@ pub mod eventsource; pub mod eventtarget; pub mod extendableevent; pub mod extendablemessageevent; -pub mod fakexrdevicecontroller; +pub mod fakexrdevice; pub mod file; pub mod filelist; pub mod filereader; diff --git a/components/script/dom/webidls/FakeXRDevice.webidl b/components/script/dom/webidls/FakeXRDevice.webidl new file mode 100644 index 00000000000..5e310c4d75f --- /dev/null +++ b/components/script/dom/webidls/FakeXRDevice.webidl @@ -0,0 +1,57 @@ +/* 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://github.com/immersive-web/webxr-test-api/ + +[Exposed=Window, Pref="dom.webxr.test"] +interface FakeXRDevice { + // Sets the values to be used for subsequent + // requestAnimationFrame() callbacks. + [Throws] void setViews(sequence<FakeXRViewInit> views); + + // // behaves as if device was disconnected + // Promise<void> disconnect(); + + // Sets the origin of the viewer + [Throws] void setViewerOrigin(FakeXRRigidTransformInit origin, optional boolean emulatedPosition = false); + + // // Simulates devices focusing and blurring sessions. + // void simulateVisibilityChange(XRVisibilityState); + + // void setBoundsGeometry(sequence<FakeXRBoundsPoint> boundsCoodinates); + // // Sets eye level used for calculating floor-level spaces + // void setEyeLevel(float eyeLevel); + + + // Promise<FakeXRInputController> + // simulateInputSourceConnection(FakeXRInputSourceInit); +}; + +// https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport +dictionary FakeXRViewInit { + required XREye eye; + // https://immersive-web.github.io/webxr/#view-projection-matrix + required sequence<float> projectionMatrix; + // https://immersive-web.github.io/webxr/#view-offset + required FakeXRRigidTransformInit viewOffset; + // https://immersive-web.github.io/webxr/#dom-xrwebgllayer-getviewport + required FakeXRViewportInit viewport; +}; + +// https://immersive-web.github.io/webxr/#xrviewport +dictionary FakeXRViewportInit { + required long x; + required long y; + required long width; + required long height; +}; + +dictionary FakeXRBoundsPoint { + double x; double z; +}; + +dictionary FakeXRRigidTransformInit { + required sequence<float> position; + required sequence<float> orientation; +}; diff --git a/components/script/dom/webidls/FakeXRDeviceController.webidl b/components/script/dom/webidls/FakeXRDeviceController.webidl deleted file mode 100644 index cacdb2f9819..00000000000 --- a/components/script/dom/webidls/FakeXRDeviceController.webidl +++ /dev/null @@ -1,49 +0,0 @@ -/* 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://github.com/immersive-web/webxr-test-api/ - -[Exposed=Window, Pref="dom.webxr.test"] -interface FakeXRDeviceController { - // Creates and attaches a XRFrameOfReference of the type specified to the device. - // void setFrameOfReference(XRFrameOfReferenceType, FakeXRFrameOfReferenceInit); - - // // Sets the values to be used for subsequent - // // requestAnimationFrame() callbacks. - [Throws] void setViews(sequence<FakeXRViewInit> views); - - [Throws] void setViewerOrigin(FakeXRRigidTransform origin); - - // Simulates the user activating the reset pose on a device. - // void simulateResetPose(); - - // Simulates the platform ending the sessions. - // void simulateForcedEndSessions(); - - // Simulates devices focusing and blurring sessions. - // void simulateBlurSession(XRSession); - // void simulateFocusSession(XRSession); - - // void setBoundsGeometry(Array<FakeXRBoundsPoint> boundsCoodinates)l - - // Promise<FakeXRInputSourceController> - // simulateInputSourceConnection(FakeXRInputSourceInit); -}; - -dictionary FakeXRViewInit { - required XREye eye; - // https://immersive-web.github.io/webxr/#view-projection-matrix - required sequence<float> projectionMatrix; - // https://immersive-web.github.io/webxr/#view-offset - required FakeXRRigidTransform viewOffset; -}; - -dictionary FakeXRBoundsPoint { - double x; double z; -}; - -dictionary FakeXRRigidTransform { - required sequence<float> position; - required sequence<float> orientation; -}; diff --git a/components/script/dom/webidls/XRTest.webidl b/components/script/dom/webidls/XRTest.webidl index 30c485321d4..f74b9b82331 100644 --- a/components/script/dom/webidls/XRTest.webidl +++ b/components/script/dom/webidls/XRTest.webidl @@ -8,18 +8,28 @@ interface XRTest { // Simulates connecting a device to the system. // Used to instantiate a fake device for use in tests. - Promise<FakeXRDeviceController> simulateDeviceConnection(FakeXRDeviceInit init); - - // // Simulates a device being disconnected from the system. - // Promise<void> simulateDeviceDisconnection(XRDevice); + Promise<FakeXRDevice> simulateDeviceConnection(FakeXRDeviceInit init); // // Simulates a user activation (aka user gesture) for the current scope. // // The activation is only guaranteed to be valid in the provided function and only applies to WebXR // // Device API methods. // void simulateUserActivation(Function); + + // // Disconnect all fake devices + // Promise<void> disconnectAllDevices(); }; dictionary FakeXRDeviceInit { - // TODO: Subject to change to match spec changes. required boolean supportsImmersive; + required sequence<FakeXRViewInit> views; + + boolean supportsUnbounded = false; + // Whether the space supports tracking in inline sessions + boolean supportsTrackingInInline = true; + // The bounds coordinates. If null, bounded reference spaces are not supported. + sequence<FakeXRBoundsPoint> boundsCoodinates; + // Eye level used for calculating floor-level spaces + float eyeLevel = 1.5; + FakeXRRigidTransformInit viewerOrigin; }; + diff --git a/components/script/dom/xrtest.rs b/components/script/dom/xrtest.rs index 07fac9d6a89..6808ce262cd 100644 --- a/components/script/dom/xrtest.rs +++ b/components/script/dom/xrtest.rs @@ -11,13 +11,13 @@ use crate::dom::bindings::codegen::Bindings::XRTestBinding::{ }; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; -use crate::dom::fakexrdevicecontroller::FakeXRDeviceController; +use crate::dom::fakexrdevice::{get_origin, get_views, FakeXRDevice}; use crate::dom::globalscope::GlobalScope; use crate::dom::promise::Promise; use dom_struct::dom_struct; use std::cell::Cell; use std::rc::Rc; -use webvr_traits::WebVRMsg; +use webvr_traits::{MockVRInit, WebVRMsg}; #[dom_struct] pub struct XRTest { @@ -52,14 +52,40 @@ impl XRTestMethods for XRTest { return p; } + let origin = if let Some(ref o) = init.viewerOrigin { + match get_origin(&o) { + Ok(origin) => origin, + Err(e) => { + p.reject_error(e); + return p; + }, + } + } else { + Default::default() + }; + + let views = match get_views(&init.views) { + Ok(views) => views, + Err(e) => { + p.reject_error(e); + return p; + }, + }; + + let init = MockVRInit { + viewer_origin: Some(origin), + views: Some(views), + eye_level: None, + }; + self.session_started.set(true); self.global() .as_window() .webvr_thread() .unwrap() - .send(WebVRMsg::CreateMockDisplay) + .send(WebVRMsg::CreateMockDisplay(init)) .unwrap(); - p.resolve_native(&FakeXRDeviceController::new(&self.global())); + p.resolve_native(&FakeXRDevice::new(&self.global())); p } |