OLD | NEW |
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <script type="text/javascript"> | 3 <script type="text/javascript"> |
4 var canvas; | 4 var canvas; |
5 var w, h; | 5 var w, h; |
6 var gl; | 6 var gl; |
7 var extension; | 7 var extension; |
8 | 8 |
9 var alreadySetAutomationId = false; | 9 var alreadySetAutomationId = false; |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, a); | 52 gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, a); |
53 | 53 |
54 if (!alreadySetAutomationId) | 54 if (!alreadySetAutomationId) |
55 window.domAutomationController.setAutomationId(1); | 55 window.domAutomationController.setAutomationId(1); |
56 if (a[0] == 0 && a[1] == 0 && a[2] == 255) | 56 if (a[0] == 0 && a[1] == 0 && a[2] == 255) |
57 window.domAutomationController.send("SUCCESS"); | 57 window.domAutomationController.send("SUCCESS"); |
58 else | 58 else |
59 window.domAutomationController.send("FAILED"); | 59 window.domAutomationController.send("FAILED"); |
60 } | 60 } |
61 | 61 |
| 62 function testQuantityLoss() { |
| 63 var count = 0; |
| 64 var iterations = 128; |
| 65 var garbageCanvases = []; |
| 66 |
| 67 function createAndDiscardContext() { |
| 68 count++; |
| 69 |
| 70 var c = document.createElement("canvas"); |
| 71 c.width = 1; |
| 72 c.height = 1; |
| 73 garbageCanvases.push(c); |
| 74 |
| 75 var ctx = c.getContext("experimental-webgl"); |
| 76 if (!ctx) { |
| 77 return false; |
| 78 } |
| 79 ctx.clear(gl.COLOR_BUFFER_BIT); |
| 80 |
| 81 if (count < iterations) { |
| 82 window.requestAnimationFrame(createAndDiscardContext); |
| 83 } else { |
| 84 // Remove the references to the garbage canvases, then attempt to trigger |
| 85 // a garbage collect. |
| 86 garbageCanvases = null; |
| 87 |
| 88 window.domAutomationController.setAutomationId(1); |
| 89 alreadySetAutomationId = true; |
| 90 window.domAutomationController.send("LOADED"); |
| 91 |
| 92 // Trying to provoke garbage collection through excessive allocations. |
| 93 setInterval(function() { |
| 94 var garbageArray = new Uint8Array(1024 * 1024); |
| 95 garbageArray[0] = 255; |
| 96 }, 10); |
| 97 } |
| 98 }; |
| 99 |
| 100 createAndDiscardContext(); |
| 101 } |
| 102 |
62 function contextLostTest(kind) | 103 function contextLostTest(kind) |
63 { | 104 { |
64 switch (kind) { | 105 switch (kind) { |
65 case "WEBGL_lose_context": { | 106 case "WEBGL_lose_context": { |
66 extension = gl.getExtension("WEBKIT_WEBGL_lose_context") || | 107 extension = gl.getExtension("WEBKIT_WEBGL_lose_context") || |
67 gl.getExtension("WEBGL_lose_context"); | 108 gl.getExtension("WEBGL_lose_context"); |
68 extension.loseContext(); | 109 extension.loseContext(); |
69 break; | 110 break; |
70 } | 111 } |
71 case "kill": | 112 case "kill": |
72 // nothing -- the browser test navigates to about:gpucrash and kills | 113 // nothing -- the browser test navigates to about:gpucrash and kills |
73 // the GPU process. | 114 // the GPU process. |
74 break; | 115 break; |
75 case "kill_after_notification": | 116 case "kill_after_notification": |
76 // The browser test waits for notification from the page that it | 117 // The browser test waits for notification from the page that it |
77 // has been loaded before navigating to about:gpucrash. | 118 // has been loaded before navigating to about:gpucrash. |
78 window.domAutomationController.setAutomationId(1); | 119 window.domAutomationController.setAutomationId(1); |
79 alreadySetAutomationId = true; | 120 alreadySetAutomationId = true; |
80 window.domAutomationController.send("LOADED"); | 121 window.domAutomationController.send("LOADED"); |
81 break; | 122 break; |
| 123 case "forced_quantity_loss": |
| 124 // Test creates many new contexts, forcing the original context to be |
| 125 // lost. Then a garbage collect is triggered and the original context is |
| 126 // watched to ensure it restores properly. |
| 127 testQuantityLoss(); |
| 128 break; |
82 } | 129 } |
83 } | 130 } |
84 | 131 |
85 function onLoad() { | 132 function onLoad() { |
86 canvas = document.getElementById("canvas1"); | 133 canvas = document.getElementById("canvas1"); |
87 w = canvas.width; | 134 w = canvas.width; |
88 h = canvas.height; | 135 h = canvas.height; |
89 if (!canvas) | 136 if (!canvas) |
90 return; | 137 return; |
91 canvas.addEventListener("webglcontextlost", testContextLost, false); | 138 canvas.addEventListener("webglcontextlost", testContextLost, false); |
(...skipping 10 matching lines...) Expand all Loading... |
102 if (query) | 149 if (query) |
103 contextLostTest(query[1]); | 150 contextLostTest(query[1]); |
104 } | 151 } |
105 </script> | 152 </script> |
106 </head> | 153 </head> |
107 <body onload="onLoad()"> | 154 <body onload="onLoad()"> |
108 <canvas id="canvas1" width="16px" height="32px"> | 155 <canvas id="canvas1" width="16px" height="32px"> |
109 </canvas> | 156 </canvas> |
110 </body> | 157 </body> |
111 </html> | 158 </html> |
OLD | NEW |