- Revision
- 288429
- Author
- [email protected]
- Date
- 2022-01-23 20:48:29 -0800 (Sun, 23 Jan 2022)
Log Message
Position:fixed layers shouldn't allocate a backing buffer if all children are offscreen.
https://bugs.webkit.org/show_bug.cgi?id=235420
<rdar://86612099>
Patch by Matt Woodrow <[email protected]> on 2022-01-23
Reviewed by Simon Fraser and Darin Adler.
Source/WebCore:
Adds a bounds intersection check to isPaintDestinationForDescendantLayers,
so that we can exclude descendants that definitely won't draw anything into
the compositing layer. Uses a conservative check, which gives up if there are
any transforms in the ancestor chain.
Test: compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html
* rendering/RenderLayerBacking.cpp:
(WebCore::intersectsWithAncestor):
(WebCore::RenderLayerBacking::isPaintDestinationForDescendantLayers const):
LayoutTests:
Adds a test that has a viewport sized position:fixed element (with compositing
layer), and a single child which is entirely offscreen. Tests that we correctly
determine that we don't need a backing store for the layer.
* compositing/backing/no-backing-for-offscreen-children-of-position-fixed-expected.txt: Added.
* compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (288428 => 288429)
--- trunk/LayoutTests/ChangeLog 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/LayoutTests/ChangeLog 2022-01-24 04:48:29 UTC (rev 288429)
@@ -1,3 +1,18 @@
+2022-01-23 Matt Woodrow <[email protected]>
+
+ Position:fixed layers shouldn't allocate a backing buffer if all children are offscreen.
+ https://bugs.webkit.org/show_bug.cgi?id=235420
+ <rdar://86612099>
+
+ Reviewed by Simon Fraser and Darin Adler.
+
+ Adds a test that has a viewport sized position:fixed element (with compositing
+ layer), and a single child which is entirely offscreen. Tests that we correctly
+ determine that we don't need a backing store for the layer.
+
+ * compositing/backing/no-backing-for-offscreen-children-of-position-fixed-expected.txt: Added.
+ * compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html: Added.
+
2022-01-23 Tyler Wilcock <[email protected]>
AX Isolated Tree Mode: Re-compute AXPropertyName::IsEnabled when a node experiences AXDisabledStateChanged
Copied: trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed-expected.txt (from rev 288428, trunk/LayoutTests/compositing/clip-child-by-non-stacking-ancestor-expected.txt) (0 => 288429)
--- trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed-expected.txt (rev 0)
+++ trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed-expected.txt 2022-01-24 04:48:29 UTC (rev 288429)
@@ -0,0 +1,16 @@
+(GraphicsLayer
+ (anchor 0.00 0.00)
+ (bounds 800.00 600.00)
+ (children 1
+ (GraphicsLayer
+ (bounds 800.00 600.00)
+ (contentsOpaque 1)
+ (children 1
+ (GraphicsLayer
+ (bounds 200.00 200.00)
+ )
+ )
+ )
+ )
+)
+
Added: trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html (0 => 288429)
--- trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html (rev 0)
+++ trunk/LayoutTests/compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html 2022-01-24 04:48:29 UTC (rev 288429)
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+ if (window.testRunner)
+ testRunner.dumpAsText();
+
+ function dumpLayers()
+ {
+ var layersResult = document.getElementById('layers');
+ if (window.testRunner)
+ layersResult.innerText = window.internals.layerTreeAsText(document);
+
+ }
+ window.addEventListener('load', dumpLayers, false)
+ </script>
+</head>
+<body>
+ <div style="position: fixed; left: 0; top: 0; width:200px; height:200px;">
+ <div style="position: absolute; left: -300px; width: 300px; height: 200px; background-color: blue;"></div>
+ </div>
+<pre id="layers">Layer tree goes here in DRT</pre>
+</body>
+</html>
Modified: trunk/LayoutTests/compositing/clip-child-by-non-stacking-ancestor-expected.txt (288428 => 288429)
--- trunk/LayoutTests/compositing/clip-child-by-non-stacking-ancestor-expected.txt 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/LayoutTests/compositing/clip-child-by-non-stacking-ancestor-expected.txt 2022-01-24 04:48:29 UTC (rev 288429)
@@ -10,7 +10,6 @@
(position 8.00 8.00)
(bounds 100.00 100.00)
(contentsOpaque 1)
- (drawsContent 1)
)
)
)
Modified: trunk/LayoutTests/compositing/geometry/limit-layer-bounds-fixed-expected.txt (288428 => 288429)
--- trunk/LayoutTests/compositing/geometry/limit-layer-bounds-fixed-expected.txt 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/LayoutTests/compositing/geometry/limit-layer-bounds-fixed-expected.txt 2022-01-24 04:48:29 UTC (rev 288429)
@@ -15,7 +15,6 @@
(offsetFromRenderer width=-100 height=-100)
(position 0.00 3000.00)
(bounds 300.00 200.00)
- (drawsContent 1)
)
)
)
Modified: trunk/LayoutTests/platform/ios-wk2/compositing/geometry/limit-layer-bounds-fixed-expected.txt (288428 => 288429)
--- trunk/LayoutTests/platform/ios-wk2/compositing/geometry/limit-layer-bounds-fixed-expected.txt 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/LayoutTests/platform/ios-wk2/compositing/geometry/limit-layer-bounds-fixed-expected.txt 2022-01-24 04:48:29 UTC (rev 288429)
@@ -15,7 +15,6 @@
(offsetFromRenderer width=-100 height=-100)
(position 0.00 3000.00)
(bounds 300.00 200.00)
- (drawsContent 1)
)
)
)
Modified: trunk/Source/WebCore/ChangeLog (288428 => 288429)
--- trunk/Source/WebCore/ChangeLog 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/Source/WebCore/ChangeLog 2022-01-24 04:48:29 UTC (rev 288429)
@@ -1,3 +1,22 @@
+2022-01-23 Matt Woodrow <[email protected]>
+
+ Position:fixed layers shouldn't allocate a backing buffer if all children are offscreen.
+ https://bugs.webkit.org/show_bug.cgi?id=235420
+ <rdar://86612099>
+
+ Reviewed by Simon Fraser and Darin Adler.
+
+ Adds a bounds intersection check to isPaintDestinationForDescendantLayers,
+ so that we can exclude descendants that definitely won't draw anything into
+ the compositing layer. Uses a conservative check, which gives up if there are
+ any transforms in the ancestor chain.
+
+ Test: compositing/backing/no-backing-for-offscreen-children-of-position-fixed.html
+
+ * rendering/RenderLayerBacking.cpp:
+ (WebCore::intersectsWithAncestor):
+ (WebCore::RenderLayerBacking::isPaintDestinationForDescendantLayers const):
+
2022-01-23 Darin Adler <[email protected]>
Fix "componet" typo in just-landed patch.
Modified: trunk/Source/WebCore/rendering/RenderLayerBacking.cpp (288428 => 288429)
--- trunk/Source/WebCore/rendering/RenderLayerBacking.cpp 2022-01-24 02:07:06 UTC (rev 288428)
+++ trunk/Source/WebCore/rendering/RenderLayerBacking.cpp 2022-01-24 04:48:29 UTC (rev 288429)
@@ -2790,12 +2790,34 @@
return LayerTraversal::Continue;
}
+static std::optional<bool> intersectsWithAncestor(const RenderLayer& child, const RenderLayer& ancestor, const LayoutRect& ancestorCompositedBounds)
+{
+ // If any layers between child and ancestor are transformed, then adjusting the offset is
+ // insufficient to convert coordinates into ancestor's coordinate space.
+ for (auto* layer = &child; layer != &ancestor; layer = layer->parent()) {
+ if (!layer->canUseOffsetFromAncestor())
+ return std::nullopt;
+ }
+
+ auto offset = child.convertToLayerCoords(&ancestor, { }, RenderLayer::AdjustForColumns);
+ auto overlap = child.overlapBounds();
+ overlap.moveBy(offset);
+ return overlap.intersects(ancestorCompositedBounds);
+}
+
// Conservative test for having no rendered children.
bool RenderLayerBacking::isPaintDestinationForDescendantLayers(RenderLayer::PaintedContentRequest& request) const
{
bool hasPaintingDescendant = false;
- traverseVisibleNonCompositedDescendantLayers(m_owningLayer, [&hasPaintingDescendant, &request](const RenderLayer& layer) {
- hasPaintingDescendant |= layer.isVisuallyNonEmpty(&request);
+ traverseVisibleNonCompositedDescendantLayers(m_owningLayer, [&hasPaintingDescendant, &request, this](const RenderLayer& layer) {
+ RenderLayer::PaintedContentRequest localRequest;
+ if (layer.isVisuallyNonEmpty(&localRequest)) {
+ bool mayIntersect = intersectsWithAncestor(layer, m_owningLayer, compositedBounds()).value_or(true);
+ if (mayIntersect) {
+ hasPaintingDescendant = true;
+ request.setHasPaintedContent();
+ }
+ }
return (hasPaintingDescendant && request.isSatisfied()) ? LayerTraversal::Stop : LayerTraversal::Continue;
});