Title: [293027] trunk/Source/WebCore
Revision
293027
Author
[email protected]
Date
2022-04-19 11:15:28 -0700 (Tue, 19 Apr 2022)

Log Message

[LFC][Integration] Use WeakPtr for InlineContent in iterator
https://bugs.webkit.org/show_bug.cgi?id=239492

Reviewed by Alan Bujtas.

Simplify the logic and increase robustness.

* layout/integration/inline/InlineIteratorBoxModernPath.h:
(WebCore::InlineIterator::BoxModernPath::atEnd const):

If the layout goes away we are "at end", avoiding hitting null pointers.

* layout/integration/inline/InlineIteratorLineBoxModernPath.h:
(WebCore::InlineIterator::LineBoxIteratorModernPath::atEnd const):
* layout/integration/inline/LayoutIntegrationInlineContent.cpp:
(WebCore::LayoutIntegration::InlineContent::~InlineContent):
(WebCore::LayoutIntegration::InlineContent::clearAndDetach): Deleted.

No need for "detached" state, InlineContent is simply deleted.

* layout/integration/inline/LayoutIntegrationInlineContent.h:

RefCounted -> CanMakeWeakPtr

(WebCore::LayoutIntegration::InlineContent::create): Deleted.
* layout/integration/inline/LayoutIntegrationLineLayout.cpp:
(WebCore::LayoutIntegration::LineLayout::adjustForPagination):
(WebCore::LayoutIntegration::LineLayout::ensureInlineContent):
(WebCore::LayoutIntegration::LineLayout::clearInlineContent):
* layout/integration/inline/LayoutIntegrationLineLayout.h:
* layout/integration/inline/LayoutIntegrationPagination.cpp:
(WebCore::LayoutIntegration::makeAdjustedContent):
(WebCore::LayoutIntegration::adjustLinePositionsForPagination):
* layout/integration/inline/LayoutIntegrationPagination.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293026 => 293027)


--- trunk/Source/WebCore/ChangeLog	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/ChangeLog	2022-04-19 18:15:28 UTC (rev 293027)
@@ -1,3 +1,40 @@
+2022-04-19  Antti Koivisto  <[email protected]>
+
+        [LFC][Integration] Use WeakPtr for InlineContent in iterator
+        https://bugs.webkit.org/show_bug.cgi?id=239492
+
+        Reviewed by Alan Bujtas.
+
+        Simplify the logic and increase robustness.
+
+        * layout/integration/inline/InlineIteratorBoxModernPath.h:
+        (WebCore::InlineIterator::BoxModernPath::atEnd const):
+
+        If the layout goes away we are "at end", avoiding hitting null pointers.
+
+        * layout/integration/inline/InlineIteratorLineBoxModernPath.h:
+        (WebCore::InlineIterator::LineBoxIteratorModernPath::atEnd const):
+        * layout/integration/inline/LayoutIntegrationInlineContent.cpp:
+        (WebCore::LayoutIntegration::InlineContent::~InlineContent):
+        (WebCore::LayoutIntegration::InlineContent::clearAndDetach): Deleted.
+
+        No need for "detached" state, InlineContent is simply deleted.
+
+        * layout/integration/inline/LayoutIntegrationInlineContent.h:
+
+        RefCounted -> CanMakeWeakPtr
+
+        (WebCore::LayoutIntegration::InlineContent::create): Deleted.
+        * layout/integration/inline/LayoutIntegrationLineLayout.cpp:
+        (WebCore::LayoutIntegration::LineLayout::adjustForPagination):
+        (WebCore::LayoutIntegration::LineLayout::ensureInlineContent):
+        (WebCore::LayoutIntegration::LineLayout::clearInlineContent):
+        * layout/integration/inline/LayoutIntegrationLineLayout.h:
+        * layout/integration/inline/LayoutIntegrationPagination.cpp:
+        (WebCore::LayoutIntegration::makeAdjustedContent):
+        (WebCore::LayoutIntegration::adjustLinePositionsForPagination):
+        * layout/integration/inline/LayoutIntegrationPagination.h:
+
 2022-04-19  Chris Dumez  <[email protected]>
 
         Introduce makeAtomString()

Modified: trunk/Source/WebCore/layout/integration/inline/InlineIteratorBoxModernPath.h (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/InlineIteratorBoxModernPath.h	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/InlineIteratorBoxModernPath.h	2022-04-19 18:15:28 UTC (rev 293027)
@@ -204,7 +204,7 @@
 
     bool operator==(const BoxModernPath& other) const { return m_inlineContent == other.m_inlineContent && m_boxIndex == other.m_boxIndex; }
 
-    bool atEnd() const { return m_boxIndex == boxes().size(); }
+    bool atEnd() const { return !m_inlineContent || m_boxIndex == boxes().size(); }
     const InlineDisplay::Box& box() const { return boxes()[m_boxIndex]; }
     auto& inlineContent() const { return *m_inlineContent; }
 
@@ -269,7 +269,7 @@
     const RenderText& renderText() const { return downcast<RenderText>(renderer()); }
     TextDirection direction() const { return bidiLevel() % 2 ? TextDirection::RTL : TextDirection::LTR; }
 
-    RefPtr<const LayoutIntegration::InlineContent> m_inlineContent;
+    WeakPtr<const LayoutIntegration::InlineContent> m_inlineContent;
     size_t m_boxIndex { 0 };
 };
 

Modified: trunk/Source/WebCore/layout/integration/inline/InlineIteratorLineBoxModernPath.h (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/InlineIteratorLineBoxModernPath.h	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/InlineIteratorLineBoxModernPath.h	2022-04-19 18:15:28 UTC (rev 293027)
@@ -91,7 +91,7 @@
 
     bool operator==(const LineBoxIteratorModernPath& other) const { return m_inlineContent == other.m_inlineContent && m_lineIndex == other.m_lineIndex; }
 
-    bool atEnd() const { return m_lineIndex == lines().size(); }
+    bool atEnd() const { return !m_inlineContent || m_lineIndex == lines().size(); }
 
     BoxModernPath firstLeafBox() const
     {
@@ -120,7 +120,7 @@
     const LayoutIntegration::InlineContent::Lines& lines() const { return m_inlineContent->lines; }
     const LayoutIntegration::Line& line() const { return lines()[m_lineIndex]; }
 
-    RefPtr<const LayoutIntegration::InlineContent> m_inlineContent;
+    WeakPtr<const LayoutIntegration::InlineContent> m_inlineContent;
     size_t m_lineIndex { 0 };
 };
 

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.cpp (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.cpp	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.cpp	2022-04-19 18:15:28 UTC (rev 293027)
@@ -87,10 +87,8 @@
 
 InlineContent::~InlineContent()
 {
-    if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) {
-        for (auto& box : boxes)
-            TextPainter::removeGlyphDisplayList(box);
-    }
+    for (auto& box : boxes)
+        TextPainter::removeGlyphDisplayList(box);
 }
 
 const RenderObject& InlineContent::rendererForLayoutBox(const Layout::Box& layoutBox) const
@@ -173,17 +171,6 @@
     return it->value;
 }
 
-void InlineContent::clearAndDetach()
-{
-    for (auto& box : boxes)
-        TextPainter::removeGlyphDisplayList(box);
-
-    releaseCaches();
-    boxes.clear();
-    lines.clear();
-    m_lineLayout = nullptr;
-}
-
 void InlineContent::releaseCaches()
 {
     m_firstBoxIndexCache = { };

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.h (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.h	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationInlineContent.h	2022-04-19 18:15:28 UTC (rev 293027)
@@ -32,6 +32,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/IteratorRange.h>
 #include <wtf/Vector.h>
+#include <wtf/WeakPtr.h>
 
 namespace WebCore {
 
@@ -50,8 +51,10 @@
 
 class LineLayout;
 
-struct InlineContent : public RefCounted<InlineContent> {
-    static Ref<InlineContent> create(const LineLayout& lineLayout) { return adoptRef(*new InlineContent(lineLayout)); }
+struct InlineContent : public CanMakeWeakPtr<InlineContent> {
+    WTF_MAKE_STRUCT_FAST_ALLOCATED;
+
+    InlineContent(const LineLayout&);
     ~InlineContent();
 
     using Boxes = Vector<InlineDisplay::Box>;
@@ -86,12 +89,9 @@
     std::optional<size_t> firstBoxIndexForLayoutBox(const Layout::Box&) const;
     const Vector<size_t>& nonRootInlineBoxIndexesForLayoutBox(const Layout::Box&) const;
 
-    void clearAndDetach();
     void releaseCaches();
 
 private:
-    InlineContent(const LineLayout&);
-
     CheckedPtr<const LineLayout> m_lineLayout;
 
     using FirstBoxIndexCache = HashMap<CheckedRef<const Layout::Box>, size_t>;

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.cpp	2022-04-19 18:15:28 UTC (rev 293027)
@@ -551,7 +551,7 @@
         return;
 
     auto paginedInlineContent = adjustLinePositionsForPagination(*m_inlineContent, flow());
-    if (paginedInlineContent.ptr() == m_inlineContent) {
+    if (!paginedInlineContent) {
         m_isPaginatedContent = false;
         return;
     }
@@ -574,7 +574,7 @@
 InlineContent& LineLayout::ensureInlineContent()
 {
     if (!m_inlineContent)
-        m_inlineContent = InlineContent::create(*this);
+        m_inlineContent = makeUnique<InlineContent>(*this);
     return *m_inlineContent;
 }
 
@@ -887,7 +887,6 @@
 {
     if (!m_inlineContent)
         return;
-    m_inlineContent->clearAndDetach();
     m_inlineContent = nullptr;
 }
 

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationLineLayout.h	2022-04-19 18:15:28 UTC (rev 293027)
@@ -144,7 +144,7 @@
     Layout::InlineFormattingState& m_inlineFormattingState;
     // FIXME: This should be part of LayoutState.
     std::unique_ptr<Layout::InlineDamage> m_lineDamage;
-    RefPtr<InlineContent> m_inlineContent;
+    std::unique_ptr<InlineContent> m_inlineContent;
     bool m_isPaginatedContent { false };
 };
 

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.cpp (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.cpp	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.cpp	2022-04-19 18:15:28 UTC (rev 293027)
@@ -45,7 +45,7 @@
 };
 using PaginatedLines = Vector<PaginatedLine, 20>;
 
-static PaginatedLine computeLineTopAndBottomWithOverflow(const RenderBlockFlow&, InlineContent::Lines& lines, unsigned lineIndex, Vector<Strut>& struts)
+static PaginatedLine computeLineTopAndBottomWithOverflow(const RenderBlockFlow&, const InlineContent::Lines& lines, unsigned lineIndex, Vector<Strut>& struts)
 {
     LayoutUnit offset = 0;
     for (auto& strut : struts) {
@@ -117,7 +117,7 @@
     flow.updateMinimumPageHeight(0, LayoutUnit(inlineContent.lines[minimumLineCount - 1].lineBoxBottom()));
 }
 
-static Ref<InlineContent> makeAdjustedContent(const InlineContent& inlineContent, Vector<float> adjustments)
+static std::unique_ptr<InlineContent> makeAdjustedContent(const InlineContent& inlineContent, Vector<float> adjustments)
 {
     auto moveVertically = [](FloatRect rect, float offset) {
         rect.move(FloatSize(0, offset));
@@ -149,7 +149,7 @@
         return adjustedBox;
     };
 
-    auto adjustedContent = InlineContent::create(inlineContent.lineLayout());
+    auto adjustedContent = makeUnique<InlineContent>(inlineContent.lineLayout());
 
     for (size_t lineIndex = 0; lineIndex < inlineContent.lines.size(); ++lineIndex)
         adjustedContent->lines.append(adjustedLine(inlineContent.lines[lineIndex], adjustments[lineIndex]));
@@ -160,7 +160,7 @@
     return adjustedContent;
 }
 
-Ref<InlineContent> adjustLinePositionsForPagination(InlineContent& inlineContent, RenderBlockFlow& flow)
+std::unique_ptr<InlineContent> adjustLinePositionsForPagination(const InlineContent& inlineContent, RenderBlockFlow& flow)
 {
     Vector<Strut> struts;
     auto lineCount = inlineContent.lines.size();
@@ -167,7 +167,7 @@
     updateMinimumPageHeight(flow, inlineContent, lineCount);
     // First pass with no pagination offset?
     if (!flow.pageLogicalHeightForOffset(0))
-        return inlineContent;
+        return nullptr;
 
     auto widows = flow.style().hasAutoWidows() ? 1 : std::max<int>(flow.style().widows(), 1);
     auto orphans = flow.style().hasAutoOrphans() ? 1 : std::max<int>(flow.style().orphans(), 1);
@@ -190,7 +190,7 @@
     }
 
     if (struts.isEmpty())
-        return inlineContent;
+        return nullptr;
 
     auto adjustments = Vector<float>(lineCount, 0);
     for (auto& strut : struts) {

Modified: trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.h (293026 => 293027)


--- trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.h	2022-04-19 18:07:05 UTC (rev 293026)
+++ trunk/Source/WebCore/layout/integration/inline/LayoutIntegrationPagination.h	2022-04-19 18:15:28 UTC (rev 293027)
@@ -35,7 +35,7 @@
 
 namespace LayoutIntegration {
     
-Ref<InlineContent> adjustLinePositionsForPagination(InlineContent&, RenderBlockFlow&);
+std::unique_ptr<InlineContent> adjustLinePositionsForPagination(const InlineContent&, RenderBlockFlow&);
 
 }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to