Skip to content

Commit

Permalink
Toggling visibility:hidden on the parent of a <canvas> can cause the …
Browse files Browse the repository at this point in the history
…previous frame's contents to be shown.

https://bugs.webkit.org/show_bug.cgi?id=274262
<rdar://128226178>

Reviewed by Simon Fraser.

We should only try to use 'copy' compositing mode to transfer the canvas buffer into the layer (and thus
omit any pixel clearing) if there is visible content to copy.

* LayoutTests/compositing/canvas/copy-backing-store-visibility-hidden-expected.html: Added.
* LayoutTests/compositing/canvas/copy-backing-store-visibility-hidden.html: Added.
* Source/WebCore/rendering/RenderLayerBacking.cpp:
(WebCore::RenderLayerBacking::updateConfiguration):

Canonical link: https://commits.webkit.org/279302@main
  • Loading branch information
mattwoodrow committed May 25, 2024
1 parent be37d4d commit d611425
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script>

if (window.testRunner) {
testRunner.waitUntilDone();
}

async function doTest() {
var canvasElement = document.getElementById("canvas");

let ctx = canvas.getContext('2d');

ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);

await new Promise(resolve => requestAnimationFrame(resolve));

ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 100, 100);

await new Promise(resolve => requestAnimationFrame(resolve));

document.getElementById("parent").style.visibility = "hidden";

if (window.testRunner) {
testRunner.notifyDone();
}
}

window.addEventListener('load', doTest, false);
</script>
</head>

<body>
<div id="parent">
<canvas id="canvas"></canvas>
</div>
</body>

</html>
2 changes: 1 addition & 1 deletion Source/WebCore/rendering/RenderLayerBacking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@ bool RenderLayerBacking::updateConfiguration(const RenderLayer* compositingAnces
layerConfigChanged = true;
}

bool shouldPaintUsingCompositeCopy = unscaledBitmap && is<RenderHTMLCanvas>(renderer());
bool shouldPaintUsingCompositeCopy = unscaledBitmap && is<RenderHTMLCanvas>(renderer()) && m_owningLayer.hasVisibleContent();
if (shouldPaintUsingCompositeCopy != m_shouldPaintUsingCompositeCopy) {
m_shouldPaintUsingCompositeCopy = shouldPaintUsingCompositeCopy;
m_graphicsLayer->setShouldPaintUsingCompositeCopy(shouldPaintUsingCompositeCopy);
Expand Down

0 comments on commit d611425

Please sign in to comment.