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

Unified Diff: LayoutTests/fast/canvas/script-tests/canvas-lost-gpu-context.js

Issue 16032003: Fixing Canvas2DLayerBridge to handle lost graphics contexts (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Resolved merge with rate limiter CL Created 7 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: LayoutTests/fast/canvas/script-tests/canvas-lost-gpu-context.js
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-lost-gpu-context.js b/LayoutTests/fast/canvas/script-tests/canvas-lost-gpu-context.js
new file mode 100644
index 0000000000000000000000000000000000000000..623134a7b2b0d9f36ba931549cd5495f768b9361
--- /dev/null
+++ b/LayoutTests/fast/canvas/script-tests/canvas-lost-gpu-context.js
@@ -0,0 +1,62 @@
+description("Test the behavior of canvas recovery after a gpu context loss");
+
+var recoveryLoopPeriod = 5;
+var ctx;
+var imageData;
+var imgdata;
+
+if (window.internals && window.testRunner) {
+ testRunner.dumpAsText();
+ ctx = document.createElement('canvas').getContext('2d');
+ document.body.appendChild(ctx.canvas);
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
+ imageData = ctx.getImageData(0, 0, 1, 1);
+ imgdata = imageData.data;
+ shouldBe("imgdata[0]", "255");
+ shouldBe("imgdata[1]", "0");
+ shouldBe("imgdata[2]", "0");
+ shouldBe("imgdata[3]", "255");
+
+ window.internals.loseSharedGraphicsContext3D();
+ // Verify whether canvas contents are lost with the graphics context.
+ imageData = ctx.getImageData(0, 0, 1, 1);
+ if (imageData.data[0] == 255) {
+ debug('<span>Aborting test: Graphics context loss did not destroy canvas contents. This is expected if canvas is not accelerated.</span>');
+ } else {
+ // Redrawing immediately will fail because we are working with an
+ // unrecovered context here. The context recovery is asynchronous
+ // because it requires the context loss notification task to be
+ // processed on the renderer main thread, which triggers the
+ // re-creation of the SharedGC3D.
+ ctx.fillStyle = '#0f0';
+ ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
+ imageData = ctx.getImageData(0, 0, 1, 1);
+ imgdata = imageData.data;
+ shouldBe("imgdata[0]", "0");
+ shouldBe("imgdata[1]", "0");
+ shouldBe("imgdata[2]", "0");
+ shouldBe("imgdata[3]", "0");
+
+ testRunner.waitUntilDone();
+ setTimeout(recoveryLoop, recoveryLoopPeriod);
+ }
+} else {
+ testFailed('This test requires window.internals and window.testRunner.');
+}
+
+// Graphics context recovery happens asynchronously. To test for recovery, we keep
+// retrying to use the canvas until it succeeds, which should hapen long before the test
+// times-out.
+function recoveryLoop() {
+ ctx.fillStyle = '#00f';
+ ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
+ imageData = ctx.getImageData(0, 0, 1, 1);
+ if (imageData.data[2] == 255) {
+ testPassed('Graphics context recovered.');
+ testRunner.notifyDone();
+ } else {
+ // Context not yet recovered. Try again.
+ setTimeout(recoveryLoop, recoveryLoopPeriod);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698