Title: [293943] trunk/Source/WebCore
Revision
293943
Author
simon.fra...@apple.com
Date
2022-05-06 19:07:00 -0700 (Fri, 06 May 2022)

Log Message

Optimize shouldApplyContainment methods
https://bugs.webkit.org/show_bug.cgi?id=240164

Reviewed by Alan Bujtas.

Based on a patch by Rob Buis.

Optimize shouldApplyContainment methods by allowing OptionSet as a parameter.
Also restrict the principal box checks to a single location.

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::computeIntrinsicLogicalWidths const):
* rendering/RenderBlockFlow.cpp:
(WebCore::RenderBlockFlow::computeIntrinsicLogicalWidths const):
* rendering/RenderElement.h:
(WebCore::RenderElement::canContainFixedPositionObjects const):
(WebCore::RenderElement::canContainAbsolutelyPositionedObjects const):
(WebCore::RenderElement::shouldApplyLayoutOrPaintContainment const):
(WebCore::RenderElement::shouldApplySizeOrStyleContainment const):
(WebCore::RenderElement::shouldApplyLayoutContainment const):
(WebCore::RenderElement::shouldApplyPaintContainment const):
(WebCore::RenderElement::shouldApplySizeContainment const):
(WebCore::RenderElement::shouldApplyInlineSizeContainment const):
(WebCore::RenderElement::shouldApplyStyleContainment const):
(WebCore::RenderElement::shouldApplyAnyContainment const):
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::computeIntrinsicLogicalWidths const):
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeEmptyTracksForAutoRepeat const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293942 => 293943)


--- trunk/Source/WebCore/ChangeLog	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/ChangeLog	2022-05-07 02:07:00 UTC (rev 293943)
@@ -1,3 +1,36 @@
+2022-05-06  Simon Fraser  <simon.fra...@apple.com>
+
+        Optimize shouldApplyContainment methods
+        https://bugs.webkit.org/show_bug.cgi?id=240164
+
+        Reviewed by Alan Bujtas.
+
+        Based on a patch by Rob Buis.
+
+        Optimize shouldApplyContainment methods by allowing OptionSet as a parameter.
+        Also restrict the principal box checks to a single location.
+
+        * rendering/RenderBlock.cpp:
+        (WebCore::RenderBlock::computeIntrinsicLogicalWidths const):
+        * rendering/RenderBlockFlow.cpp:
+        (WebCore::RenderBlockFlow::computeIntrinsicLogicalWidths const):
+        * rendering/RenderElement.h:
+        (WebCore::RenderElement::canContainFixedPositionObjects const):
+        (WebCore::RenderElement::canContainAbsolutelyPositionedObjects const):
+        (WebCore::RenderElement::shouldApplyLayoutOrPaintContainment const):
+        (WebCore::RenderElement::shouldApplySizeOrStyleContainment const):
+        (WebCore::RenderElement::shouldApplyLayoutContainment const):
+        (WebCore::RenderElement::shouldApplyPaintContainment const):
+        (WebCore::RenderElement::shouldApplySizeContainment const):
+        (WebCore::RenderElement::shouldApplyInlineSizeContainment const):
+        (WebCore::RenderElement::shouldApplyStyleContainment const):
+        (WebCore::RenderElement::shouldApplyAnyContainment const):
+        * rendering/RenderFlexibleBox.cpp:
+        (WebCore::RenderFlexibleBox::computeIntrinsicLogicalWidths const):
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::layoutBlock):
+        (WebCore::RenderGrid::computeEmptyTracksForAutoRepeat const):
+
 2022-05-06  Commit Queue  <commit-qu...@webkit.org>
 
         Unreviewed, reverting r293824.

Modified: trunk/Source/WebCore/rendering/RenderBlock.cpp (293942 => 293943)


--- trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/rendering/RenderBlock.cpp	2022-05-07 02:07:00 UTC (rev 293943)
@@ -2255,7 +2255,7 @@
 void RenderBlock::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
 {
     ASSERT(!childrenInline());
-    auto shouldIgnoreDescendantContentForLogicalWidth = shouldApplySizeContainment() || shouldApplyInlineSizeContainment();
+    auto shouldIgnoreDescendantContentForLogicalWidth = shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize });
     if (!shouldIgnoreDescendantContentForLogicalWidth)
         computeBlockPreferredLogicalWidths(minLogicalWidth, maxLogicalWidth);
 

Modified: trunk/Source/WebCore/rendering/RenderBlockFlow.cpp (293942 => 293943)


--- trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/rendering/RenderBlockFlow.cpp	2022-05-07 02:07:00 UTC (rev 293943)
@@ -345,7 +345,7 @@
 
 void RenderBlockFlow::computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const
 {
-    auto shouldIgnoreDescendantContentForLogicalWidth = shouldApplySizeContainment() || shouldApplyInlineSizeContainment();
+    auto shouldIgnoreDescendantContentForLogicalWidth = shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize });
     if (!shouldIgnoreDescendantContentForLogicalWidth) {
         if (childrenInline())
             computeInlinePreferredLogicalWidths(minLogicalWidth, maxLogicalWidth);

Modified: trunk/Source/WebCore/rendering/RenderElement.h (293942 => 293943)


--- trunk/Source/WebCore/rendering/RenderElement.h	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/rendering/RenderElement.h	2022-05-07 02:07:00 UTC (rev 293943)
@@ -92,6 +92,8 @@
     bool shouldApplyStyleContainment() const;
     bool shouldApplyPaintContainment() const;
     bool shouldApplyAnyContainment() const;
+    bool shouldApplyLayoutOrPaintContainment(OptionSet<Containment>) const;
+    bool shouldApplySizeOrStyleContainment(OptionSet<Containment>) const;
 
     Color selectionColor(CSSPropertyID) const;
     std::unique_ptr<RenderStyle> selectionPseudoStyle() const;
@@ -475,23 +477,19 @@
 {
     return isRenderView()
         || (canEstablishContainingBlockWithTransform() && hasTransform())
-        // FIXME: will-change should create containing blocks on inline boxes (bug 225035)
-        || (isRenderBlock() && style().willChange() && style().willChange()->createsContainingBlockForOutOfFlowPositioned())
+        || (isRenderBlock() && style().willChange() && style().willChange()->createsContainingBlockForOutOfFlowPositioned()) // FIXME: will-change should create containing blocks on inline boxes (bug 225035)
         || isSVGForeignObject()
-        || shouldApplyLayoutContainment()
-        || shouldApplyPaintContainment();
+        || shouldApplyLayoutOrPaintContainment({ Containment::Layout, Containment::Paint });
 }
 
 inline bool RenderElement::canContainAbsolutelyPositionedObjects() const
 {
-    return style().position() != PositionType::Static
+    return isRenderView()
+        || style().position() != PositionType::Static
         || (canEstablishContainingBlockWithTransform() && hasTransformRelatedProperty())
-        // FIXME: will-change should create containing blocks on inline boxes (bug 225035)
-        || (isRenderBlock() && style().willChange() && style().willChange()->createsContainingBlockForAbsolutelyPositioned())
+        || (isRenderBlock() && style().willChange() && style().willChange()->createsContainingBlockForAbsolutelyPositioned()) // FIXME: will-change should create containing blocks on inline boxes (bug 225035)
         || isSVGForeignObject()
-        || shouldApplyLayoutContainment()
-        || shouldApplyPaintContainment()
-        || isRenderView();
+        || shouldApplyLayoutOrPaintContainment({ Containment::Layout, Containment::Paint });
 }
 
 inline bool RenderElement::canEstablishContainingBlockWithTransform() const
@@ -499,40 +497,45 @@
     return isRenderBlock() || (isTablePart() && !isRenderTableCol());
 }
 
+inline bool RenderElement::shouldApplyLayoutOrPaintContainment(OptionSet<Containment> options) const
+{
+    return style().effectiveContainment().containsAny(options) && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isRenderBlockFlow());
+}
+
+inline bool RenderElement::shouldApplySizeOrStyleContainment(OptionSet<Containment> options) const
+{
+    return style().effectiveContainment().containsAny(options) && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isTableCaption()) && !isTable();
+}
+
 inline bool RenderElement::shouldApplyLayoutContainment() const
 {
-    return style().containsLayout() && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isRenderBlockFlow());
+    return shouldApplyLayoutOrPaintContainment(Containment::Layout);
 }
 
+inline bool RenderElement::shouldApplyPaintContainment() const
+{
+    return shouldApplyLayoutOrPaintContainment(Containment::Paint);
+}
+
 inline bool RenderElement::shouldApplySizeContainment() const
 {
-    return style().containsSize() && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isTableCaption()) && !isTable();
+    return shouldApplySizeOrStyleContainment(Containment::Size);
 }
 
 inline bool RenderElement::shouldApplyInlineSizeContainment() const
 {
-    return style().effectiveContainment().contains(Containment::InlineSize) && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isTableCaption()) && !isTable();
+    return shouldApplySizeOrStyleContainment(Containment::InlineSize);
 }
 
 inline bool RenderElement::shouldApplyStyleContainment() const
 {
-    if (!style().containsStyle())
-        return false;
-    return (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isTableCaption()) && !isTable();
+    return shouldApplySizeOrStyleContainment(Containment::Style);
 }
 
-inline bool RenderElement::shouldApplyPaintContainment() const
-{
-    return style().containsPaint() && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isRenderBlockFlow());
-}
-
 inline bool RenderElement::shouldApplyAnyContainment() const
 {
-    if (style().effectiveContainment().isEmpty())
-        return false;
-    if ((style().containsLayout() || style().containsPaint()) && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isRenderBlockFlow()))
-        return true;
-    return (style().containsSize() || style().containsStyle()) && (!isInline() || isAtomicInlineLevelBox()) && !isRubyText() && (!isTablePart() || isTableCaption()) && !isTable();
+    return shouldApplyLayoutOrPaintContainment({ Containment::Layout, Containment::Paint })
+        || shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize, Containment::Style });
 }
 
 inline bool RenderElement::createsGroupForStyle(const RenderStyle& style)

Modified: trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp (293942 => 293943)


--- trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/rendering/RenderFlexibleBox.cpp	2022-05-07 02:07:00 UTC (rev 293943)
@@ -103,7 +103,7 @@
         minLogicalWidth += scrollbarWidth;
     };
 
-    auto shouldIgnoreFlexItemContentForLogicalWidth = shouldApplySizeContainment() || shouldApplyInlineSizeContainment();
+    auto shouldIgnoreFlexItemContentForLogicalWidth = shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize });
     if (shouldIgnoreFlexItemContentForLogicalWidth) {
         addScrollbarWidth();
         return;

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (293942 => 293943)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-05-07 01:52:24 UTC (rev 293942)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-05-07 02:07:00 UTC (rev 293943)
@@ -299,7 +299,7 @@
         // logical width is always definite as the above call to updateLogicalWidth() properly resolves intrinsic 
         // sizes. We cannot do the same for heights though because many code paths inside updateLogicalHeight() require 
         // a previous call to setLogicalHeight() to resolve heights properly (like for positioned items for example).
-        auto shouldIgnoreGridItemContentForLogicalWidth = shouldApplySizeContainment() || shouldApplyInlineSizeContainment();
+        auto shouldIgnoreGridItemContentForLogicalWidth = shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize });
         if (shouldIgnoreGridItemContentForLogicalWidth)
             computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForColumns);
         else
@@ -643,7 +643,7 @@
     unsigned firstAutoRepeatTrack = insertionPoint + grid.explicitGridStart(direction);
     unsigned lastAutoRepeatTrack = firstAutoRepeatTrack + grid.autoRepeatTracks(direction);
 
-    if (!grid.hasGridItems() || shouldApplySizeContainment() || shouldApplyInlineSizeContainment()) {
+    if (!grid.hasGridItems() || shouldApplySizeOrStyleContainment({ Containment::Size, Containment::InlineSize })) {
         emptyTrackIndexes = makeUnique<OrderedTrackIndexSet>();
         for (unsigned trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepeatTrack; ++trackIndex)
             emptyTrackIndexes->add(trackIndex);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to