Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: content/test/data/gpu/pixel_offscreenCanvas_2d_commit_worker.html

Issue 2594843002: Implementing promise-based commit for driving OffscreenCanvas animations (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 worker thread: Four-color square on whi te background.</title> 11 <title>OffscreenCanvas 2d commit flow on worker thread: Four-color square on whi te 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
19 var g_offscreen2d;
20 var g_animationFrameNumber = 0;
21
18 self.onmessage = function(e) { 22 self.onmessage = function(e) {
19 var transferredCanvas = e.data; 23 var transferredCanvas = e.data;
20 var offscreen2d = transferredCanvas.getContext("2d"); 24 g_offscreen2d = transferredCanvas.getContext("2d");
21 offscreen2d.fillStyle = "red"; 25 drawLoop();
22 offscreen2d.fillRect(0, 0, 100, 100); 26 }
23 offscreen2d.fillStyle = "green"; 27
24 offscreen2d.fillRect(100, 0, 100, 100); 28 function drawLoop()
25 offscreen2d.fillStyle = "blue"; 29 {
26 offscreen2d.fillRect(0, 100, 100, 100); 30 if (g_animationFrameNumber < 3) {
27 offscreen2d.fillStyle = "black"; 31 g_offscreen2d.fillStyle = "red";
28 offscreen2d.fillRect(100, 100, 100, 100); 32 g_offscreen2d.fillRect(0, 0, 200, 200);
29 offscreen2d.commit(); 33 g_animationFrameNumber++;
34 g_offscreen2d.commit().then(drawLoop);
35 } else {
36 g_offscreen2d.fillStyle = "red";
37 g_offscreen2d.fillRect(0, 0, 100, 100);
38 g_offscreen2d.fillStyle = "green";
39 g_offscreen2d.fillRect(100, 0, 100, 100);
40 g_offscreen2d.fillStyle = "blue";
41 g_offscreen2d.fillRect(0, 100, 100, 100);
42 g_offscreen2d.fillStyle = "black";
43 g_offscreen2d.fillRect(100, 100, 100, 100);
44 g_offscreen2d.commit()
45
46 // The following fill is never committed
47 g_offscreen2d.fillStyle = "blue";
48 g_offscreen2d.fillRect(0, 0, 200, 200);
30 self.postMessage(""); 49 self.postMessage("");
31 }; 50 }
51 }
32 </script> 52 </script>
33 <script> 53 <script>
34 var g_swapsBeforeAck = 15; 54 var g_swapsBeforeAck = 15;
35 55
36 function makeWorker(script) 56 function makeWorker(script)
37 { 57 {
38 var blob = new Blob([script]); 58 var blob = new Blob([script]);
39 return new Worker(URL.createObjectURL(blob)); 59 return new Worker(URL.createObjectURL(blob));
40 } 60 }
41 61
42 function waitForFinish() 62 function waitForFinish()
43 { 63 {
44 if (g_swapsBeforeAck == 0) { 64 if (g_swapsBeforeAck == 0) {
45 domAutomationController.setAutomationId(1); 65 domAutomationController.setAutomationId(1);
46 domAutomationController.send("SUCCESS"); 66 domAutomationController.send("SUCCESS");
47 } else { 67 } else {
48 g_swapsBeforeAck--; 68 g_swapsBeforeAck--;
49 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1; 69 document.getElementById('container').style.zIndex = g_swapsBeforeAck + 1;
50 window.webkitRequestAnimationFrame(waitForFinish); 70 window.requestAnimationFrame(waitForFinish);
51 } 71 }
52 } 72 }
53 73
54 function main() 74 function main()
55 { 75 {
56 var canvas2D = document.getElementById("c"); 76 var canvas2D = document.getElementById("c");
57 var offscreenCanvas = canvas2D.transferControlToOffscreen(); 77 var offscreenCanvas = canvas2D.transferControlToOffscreen();
58 var worker = makeWorker(document.getElementById("myWorker").textContent); 78 var worker = makeWorker(document.getElementById("myWorker").textContent);
59 worker.onmessage = function (e) { 79 worker.onmessage = function (e) {
60 waitForFinish(); 80 waitForFinish();
61 }; 81 };
62 worker.postMessage(offscreenCanvas, [offscreenCanvas]); 82 worker.postMessage(offscreenCanvas, [offscreenCanvas]);
63 } 83 }
64 </script> 84 </script>
65 </head> 85 </head>
66 <body onload="main()"> 86 <body onload="main()">
67 <div style="position:relative; width:300px; height:300px; background-color:white "> 87 <div style="position:relative; width:300px; height:300px; background-color:white ">
68 </div> 88 </div>
69 <div id="container" style="position:absolute; top:0px; left:0px"> 89 <div id="container" style="position:absolute; top:0px; left:0px">
70 <canvas id="c" width="200" height="200" class="nomargin"></canvas> 90 <canvas id="c" width="200" height="200" class="nomargin"></canvas>
71 </div> 91 </div>
72 </body> 92 </body>
73 </html> 93 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698