blob: a3b8e7ac1345c6cf26977d791042ed61b38942ba [file] [edit]
// copyTo() of the VideoFrame of a WebGPU canvas gives straight alpha values in the requested color
// space, and drawing the frame gives the same values, for every format, alpha mode and color space of
// the canvas. Runs in the window and, with videoframe-copyto-worker.js, in a worker.
let device;
promise_setup(async () => {
const adapter = await navigator.gpu.requestAdapter();
device = await adapter.requestDevice();
});
async function testCopyTo(t, { canvasKind, format, alphaMode, colorSpace, contents })
{
let canvas = createTestCanvas(canvasKind);
let context = canvas.getContext("webgpu");
let frame = null;
t.add_cleanup(() => {
frame?.close();
context?.unconfigure();
detachTestCanvas(canvas);
frame = null;
context = null;
canvas = null;
collectGarbage();
});
assert_not_equals(context, null, "getContext()");
context.configure({ device, format, alphaMode, colorSpace, toneMapping: { mode: "standard" } });
// The colors of a WebGPU canvas are premultiplied, and those of an opaque one are drawn as they are.
const [r, g, b, a] = canvasFillColor(contents, true);
const encoder = device.createCommandEncoder();
const pass = encoder.beginRenderPass({
colorAttachments: [{ view: context.getCurrentTexture().createView(), clearValue: { r, g, b, a }, loadOp: "clear", storeOp: "store" }],
});
pass.end();
device.queue.submit([encoder.finish()]);
frame = new VideoFrame(canvas, { timestamp: 0 });
await assertCanvasFrameValues(frame, { colorSpace, isOpaque: alphaMode == "opaque", isPremultiplied: true }, contents);
}
for (const canvasKind of copyToCanvasKinds) {
for (const format of ["bgra8unorm", "rgba8unorm", "rgba16float"]) {
for (const alphaMode of ["opaque", "premultiplied"]) {
for (const colorSpace of ["srgb", "display-p3", "srgb-linear", "display-p3-linear"]) {
for (const contents of copyToContents) {
const params = { canvasKind, format, alphaMode, colorSpace, contents };
promise_test(t => testCopyTo(t, params), copyToTestName(params));
}
}
}
}
}