mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
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 -->
This commit is contained in:
commit
b4ed3b6f3c
19 changed files with 263 additions and 194 deletions
121
components/script/dom/fakexrdevice.rs
Normal file
121
components/script/dom/fakexrdevice.rs
Normal file
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
57
components/script/dom/webidls/FakeXRDevice.webidl
Normal file
57
components/script/dom/webidls/FakeXRDevice.webidl
Normal file
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue