Commit 9fe8a648 authored by Piotr Bialecki's avatar Piotr Bialecki Committed by Commit Bot

CL followup - run ESLint, throw from math helper

- ran ESLint on webxr-test.js and xr-internal-device-mocking.js
- xr-internal-device-mocking.js now stores the
  `MockRuntime._injectAdditionalFrameData()` before overwriting it with
  its own implementation, and calls the original implementation as the
  first step
- throw instead of console.warn when math helper encounters unexpected
  combinations of .w component

Changes: 
Change-Id: I94c015b5c89cfbc0e1a4b90db6ec44a198f4ce05
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008073
Commit-Queue: Piotr Bialecki <bialpio@chromium.org>
Commit-Queue: Klaus Weidner <klausw@chromium.org>
Auto-Submit: Piotr Bialecki <bialpio@chromium.org>
Reviewed-by: default avatarKlaus Weidner <klausw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#732977}
parent 665fc90a
...@@ -23,7 +23,7 @@ class XRMathHelper { ...@@ -23,7 +23,7 @@ class XRMathHelper {
// .w is treated here like an entity type, 1 signifies points, 0 signifies vectors. // .w is treated here like an entity type, 1 signifies points, 0 signifies vectors.
// point - point, point - vector, vector - vector are ok, vector - point is not. // point - point, point - vector, vector - vector are ok, vector - point is not.
if (lhs.w != rhs.w && lhs.w == 0.0) { if (lhs.w != rhs.w && lhs.w == 0.0) {
console.warn("vector - point not allowed: " + toString(lhs) + "-" + toString(rhs)); throw new Error("vector - point not allowed: " + toString(lhs) + "-" + toString(rhs));
} }
return {x : lhs.x - rhs.x, y : lhs.y - rhs.y, z : lhs.z - rhs.z, w : lhs.w - rhs.w}; return {x : lhs.x - rhs.x, y : lhs.y - rhs.y, z : lhs.z - rhs.z, w : lhs.w - rhs.w};
...@@ -31,7 +31,7 @@ class XRMathHelper { ...@@ -31,7 +31,7 @@ class XRMathHelper {
static add(lhs, rhs) { static add(lhs, rhs) {
if (lhs.w == rhs.w && lhs.w == 1.0) { if (lhs.w == rhs.w && lhs.w == 1.0) {
console.warn("point + point not allowed", p1, p2); throw new Error("point + point not allowed", p1, p2);
} }
return {x : lhs.x + rhs.x, y : lhs.y + rhs.y, z : lhs.z + rhs.z, w : lhs.w + rhs.w}; return {x : lhs.x + rhs.x, y : lhs.y + rhs.y, z : lhs.z + rhs.z, w : lhs.w + rhs.w};
...@@ -39,7 +39,7 @@ class XRMathHelper { ...@@ -39,7 +39,7 @@ class XRMathHelper {
static cross(lhs, rhs) { static cross(lhs, rhs) {
if (lhs.w != 0.0 || rhs.w != 0.0) { if (lhs.w != 0.0 || rhs.w != 0.0) {
console.warn("cross product not allowed: " + toString(lhs) + "x" + toString(rhs)); throw new Error("cross product not allowed: " + toString(lhs) + "x" + toString(rhs));
} }
return { return {
...@@ -52,7 +52,7 @@ class XRMathHelper { ...@@ -52,7 +52,7 @@ class XRMathHelper {
static dot(lhs, rhs) { static dot(lhs, rhs) {
if (lhs.w != 0 || rhs.w != 0) { if (lhs.w != 0 || rhs.w != 0) {
console.warn("dot product not allowed: " + toString(lhs) + "x" + toString(rhs)); throw new Error("dot product not allowed: " + toString(lhs) + "x" + toString(rhs));
} }
return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z; return lhs.x * rhs.x + lhs.y * rhs.y + lhs.z * rhs.z;
...@@ -60,7 +60,7 @@ class XRMathHelper { ...@@ -60,7 +60,7 @@ class XRMathHelper {
static mul(scalar, vector) { static mul(scalar, vector) {
if (vector.w != 0) { if (vector.w != 0) {
console.warn("scalar * vector not allowed", scalar, vector); throw new Error("scalar * vector not allowed", scalar, vector);
} }
return {x : vector.x * scalar, y : vector.y * scalar, z : vector.z * scalar, w : vector.w}; return {x : vector.x * scalar, y : vector.y * scalar, z : vector.z * scalar, w : vector.w};
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// https://github.com/immersive-web/webxr-test-api // https://github.com/immersive-web/webxr-test-api
let default_standing = new gfx.mojom.Transform(); const default_standing = new gfx.mojom.Transform();
default_standing.matrix = [1, 0, 0, 0, default_standing.matrix = [1, 0, 0, 0,
0, 1, 0, 0, 0, 1, 0, 0,
0, 0, 1, 0, 0, 0, 1, 0,
...@@ -15,26 +15,26 @@ const default_stage_parameters = { ...@@ -15,26 +15,26 @@ const default_stage_parameters = {
}; };
function getMatrixFromTransform(transform) { function getMatrixFromTransform(transform) {
let x = transform.orientation[0]; const x = transform.orientation[0];
let y = transform.orientation[1]; const y = transform.orientation[1];
let z = transform.orientation[2]; const z = transform.orientation[2];
let w = transform.orientation[3]; const w = transform.orientation[3];
let m11 = 1.0 - 2.0 * (y * y + z * z); const m11 = 1.0 - 2.0 * (y * y + z * z);
let m21 = 2.0 * (x * y + z * w); const m21 = 2.0 * (x * y + z * w);
let m31 = 2.0 * (x * z - y * w); const m31 = 2.0 * (x * z - y * w);
let m12 = 2.0 * (x * y - z * w); const m12 = 2.0 * (x * y - z * w);
let m22 = 1.0 - 2.0 * (x * x + z * z); const m22 = 1.0 - 2.0 * (x * x + z * z);
let m32 = 2.0 * (y * z + x * w); const m32 = 2.0 * (y * z + x * w);
let m13 = 2.0 * (x * z + y * w); const m13 = 2.0 * (x * z + y * w);
let m23 = 2.0 * (y * z - x * w); const m23 = 2.0 * (y * z - x * w);
let m33 = 1.0 - 2.0 * (x * x + y * y); const m33 = 1.0 - 2.0 * (x * x + y * y);
let m14 = transform.position[0]; const m14 = transform.position[0];
let m24 = transform.position[1]; const m24 = transform.position[1];
let m34 = transform.position[2]; const m34 = transform.position[2];
// Column-major linearized order is expected. // Column-major linearized order is expected.
return [m11, m21, m31, 0, return [m11, m21, m31, 0,
...@@ -44,7 +44,7 @@ function getMatrixFromTransform(transform) { ...@@ -44,7 +44,7 @@ function getMatrixFromTransform(transform) {
} }
function composeGFXTransform(fakeTransformInit) { function composeGFXTransform(fakeTransformInit) {
let transform = new gfx.mojom.Transform(); const transform = new gfx.mojom.Transform();
transform.matrix = getMatrixFromTransform(fakeTransformInit); transform.matrix = getMatrixFromTransform(fakeTransformInit);
return transform; return transform;
} }
...@@ -64,7 +64,7 @@ class ChromeXRTest { ...@@ -64,7 +64,7 @@ class ChromeXRTest {
} }
simulateUserActivation(callback) { simulateUserActivation(callback) {
let button = document.createElement('button'); const button = document.createElement('button');
button.textContent = 'click to continue test'; button.textContent = 'click to continue test';
button.style.display = 'block'; button.style.display = 'block';
button.style.fontSize = '20px'; button.style.fontSize = '20px';
...@@ -95,7 +95,7 @@ class MockVRService { ...@@ -95,7 +95,7 @@ class MockVRService {
// Test methods // Test methods
addRuntime(fakeDeviceInit) { addRuntime(fakeDeviceInit) {
let runtime = new MockRuntime(fakeDeviceInit, this); const runtime = new MockRuntime(fakeDeviceInit, this);
this.runtimes_.push(runtime); this.runtimes_.push(runtime);
if (this.client_) { if (this.client_) {
...@@ -114,7 +114,7 @@ class MockVRService { ...@@ -114,7 +114,7 @@ class MockVRService {
} }
removeRuntime(device) { removeRuntime(device) {
let index = this.runtimes_.indexOf(device); const index = this.runtimes_.indexOf(device);
if (index >= 0) { if (index >= 0) {
this.runtimes_.splice(index, 1); this.runtimes_.splice(index, 1);
if (this.client_) { if (this.client_) {
...@@ -132,7 +132,7 @@ class MockVRService { ...@@ -132,7 +132,7 @@ class MockVRService {
} }
requestSession(sessionOptions, was_activation) { requestSession(sessionOptions, was_activation) {
let requests = []; const requests = [];
// Request a session from all the runtimes. // Request a session from all the runtimes.
for (let i = 0; i < this.runtimes_.length; i++) { for (let i = 0; i < this.runtimes_.length; i++) {
requests[i] = this.runtimes_[i].requestRuntimeSession(sessionOptions); requests[i] = this.runtimes_[i].requestRuntimeSession(sessionOptions);
...@@ -143,12 +143,12 @@ class MockVRService { ...@@ -143,12 +143,12 @@ class MockVRService {
for (let i = 0; i < results.length; i++) { for (let i = 0; i < results.length; i++) {
if (results[i].session) { if (results[i].session) {
// Construct a dummy metrics recorder // Construct a dummy metrics recorder
let metricsRecorderPtr = new device.mojom.XRSessionMetricsRecorderPtr(); const metricsRecorderPtr = new device.mojom.XRSessionMetricsRecorderPtr();
let metricsRecorderRequest = mojo.makeRequest(metricsRecorderPtr); const metricsRecorderRequest = mojo.makeRequest(metricsRecorderPtr);
let metricsRecorderBinding = new mojo.Binding( const metricsRecorderBinding = new mojo.Binding(
device.mojom.XRSessionMetricsRecorder, new MockXRSessionMetricsRecorder(), metricsRecorderRequest); device.mojom.XRSessionMetricsRecorder, new MockXRSessionMetricsRecorder(), metricsRecorderRequest);
let success = { const success = {
session: results[i].session, session: results[i].session,
metricsRecorder: metricsRecorderPtr, metricsRecorder: metricsRecorderPtr,
}; };
...@@ -177,7 +177,7 @@ class MockVRService { ...@@ -177,7 +177,7 @@ class MockVRService {
} }
supportsSession(sessionOptions) { supportsSession(sessionOptions) {
let requests = []; const requests = [];
// Check supports on all the runtimes. // Check supports on all the runtimes.
for (let i = 0; i < this.runtimes_.length; i++) { for (let i = 0; i < this.runtimes_.length; i++) {
requests[i] = this.runtimes_[i].runtimeSupportsSession(sessionOptions); requests[i] = this.runtimes_[i].runtimeSupportsSession(sessionOptions);
...@@ -194,7 +194,7 @@ class MockVRService { ...@@ -194,7 +194,7 @@ class MockVRService {
// If there were no successful results, returns false. // If there were no successful results, returns false.
return {supportsSession: false}; return {supportsSession: false};
}); });
}; }
} }
// Implements XRFrameDataProvider and XRPresentationProvider. Maintains a mock // Implements XRFrameDataProvider and XRPresentationProvider. Maintains a mock
...@@ -207,7 +207,8 @@ class MockRuntime { ...@@ -207,7 +207,8 @@ class MockRuntime {
"local": device.mojom.XRSessionFeature.REF_SPACE_LOCAL, "local": device.mojom.XRSessionFeature.REF_SPACE_LOCAL,
"local-floor": device.mojom.XRSessionFeature.REF_SPACE_LOCAL_FLOOR, "local-floor": device.mojom.XRSessionFeature.REF_SPACE_LOCAL_FLOOR,
"bounded-floor": device.mojom.XRSessionFeature.REF_SPACE_BOUNDED_FLOOR, "bounded-floor": device.mojom.XRSessionFeature.REF_SPACE_BOUNDED_FLOOR,
"unbounded": device.mojom.XRSessionFeature.REF_SPACE_UNBOUNDED }; "unbounded": device.mojom.XRSessionFeature.REF_SPACE_UNBOUNDED,
};
static sessionModeToMojoMap = { static sessionModeToMojoMap = {
"inline": device.mojom.XRSessionMode.kInline, "inline": device.mojom.XRSessionMode.kInline,
...@@ -239,18 +240,18 @@ class MockRuntime { ...@@ -239,18 +240,18 @@ class MockRuntime {
let supportedModes = []; let supportedModes = [];
if (fakeDeviceInit.supportedModes) { if (fakeDeviceInit.supportedModes) {
supportedModes = fakeDeviceInit.supportedModes.slice(); supportedModes = fakeDeviceInit.supportedModes.slice();
if(fakeDeviceInit.supportedModes.length === 0) { if (fakeDeviceInit.supportedModes.length === 0) {
supportedModes = ["inline"]; supportedModes = ["inline"];
} }
} else { } else {
// Back-compat mode. // Back-compat mode.
console.warn("Please use `supportedModes` to signal which modes are supported by this device."); console.warn("Please use `supportedModes` to signal which modes are supported by this device.");
if(fakeDeviceInit.supportsImmersive == null) { if (fakeDeviceInit.supportsImmersive == null) {
throw new TypeError("'supportsImmersive' must be set"); throw new TypeError("'supportsImmersive' must be set");
} }
supportedModes = ["inline"]; supportedModes = ["inline"];
if(fakeDeviceInit.supportsImmersive) { if (fakeDeviceInit.supportsImmersive) {
supportedModes.push("immersive-vr"); supportedModes.push("immersive-vr");
} }
} }
...@@ -259,7 +260,7 @@ class MockRuntime { ...@@ -259,7 +260,7 @@ class MockRuntime {
// Initialize DisplayInfo first to set the defaults, then override with // Initialize DisplayInfo first to set the defaults, then override with
// anything from the deviceInit // anything from the deviceInit
if(this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveVr) if (this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveVr)
|| this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) { || this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) {
this.displayInfo_ = this.getImmersiveDisplayInfo(); this.displayInfo_ = this.getImmersiveDisplayInfo();
} else if (this.supportedModes_.includes(device.mojom.XRSessionMode.kInline)) { } else if (this.supportedModes_.includes(device.mojom.XRSessionMode.kInline)) {
...@@ -292,8 +293,9 @@ class MockRuntime { ...@@ -292,8 +293,9 @@ class MockRuntime {
} }
_convertModeToEnum(sessionMode) { _convertModeToEnum(sessionMode) {
if(sessionMode in MockRuntime.sessionModeToMojoMap) if (sessionMode in MockRuntime.sessionModeToMojoMap) {
return MockRuntime.sessionModeToMojoMap[sessionMode]; return MockRuntime.sessionModeToMojoMap[sessionMode];
}
throw new TypeError("Unrecognized value for XRSessionMode enum: " + sessionMode); throw new TypeError("Unrecognized value for XRSessionMode enum: " + sessionMode);
} }
...@@ -333,8 +335,8 @@ class MockRuntime { ...@@ -333,8 +335,8 @@ class MockRuntime {
} }
setViewerOrigin(origin, emulatedPosition = false) { setViewerOrigin(origin, emulatedPosition = false) {
let p = origin.position; const p = origin.position;
let q = origin.orientation; const q = origin.orientation;
this.pose_ = { this.pose_ = {
orientation: { x: q[0], y: q[1], z: q[2], w: q[3] }, orientation: { x: q[0], y: q[1], z: q[2], w: q[3] },
position: { x: p[0], y: p[1], z: p[2] }, position: { x: p[0], y: p[1], z: p[2] },
...@@ -354,7 +356,7 @@ class MockRuntime { ...@@ -354,7 +356,7 @@ class MockRuntime {
simulateVisibilityChange(visibilityState) { simulateVisibilityChange(visibilityState) {
let mojoState = null; let mojoState = null;
switch(visibilityState) { switch (visibilityState) {
case "visible": case "visible":
mojoState = device.mojom.XRVisibilityState.VISIBLE; mojoState = device.mojom.XRVisibilityState.VISIBLE;
break; break;
...@@ -422,17 +424,17 @@ class MockRuntime { ...@@ -422,17 +424,17 @@ class MockRuntime {
} }
simulateInputSourceConnection(fakeInputSourceInit) { simulateInputSourceConnection(fakeInputSourceInit) {
let index = this.next_input_source_index_; const index = this.next_input_source_index_;
this.next_input_source_index_++; this.next_input_source_index_++;
let source = new MockXRInputSource(fakeInputSourceInit, index, this); const source = new MockXRInputSource(fakeInputSourceInit, index, this);
this.input_sources_.set(index, source); this.input_sources_.set(index, source);
return source; return source;
} }
// Helper methods // Helper methods
getNonImmersiveDisplayInfo() { getNonImmersiveDisplayInfo() {
let displayInfo = this.getImmersiveDisplayInfo(); const displayInfo = this.getImmersiveDisplayInfo();
displayInfo.capabilities.canPresent = false; displayInfo.capabilities.canPresent = false;
displayInfo.leftEye = null; displayInfo.leftEye = null;
...@@ -497,16 +499,16 @@ class MockRuntime { ...@@ -497,16 +499,16 @@ class MockRuntime {
rightDegrees: fakeXRViewInit.fieldOfView.rightDegrees rightDegrees: fakeXRViewInit.fieldOfView.rightDegrees
}; };
} else { } else {
let m = fakeXRViewInit.projectionMatrix; const m = fakeXRViewInit.projectionMatrix;
function toDegrees(tan) { function toDegrees(tan) {
return Math.atan(tan) * 180 / Math.PI; return Math.atan(tan) * 180 / Math.PI;
} }
let leftTan = (1 - m[8]) / m[0]; const leftTan = (1 - m[8]) / m[0];
let rightTan = (1 + m[8]) / m[0]; const rightTan = (1 + m[8]) / m[0];
let upTan = (1 + m[9]) / m[5]; const upTan = (1 + m[9]) / m[5];
let downTan = (1 - m[9]) / m[5]; const downTan = (1 - m[9]) / m[5];
fov = { fov = {
upDegrees: toDegrees(upTan), upDegrees: toDegrees(upTan),
...@@ -536,7 +538,7 @@ class MockRuntime { ...@@ -536,7 +538,7 @@ class MockRuntime {
this.supportedFeatures_ = []; this.supportedFeatures_ = [];
for (let i = 0; i < supportedFeatures.length; i++) { for (let i = 0; i < supportedFeatures.length; i++) {
let feature = convertFeatureToMojom(supportedFeatures[i]); const feature = convertFeatureToMojom(supportedFeatures[i]);
if (feature !== device.mojom.XRSessionFeature.INVALID) { if (feature !== device.mojom.XRSessionFeature.INVALID) {
this.supportedFeatures_.push(feature); this.supportedFeatures_.push(feature);
} }
...@@ -545,7 +547,7 @@ class MockRuntime { ...@@ -545,7 +547,7 @@ class MockRuntime {
// These methods are intended to be used by MockXRInputSource only. // These methods are intended to be used by MockXRInputSource only.
addInputSource(source) { addInputSource(source) {
if(!this.input_sources_.has(source.source_id_)) { if (!this.input_sources_.has(source.source_id_)) {
this.input_sources_.set(source.source_id_, source); this.input_sources_.set(source.source_id_, source);
} }
} }
...@@ -554,14 +556,16 @@ class MockRuntime { ...@@ -554,14 +556,16 @@ class MockRuntime {
this.input_sources_.delete(source.source_id_); this.input_sources_.delete(source.source_id_);
} }
// Mojo function implementations. // Extension point for non-standard modules.
_injectAdditionalFrameData(options, frameData) { _injectAdditionalFrameData(options, frameData) {
} }
// Mojo function implementations.
// XRFrameDataProvider implementation. // XRFrameDataProvider implementation.
getFrameData(options) { getFrameData(options) {
let mojo_space_reset = this.send_mojo_space_reset_; const mojo_space_reset = this.send_mojo_space_reset_;
this.send_mojo_space_reset_ = false; this.send_mojo_space_reset_ = false;
if (this.pose_) { if (this.pose_) {
this.pose_.poseIndex++; this.pose_.poseIndex++;
...@@ -574,18 +578,18 @@ class MockRuntime { ...@@ -574,18 +578,18 @@ class MockRuntime {
let input_state = null; let input_state = null;
if (this.input_sources_.size > 0) { if (this.input_sources_.size > 0) {
input_state = []; input_state = [];
for (let input_source of this.input_sources_.values()) { for (const input_source of this.input_sources_.values()) {
input_state.push(input_source.getInputSourceState()); input_state.push(input_source.getInputSourceState());
} }
} }
// Convert current document time to monotonic time. // Convert current document time to monotonic time.
let now = window.performance.now() / 1000.0; let now = window.performance.now() / 1000.0;
let diff = now - internals.monotonicTimeToZeroBasedDocumentTime(now); const diff = now - internals.monotonicTimeToZeroBasedDocumentTime(now);
now += diff; now += diff;
now *= 1000000; now *= 1000000;
let frameData = { const frameData = {
pose: this.pose_, pose: this.pose_,
mojoSpaceReset: mojo_space_reset, mojoSpaceReset: mojo_space_reset,
inputState: input_state, inputState: input_state,
...@@ -597,10 +601,10 @@ class MockRuntime { ...@@ -597,10 +601,10 @@ class MockRuntime {
bufferSize: {}, bufferSize: {},
}; };
this._injectAdditionalFrameData(options, frameData);
this._calculateHitTestResults(frameData); this._calculateHitTestResults(frameData);
this._injectAdditionalFrameData(options, frameData);
return Promise.resolve({ return Promise.resolve({
frameData: frameData, frameData: frameData,
}); });
...@@ -630,7 +634,7 @@ class MockRuntime { ...@@ -630,7 +634,7 @@ class MockRuntime {
// XREnvironmentIntegrationProvider implementation: // XREnvironmentIntegrationProvider implementation:
subscribeToHitTest(nativeOriginInformation, entityTypes, ray) { subscribeToHitTest(nativeOriginInformation, entityTypes, ray) {
if(!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) { if (!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) {
// Reject outside of AR. // Reject outside of AR.
return Promise.resolve({ return Promise.resolve({
result : device.mojom.SubscribeToHitTestResult.FAILED, result : device.mojom.SubscribeToHitTestResult.FAILED,
...@@ -638,17 +642,17 @@ class MockRuntime { ...@@ -638,17 +642,17 @@ class MockRuntime {
}); });
} }
if(nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) { if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) {
if(!this.input_sources_.has(nativeOriginInformation.inputSourceId)) { if (!this.input_sources_.has(nativeOriginInformation.inputSourceId)) {
// Reject - unknown input source ID. // Reject - unknown input source ID.
return Promise.resolve({ return Promise.resolve({
result : device.mojom.SubscribeToHitTestResult.FAILED, result : device.mojom.SubscribeToHitTestResult.FAILED,
subscriptionId : 0 subscriptionId : 0
}); });
} }
} else if(nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) { } else if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) {
// Bounded_floor & unbounded ref spaces are not yet supported for AR: // Bounded_floor & unbounded ref spaces are not yet supported for AR:
if(nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.UNBOUNDED if (nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.UNBOUNDED
|| nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.BOUNDED_FLOOR) { || nativeOriginInformation.referenceSpaceCategory == device.mojom.XRReferenceSpaceCategory.BOUNDED_FLOOR) {
return Promise.resolve({ return Promise.resolve({
result : device.mojom.SubscribeToHitTestResult.FAILED, result : device.mojom.SubscribeToHitTestResult.FAILED,
...@@ -677,7 +681,7 @@ class MockRuntime { ...@@ -677,7 +681,7 @@ class MockRuntime {
requestRuntimeSession(sessionOptions) { requestRuntimeSession(sessionOptions) {
return this.runtimeSupportsSession(sessionOptions).then((result) => { return this.runtimeSupportsSession(sessionOptions).then((result) => {
// The JavaScript bindings convert c_style_names to camelCase names. // The JavaScript bindings convert c_style_names to camelCase names.
let options = new device.mojom.XRPresentationTransportOptions(); const options = new device.mojom.XRPresentationTransportOptions();
options.transportMethod = options.transportMethod =
device.mojom.XRPresentationTransportMethod.SUBMIT_AS_MAILBOX_HOLDER; device.mojom.XRPresentationTransportMethod.SUBMIT_AS_MAILBOX_HOLDER;
options.waitForTransferNotification = true; options.waitForTransferNotification = true;
...@@ -691,15 +695,15 @@ class MockRuntime { ...@@ -691,15 +695,15 @@ class MockRuntime {
transportOptions: options transportOptions: options
}; };
let dataProviderPtr = new device.mojom.XRFrameDataProviderPtr(); const dataProviderPtr = new device.mojom.XRFrameDataProviderPtr();
let dataProviderRequest = mojo.makeRequest(dataProviderPtr); const dataProviderRequest = mojo.makeRequest(dataProviderPtr);
this.dataProviderBinding_ = new mojo.Binding( this.dataProviderBinding_ = new mojo.Binding(
device.mojom.XRFrameDataProvider, this, dataProviderRequest); device.mojom.XRFrameDataProvider, this, dataProviderRequest);
let clientReceiver = mojo.makeRequest(this.sessionClient_); const clientReceiver = mojo.makeRequest(this.sessionClient_);
let enabled_features = []; const enabled_features = [];
for(let i = 0; i < sessionOptions.requiredFeatures.length; i++) { for (let i = 0; i < sessionOptions.requiredFeatures.length; i++) {
if (this.supportedFeatures_.indexOf(sessionOptions.requiredFeatures[i]) !== -1) { if (this.supportedFeatures_.indexOf(sessionOptions.requiredFeatures[i]) !== -1) {
enabled_features.push(sessionOptions.requiredFeatures[i]); enabled_features.push(sessionOptions.requiredFeatures[i]);
} else { } else {
...@@ -738,7 +742,7 @@ class MockRuntime { ...@@ -738,7 +742,7 @@ class MockRuntime {
// Modifies passed in frameData to add hit test results. // Modifies passed in frameData to add hit test results.
_calculateHitTestResults(frameData) { _calculateHitTestResults(frameData) {
if(!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) { if (!this.supportedModes_.includes(device.mojom.XRSessionMode.kImmersiveAr)) {
return; return;
} }
...@@ -746,14 +750,14 @@ class MockRuntime { ...@@ -746,14 +750,14 @@ class MockRuntime {
frameData.hitTestSubscriptionResults.results = []; frameData.hitTestSubscriptionResults.results = [];
frameData.hitTestSubscriptionResults.transientInputResults = []; frameData.hitTestSubscriptionResults.transientInputResults = [];
if(!this.world_) { if (!this.world_) {
return; return;
} }
// Non-transient hit test: // Non-transient hit test:
for(const [id, subscription] of this.hitTestSubscriptions_) { for (const [id, subscription] of this.hitTestSubscriptions_) {
const mojo_from_native_origin = this._getMojoFromNativeOrigin(subscription.nativeOriginInformation); const mojo_from_native_origin = this._getMojoFromNativeOrigin(subscription.nativeOriginInformation);
if(!mojo_from_native_origin) continue; if (!mojo_from_native_origin) continue;
const ray_origin = {x: subscription.ray.origin.x, y: subscription.ray.origin.y, z: subscription.ray.origin.z, w: 1}; const ray_origin = {x: subscription.ray.origin.x, y: subscription.ray.origin.y, z: subscription.ray.origin.z, w: 1};
const ray_direction = {x: subscription.ray.direction.x, y: subscription.ray.direction.y, z: subscription.ray.direction.z, w: 0}; const ray_direction = {x: subscription.ray.direction.x, y: subscription.ray.direction.y, z: subscription.ray.direction.z, w: 0};
...@@ -775,7 +779,7 @@ class MockRuntime { ...@@ -775,7 +779,7 @@ class MockRuntime {
_hitTestWorld(origin, direction, entityTypes) { _hitTestWorld(origin, direction, entityTypes) {
let result = []; let result = [];
for(const region of this.world_.hitTestRegions) { for (const region of this.world_.hitTestRegions) {
const partial_result = this._hitTestRegion( const partial_result = this._hitTestRegion(
region, region,
origin, direction, origin, direction,
...@@ -785,7 +789,7 @@ class MockRuntime { ...@@ -785,7 +789,7 @@ class MockRuntime {
} }
return result.sort((lhs, rhs) => lhs.distance - rhs.distance); return result.sort((lhs, rhs) => lhs.distance - rhs.distance);
}; }
// Hit tests the passed in ray (expressed as origin and direction) against world region. // Hit tests the passed in ray (expressed as origin and direction) against world region.
// |entityTypes| is a set of FakeXRRegionTypes. // |entityTypes| is a set of FakeXRRegionTypes.
...@@ -798,14 +802,14 @@ class MockRuntime { ...@@ -798,14 +802,14 @@ class MockRuntime {
"mesh":null "mesh":null
}; };
if(!entityTypes.includes(regionNameToMojoEnum[region.type])) { if (!entityTypes.includes(regionNameToMojoEnum[region.type])) {
return []; return [];
} }
const result = []; const result = [];
for(const face of region.faces) { for (const face of region.faces) {
const maybe_hit = this._hitTestFace(face, origin, direction); const maybe_hit = this._hitTestFace(face, origin, direction);
if(maybe_hit) { if (maybe_hit) {
result.push(maybe_hit); result.push(maybe_hit);
} }
} }
...@@ -845,7 +849,7 @@ class MockRuntime { ...@@ -845,7 +849,7 @@ class MockRuntime {
const numerator = dot(sub(point_A, origin), normal); const numerator = dot(sub(point_A, origin), normal);
const denominator = dot(direction, normal); const denominator = dot(direction, normal);
if(Math.abs(denominator) < 0.0001) { if (Math.abs(denominator) < 0.0001) {
// Planes are nearly parallel - there's either infinitely many intersection points or 0. // Planes are nearly parallel - there's either infinitely many intersection points or 0.
// Both cases signify a "no hit" for us. // Both cases signify a "no hit" for us.
return null; return null;
...@@ -853,7 +857,7 @@ class MockRuntime { ...@@ -853,7 +857,7 @@ class MockRuntime {
// Single intersection point between the infinite plane and the line (*not* ray). // Single intersection point between the infinite plane and the line (*not* ray).
// Need to calculate the hit test matrix taking into account the face vertices. // Need to calculate the hit test matrix taking into account the face vertices.
const distance = numerator / denominator; const distance = numerator / denominator;
if(distance < 0) { if (distance < 0) {
// Line - plane intersection exists, but not the half-line - plane does not. // Line - plane intersection exists, but not the half-line - plane does not.
return null; return null;
} else { } else {
...@@ -864,7 +868,7 @@ class MockRuntime { ...@@ -864,7 +868,7 @@ class MockRuntime {
let z_axis = null; let z_axis = null;
const cos_direction_and_y_axis = dot(direction, y_axis); const cos_direction_and_y_axis = dot(direction, y_axis);
if(Math.abs(cos_direction_and_y_axis) > 0.9999) { if (Math.abs(cos_direction_and_y_axis) > 0.9999) {
// Ray and the hit test normal are co-linear - try using the 'up' or 'right' vector's projection on the face plane as the Z axis. // Ray and the hit test normal are co-linear - try using the 'up' or 'right' vector's projection on the face plane as the Z axis.
// Note: this edge case is currently not covered by the spec. // Note: this edge case is currently not covered by the spec.
const up = {x: 0.0, y: 1.0, z: 0.0, w: 0.0}; const up = {x: 0.0, y: 1.0, z: 0.0, w: 0.0};
...@@ -881,7 +885,7 @@ class MockRuntime { ...@@ -881,7 +885,7 @@ class MockRuntime {
const x_axis = normalize(cross(y_axis, z_axis)); const x_axis = normalize(cross(y_axis, z_axis));
// Filter out the points not in polygon. // Filter out the points not in polygon.
if(!XRMathHelper.pointInFace(intersection_point, face)) { if (!XRMathHelper.pointInFace(intersection_point, face)) {
return null; return null;
} }
...@@ -928,19 +932,19 @@ class MockRuntime { ...@@ -928,19 +932,19 @@ class MockRuntime {
]; ];
}; };
if(nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) { if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.inputSourceId) {
if(!this.input_sources_.has(nativeOriginInformation.inputSourceId)) { if (!this.input_sources_.has(nativeOriginInformation.inputSourceId)) {
return null; return null;
} else { } else {
const inputSource = this.input_sources_.get(nativeOriginInformation.inputSourceId); const inputSource = this.input_sources_.get(nativeOriginInformation.inputSourceId);
return inputSource.mojo_from_input_.matrix; return inputSource.mojo_from_input_.matrix;
} }
} else if(nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) { } else if (nativeOriginInformation.$tag == device.mojom.XRNativeOriginInformation.Tags.referenceSpaceCategory) {
switch(nativeOriginInformation.referenceSpaceCategory) { switch (nativeOriginInformation.referenceSpaceCategory) {
case device.mojom.XRReferenceSpaceCategory.LOCAL: case device.mojom.XRReferenceSpaceCategory.LOCAL:
return identity(); return identity();
case device.mojom.XRReferenceSpaceCategory.LOCAL_FLOOR: case device.mojom.XRReferenceSpaceCategory.LOCAL_FLOOR:
if(this.displayInfo_ == null || this.displayInfo_.stageParameters == null if (this.displayInfo_ == null || this.displayInfo_.stageParameters == null
|| this.displayInfo_.stageParameters.standingTransform == null) { || this.displayInfo_.stageParameters.standingTransform == null) {
console.warn("Standing transform not available."); console.warn("Standing transform not available.");
return null; return null;
...@@ -1097,10 +1101,10 @@ class MockXRInputSource { ...@@ -1097,10 +1101,10 @@ class MockXRInputSource {
return; return;
} }
let supported_button_map = {}; const supported_button_map = {};
this.gamepad_ = this.getEmptyGamepad(); this.gamepad_ = this.getEmptyGamepad();
for (let i = 0; i < supportedButtons.length; i++) { for (let i = 0; i < supportedButtons.length; i++) {
let buttonType = supportedButtons[i].buttonType; const buttonType = supportedButtons[i].buttonType;
this.supported_buttons_.push(buttonType); this.supported_buttons_.push(buttonType);
supported_button_map[buttonType] = supportedButtons[i]; supported_button_map[buttonType] = supportedButtons[i];
} }
...@@ -1127,7 +1131,7 @@ class MockXRInputSource { ...@@ -1127,7 +1131,7 @@ class MockXRInputSource {
pressed: false, pressed: false,
touched: false, touched: false,
value: 0 value: 0
} };
} }
} }
...@@ -1143,8 +1147,8 @@ class MockXRInputSource { ...@@ -1143,8 +1147,8 @@ class MockXRInputSource {
throw new Error("Tried to update state on an unsupported button"); throw new Error("Tried to update state on an unsupported button");
} }
let buttonIndex = this.getButtonIndex(buttonState.buttonType); const buttonIndex = this.getButtonIndex(buttonState.buttonType);
let axesStartIndex = this.getAxesStartIndex(buttonState.buttonType); const axesStartIndex = this.getAxesStartIndex(buttonState.buttonType);
if (buttonIndex == -1) { if (buttonIndex == -1) {
throw new Error("Unknown Button Type!"); throw new Error("Unknown Button Type!");
...@@ -1162,7 +1166,7 @@ class MockXRInputSource { ...@@ -1162,7 +1166,7 @@ class MockXRInputSource {
// Helpers for Mojom // Helpers for Mojom
getInputSourceState() { getInputSourceState() {
let input_state = new device.mojom.XRInputSourceState(); const input_state = new device.mojom.XRInputSourceState();
input_state.sourceId = this.source_id_; input_state.sourceId = this.source_id_;
...@@ -1180,7 +1184,7 @@ class MockXRInputSource { ...@@ -1180,7 +1184,7 @@ class MockXRInputSource {
input_state.emulatedPosition = this.emulated_position_; input_state.emulatedPosition = this.emulated_position_;
if (this.desc_dirty_) { if (this.desc_dirty_) {
let input_desc = new device.mojom.XRInputSourceDescription(); const input_desc = new device.mojom.XRInputSourceDescription();
switch (this.target_ray_mode_) { switch (this.target_ray_mode_) {
case 'gaze': case 'gaze':
...@@ -1223,7 +1227,7 @@ class MockXRInputSource { ...@@ -1223,7 +1227,7 @@ class MockXRInputSource {
getEmptyGamepad() { getEmptyGamepad() {
// Mojo complains if some of the properties on Gamepad are null, so set // Mojo complains if some of the properties on Gamepad are null, so set
// everything to reasonable defaults that tests can override. // everything to reasonable defaults that tests can override.
let gamepad = new device.mojom.Gamepad(); const gamepad = new device.mojom.Gamepad();
gamepad.connected = true; gamepad.connected = true;
gamepad.id = ""; gamepad.id = "";
gamepad.timestamp = 0; gamepad.timestamp = 0;
...@@ -1252,8 +1256,8 @@ class MockXRInputSource { ...@@ -1252,8 +1256,8 @@ class MockXRInputSource {
return; return;
} }
let buttonIndex = this.getButtonIndex(buttonState.buttonType); const buttonIndex = this.getButtonIndex(buttonState.buttonType);
let axesStartIndex = this.getAxesStartIndex(buttonState.buttonType); const axesStartIndex = this.getAxesStartIndex(buttonState.buttonType);
if (buttonIndex == -1) { if (buttonIndex == -1) {
throw new Error("Unknown Button Type!"); throw new Error("Unknown Button Type!");
...@@ -1314,8 +1318,8 @@ class MockXRPresentationProvider { ...@@ -1314,8 +1318,8 @@ class MockXRPresentationProvider {
} }
bindProvider(request) { bindProvider(request) {
let providerPtr = new device.mojom.XRPresentationProviderPtr(); const providerPtr = new device.mojom.XRPresentationProviderPtr();
let providerRequest = mojo.makeRequest(providerPtr); const providerRequest = mojo.makeRequest(providerPtr);
this.binding_.close(); this.binding_.close();
...@@ -1356,7 +1360,7 @@ class MockXRPresentationProvider { ...@@ -1356,7 +1360,7 @@ class MockXRPresentationProvider {
// This is a temporary workaround for the fact that spinning up webxr before // This is a temporary workaround for the fact that spinning up webxr before
// the mojo interceptors are created will cause the interceptors to not get // the mojo interceptors are created will cause the interceptors to not get
// registered, so we have to create this before we query xr; // registered, so we have to create this before we query xr;
let XRTest = new ChromeXRTest(); const XRTest = new ChromeXRTest();
// This test API is also used to run Chrome's internal legacy VR tests; however, // This test API is also used to run Chrome's internal legacy VR tests; however,
// those fail if navigator.xr has been used. Those tests will set a bool telling // those fail if navigator.xr has been used. Those tests will set a bool telling
......
...@@ -11,9 +11,9 @@ MockRuntime.prototype.setHitTestResults = function(results) { ...@@ -11,9 +11,9 @@ MockRuntime.prototype.setHitTestResults = function(results) {
// XREnvironmentIntegrationProvider implementation // XREnvironmentIntegrationProvider implementation
MockRuntime.prototype.requestHitTest = function(ray) { MockRuntime.prototype.requestHitTest = function(ray) {
var hit_results = this.hittest_results_; let hit_results = this.hittest_results_;
if (!hit_results) { if (!hit_results) {
var hit = new device.mojom.XRHitResult(); const hit = new device.mojom.XRHitResult();
// No change to the underlying matrix/leaving it null results in identity. // No change to the underlying matrix/leaving it null results in identity.
hit.hitMatrix = new gfx.mojom.Transform(); hit.hitMatrix = new gfx.mojom.Transform();
...@@ -30,7 +30,10 @@ MockRuntime.prototype.getMissingFrameCount = function() { ...@@ -30,7 +30,10 @@ MockRuntime.prototype.getMissingFrameCount = function() {
return this.presentation_provider_.missing_frame_count_; return this.presentation_provider_.missing_frame_count_;
}; };
MockRuntime.prototype._injectAdditionalFrameData_preLightEstimation = MockRuntime.prototype._injectAdditionalFrameData;
MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) { MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) {
this._injectAdditionalFrameData_preLightEstimation(options, frameData);
if (!options || !options.includeLightingEstimationData) { if (!options || !options.includeLightingEstimationData) {
return; return;
} }
...@@ -38,7 +41,7 @@ MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData) ...@@ -38,7 +41,7 @@ MockRuntime.prototype._injectAdditionalFrameData = function(options, frameData)
frameData.lightEstimationData = { frameData.lightEstimationData = {
lightProbe: { lightProbe: {
sphericalHarmonics: { sphericalHarmonics: {
coefficients: new Array(9).fill().map((x, i) => { return { red: i, green: i, blue: i }; }), coefficients: new Array(9).fill().map((x, i) => ({ red: i, green: i, blue: i })),
}, },
mainLightDirection: { x: 0, y: 1, z: 0 }, mainLightDirection: { x: 0, y: 1, z: 0 },
mainLightIntensity: { red: 1, green: 1, blue: 1 }, mainLightIntensity: { red: 1, green: 1, blue: 1 },
...@@ -82,7 +85,7 @@ MockXRInputSource.prototype.getInputSourceStateCommon = ...@@ -82,7 +85,7 @@ MockXRInputSource.prototype.getInputSourceStateCommon =
MockXRInputSource.prototype.getInputSourceState; MockXRInputSource.prototype.getInputSourceState;
MockXRInputSource.prototype.getInputSourceState = function() { MockXRInputSource.prototype.getInputSourceState = function() {
let input_state = this.getInputSourceStateCommon(); const input_state = this.getInputSourceStateCommon();
console.log('getInputSourceState this.overlay_pointer_position_=' + JSON.stringify(this.overlay_pointer_position_)); console.log('getInputSourceState this.overlay_pointer_position_=' + JSON.stringify(this.overlay_pointer_position_));
if (this.overlay_pointer_position_) { if (this.overlay_pointer_position_) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment