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 uare on white background.</title> |
Ken Russell (switch to Gerrit)
2016/09/26 18:21:47
Same here.
| |
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 </style> | |
Ken Russell (switch to Gerrit)
2016/09/26 18:21:47
This extra closing "style" tag looks wrong.
| |
17 <script id="myWorker" type="text/worker"> | 18 <script id="myWorker" type="text/worker"> |
18 self.onmessage = function(e) { | 19 self.onmessage = function(e) { |
19 var transferredOffscreenCanvas = e.data; | 20 var canvas1 = new OffscreenCanvas(100, 100); |
20 var gl = transferredOffscreenCanvas.getContext("webgl"); | 21 var gl1 = canvas1.getContext('webgl'); |
21 gl.clearColor(1.0, 0.0, 0.0, 1.0); | 22 gl1.clearColor(0.0, 1.0, 0.0, 1.0); |
22 gl.clear(gl.COLOR_BUFFER_BIT); | 23 gl1.clear(gl1.COLOR_BUFFER_BIT); |
23 gl.commit(); | 24 |
24 self.postMessage(""); | 25 var canvas2 = new OffscreenCanvas(100, 100); |
26 var gl2 = canvas2.getContext('webgl'); | |
27 gl2.clearColor(0.0, 0.0, 1.0, 1.0); | |
28 gl2.clear(gl2.COLOR_BUFFER_BIT); | |
29 | |
30 var image1 = canvas1.transferToImageBitmap(); | |
31 var image2 = canvas2.transferToImageBitmap(); | |
32 self.postMessage({bitmap1: image1, bitmap2: image2}, [image1, image2]); | |
25 }; | 33 }; |
26 </script> | 34 </script> |
27 <script> | 35 <script> |
28 var g_swapsBeforeAck = 15; | 36 var g_swapsBeforeAck = 15; |
29 | 37 |
30 function makeWorker(script) { | 38 function makeWorker(script) { |
31 var blob = new Blob([script]); | 39 var blob = new Blob([script]); |
32 return new Worker(URL.createObjectURL(blob)); | 40 return new Worker(URL.createObjectURL(blob)); |
33 } | 41 } |
34 | 42 |
35 function main() | 43 function main() |
36 { | 44 { |
37 draw(); | 45 draw(); |
38 } | 46 } |
39 | 47 |
40 function draw() | 48 function draw() |
41 { | 49 { |
42 var canvas = document.getElementById("c"); | |
43 var offscreenCanvas = canvas.transferControlToOffscreen(); | |
44 var worker = makeWorker(document.getElementById("myWorker").textContent); | 50 var worker = makeWorker(document.getElementById("myWorker").textContent); |
45 worker.postMessage(offscreenCanvas, [offscreenCanvas]); | 51 |
46 worker.onmessage = function (e) { | 52 worker.onmessage = function(msg) { |
53 var bitmap1 = msg.data.bitmap1; | |
54 var bitmap2 = msg.data.bitmap2; | |
55 var canvas1 = document.getElementById("canvas1"); | |
56 var ctx1 = canvas1.getContext('bitmaprenderer'); | |
57 ctx1.transferFromImageBitmap(bitmap1); | |
58 | |
59 var canvas2 = document.getElementById('canvas2'); | |
60 var ctx2 = canvas2.getContext('bitmaprenderer'); | |
61 ctx2.transferFromImageBitmap(bitmap2); | |
47 waitForFinish(); | 62 waitForFinish(); |
48 } | 63 } |
64 | |
65 worker.postMessage(""); | |
49 } | 66 } |
50 | 67 |
51 function waitForFinish() | 68 function waitForFinish() |
52 { | 69 { |
53 if (g_swapsBeforeAck == 0) { | 70 if (g_swapsBeforeAck == 0) { |
54 domAutomationController.setAutomationId(1); | 71 domAutomationController.setAutomationId(1); |
55 domAutomationController.send("SUCCESS"); | 72 domAutomationController.send("SUCCESS"); |
56 } else { | 73 } else { |
57 g_swapsBeforeAck--; | 74 g_swapsBeforeAck--; |
58 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; | 75 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; |
59 window.webkitRequestAnimationFrame(waitForFinish); | 76 window.webkitRequestAnimationFrame(waitForFinish); |
60 } | 77 } |
61 } | 78 } |
62 </script> | 79 </script> |
63 </head> | 80 </head> |
64 <body onload="main()"> | 81 <body onload="main()"> |
65 <div style="position:relative; width:200px; height:200px; background-color:white "> | 82 <div style="position:relative; width:200px; height:200px; background-color:white "> |
66 </div> | 83 </div> |
67 <div id="container" style="position:absolute; top:0px; left:0px"> | 84 <div id="container" style="position:absolute; top:0px; left:0px"> |
68 <canvas id="c" width="200" height="200" class="nomargin"></canvas> | 85 <canvas id="canvas1" width="100" height="100" class="nomargin"></canvas> |
86 </div> | |
87 <div id="container" style="position:absolute; top:0px; left:150px"> | |
88 <canvas id="canvas2" width="100" height="100" class="nomargin"></canvas> | |
69 </div> | 89 </div> |
70 </body> | 90 </body> |
71 </html> | 91 </html> |
OLD | NEW |