blob: 292d30d96004fc8ae39900bc6caf68422ea4461d [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="../xr/resources/xr-internal-device-mocking.js"></script>
<script src="../xr/resources/xr-test-utils.js"></script>
<script src="../xr/resources/test-constants.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "A frame should be submitted if the base layer was written to "
+ "during requestAnimationFrame";
let fakeDeviceInitParams = { supportsImmersive: true };
let requestSessionOptions = [{ immersive: true }];
let testFunction =
(session, t, fakeDeviceController) => new Promise((resolve, reject) => {
// Session must have a baseLayer or else frame requests will be ignored.
let webglLayer = new XRWebGLLayer(session, gl);
session.baseLayer = webglLayer;
function onSkipFrame(time, xrFrame) {
assert_equals(fakeDeviceController.getSubmitFrameCount(), 0);
assert_equals(fakeDeviceController.getMissingFrameCount(), 0);
// No GL commands issued.
session.requestAnimationFrame(onDrawToCanvas);
}
function onDrawToCanvas(time, xrFrame) {
// Ensure the previous step did not submit a frame.
assert_equals(fakeDeviceController.getSubmitFrameCount(), 0);
assert_equals(fakeDeviceController.getMissingFrameCount(), 1);
// Clear the canvas, but don't touch the framebuffer.
gl.clear(gl.COLOR_BUFFER_BIT);
session.requestAnimationFrame(onDrawToFramebuffer);
}
function onDrawToFramebuffer(time, xrFrame) {
// Ensure both previous steps did not submit frames.
assert_equals(fakeDeviceController.getSubmitFrameCount(), 0);
assert_equals(fakeDeviceController.getMissingFrameCount(), 2);
// Clear the VRWebGLLayer framebuffer.
gl.bindFramebuffer(gl.FRAMEBUFFER, webglLayer.framebuffer);
gl.clear(gl.COLOR_BUFFER_BIT);
// After the function returns ensure the frame was submitted.
window.setTimeout(() => {
assert_equals(fakeDeviceController.getSubmitFrameCount(), 1);
assert_equals(fakeDeviceController.getMissingFrameCount(), 2);
// Finished test.
resolve();
}, 100);
}
session.requestAnimationFrame(onSkipFrame);
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>