<!DOCTYPE html>
<meta charset="utf-8">
<title>WebGPU onscreen canvas (not in DOM) getCurrentTexture expiry tests</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="./canvas-get-current-texture-expiry.js"></script>
<script>
"use strict";
setup({single_test: true});
onload = async function() {
const canvas = document.createElement('canvas');
canvas.width = 1;
canvas.height = 1;
// Position set to always sit at top left to make sure the canvas is visible
canvas.style.position = 'fixed';
canvas.style.top = '0';
canvas.style.left = '0';
// Set it to transparent so that if multiple canvas are created, they are still visible.
canvas.style.opacity = '50%';
const adapter = await navigator.gpu.requestAdapter();
assert_true(adapter instanceof GPUAdapter, 'Failed to request WebGPU adapter');
const device = await adapter.requestDevice();
assert_true(device instanceof GPUDevice, 'Failed to request WebGPU device');
const ctx = canvas.getContext('webgpu');
assert_true(ctx instanceof GPUCanvasContext, 'Failed to get WebGPU context from canvas');
ctx.configure({
device: device,
format: navigator.gpu.getPreferredCanvasFormat(),
usage: GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_SRC,
});
await test(ctx, device, 'runInNewCanvasFrame', true);
await test(ctx, device, 'runInNewCanvasFrame', false);
await test(ctx, device, 'requestAnimationFrame', true);
await test(ctx, device, 'requestAnimationFrame', false);
done();
}
</script>