From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann <daniel.baumann@progress-linux.org> Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org> --- .../test_offscreencanvas_dynamic_fallback.html | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 dom/canvas/test/test_offscreencanvas_dynamic_fallback.html (limited to 'dom/canvas/test/test_offscreencanvas_dynamic_fallback.html') diff --git a/dom/canvas/test/test_offscreencanvas_dynamic_fallback.html b/dom/canvas/test/test_offscreencanvas_dynamic_fallback.html new file mode 100644 index 0000000000..732518668b --- /dev/null +++ b/dom/canvas/test/test_offscreencanvas_dynamic_fallback.html @@ -0,0 +1,80 @@ +<!DOCTYPE HTML> +<html> +<head> +<title>WebGL in OffscreenCanvas</title> +<script src="/tests/SimpleTest/SimpleTest.js"></script> +<script src="/tests/SimpleTest/WindowSnapshot.js"></script> +<link rel="stylesheet" href="/tests/SimpleTest/test.css"> +</head> +<body> +<script> + +SimpleTest.waitForExplicitFinish(); + +function createCanvas(initWithMask) { + var canvas = document.createElement("canvas"); + canvas.width = 64; + canvas.height = 64; + document.body.appendChild(canvas); + if (initWithMask) { + canvas.style.mask = "url('offscreencanvas_mask.svg#fade_mask_both')"; + } + + return canvas; +} + +async function getRefSnapshot(initWithMask) { + var refCanvas = createCanvas(!initWithMask); + var ctx = refCanvas.getContext("2d"); + ctx.rect(0, 0, 64, 64); + ctx.fillStyle = "#00FF00"; + ctx.fill(); + var result = await snapshotWindow(window); + document.body.removeChild(refCanvas); + return result; +} + +function runTest(initWithMask) { + var htmlCanvas = createCanvas(initWithMask); + var worker = new Worker("offscreencanvas.js"); + + worker.onmessage = async function(evt) { + var msg = evt.data || {}; + if (msg.type == "draw") { + if (msg.count === 10) { + // Change the fallback state dynamically when drawing count reaches 10. + if (initWithMask) { + htmlCanvas.style.mask = ""; + } else { + htmlCanvas.style.mask = "url('offscreencanvas_mask.svg#fade_mask_both')"; + } + } else if (msg.count === 20) { + worker.terminate(); + var snapshotFallback = await snapshotWindow(window); + document.body.removeChild(htmlCanvas); + + var results = compareSnapshots(snapshotFallback, await getRefSnapshot(initWithMask), true); + ok(results[0], "after dynamic fallback, screenshots should be the same"); + + if (initWithMask) { + SimpleTest.finish(); + } else { + runTest(true); + } + } + } + } + + var offscreenCanvas = htmlCanvas.transferControlToOffscreen(); + + worker.postMessage({test: 'webgl_fallback', canvas: offscreenCanvas}, [offscreenCanvas]); +} + +SpecialPowers.pushPrefEnv({'set': [ + ['gfx.offscreencanvas.enabled', true], + ['webgl.force-enabled', true], +]}, runTest.bind(false)); + +</script> +</body> +</html> -- cgit v1.2.3