| OLD | NEW |
| (Empty) | |
| 1 description("Test the behavior of canvas recovery after a gpu context loss"); |
| 2 |
| 3 var recoveryLoopPeriod = 5; |
| 4 var ctx; |
| 5 var imageData; |
| 6 var imgdata; |
| 7 |
| 8 if (window.internals && window.testRunner) { |
| 9 testRunner.dumpAsText(); |
| 10 ctx = document.createElement('canvas').getContext('2d'); |
| 11 document.body.appendChild(ctx.canvas); |
| 12 ctx.fillStyle = '#f00'; |
| 13 ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 14 imageData = ctx.getImageData(0, 0, 1, 1); |
| 15 imgdata = imageData.data; |
| 16 shouldBe("imgdata[0]", "255"); |
| 17 shouldBe("imgdata[1]", "0"); |
| 18 shouldBe("imgdata[2]", "0"); |
| 19 shouldBe("imgdata[3]", "255"); |
| 20 |
| 21 window.internals.loseSharedGraphicsContext3D(); |
| 22 // Verify whether canvas contents are lost with the graphics context. |
| 23 imageData = ctx.getImageData(0, 0, 1, 1); |
| 24 if (imageData.data[0] == 255) { |
| 25 debug('<span>Aborting test: Graphics context loss did not destroy canvas
contents. This is expected if canvas is not accelerated.</span>'); |
| 26 } else { |
| 27 // Redrawing immediately will fail because we are working with an |
| 28 // unrecovered context here. The context recovery is asynchronous |
| 29 // because it requires the context loss notification task to be |
| 30 // processed on the renderer main thread, which triggers the |
| 31 // re-creation of the SharedGC3D. |
| 32 ctx.fillStyle = '#0f0'; |
| 33 ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 34 imageData = ctx.getImageData(0, 0, 1, 1); |
| 35 imgdata = imageData.data; |
| 36 shouldBe("imgdata[0]", "0"); |
| 37 shouldBe("imgdata[1]", "0"); |
| 38 shouldBe("imgdata[2]", "0"); |
| 39 shouldBe("imgdata[3]", "0"); |
| 40 |
| 41 testRunner.waitUntilDone(); |
| 42 setTimeout(recoveryLoop, recoveryLoopPeriod); |
| 43 } |
| 44 } else { |
| 45 testFailed('This test requires window.internals and window.testRunner.'); |
| 46 } |
| 47 |
| 48 // Graphics context recovery happens asynchronously. To test for recovery, we k
eep |
| 49 // retrying to use the canvas until it succeeds, which should hapen long before
the test |
| 50 // times-out. |
| 51 function recoveryLoop() { |
| 52 ctx.fillStyle = '#00f'; |
| 53 ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 54 imageData = ctx.getImageData(0, 0, 1, 1); |
| 55 if (imageData.data[2] == 255) { |
| 56 testPassed('Graphics context recovered.'); |
| 57 testRunner.notifyDone(); |
| 58 } else { |
| 59 // Context not yet recovered. Try again. |
| 60 setTimeout(recoveryLoop, recoveryLoopPeriod); |
| 61 } |
| 62 } |
| OLD | NEW |