| <html> | |
| <head> | |
| <script type="text/javascript"> | |
| let activeGl = null; | |
| let retryTimerId = null; | |
| const MAX_ATTEMPTS = 200; | |
| const RETRY_DELAY_MS = 100; | |
| function cleanupContext() { | |
| if (retryTimerId !== null) { | |
| clearTimeout(retryTimerId); | |
| retryTimerId = null; | |
| } | |
| if (activeGl && !activeGl.isContextLost()) { | |
| const loseContext = activeGl.getExtension("WEBGL_lose_context"); | |
| if (loseContext) { | |
| loseContext.loseContext(); | |
| } | |
| } | |
| activeGl = null; | |
| } | |
| function ensureGpuChannel(attempt) { | |
| retryTimerId = null; | |
| // Create a fresh WebGL context to ensure the GPU process was created and | |
| // this renderer's GpuChannel is established without issuing a synchronous | |
| // gl.readPixels() readback stall. | |
| const canvas = document.createElement("canvas"); | |
| canvas.width = 32; | |
| canvas.height = 32; | |
| const gl = canvas.getContext("webgl"); | |
| if (gl) { | |
| gl.clearColor(1, 0, 0, 1); | |
| gl.clear(gl.COLOR_BUFFER_BIT); | |
| gl.flush(); | |
| } | |
| const hasChannel = | |
| !window.chrome || !chrome.gpuBenchmarking || | |
| chrome.gpuBenchmarking.hasGpuChannel(); | |
| if (!gl || gl.isContextLost() || !hasChannel) { | |
| if (gl && !gl.isContextLost()) { | |
| const loseContext = gl.getExtension("WEBGL_lose_context"); | |
| if (loseContext) { | |
| loseContext.loseContext(); | |
| } | |
| } | |
| if (attempt + 1 < MAX_ATTEMPTS) { | |
| retryTimerId = setTimeout( | |
| () => ensureGpuChannel(attempt + 1), RETRY_DELAY_MS); | |
| return; | |
| } | |
| console.error( | |
| `Failed to establish WebGL context / GPU channel after ` + | |
| `${MAX_ATTEMPTS} attempts (gl=${!!gl}, ` + | |
| `contextLost=${gl ? gl.isContextLost() : "n/a"}, ` + | |
| `hasChannel=${hasChannel})`); | |
| window.domAutomationController.send("FAILED"); | |
| return; | |
| } | |
| activeGl = gl; | |
| window.domAutomationController.send("SUCCESS"); | |
| } | |
| function onLoad() { | |
| window.domAutomationController.reset = function() { | |
| cleanupContext(); | |
| window.domAutomationController._loaded = false; | |
| window.domAutomationController._succeeded = false; | |
| window.domAutomationController._finished = false; | |
| retryTimerId = setTimeout(() => ensureGpuChannel(0), 0); | |
| }; | |
| window.domAutomationController.send("LOADED"); | |
| } | |
| </script> | |
| </head> | |
| <body onload="onLoad()"> | |
| GPU process crash test running. | |
| </body> | |
| </html> |