Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
| 2 | 2 |
|
xidachen
2016/09/22 19:05:54
Since the implementation for worker is not ready y
xlai (Olivia)
2016/09/22 19:36:18
Not really. The implementation for worker on accel
xidachen
2016/09/22 19:42:33
That makes sense, I didn't realize that this is fo
| |
| 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 main thread: green square on white backgro und.</title> | 11 <title>OffscreenCanvas 2d commit flow on worker thread: green square on white ba ckground.</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"> | |
| 18 self.onmessage = function(e) { | |
| 19 var transferredCanvas = e.data; | |
| 20 var offscreen2d = transferredCanvas.getContext("2d"); | |
| 21 offscreen2d.fillStyle = "blue"; | |
| 22 offscreen2d.fillRect(0, 0, transferredCanvas.width, transferredCanvas.height ); | |
| 23 offscreen2d.commit(); | |
| 24 }; | |
| 25 </script> | |
| 17 <script> | 26 <script> |
| 18 var g_swapsBeforeAck = 15; | 27 var g_swapsBeforeAck = 15; |
| 19 | 28 |
| 20 function main() | 29 function main() |
| 21 { | 30 { |
| 22 draw(); | 31 draw(); |
| 23 waitForFinish(); | 32 waitForFinish(); |
| 24 } | 33 } |
| 25 | 34 |
| 35 function makeWorker(script) | |
| 36 { | |
| 37 var blob = new Blob([script]); | |
| 38 return new Worker(URL.createObjectURL(blob)); | |
| 39 } | |
| 40 | |
| 26 function draw() | 41 function draw() |
| 27 { | 42 { |
| 28 var canvas = document.getElementById("c"); | 43 var canvas2D = document.getElementById("c"); |
| 29 var offscreenCanvas = canvas.transferControlToOffscreen(); | 44 var offscreenCanvas = canvas2D.transferControlToOffscreen(); |
| 30 var gl = offscreenCanvas.getContext("webgl"); | 45 var worker = makeWorker(document.getElementById("myWorker").textContent); |
| 31 gl.clearColor(0.0, 1.0, 0.0, 1.0); | 46 worker.postMessage(offscreenCanvas, [offscreenCanvas]); |
| 32 gl.clear(gl.COLOR_BUFFER_BIT); | |
| 33 gl.commit(); | |
| 34 } | 47 } |
| 35 | 48 |
| 36 function waitForFinish() | 49 function waitForFinish() |
| 37 { | 50 { |
| 38 if (g_swapsBeforeAck == 0) { | 51 if (g_swapsBeforeAck == 0) { |
| 39 domAutomationController.setAutomationId(1); | 52 domAutomationController.setAutomationId(1); |
| 40 domAutomationController.send("SUCCESS"); | 53 domAutomationController.send("SUCCESS"); |
| 41 } else { | 54 } else { |
| 42 g_swapsBeforeAck--; | 55 g_swapsBeforeAck--; |
| 43 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; | 56 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; |
| 44 window.webkitRequestAnimationFrame(waitForFinish); | 57 window.webkitRequestAnimationFrame(waitForFinish); |
| 45 } | 58 } |
| 46 } | 59 } |
| 60 | |
| 47 </script> | 61 </script> |
| 48 </head> | 62 </head> |
| 49 <body onload="main()"> | 63 <body onload="main()"> |
| 50 <div style="position:relative; width:200px; height:200px; background-color:white "> | 64 <div style="position:relative; width:350px; height:350px; background-color:white "> |
| 51 </div> | 65 </div> |
| 52 <div id="container" style="position:absolute; top:0px; left:0px"> | 66 <div id="container" style="position:absolute; top:0px; left:0px"> |
| 53 <canvas id="c" width="200" height="200" class="nomargin"></canvas> | 67 <canvas id="c" width="320" height="320" class="nomargin"></canvas> |
| 54 </div> | 68 </div> |
| 55 </body> | 69 </body> |
| 56 </html> | 70 </html> |
| OLD | NEW |