4 <title>WebGL in OffscreenCanvas
</title>
5 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
6 <script src=
"offscreencanvas.js"></script>
7 <link rel=
"stylesheet" href=
"/tests/SimpleTest/test.css">
10 <canvas id=
"c" width=
"64" height=
"64"></canvas>
11 <canvas id=
"c-mt" width=
"64" height=
"64"></canvas>
12 <canvas id=
"c-ref" width=
"64" height=
"64"></canvas>
15 SimpleTest
.waitForExplicitFinish();
17 function testBlob(blob
, callback
) {
19 // Fill c-ref with green color.
20 var c
= document
.getElementById("c-ref");
21 var ctx
= c
.getContext("2d");
22 ctx
.rect(0, 0, 64, 64);
23 ctx
.fillStyle
= "#00FF00";
25 var reader
= new FileReader();
26 reader
.onload = function(e
) {
27 ok(c
.toDataURL() == e
.target
.result
, "toBlob should return a 64x64 green square");
30 reader
.readAsDataURL(blob
);
33 function runTestOnMainThread() {
34 var htmlCanvas
= document
.getElementById("c-mt");
35 ok(htmlCanvas
, "Should have HTML canvas element");
37 window
.onmessage = function(evt
) {
38 var msg
= evt
.data
|| {};
39 if (msg
.type
== "test") {
40 ok(msg
.result
, msg
.name
);
42 if (msg
.type
== "blob") {
43 testBlob(msg
.blob
, SimpleTest
.finish
);
47 ok(htmlCanvas
.transferControlToOffscreen
, "HTMLCanvasElement has transferControlToOffscreen function");
49 var offscreenCanvas
= htmlCanvas
.transferControlToOffscreen();
50 ok(offscreenCanvas
, "Expected transferControlToOffscreen to succeed");
52 entryFunction('webgl_toblob', '', offscreenCanvas
);
57 var htmlCanvas
= document
.getElementById("c");
58 var worker
= new Worker("offscreencanvas.js");
60 ok(htmlCanvas
, "Should have HTML canvas element");
61 ok(worker
, "Web worker successfully created");
63 worker
.onmessage = function(evt
) {
64 var msg
= evt
.data
|| {};
65 if (msg
.type
== "test") {
66 ok(msg
.result
, msg
.name
);
68 if (msg
.type
== "blob") {
69 testBlob(msg
.blob
, function() {
71 runTestOnMainThread();
76 ok(htmlCanvas
.transferControlToOffscreen
, "HTMLCanvasElement has transferControlToOffscreen function");
78 var offscreenCanvas
= htmlCanvas
.transferControlToOffscreen();
79 ok(offscreenCanvas
, "Expected transferControlToOffscreen to succeed");
81 worker
.postMessage({test
: 'webgl_toblob', canvas
: offscreenCanvas
}, [offscreenCanvas
]);
84 SpecialPowers
.pushPrefEnv({'set': [
85 ['webgl.force-enabled', true],