blob: 43ff8f5840299d565ca9bcb71ad48481078a1599 [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-test-utils.js"></script>
<script src="../xr/resources/test-constants.js"></script>
<canvas id="webgl-canvas"></canvas>
<script>
let testName = "Ensure framebuffer scaling works as expected.";
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);
let defaultFramebufferWidth = webglLayer.framebufferWidth;
let defaultFramebufferHeight = webglLayer.framebufferHeight;
let nativeScale = XRWebGLLayer.getNativeFramebufferScaleFactor(session);
t.step(() => {
// Ensure the framebuffer default sizes and native scale are all non-zero.
assert_greater_than(defaultFramebufferWidth, 0);
assert_greater_than(defaultFramebufferHeight, 0);
assert_greater_than(nativeScale, 0);
// The native scale should be the inverse for the default framebuffer scale.
assert_approx_equals(nativeScale, 1/fakeDeviceController.displayInfo_.webxrDefaultFramebufferScale, FLOAT_EPSILON);
});
webglLayer = new XRWebGLLayer(session, gl, { framebufferScaleFactor: nativeScale });
t.step(() => {
// Ensure that requesting a native scale framebuffer gives the expected result.
assert_approx_equals(webglLayer.framebufferWidth, defaultFramebufferWidth*nativeScale, 2);
assert_approx_equals(webglLayer.framebufferHeight, defaultFramebufferHeight*nativeScale, 2);
});
webglLayer = new XRWebGLLayer(session, gl, { framebufferScaleFactor: 0 });
t.step(() => {
// Ensure that the framebuffer has a lower bounds clamp.
assert_greater_than(webglLayer.framebufferWidth, 0);
assert_greater_than(webglLayer.framebufferHeight, 0);
});
webglLayer = new XRWebGLLayer(session, gl, { framebufferScaleFactor: 100 });
t.step(() => {
// Ensure that the framebuffer has a reasonable upper bounds clamp.
assert_less_than(webglLayer.framebufferWidth, defaultFramebufferWidth*100);
assert_less_than(webglLayer.framebufferHeight, defaultFramebufferHeight*100);
});
resolve();
});
xr_session_promise_test(
testFunction, fakeDeviceInitParams, requestSessionOptions, testName);
</script>