Skip to content

Commit 708284f

Browse files
alcooper91chromium-wpt-export-bot
authored andcommitted
Relax requirements around depth sensing preferences
The Depth Sensing spec was recently updated to allow UAs to determine the supported format if the "preferences" arrays passed in to the depthSensing dictionary on XRSessionInit are empty. This updates Chrome to take advantage of that API shape. Bug: 344484984 Change-Id: Ib71c395af0cc354b835e96169f5420c552481e36 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5594551 Reviewed-by: Elly FJ <[email protected]> Commit-Queue: Alexander Cooper <[email protected]> Reviewed-by: Piotr Bialecki <[email protected]> Reviewed-by: Tom Sepez <[email protected]> Cr-Commit-Position: refs/heads/main@{#1309698}
1 parent aa48f7f commit 708284f

File tree

3 files changed

+177
-13
lines changed

3 files changed

+177
-13
lines changed

resources/chromium/webxr-test.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -1188,16 +1188,18 @@ class MockRuntime {
11881188

11891189
const enabled_features = [];
11901190
for (let i = 0; i < sessionOptions.requiredFeatures.length; i++) {
1191-
if (this.supportedFeatures_.indexOf(sessionOptions.requiredFeatures[i]) !== -1) {
1192-
enabled_features.push(sessionOptions.requiredFeatures[i]);
1191+
const feature = sessionOptions.requiredFeatures[i];
1192+
if (this._runtimeSupportsFeature(feature, sessionOptions)) {
1193+
enabled_features.push(feature);
11931194
} else {
11941195
return Promise.resolve({session: null});
11951196
}
11961197
}
11971198

11981199
for (let i =0; i < sessionOptions.optionalFeatures.length; i++) {
1199-
if (this.supportedFeatures_.indexOf(sessionOptions.optionalFeatures[i]) !== -1) {
1200-
enabled_features.push(sessionOptions.optionalFeatures[i]);
1200+
const feature = sessionOptions.optionalFeatures[i];
1201+
if (this._runtimeSupportsFeature(feature, sessionOptions)) {
1202+
enabled_features.push(feature);
12011203
}
12021204
}
12031205

@@ -1234,20 +1236,31 @@ class MockRuntime {
12341236

12351237
_runtimeSupportsSession(options) {
12361238
let result = this.supportedModes_.includes(options.mode);
1237-
1238-
if (options.requiredFeatures.includes(xrSessionMojom.XRSessionFeature.DEPTH)
1239-
|| options.optionalFeatures.includes(xrSessionMojom.XRSessionFeature.DEPTH)) {
1240-
result &= options.depthOptions.usagePreferences.includes(
1241-
xrSessionMojom.XRDepthUsage.kCPUOptimized);
1242-
result &= options.depthOptions.dataFormatPreferences.includes(
1243-
xrSessionMojom.XRDepthDataFormat.kLuminanceAlpha);
1244-
}
1245-
12461239
return Promise.resolve({
12471240
supportsSession: result,
12481241
});
12491242
}
12501243

1244+
_runtimeSupportsFeature(feature, options) {
1245+
if (this.supportedFeatures_.indexOf(feature) === -1) {
1246+
return false;
1247+
}
1248+
1249+
switch (feature) {
1250+
case xrSessionMojom.XRSessionFeature.DEPTH:
1251+
// This matches what Chrome can currently support.
1252+
return options.depthOptions &&
1253+
(options.depthOptions.usagePreferences.length == 0 ||
1254+
options.depthOptions.usagePreferences.includes(
1255+
xrSessionMojom.XRDepthUsage.kCPUOptimized)) &&
1256+
(options.depthOptions.dataFormatPreferences.length == 0 ||
1257+
options.depthOptions.dataFormatPreferences.includes(
1258+
xrSessionMojom.XRDepthDataFormat.kLuminanceAlpha));
1259+
default:
1260+
return true;
1261+
}
1262+
}
1263+
12511264
// Private functions - utilities:
12521265
_nativeOriginKnown(nativeOriginInformation){
12531266

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<!DOCTYPE html>
2+
<script src=/resources/testharness.js></script>
3+
<script src=/resources/testharnessreport.js></script>
4+
<script src="../resources/webxr_util.js"></script>
5+
<script src="../resources/webxr_test_constants.js"></script>
6+
<script src="../resources/webxr_test_constants_fake_depth.js"></script>
7+
<script>
8+
const depthConfigurationTestGenerator =
9+
function (sessionOptions, shouldGrantSession, shouldDepthBeEnabled = true) {
10+
return (t) => {
11+
return navigator.xr.test.simulateDeviceConnection(IMMERSIVE_AR_DEVICE)
12+
.then((controller) => new Promise((resolve, reject) => {
13+
navigator.xr.test.simulateUserActivation(() => {
14+
navigator.xr.requestSession('immersive-ar', sessionOptions)
15+
.then((session) => {
16+
return session.end().then(() => {
17+
if (!shouldGrantSession) {
18+
reject("Session granted when expected rejection.");
19+
return;
20+
}
21+
22+
t.step(() => {
23+
let depthEnabled = session.enabledFeatures.includes('depth-sensing');
24+
assert_true(depthEnabled == shouldDepthBeEnabled);
25+
});
26+
27+
resolve();
28+
});
29+
})
30+
.catch((err) => {
31+
if (shouldGrantSession) {
32+
reject("Session rejected with error: " + err);
33+
return;
34+
}
35+
36+
resolve();
37+
});
38+
});
39+
}));
40+
};
41+
};
42+
43+
// Valid configurations when depth is a required feature
44+
xr_promise_test(
45+
"depthSensing - Required - Fully populated grants session",
46+
depthConfigurationTestGenerator({
47+
'requiredFeatures': ['depth-sensing'],
48+
depthSensing: {
49+
usagePreference: DEPTH_CONFIG_ALL_USAGES,
50+
dataFormatPreference: DEPTH_CONFIG_ALL_FORMATS
51+
},
52+
}, /*shouldGrantSession=*/true));
53+
54+
xr_promise_test(
55+
"depthSensing - Required - Empty usage grants session",
56+
depthConfigurationTestGenerator({
57+
'requiredFeatures': ['depth-sensing'],
58+
depthSensing: {
59+
usagePreference: [],
60+
dataFormatPreference: DEPTH_CONFIG_ALL_FORMATS
61+
},
62+
}, /*shouldGrantSession=*/true));
63+
64+
xr_promise_test(
65+
"depthSensing - Required - Empty format grants session",
66+
depthConfigurationTestGenerator({
67+
'requiredFeatures': ['depth-sensing'],
68+
depthSensing: {
69+
usagePreference: DEPTH_CONFIG_ALL_USAGES,
70+
dataFormatPreference: [],
71+
},
72+
}, /*shouldGrantSession=*/true));
73+
74+
xr_promise_test(
75+
"depthSensing - Required - Empty usage and format grants session",
76+
depthConfigurationTestGenerator({
77+
'requiredFeatures': ['depth-sensing'],
78+
depthSensing: {
79+
usagePreference: [],
80+
dataFormatPreference: [],
81+
},
82+
}, /*shouldGrantSession=*/true));
83+
84+
// Invalid configurations when depth is a required feature
85+
xr_promise_test(
86+
"depthSensing - Required - Missing usage rejects session",
87+
depthConfigurationTestGenerator({
88+
'requiredFeatures': ['depth-sensing'],
89+
depthSensing: {
90+
dataFormatPreference: [],
91+
},
92+
}, /*shouldGrantSession=*/false));
93+
94+
xr_promise_test(
95+
"depthSensing - Required - Missing format rejects session",
96+
depthConfigurationTestGenerator({
97+
'requiredFeatures': ['depth-sensing'],
98+
depthSensing: {
99+
usagePreference: [],
100+
},
101+
}, /*shouldGrantSession=*/false));
102+
103+
xr_promise_test(
104+
"depthSensing - Required - Missing usage and format rejects session",
105+
depthConfigurationTestGenerator({
106+
'requiredFeatures': ['depth-sensing'],
107+
depthSensing: {},
108+
}, /*shouldGrantSession=*/false));
109+
110+
xr_promise_test(
111+
"depthSensing - Required - Missing configuration rejects session",
112+
depthConfigurationTestGenerator({
113+
'requiredFeatures': ['depth-sensing'],
114+
}, /*shouldGrantSession=*/false));
115+
116+
// Invalid configurations when depth is an optional feature
117+
xr_promise_test(
118+
"depthSensing - Optional - Missing usage optional still rejects session",
119+
depthConfigurationTestGenerator({
120+
'optionalFeatures': ['depth-sensing'],
121+
depthSensing: {
122+
dataFormatPreference: [],
123+
},
124+
}, /*shouldGrantSession=*/false));
125+
126+
xr_promise_test(
127+
"depthSensing - Optional - Missing format optional still rejects session",
128+
depthConfigurationTestGenerator({
129+
'optionalFeatures': ['depth-sensing'],
130+
depthSensing: {
131+
usagePreference: [],
132+
},
133+
}, /*shouldGrantSession=*/false));
134+
135+
xr_promise_test(
136+
"depthSensing - Optional - Missing usage and format optional still rejects session",
137+
depthConfigurationTestGenerator({
138+
'optionalFeatures': ['depth-sensing'],
139+
depthSensing: {},
140+
}, /*shouldGrantSession=*/false));
141+
142+
xr_promise_test(
143+
"depthSensing - Optional - Missing configuration optional grants session without depth",
144+
depthConfigurationTestGenerator({
145+
'optionalFeatures': ['depth-sensing'],
146+
}, /*shouldGrantSession=*/true,
147+
/*shouldDepthBeEnabled=*/false));
148+
</script>

webxr/resources/webxr_test_constants_fake_depth.js

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const getExpectedValueAt = function(column, row) {
6767
return Math.pow(column+1, row) * RAW_VALUE_TO_METERS;
6868
};
6969

70+
const DEPTH_CONFIG_ALL_FORMATS = ['luminance-alpha', 'float32'];
71+
const DEPTH_CONFIG_ALL_USAGES= ['gpu-optimized', 'cpu-optimized'];
72+
7073
const VALID_DEPTH_CONFIG_CPU_USAGE = {
7174
usagePreference: ['cpu-optimized'],
7275
dataFormatPreference: ['luminance-alpha', 'float32'],

0 commit comments

Comments
 (0)