| 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/gpu_tests/pixel_test_pages.py. This will ens
ure | 5 associated test in content/test/gpu/gpu_tests/pixel_test_pages.py. This will ens
ure |
| 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 2d commit flow on main thread: Two Canvases</title> | 11 <title>OffscreenCanvas 2d commit flow on main thread: Two Canvases</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 </head> | 17 </head> |
| 18 <body onload="main()"> | 18 <body onload="main()"> |
| 19 <div style="position:relative; width:600px; height:300px; background-color:white
"> | 19 <div style="position:relative; width:400px; height:200px; background-color:white
"> |
| 20 </div> | 20 </div> |
| 21 <div id="container" style="position:absolute; top:0px; left:0px"> | 21 <div id="container" style="position:absolute; top:0px; left:0px"> |
| 22 <canvas id="canvas1" width="300" height="300" class="nomargin"></canvas> | 22 <canvas id="canvas1" width="200" height="200" class="nomargin"></canvas> |
| 23 <canvas id="canvas2" width="300" height="300" class="nomargin"></canvas> | 23 <canvas id="canvas2" width="200" height="200" class="nomargin"></canvas> |
| 24 </div> | 24 </div> |
| 25 <script> | 25 <script> |
| 26 /* This pixel test checks the following: | 26 /* This pixel test checks the following: |
| 27 1. Whether submission of frames for multiple canvases happen about the same | 27 1. Whether submission of frames for multiple canvases happen about the same |
| 28 time for OffscreenCanvas.commit() that are invoked in the same JS task. | 28 time for OffscreenCanvas.commit() that are invoked in the same JS task. |
| 29 2. Whether overdraw frame in one animation loop is handled well. | 29 2. Whether overdraw frame in one animation loop is handled well. |
| 30 3. Whether the drawn 2d image is position upright in commit(). | 30 3. Whether the drawn 2d image is position upright in commit(). |
| 31 4. Drawing to OffscreenCanvas without commit() has no rendering results. | 31 4. Drawing to OffscreenCanvas without commit() has no rendering results. |
| 32 | 32 |
| 33 Correct end result of this test: The left canvas shows a seven-spike skyblue | 33 Correct end result of this test: The left canvas shows a seven-spike skyblue |
| 34 star on the top-left corner of a green background and the right canvas shows | 34 star on the top-left corner of a green background and the right canvas shows |
| 35 a sky-blue fill. | 35 a sky-blue fill. |
| 36 */ | 36 */ |
| 37 | 37 |
| 38 var g_swapsBeforeAck = 15; | 38 var g_swapsBeforeAck = 15; |
| 39 var g_asyncCallbackNumber = 2; | 39 var g_asyncCallbackNumber = 2; |
| 40 | 40 |
| 41 function getOffscreenContext(htmlCanvasId) { | 41 function getOffscreenContext(htmlCanvasId) { |
| 42 return document.getElementById(htmlCanvasId).transferControlToOffscreen().getC
ontext("2d"); | 42 return document.getElementById(htmlCanvasId).transferControlToOffscreen().getC
ontext("2d"); |
| 43 } | 43 } |
| 44 | 44 |
| 45 function startTest() { | 45 function startTest() { |
| 46 var ctx1 = getOffscreenContext("canvas1"); | 46 var ctx1 = getOffscreenContext("canvas1"); |
| 47 var ctx2 = getOffscreenContext("canvas2"); | 47 var ctx2 = getOffscreenContext("canvas2"); |
| 48 | 48 |
| 49 ctx1.fillStyle = "green"; | 49 ctx1.fillStyle = "green"; |
| 50 ctx1.fillRect(0, 0, 300, 300); | 50 ctx1.fillRect(0, 0, 200, 200); |
| 51 // The promise returned by this ctx1.commit() must be resolved at | 51 // The promise returned by this ctx1.commit() must be resolved at |
| 52 // about the same time as the other ctx2.commit() below as they are in the | 52 // about the same time as the other ctx2.commit() below as they are in the |
| 53 // same JS task. | 53 // same JS task. |
| 54 ctx1.commit().then(function() { | 54 ctx1.commit().then(function() { |
| 55 ctx2.fillRect(0, 0, 300, 300); | 55 ctx2.fillRect(0, 0, 200, 200); |
| 56 // This ctx2.commit() must happen after the other ctx2.commit() below. | 56 // This ctx2.commit() must happen after the other ctx2.commit() below. |
| 57 ctx2.commit(); | 57 ctx2.commit(); |
| 58 if (--g_asyncCallbackNumber == 0) waitForFinish(); | 58 if (--g_asyncCallbackNumber == 0) waitForFinish(); |
| 59 }); | 59 }); |
| 60 | 60 |
| 61 function drawStar(ctx, cx, cy, spikes, outerRadius, innerRadius) { | 61 function drawStar(ctx, cx, cy, spikes, outerRadius, innerRadius) { |
| 62 var rot = Math.PI / 2 * 3; | 62 var rot = Math.PI / 2 * 3; |
| 63 var x = cx; | 63 var x = cx; |
| 64 var y = cy; | 64 var y = cy; |
| 65 var step = Math.PI / spikes; | 65 var step = Math.PI / spikes; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 ctx.closePath(); | 81 ctx.closePath(); |
| 82 ctx.lineWidth = 5; | 82 ctx.lineWidth = 5; |
| 83 ctx.strokeStyle = 'black'; | 83 ctx.strokeStyle = 'black'; |
| 84 ctx.stroke(); | 84 ctx.stroke(); |
| 85 ctx.fillStyle = 'skyblue'; | 85 ctx.fillStyle = 'skyblue'; |
| 86 ctx.fill(); | 86 ctx.fill(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // Do something complex to ctx2. | 89 // Do something complex to ctx2. |
| 90 ctx2.fillStyle = "blue"; | 90 ctx2.fillStyle = "blue"; |
| 91 ctx2.fillRect(0, 0, 300, 300); | 91 ctx2.fillRect(0, 0, 200, 200); |
| 92 drawStar(ctx2, 150, 150, 25, 80, 60); | 92 drawStar(ctx2, 100, 100, 25, 60, 40); |
| 93 // This ctx2.commit() must be resolved at about the same time as the first | 93 // This ctx2.commit() must be resolved at about the same time as the first |
| 94 // ctx1.commit() above because they are in the same JS task, no matter how | 94 // ctx1.commit() above because they are in the same JS task, no matter how |
| 95 // complex the drawing operation is. | 95 // complex the drawing operation is. |
| 96 ctx2.commit().then(function() { | 96 ctx2.commit().then(function() { |
| 97 drawStar(ctx1, 100, 100, 7, 80, 30); | 97 drawStar(ctx1, 80, 80, 7, 60, 30); |
| 98 ctx1.commit(); | 98 ctx1.commit(); |
| 99 | 99 |
| 100 // The following fill is never committed | 100 // The following fill is never committed |
| 101 ctx1.fillStyle = "red"; | 101 ctx1.fillStyle = "red"; |
| 102 ctx1.fillRect(0, 0, 200, 200); | 102 ctx1.fillRect(0, 0, 200, 200); |
| 103 if (--g_asyncCallbackNumber == 0) waitForFinish(); | 103 if (--g_asyncCallbackNumber == 0) waitForFinish(); |
| 104 }); | 104 }); |
| 105 | 105 |
| 106 } | 106 } |
| 107 | 107 |
| 108 function main() { | 108 function main() { |
| 109 startTest(); | 109 startTest(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 function waitForFinish() | 112 function waitForFinish() |
| 113 { | 113 { |
| 114 if (g_swapsBeforeAck == 0) { | 114 if (g_swapsBeforeAck == 0) { |
| 115 domAutomationController.setAutomationId(1); | 115 domAutomationController.setAutomationId(1); |
| 116 domAutomationController.send("SUCCESS"); | 116 domAutomationController.send("SUCCESS"); |
| 117 } else { | 117 } else { |
| 118 g_swapsBeforeAck--; | 118 g_swapsBeforeAck--; |
| 119 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; | 119 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; |
| 120 requestAnimationFrame(waitForFinish); | 120 requestAnimationFrame(waitForFinish); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 </script> | 124 </script> |
| 125 </body> | 125 </body> |
| 126 </html> | 126 </html> |
| OLD | NEW |