OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 | 2 |
3 <!-- READ BEFORE UPDATING: | 3 <!-- READ BEFORE UPDATING: |
4 If this test is updated make sure to increment the "revision" value of the | 4 If this test is updated make sure to increment the "revision" value of the |
5 associated test in content/test/gpu/page_sets/pixel_tests.py. This will ensure | 5 associated test in content/test/gpu/page_sets/pixel_tests.py. This will ensure |
6 that the baseline images are regenerated on the next run. | 6 that the baseline images are regenerated on the next run. |
7 --> | 7 --> |
8 | 8 |
9 <html> | 9 <html> |
10 <head> | 10 <head> |
11 <title>OffscreenCanvas commit flow on worker thread: red square on white backgro
und.</title> | 11 <title>OffscreenCanvas transferToImageBitmap on worker thread: green and blue sq
uares on white background.</title> |
12 <style type="text/css"> | 12 <style type="text/css"> |
13 .nomargin { | 13 .nomargin { |
14 margin: 0px auto; | 14 margin: 0px auto; |
15 } | 15 } |
16 </style> | 16 </style> |
17 <script id="myWorker" type="text/worker"> | 17 <script id="myWorker" type="text/worker"> |
18 self.onmessage = function(e) { | 18 self.onmessage = function(e) { |
19 var transferredOffscreenCanvas = e.data; | 19 var canvas1 = new OffscreenCanvas(100, 100); |
20 var gl = transferredOffscreenCanvas.getContext("webgl"); | 20 var gl1 = canvas1.getContext('webgl'); |
21 gl.clearColor(1.0, 0.0, 0.0, 1.0); | 21 gl1.clearColor(0.0, 1.0, 0.0, 1.0); |
22 gl.clear(gl.COLOR_BUFFER_BIT); | 22 gl1.clear(gl1.COLOR_BUFFER_BIT); |
23 gl.commit(); | 23 |
24 self.postMessage(""); | 24 var canvas2 = new OffscreenCanvas(100, 100); |
| 25 var gl2 = canvas2.getContext('webgl'); |
| 26 gl2.clearColor(0.0, 0.0, 1.0, 1.0); |
| 27 gl2.clear(gl2.COLOR_BUFFER_BIT); |
| 28 |
| 29 var image1 = canvas1.transferToImageBitmap(); |
| 30 var image2 = canvas2.transferToImageBitmap(); |
| 31 self.postMessage({bitmap1: image1, bitmap2: image2}, [image1, image2]); |
25 }; | 32 }; |
26 </script> | 33 </script> |
27 <script> | 34 <script> |
28 var g_swapsBeforeAck = 15; | 35 var g_swapsBeforeAck = 15; |
29 | 36 |
30 function makeWorker(script) { | 37 function makeWorker(script) { |
31 var blob = new Blob([script]); | 38 var blob = new Blob([script]); |
32 return new Worker(URL.createObjectURL(blob)); | 39 return new Worker(URL.createObjectURL(blob)); |
33 } | 40 } |
34 | 41 |
35 function main() | 42 function main() |
36 { | 43 { |
37 draw(); | 44 draw(); |
38 } | 45 } |
39 | 46 |
40 function draw() | 47 function draw() |
41 { | 48 { |
42 var canvas = document.getElementById("c"); | |
43 var offscreenCanvas = canvas.transferControlToOffscreen(); | |
44 var worker = makeWorker(document.getElementById("myWorker").textContent); | 49 var worker = makeWorker(document.getElementById("myWorker").textContent); |
45 worker.postMessage(offscreenCanvas, [offscreenCanvas]); | 50 |
46 worker.onmessage = function (e) { | 51 worker.onmessage = function(msg) { |
| 52 var bitmap1 = msg.data.bitmap1; |
| 53 var bitmap2 = msg.data.bitmap2; |
| 54 var canvas1 = document.getElementById("canvas1"); |
| 55 var ctx1 = canvas1.getContext('bitmaprenderer'); |
| 56 ctx1.transferFromImageBitmap(bitmap1); |
| 57 |
| 58 var canvas2 = document.getElementById('canvas2'); |
| 59 var ctx2 = canvas2.getContext('bitmaprenderer'); |
| 60 ctx2.transferFromImageBitmap(bitmap2); |
47 waitForFinish(); | 61 waitForFinish(); |
48 } | 62 } |
| 63 |
| 64 worker.postMessage(""); |
49 } | 65 } |
50 | 66 |
51 function waitForFinish() | 67 function waitForFinish() |
52 { | 68 { |
53 if (g_swapsBeforeAck == 0) { | 69 if (g_swapsBeforeAck == 0) { |
54 domAutomationController.setAutomationId(1); | 70 domAutomationController.setAutomationId(1); |
55 domAutomationController.send("SUCCESS"); | 71 domAutomationController.send("SUCCESS"); |
56 } else { | 72 } else { |
57 g_swapsBeforeAck--; | 73 g_swapsBeforeAck--; |
58 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; | 74 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; |
59 window.webkitRequestAnimationFrame(waitForFinish); | 75 window.webkitRequestAnimationFrame(waitForFinish); |
60 } | 76 } |
61 } | 77 } |
62 </script> | 78 </script> |
63 </head> | 79 </head> |
64 <body onload="main()"> | 80 <body onload="main()"> |
65 <div style="position:relative; width:200px; height:200px; background-color:white
"> | 81 <div style="position:relative; width:200px; height:200px; background-color:white
"> |
66 </div> | 82 </div> |
67 <div id="container" style="position:absolute; top:0px; left:0px"> | 83 <div id="container" style="position:absolute; top:0px; left:0px"> |
68 <canvas id="c" width="200" height="200" class="nomargin"></canvas> | 84 <canvas id="canvas1" width="100" height="100" class="nomargin"></canvas> |
| 85 </div> |
| 86 <div id="container" style="position:absolute; top:0px; left:150px"> |
| 87 <canvas id="canvas2" width="100" height="100" class="nomargin"></canvas> |
69 </div> | 88 </div> |
70 </body> | 89 </body> |
71 </html> | 90 </html> |
OLD | NEW |