Skip to content

Commit

Permalink
RenderLayer::recursiveUpdateLayerPositions() no longer needs a Render…
Browse files Browse the repository at this point in the history
…GeometryMap

https://bugs.webkit.org/show_bug.cgi?id=265821
rdar://119153457

Reviewed by Alan Baradlay.

Now that we no longer call `outlineBoundsForRepaint()` in `RenderLayer::computeRepaintRects()`
we don't need to pass a RenderGeometryMap around, which means that it's more efficient for
`recursiveUpdateLayerPositions()` to just not create and maintain one (the pushing and popping
is not free).

This is a minor progression on some MotionMark subtests.

* Source/WebCore/rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateLayerPositionsAfterStyleChange):
(WebCore::RenderLayer::updateLayerPositionsAfterLayout):
(WebCore::RenderLayer::recursiveUpdateLayerPositions):
(WebCore::RenderLayer::computeRepaintRects):
(WebCore::RenderLayer::updateLayerPositionsAfterOverflowScroll):
(WebCore::RenderLayer::updateLayerPositionsAfterDocumentScroll):
(WebCore::RenderLayer::recursiveUpdateLayerPositionsAfterScroll):
* Source/WebCore/rendering/RenderLayer.h:
(WebCore::RenderLayer::recursiveUpdateLayerPositionsAfterScroll):

Canonical link: https://commits.webkit.org/271541@main
  • Loading branch information
smfr committed Dec 5, 2023
1 parent 73cbb93 commit c6fb016
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 47 deletions.
57 changes: 14 additions & 43 deletions Source/WebCore/rendering/RenderLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
#include "RenderFlexibleBox.h"
#include "RenderFragmentContainer.h"
#include "RenderFragmentedFlow.h"
#include "RenderGeometryMap.h"
#include "RenderHTMLCanvas.h"
#include "RenderImage.h"
#include "RenderInline.h"
Expand Down Expand Up @@ -969,7 +968,7 @@ void RenderLayer::willUpdateLayerPositions()
void RenderLayer::updateLayerPositionsAfterStyleChange()
{
willUpdateLayerPositions();
recursiveUpdateLayerPositions(nullptr, flagsForUpdateLayerPositions(*this));
recursiveUpdateLayerPositions(flagsForUpdateLayerPositions(*this));
}

void RenderLayer::updateLayerPositionsAfterLayout(bool isRelayoutingSubtree, bool didFullRepaint)
Expand All @@ -988,34 +987,22 @@ void RenderLayer::updateLayerPositionsAfterLayout(bool isRelayoutingSubtree, boo
LOG(Compositing, "RenderLayer %p updateLayerPositionsAfterLayout", this);
willUpdateLayerPositions();

RenderGeometryMap geometryMap(UseTransforms, renderer().settings().css3DTransformInteroperabilityEnabled());
if (!isRenderViewLayer())
geometryMap.pushMappingsToAncestor(parent(), nullptr);

recursiveUpdateLayerPositions(&geometryMap, updateLayerPositionFlags(isRelayoutingSubtree, didFullRepaint));
recursiveUpdateLayerPositions(updateLayerPositionFlags(isRelayoutingSubtree, didFullRepaint));
}

void RenderLayer::recursiveUpdateLayerPositions(RenderGeometryMap* geometryMap, OptionSet<UpdateLayerPositionsFlag> flags)
void RenderLayer::recursiveUpdateLayerPositions(OptionSet<UpdateLayerPositionsFlag> flags)
{
updateLayerPosition(&flags);
if (m_scrollableArea)
m_scrollableArea->applyPostLayoutScrollPositionIfNeeded();

if (geometryMap)
geometryMap->pushMappingsToAncestor(this, parent());

// Clear our cached clip rect information.
clearClipRects();

if (m_scrollableArea && m_scrollableArea->hasOverflowControls()) {
LayoutSize offsetFromRoot;
if (geometryMap)
offsetFromRoot = LayoutSize(toFloatSize(geometryMap->absolutePoint(FloatPoint())));
else {
// FIXME: It looks suspicious to call convertToLayerCoords here
// as canUseOffsetFromAncestor may be true for an ancestor layer.
offsetFromRoot = offsetFromAncestor(root());
}
// FIXME: It looks suspicious to call convertToLayerCoords here
// as canUseOffsetFromAncestor may be true for an ancestor layer.
auto offsetFromRoot = offsetFromAncestor(root());
m_scrollableArea->positionOverflowControls(roundedIntSize(offsetFromRoot));
}

Expand All @@ -1040,7 +1027,7 @@ void RenderLayer::recursiveUpdateLayerPositions(RenderGeometryMap* geometryMap,
CheckedPtr repaintContainer = renderer().containerForRepaint().renderer;

auto oldRects = repaintRects();
computeRepaintRects(repaintContainer.get(), geometryMap);
computeRepaintRects(repaintContainer.get());
auto newRects = repaintRects();

if (checkForRepaint && shouldRepaintAfterLayout() && newRects) {
Expand Down Expand Up @@ -1088,7 +1075,7 @@ void RenderLayer::recursiveUpdateLayerPositions(RenderGeometryMap* geometryMap,
flags.add(SeenCompositedScrollingLayer);

for (RenderLayer* child = firstChild(); child; child = child->nextSibling())
child->recursiveUpdateLayerPositions(geometryMap, flags);
child->recursiveUpdateLayerPositions(flags);

if (m_scrollableArea)
m_scrollableArea->updateMarqueePosition();
Expand All @@ -1114,9 +1101,6 @@ void RenderLayer::recursiveUpdateLayerPositions(RenderGeometryMap* geometryMap,

if (isComposited())
backing()->updateAfterLayout(flags.contains(ContainingClippingLayerChangedSize), flags.contains(NeedsFullRepaintInBacking));

if (geometryMap)
geometryMap->popMappingsToAncestor(parent());
}

LayoutRect RenderLayer::repaintRectIncludingNonCompositingDescendants() const
Expand Down Expand Up @@ -1171,7 +1155,7 @@ std::optional<LayoutRect> RenderLayer::cachedClippedOverflowRect() const
return m_repaintRects.clippedOverflowRect;
}

void RenderLayer::computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap*)
void RenderLayer::computeRepaintRects(const RenderLayerModelObject* repaintContainer)
{
ASSERT(!m_visibleContentStatusDirty);

Expand Down Expand Up @@ -1205,15 +1189,11 @@ void RenderLayer::clearRepaintRects()

void RenderLayer::updateLayerPositionsAfterOverflowScroll()
{
RenderGeometryMap geometryMap(UseTransforms, renderer().settings().css3DTransformInteroperabilityEnabled());
if (!isRenderViewLayer())
geometryMap.pushMappingsToAncestor(parent(), nullptr);

willUpdateLayerPositions();

// FIXME: why is it OK to not check the ancestors of this layer in order to
// initialize the HasSeenViewportConstrainedAncestor and HasSeenAncestorWithOverflowClip flags?
recursiveUpdateLayerPositionsAfterScroll(&geometryMap, RenderLayer::IsOverflowScroll);
recursiveUpdateLayerPositionsAfterScroll(RenderLayer::IsOverflowScroll);
}

void RenderLayer::updateLayerPositionsAfterDocumentScroll()
Expand All @@ -1222,12 +1202,10 @@ void RenderLayer::updateLayerPositionsAfterDocumentScroll()
LOG(Scrolling, "RenderLayer::updateLayerPositionsAfterDocumentScroll");

willUpdateLayerPositions();

RenderGeometryMap geometryMap(UseTransforms, renderer().settings().css3DTransformInteroperabilityEnabled());
recursiveUpdateLayerPositionsAfterScroll(&geometryMap);
recursiveUpdateLayerPositionsAfterScroll();
}

void RenderLayer::recursiveUpdateLayerPositionsAfterScroll(RenderGeometryMap* geometryMap, OptionSet<UpdateLayerPositionsAfterScrollFlag> flags)
void RenderLayer::recursiveUpdateLayerPositionsAfterScroll(OptionSet<UpdateLayerPositionsAfterScrollFlag> flags)
{
// FIXME: This shouldn't be needed, but there are some corner cases where
// these flags are still dirty. Update so that the check below is valid.
Expand All @@ -1254,32 +1232,25 @@ void RenderLayer::recursiveUpdateLayerPositionsAfterScroll(RenderGeometryMap* ge

bool shouldComputeRepaintRects = (flags.contains(HasSeenViewportConstrainedAncestor) || flags.containsAll({ IsOverflowScroll, HasSeenAncestorWithOverflowClip })) && isSelfPaintingLayer();
bool isVisuallyEmpty = !isVisuallyNonEmpty();
bool shouldPushAndPopMappings = geometryMap && ((shouldComputeRepaintRects && !isVisuallyEmpty) || firstChild());
if (shouldPushAndPopMappings)
geometryMap->pushMappingsToAncestor(this, parent());

if (shouldComputeRepaintRects) {
// When scrolling, we don't compute repaint rects for visually non-empty layers.
if (isVisuallyEmpty)
clearRepaintRects();
else {
// FIXME: We could track the repaint container as we walk down the tree.
computeRepaintRects(renderer().containerForRepaint().renderer.get(), geometryMap);
computeRepaintRects(renderer().containerForRepaint().renderer.get());
}
}

for (auto* child = firstChild(); child; child = child->nextSibling())
child->recursiveUpdateLayerPositionsAfterScroll(geometryMap, flags);
child->recursiveUpdateLayerPositionsAfterScroll(flags);

// We don't update our reflection as scrolling is a translation which does not change the size()
// of an object, thus RenderReplica will still repaint itself properly as the layer position was
// updated above.

if (m_scrollableArea)
m_scrollableArea->updateMarqueePosition();

if (shouldPushAndPopMappings)
geometryMap->popMappingsToAncestor(parent());
}

#if ENABLE(CSS_COMPOSITING)
Expand Down
7 changes: 3 additions & 4 deletions Source/WebCore/rendering/RenderLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class HitTestingTransformState;
class Region;
class RegionContext;
class RenderFragmentedFlow;
class RenderGeometryMap;
class RenderLayerBacking;
class RenderLayerCompositor;
class RenderLayerFilters;
Expand Down Expand Up @@ -972,7 +971,7 @@ class RenderLayer : public CanMakeSingleThreadWeakPtr<RenderLayer>, public CanMa
return { };
}

void computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* = nullptr);
void computeRepaintRects(const RenderLayerModelObject* repaintContainer);
void computeRepaintRectsIncludingDescendants();

void setRepaintRects(const RenderObject::RepaintRects&);
Expand Down Expand Up @@ -1004,15 +1003,15 @@ class RenderLayer : public CanMakeSingleThreadWeakPtr<RenderLayer>, public CanMa
// Returns true if the position changed.
bool updateLayerPosition(OptionSet<UpdateLayerPositionsFlag>* = nullptr);

void recursiveUpdateLayerPositions(RenderGeometryMap*, OptionSet<UpdateLayerPositionsFlag>);
void recursiveUpdateLayerPositions(OptionSet<UpdateLayerPositionsFlag>);

enum UpdateLayerPositionsAfterScrollFlag {
IsOverflowScroll = 1 << 0,
HasSeenViewportConstrainedAncestor = 1 << 1,
HasSeenAncestorWithOverflowClip = 1 << 2,
HasChangedAncestor = 1 << 3,
};
void recursiveUpdateLayerPositionsAfterScroll(RenderGeometryMap*, OptionSet<UpdateLayerPositionsAfterScrollFlag> = { });
void recursiveUpdateLayerPositionsAfterScroll(OptionSet<UpdateLayerPositionsAfterScrollFlag> = { });

RenderLayer* enclosingPaginationLayerInSubtree(const RenderLayer* rootLayer, PaginationInclusionMode) const;

Expand Down

0 comments on commit c6fb016

Please sign in to comment.