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">
12 SimpleTest
.waitForExplicitFinish();
14 function createCanvas(initWithMask
) {
15 var canvas
= document
.createElement("canvas");
18 document
.body
.appendChild(canvas
);
20 canvas
.style
.mask
= "url('offscreencanvas_mask.svg#fade_mask_both')";
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";
32 var result
= await
snapshotWindow(window
);
33 document
.body
.removeChild(refCanvas
);
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.
47 htmlCanvas
.style
.mask
= "";
49 htmlCanvas
.style
.mask
= "url('offscreencanvas_mask.svg#fade_mask_both')";
51 } else if (msg
.count
=== 20) {
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");
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));