blob: bb5de50adbd9724cc2ddc15eb712fc1891f22321 [file] [log] [blame]
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script>
<script src="file:///gen/device/vr/public/mojom/vr_service.mojom.js"></script>
<script src="../external/wpt/resources/chromium/webxr-test.js"></script>
<script src="../external/wpt/webxr/resources/webxr_test_constants.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "Ensure viewport scale changes only take effect on the next "
+ "frame and are properly clamped.";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [{ mode: 'immersive-vr' }];
let testFunction = function(session, t, fakeDeviceController) {
// Session must have a baseLayer or else frame requests will be ignored.
let webglLayer = new XRWebGLLayer(session, gl);
session.updateRenderState({ baseLayer: webglLayer });
// Need to have a valid pose or input event's don't process.
fakeDeviceController.setXRPresentationFrameData(VALID_POSE_MATRIX, [{
eye:"left",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}, {
eye:"right",
projectionMatrix: VALID_PROJECTION_MATRIX,
viewMatrix: VALID_VIEW_MATRIX
}]);
return session.requestReferenceSpace({ type: "stationary", subtype: "eye-level" }).then(
(referenceSpace) => new Promise(
(resolve) => {
let full_viewport;
function getCurrentViewport(xrFrame) {
let pose = xrFrame.getViewerPose(referenceSpace);
assert_not_equals(pose, null);
assert_not_equals(pose.views, null);
assert_greater_than(pose.views.length, 0);
return webglLayer.getViewport(pose.views[0]);
}
function onFirstFrame(time, xrFrame) {
full_viewport = getCurrentViewport(xrFrame);
webglLayer.requestViewportScaling(0.5);
let new_viewport = getCurrentViewport(xrFrame);
t.step(() => {
// Viewport should not change within this frame!
assert_equals(full_viewport.x, new_viewport.x);
assert_equals(full_viewport.y, new_viewport.y);
assert_equals(full_viewport.width, new_viewport.width);
assert_equals(full_viewport.height, new_viewport.height);
});
// This should be clamped to some non-zero lower bounds.
webglLayer.requestViewportScaling(0.0);
session.requestAnimationFrame(onSecondFrame);
}
function onSecondFrame(time, xrFrame) {
let new_viewport = getCurrentViewport(xrFrame);
t.step(() => {
// Viewport should never be zero width or height.
assert_greater_than(new_viewport.width, 0);
assert_greater_than(new_viewport.height, 0);
});
// This should be clamped to 1.0
webglLayer.requestViewportScaling(10.0);
session.requestAnimationFrame(onFinalFrame);
}
function onFinalFrame(time, xrFrame) {
let new_viewport = getCurrentViewport(xrFrame);
t.step(() => {
// Should be the full viewport again.
assert_equals(full_viewport.x, new_viewport.x);
assert_equals(full_viewport.y, new_viewport.y);
assert_equals(full_viewport.width, new_viewport.width);
assert_equals(full_viewport.height, new_viewport.height);
});
resolve();
}
session.requestAnimationFrame(onFirstFrame);
}
)
);
};
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>