Bug 1935611 - Fix libyuv/libpng link failed for loongarch64. r=glandium,tnikkel,ng
[gecko.git] / dom / canvas / test / test_offscreencanvas_dynamic_fallback.html
blobc98ce30f908694e20345c7b111ba015998fc78b7
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <title>WebGL in OffscreenCanvas</title>
5 <script src="/tests/SimpleTest/SimpleTest.js"></script>
6 <script src="/tests/SimpleTest/WindowSnapshot.js"></script>
7 <link rel="stylesheet" href="/tests/SimpleTest/test.css">
8 </head>
9 <body>
10 <script>
12 SimpleTest.waitForExplicitFinish();
14 function createCanvas(initWithMask) {
15 var canvas = document.createElement("canvas");
16 canvas.width = 64;
17 canvas.height = 64;
18 document.body.appendChild(canvas);
19 if (initWithMask) {
20 canvas.style.mask = "url('offscreencanvas_mask.svg#fade_mask_both')";
23 return canvas;
26 async function getRefSnapshot(initWithMask) {
27 var refCanvas = createCanvas(!initWithMask);
28 var ctx = refCanvas.getContext("2d");
29 ctx.rect(0, 0, 64, 64);
30 ctx.fillStyle = "#00FF00";
31 ctx.fill();
32 var result = await snapshotWindow(window);
33 document.body.removeChild(refCanvas);
34 return result;
37 function runTest(initWithMask) {
38 var htmlCanvas = createCanvas(initWithMask);
39 var worker = new Worker("offscreencanvas.js");
41 worker.onmessage = async function(evt) {
42 var msg = evt.data || {};
43 if (msg.type == "draw") {
44 if (msg.count === 10) {
45 // Change the fallback state dynamically when drawing count reaches 10.
46 if (initWithMask) {
47 htmlCanvas.style.mask = "";
48 } else {
49 htmlCanvas.style.mask = "url('offscreencanvas_mask.svg#fade_mask_both')";
51 } else if (msg.count === 20) {
52 worker.terminate();
53 var snapshotFallback = await snapshotWindow(window);
54 document.body.removeChild(htmlCanvas);
56 var results = compareSnapshots(snapshotFallback, await getRefSnapshot(initWithMask), true);
57 ok(results[0], "after dynamic fallback, screenshots should be the same");
59 if (initWithMask) {
60 SimpleTest.finish();
61 } else {
62 runTest(true);
68 var offscreenCanvas = htmlCanvas.transferControlToOffscreen();
70 worker.postMessage({test: 'webgl_fallback', canvas: offscreenCanvas}, [offscreenCanvas]);
73 SpecialPowers.pushPrefEnv({'set': [
74 ['webgl.force-enabled', true],
75 ]}, runTest.bind(false));
77 </script>
78 </body>
79 </html>