Changeset 252868 in webkit


Ignore:
Timestamp:
Nov 25, 2019 3:18:05 PM (4 years ago)
Author:
Antti Koivisto
Message:

User Variant for RenderBlockFlow line layout
https://bugs.webkit.org/show_bug.cgi?id=204591

Reviewed by Zalan Bujtas.

Move complex and simple line layout structures into a Variant to avoid wasting memory, and to allow easy expansion with an LFC path

  • rendering/RenderBlockFlow.cpp:

(WebCore::RenderBlockFlow::willBeDestroyed):
(WebCore::RenderBlockFlow::layoutInlineChildren):
(WebCore::RenderBlockFlow::styleDidChange):
(WebCore::RenderBlockFlow::deleteLines):
(WebCore::RenderBlockFlow::hitTestInlineChildren):
(WebCore::RenderBlockFlow::addOverflowFromInlineChildren):
(WebCore::RenderBlockFlow::markLinesDirtyInBlockRange):
(WebCore::RenderBlockFlow::inlineSelectionGaps):
(WebCore::RenderBlockFlow::paintInlineChildren):
(WebCore::RenderBlockFlow::hasLines const):
(WebCore::RenderBlockFlow::invalidateLineLayoutPath):
(WebCore::RenderBlockFlow::layoutSimpleLines):
(WebCore::RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout):
(WebCore::RenderBlockFlow::ensureLineBoxes):

  • rendering/RenderBlockFlow.h:

(WebCore::RenderBlockFlow::firstRootBox const):
(WebCore::RenderBlockFlow::lastRootBox const):
(WebCore::RenderBlockFlow::hasComplexLineLayout const):
(WebCore::RenderBlockFlow::complexLineLayout const):
(WebCore::RenderBlockFlow::complexLineLayout):
(WebCore::RenderBlockFlow::hasSimpleLineLayout const):
(WebCore::RenderBlockFlow::simpleLineLayout const):
(WebCore::RenderBlockFlow::simpleLineLayout):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252866 r252868  
     12019-11-25  Antti Koivisto  <antti@apple.com>
     2
     3        User Variant for RenderBlockFlow line layout
     4        https://bugs.webkit.org/show_bug.cgi?id=204591
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Move complex and simple line layout structures into a Variant to avoid wasting memory, and to allow easy expansion with an LFC path
     9
     10        * rendering/RenderBlockFlow.cpp:
     11        (WebCore::RenderBlockFlow::willBeDestroyed):
     12        (WebCore::RenderBlockFlow::layoutInlineChildren):
     13        (WebCore::RenderBlockFlow::styleDidChange):
     14        (WebCore::RenderBlockFlow::deleteLines):
     15        (WebCore::RenderBlockFlow::hitTestInlineChildren):
     16        (WebCore::RenderBlockFlow::addOverflowFromInlineChildren):
     17        (WebCore::RenderBlockFlow::markLinesDirtyInBlockRange):
     18        (WebCore::RenderBlockFlow::inlineSelectionGaps):
     19        (WebCore::RenderBlockFlow::paintInlineChildren):
     20        (WebCore::RenderBlockFlow::hasLines const):
     21        (WebCore::RenderBlockFlow::invalidateLineLayoutPath):
     22        (WebCore::RenderBlockFlow::layoutSimpleLines):
     23        (WebCore::RenderBlockFlow::deleteLineBoxesBeforeSimpleLineLayout):
     24        (WebCore::RenderBlockFlow::ensureLineBoxes):
     25        * rendering/RenderBlockFlow.h:
     26        (WebCore::RenderBlockFlow::firstRootBox const):
     27        (WebCore::RenderBlockFlow::lastRootBox const):
     28        (WebCore::RenderBlockFlow::hasComplexLineLayout const):
     29        (WebCore::RenderBlockFlow::complexLineLayout const):
     30        (WebCore::RenderBlockFlow::complexLineLayout):
     31        (WebCore::RenderBlockFlow::hasSimpleLineLayout const):
     32        (WebCore::RenderBlockFlow::simpleLineLayout const):
     33        (WebCore::RenderBlockFlow::simpleLineLayout):
     34
    1352019-11-25  Zalan Bujtas  <zalan@apple.com>
    236
  • trunk/Source/WebCore/rendering/RenderBlockFlow.cpp

    r252716 r252868  
    153153    }
    154154
    155     if (m_complexLineLayout)
    156         m_complexLineLayout->lineBoxes().deleteLineBoxes();
     155    if (complexLineLayout())
     156        complexLineLayout()->lineBoxes().deleteLineBoxes();
    157157
    158158    blockWillBeDestroyed();
     
    676676    }
    677677
    678     m_simpleLineLayout = nullptr;
    679 
    680     if (!m_complexLineLayout)
    681         m_complexLineLayout = makeUnique<ComplexLineLayout>(*this);
    682 
    683     m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
     678    if (!complexLineLayout())
     679        m_lineLayout = makeUnique<ComplexLineLayout>(*this);
     680
     681    complexLineLayout()->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
    684682}
    685683
     
    20722070    if (diff >= StyleDifference::Repaint) {
    20732071        // FIXME: This could use a cheaper style-only test instead of SimpleLineLayout::canUseFor.
    2074         if (selfNeedsLayout() || !m_simpleLineLayout || !SimpleLineLayout::canUseFor(*this))
     2072        if (selfNeedsLayout() || !simpleLineLayout() || !SimpleLineLayout::canUseFor(*this))
    20752073            invalidateLineLayoutPath();
    20762074    }
     
    21092107        m_floatingObjects->clearLineBoxTreePointers();
    21102108
    2111     if (m_simpleLineLayout) {
    2112         ASSERT(!m_complexLineLayout);
    2113         m_simpleLineLayout = nullptr;
    2114     } else if (m_complexLineLayout)
    2115         m_complexLineLayout->lineBoxes().deleteLineBoxTree();
     2109    if (complexLineLayout())
     2110        complexLineLayout()->lineBoxes().deleteLineBoxTree();
     2111    else
     2112        m_lineLayout = nullptr;
    21162113
    21172114    RenderBlock::deleteLines();
     
    29502947        return SimpleLineLayout::hitTestFlow(*this, *simpleLineLayout, request, result, locationInContainer, accumulatedOffset, hitTestAction);
    29512948
    2952     return m_complexLineLayout && m_complexLineLayout->lineBoxes().hitTest(this, request, result, locationInContainer, accumulatedOffset, hitTestAction);
     2949    return complexLineLayout() && complexLineLayout()->lineBoxes().hitTest(this, request, result, locationInContainer, accumulatedOffset, hitTestAction);
    29532950}
    29542951
     
    29612958    }
    29622959
    2963     m_complexLineLayout->addOverflowFromInlineChildren();
     2960    complexLineLayout()->addOverflowFromInlineChildren();
    29642961}
    29652962
     
    30423039
    30433040    // Floats currently affect the choice whether to use simple line layout path.
    3044     if (m_simpleLineLayout) {
     3041    if (simpleLineLayout()) {
    30453042        invalidateLineLayoutPath();
    30463043        return;
     
    31293126    LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches& cache, const PaintInfo* paintInfo)
    31303127{
    3131     ASSERT(!m_simpleLineLayout);
     3128    ASSERT(!simpleLineLayout());
    31323129
    31333130    GapRects result;
     
    35443541    }
    35453542
    3546     if (m_complexLineLayout)
    3547         m_complexLineLayout->lineBoxes().paint(this, paintInfo, paintOffset);
     3543    if (complexLineLayout())
     3544        complexLineLayout()->lineBoxes().paint(this, paintInfo, paintOffset);
    35483545}
    35493546
     
    36003597        return simpleLineLayout->lineCount();
    36013598
    3602     return m_complexLineLayout && m_complexLineLayout->lineBoxes().firstLineBox();
     3599    return complexLineLayout() && complexLineLayout()->lineBoxes().firstLineBox();
    36033600}
    36043601
     
    36083605    case UndeterminedPath:
    36093606    case ForceLineBoxesPath:
    3610         ASSERT(!m_simpleLineLayout);
     3607        ASSERT(!simpleLineLayout());
    36113608        return;
    36123609    case LineBoxesPath:
    3613         ASSERT(!m_simpleLineLayout);
     3610        ASSERT(!simpleLineLayout());
    36143611        setLineLayoutPath(UndeterminedPath);
    36153612        return;
    36163613    case SimpleLinesPath:
    36173614        // The simple line layout may have become invalid.
    3618         m_simpleLineLayout = nullptr;
     3615        m_lineLayout = nullptr;
    36193616        setLineLayoutPath(UndeterminedPath);
    36203617        if (needsLayout())
     
    36293626void RenderBlockFlow::layoutSimpleLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom)
    36303627{
    3631     bool needsLayout = selfNeedsLayout() || relayoutChildren || !m_simpleLineLayout;
     3628    bool needsLayout = selfNeedsLayout() || relayoutChildren || !simpleLineLayout();
    36323629    if (needsLayout) {
    36333630        deleteLineBoxesBeforeSimpleLineLayout();
    3634         m_simpleLineLayout = SimpleLineLayout::create(*this);
    3635     }
     3631        m_lineLayout = SimpleLineLayout::create(*this);
     3632    }
     3633    auto& simpleLineLayout = *this->simpleLineLayout();
     3634
    36363635    if (view().frameView().layoutContext().layoutState() && view().frameView().layoutContext().layoutState()->isPaginated()) {
    3637         m_simpleLineLayout->setIsPaginated();
    3638         SimpleLineLayout::adjustLinePositionsForPagination(*m_simpleLineLayout, *this);
    3639     }
     3636        simpleLineLayout.setIsPaginated();
     3637        SimpleLineLayout::adjustLinePositionsForPagination(simpleLineLayout, *this);
     3638    }
     3639
    36403640    for (auto& renderer : childrenOfType<RenderObject>(*this))
    36413641        renderer.clearNeedsLayout();
    3642     ASSERT(!m_complexLineLayout);
    3643     LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, *m_simpleLineLayout);
     3642
     3643    LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, simpleLineLayout);
    36443644    LayoutUnit lineLayoutTop = borderAndPaddingBefore();
    36453645    repaintLogicalTop = lineLayoutTop;
     
    36523652    ASSERT(lineLayoutPath() == SimpleLinesPath);
    36533653
    3654     if (m_complexLineLayout)
    3655         m_complexLineLayout->lineBoxes().deleteLineBoxes();
     3654    if (complexLineLayout())
     3655        complexLineLayout()->lineBoxes().deleteLineBoxes();
    36563656
    36573657    for (auto& renderer : childrenOfType<RenderObject>(*this)) {
     
    36643664    }
    36653665
    3666     m_complexLineLayout = nullptr;
     3666    m_lineLayout = nullptr;
    36673667}
    36683668
     
    36743674    setLineLayoutPath(ForceLineBoxesPath);
    36753675
    3676     if (!m_simpleLineLayout)
    3677         return;
    3678 
    3679     ASSERT(!m_complexLineLayout);
    3680     m_complexLineLayout = makeUnique<ComplexLineLayout>(*this);
    3681 
    3682     if (SimpleLineLayout::canUseForLineBoxTree(*this, *m_simpleLineLayout)) {
    3683         SimpleLineLayout::generateLineBoxTree(*this, *m_simpleLineLayout);
    3684         m_simpleLineLayout = nullptr;
    3685         return;
    3686     }
    3687     bool isPaginated = m_simpleLineLayout->isPaginated();
    3688     m_simpleLineLayout = nullptr;
     3676    if (!simpleLineLayout())
     3677        return;
     3678
     3679    auto simpleLineLayout = makeRef(*this->simpleLineLayout());
     3680
     3681    m_lineLayout = makeUnique<ComplexLineLayout>(*this);
     3682
     3683    if (SimpleLineLayout::canUseForLineBoxTree(*this, simpleLineLayout.get())) {
     3684        SimpleLineLayout::generateLineBoxTree(*this, simpleLineLayout.get());
     3685        return;
     3686    }
     3687
     3688    auto& complexLineLayout = *this->complexLineLayout();
    36893689
    36903690#if !ASSERT_DISABLED
     
    36963696    LayoutUnit repaintLogicalTop;
    36973697    LayoutUnit repaintLogicalBottom;
    3698     if (isPaginated) {
     3698    if (simpleLineLayout->isPaginated()) {
    36993699        PaginatedLayoutStateMaintainer state(*this);
    3700         m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
     3700        complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
    37013701        // This matches relayoutToAvoidWidows.
    37023702        if (shouldBreakAtLineToAvoidWidow())
    3703             m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
     3703            complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
    37043704        // FIXME: This is needed as long as simple and normal line layout produce different line breakings.
    37053705        repaint();
    37063706    } else
    3707         m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
     3707        complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);
    37083708
    37093709    updateLogicalHeight();
  • trunk/Source/WebCore/rendering/RenderBlockFlow.h

    r252716 r252868  
    7373    void dirtyLinesFromChangedChild(RenderObject& child) final
    7474    {
    75         if (m_complexLineLayout)
    76             m_complexLineLayout->lineBoxes().dirtyLinesFromChangedChild(*this, child);
     75        if (complexLineLayout())
     76            complexLineLayout()->lineBoxes().dirtyLinesFromChangedChild(*this, child);
    7777    }
    7878
     
    333333    LayoutPoint flipFloatForWritingModeForChild(const FloatingObject&, const LayoutPoint&) const;
    334334
    335     RootInlineBox* firstRootBox() const { return m_complexLineLayout ? m_complexLineLayout->firstRootBox() : nullptr; }
    336     RootInlineBox* lastRootBox() const { return m_complexLineLayout ? m_complexLineLayout->lastRootBox() : nullptr; }
     335    RootInlineBox* firstRootBox() const { return complexLineLayout() ? complexLineLayout()->firstRootBox() : nullptr; }
     336    RootInlineBox* lastRootBox() const { return complexLineLayout() ? complexLineLayout()->lastRootBox() : nullptr; }
    337337
    338338    bool hasLines() const;
     
    355355
    356356    const SimpleLineLayout::Layout* simpleLineLayout() const;
     357    SimpleLineLayout::Layout* simpleLineLayout();
     358    const ComplexLineLayout* complexLineLayout() const;
     359    ComplexLineLayout* complexLineLayout();
     360
    357361    void deleteLineBoxesBeforeSimpleLineLayout();
    358362    void ensureLineBoxes();
     
    524528
    525529public:
    526     ComplexLineLayout* complexLineLayout() { return m_complexLineLayout.get(); }
    527 
    528530    virtual Optional<TextAlignMode> overrideTextAlignmentForLine(bool /* endsWithSoftBreak */) const { return { }; }
    529531    virtual void adjustInlineDirectionLineBounds(int /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { }
    530532
    531533private:
     534    bool hasSimpleLineLayout() const;
     535    bool hasComplexLineLayout() const;
     536
    532537    void layoutSimpleLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom);
    533538
     
    568573    std::unique_ptr<RenderBlockFlowRareData> m_rareBlockFlowData;
    569574
    570     // FIXME: Only one of these should be needed at any given time.
    571     std::unique_ptr<ComplexLineLayout> m_complexLineLayout;
    572     RefPtr<SimpleLineLayout::Layout> m_simpleLineLayout;
     575private:
     576    Variant<std::nullptr_t, std::unique_ptr<ComplexLineLayout>, Ref<SimpleLineLayout::Layout>> m_lineLayout;
    573577
    574578    friend class LineBreaker;
     
    577581};
    578582
     583inline bool RenderBlockFlow::hasComplexLineLayout() const
     584{
     585    return WTF::holds_alternative<std::unique_ptr<ComplexLineLayout>>(m_lineLayout);
     586}
     587
     588inline const ComplexLineLayout* RenderBlockFlow::complexLineLayout() const
     589{
     590    return hasComplexLineLayout() ? WTF::get<std::unique_ptr<ComplexLineLayout>>(m_lineLayout).get() : nullptr;
     591}
     592
     593inline ComplexLineLayout* RenderBlockFlow::complexLineLayout()
     594{
     595    return hasComplexLineLayout() ? WTF::get<std::unique_ptr<ComplexLineLayout>>(m_lineLayout).get() : nullptr;
     596}
     597
     598inline bool RenderBlockFlow::hasSimpleLineLayout() const
     599{
     600    return WTF::holds_alternative<Ref<SimpleLineLayout::Layout>>(m_lineLayout);
     601}
     602
    579603inline const SimpleLineLayout::Layout* RenderBlockFlow::simpleLineLayout() const
    580604{
    581     ASSERT(lineLayoutPath() == SimpleLinesPath || !m_simpleLineLayout);
    582     return m_simpleLineLayout.get();
     605    return hasSimpleLineLayout() ? WTF::get<Ref<SimpleLineLayout::Layout>>(m_lineLayout).ptr() : nullptr;
    583606}
    584607
     608inline SimpleLineLayout::Layout* RenderBlockFlow::simpleLineLayout()
     609{
     610    return hasSimpleLineLayout() ? WTF::get<Ref<SimpleLineLayout::Layout>>(m_lineLayout).ptr() : nullptr;
     611}
     612
    585613} // namespace WebCore
    586614
Note: See TracChangeset for help on using the changeset viewer.