Skip to content

Commit

Permalink
[Cocoa] Small canvases, which aren't supposed to get compositing laye…
Browse files Browse the repository at this point in the history
…rs, get compositing layers if they have a 3D-but-could-be-2D transform

https://bugs.webkit.org/show_bug.cgi?id=259297
rdar://112439265

Reviewed by Simon Fraser.

We already have existing code which will avoid compositing small canvases. However, if
the small canvas has a 3D-but-could-be-2D transform, we'll composite it regardless. This
patch extends the current logic to not composite small canvases in this case.

This patch causes a 41% - 48% progression on the Images subtest in MotionMark. Layers
have cost, y'all.

* LayoutTests/compositing/canvas/accelerated-small-canvas-compositing-expected.txt
* LayoutTests/compositing/canvas/accelerated-small-canvas-compositing.html
* Source/WebCore/rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::requiresCompositingForTransform const): This patch doesn't
modify m_compositingPolicy, because that's global for the whole RenderLayerCompositor. We
only want to change the policy in this specific case.

Canonical link: https://commits.webkit.org/266135@main
  • Loading branch information
litherum committed Jul 18, 2023
1 parent 0aa032e commit 3dfb58b
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Tests whether an accelerated canvas creates a compositing layer.

(GraphicsLayer
(anchor 0.00 0.00)
(bounds 800.00 600.00)
(children 1
(GraphicsLayer
(bounds 800.00 600.00)
(contentsOpaque 1)
(children 1
(GraphicsLayer
(position 8.00 68.00)
(bounds 15.00 15.00)
)
)
)
)
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html><html>
<head>
<style>
canvas {
transform: translateZ(0px);
}
div {
will-change: transform;
width: 15px;
height: 15px;
}
</style>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}

function doTest() {
var c = document.getElementById('cvs_img2');
var ctx = c.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0,0,c.width, c.height);

if (window.testRunner) {
document.getElementById('layers').innerText = window.internals.layerTreeAsText(document);
testRunner.notifyDone();
}
}

window.addEventListener('load', doTest, false);
</script>
</head>
<body>
<p>Tests whether an accelerated canvas creates a compositing layer.</p>
<canvas id="cvs_img2" width="10" height="10"></canvas>
<div></div>
<pre id="layers">Layer tree goes here in DRT</pre>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Tests whether an accelerated canvas creates a compositing layer.

(GraphicsLayer
(anchor 0.00 0.00)
(bounds 800.00 600.00)
(children 1
(GraphicsLayer
(bounds 800.00 600.00)
(contentsOpaque 1)
(children 2
(GraphicsLayer
(position 8.00 54.00)
(bounds 10.00 10.00)
(drawsContent 1)
)
(GraphicsLayer
(position 8.00 68.00)
(bounds 15.00 15.00)
)
)
)
)
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Tests whether an accelerated canvas creates a compositing layer.

(GraphicsLayer
(anchor 0.00 0.00)
(bounds 800.00 600.00)
(children 1
(GraphicsLayer
(bounds 800.00 600.00)
(contentsOpaque 1)
(children 1
(GraphicsLayer
(position 8.00 72.00)
(bounds 15.00 15.00)
)
)
)
)
)

12 changes: 11 additions & 1 deletion Source/WebCore/rendering/RenderLayerCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3246,8 +3246,18 @@ bool RenderLayerCompositor::requiresCompositingForTransform(RenderLayerModelObje
// but the renderer may be an inline that doesn't suppport them.
if (!renderer.isTransformed())
return false;

auto compositingPolicy = m_compositingPolicy;
#if !USE(COMPOSITING_FOR_SMALL_CANVASES)
if (is<HTMLCanvasElement>(renderer.element())) {
auto* canvas = downcast<HTMLCanvasElement>(renderer.element());
auto canvasArea = canvas->size().area<RecordOverflow>();
if (!canvasArea.hasOverflowed() && canvasArea < canvasAreaThresholdRequiringCompositing)
compositingPolicy = CompositingPolicy::Conservative;
}
#endif

switch (m_compositingPolicy) {
switch (compositingPolicy) {
case CompositingPolicy::Normal:
return styleHas3DTransformOperation(renderer.style());
case CompositingPolicy::Conservative:
Expand Down

0 comments on commit 3dfb58b

Please sign in to comment.