Changeset 252868 in webkit
- Timestamp:
- Nov 25, 2019 3:18:05 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252866 r252868 1 2019-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 1 35 2019-11-25 Zalan Bujtas <zalan@apple.com> 2 36 -
trunk/Source/WebCore/rendering/RenderBlockFlow.cpp
r252716 r252868 153 153 } 154 154 155 if ( m_complexLineLayout)156 m_complexLineLayout->lineBoxes().deleteLineBoxes();155 if (complexLineLayout()) 156 complexLineLayout()->lineBoxes().deleteLineBoxes(); 157 157 158 158 blockWillBeDestroyed(); … … 676 676 } 677 677 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); 684 682 } 685 683 … … 2072 2070 if (diff >= StyleDifference::Repaint) { 2073 2071 // 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)) 2075 2073 invalidateLineLayoutPath(); 2076 2074 } … … 2109 2107 m_floatingObjects->clearLineBoxTreePointers(); 2110 2108 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; 2116 2113 2117 2114 RenderBlock::deleteLines(); … … 2950 2947 return SimpleLineLayout::hitTestFlow(*this, *simpleLineLayout, request, result, locationInContainer, accumulatedOffset, hitTestAction); 2951 2948 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); 2953 2950 } 2954 2951 … … 2961 2958 } 2962 2959 2963 m_complexLineLayout->addOverflowFromInlineChildren();2960 complexLineLayout()->addOverflowFromInlineChildren(); 2964 2961 } 2965 2962 … … 3042 3039 3043 3040 // Floats currently affect the choice whether to use simple line layout path. 3044 if ( m_simpleLineLayout) {3041 if (simpleLineLayout()) { 3045 3042 invalidateLineLayoutPath(); 3046 3043 return; … … 3129 3126 LayoutUnit& lastLogicalTop, LayoutUnit& lastLogicalLeft, LayoutUnit& lastLogicalRight, const LogicalSelectionOffsetCaches& cache, const PaintInfo* paintInfo) 3130 3127 { 3131 ASSERT(! m_simpleLineLayout);3128 ASSERT(!simpleLineLayout()); 3132 3129 3133 3130 GapRects result; … … 3544 3541 } 3545 3542 3546 if ( m_complexLineLayout)3547 m_complexLineLayout->lineBoxes().paint(this, paintInfo, paintOffset);3543 if (complexLineLayout()) 3544 complexLineLayout()->lineBoxes().paint(this, paintInfo, paintOffset); 3548 3545 } 3549 3546 … … 3600 3597 return simpleLineLayout->lineCount(); 3601 3598 3602 return m_complexLineLayout && m_complexLineLayout->lineBoxes().firstLineBox();3599 return complexLineLayout() && complexLineLayout()->lineBoxes().firstLineBox(); 3603 3600 } 3604 3601 … … 3608 3605 case UndeterminedPath: 3609 3606 case ForceLineBoxesPath: 3610 ASSERT(! m_simpleLineLayout);3607 ASSERT(!simpleLineLayout()); 3611 3608 return; 3612 3609 case LineBoxesPath: 3613 ASSERT(! m_simpleLineLayout);3610 ASSERT(!simpleLineLayout()); 3614 3611 setLineLayoutPath(UndeterminedPath); 3615 3612 return; 3616 3613 case SimpleLinesPath: 3617 3614 // The simple line layout may have become invalid. 3618 m_ simpleLineLayout = nullptr;3615 m_lineLayout = nullptr; 3619 3616 setLineLayoutPath(UndeterminedPath); 3620 3617 if (needsLayout()) … … 3629 3626 void RenderBlockFlow::layoutSimpleLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom) 3630 3627 { 3631 bool needsLayout = selfNeedsLayout() || relayoutChildren || ! m_simpleLineLayout;3628 bool needsLayout = selfNeedsLayout() || relayoutChildren || !simpleLineLayout(); 3632 3629 if (needsLayout) { 3633 3630 deleteLineBoxesBeforeSimpleLineLayout(); 3634 m_simpleLineLayout = SimpleLineLayout::create(*this); 3635 } 3631 m_lineLayout = SimpleLineLayout::create(*this); 3632 } 3633 auto& simpleLineLayout = *this->simpleLineLayout(); 3634 3636 3635 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 3640 3640 for (auto& renderer : childrenOfType<RenderObject>(*this)) 3641 3641 renderer.clearNeedsLayout(); 3642 ASSERT(!m_complexLineLayout); 3643 LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, *m_simpleLineLayout);3642 3643 LayoutUnit lineLayoutHeight = SimpleLineLayout::computeFlowHeight(*this, simpleLineLayout); 3644 3644 LayoutUnit lineLayoutTop = borderAndPaddingBefore(); 3645 3645 repaintLogicalTop = lineLayoutTop; … … 3652 3652 ASSERT(lineLayoutPath() == SimpleLinesPath); 3653 3653 3654 if ( m_complexLineLayout)3655 m_complexLineLayout->lineBoxes().deleteLineBoxes();3654 if (complexLineLayout()) 3655 complexLineLayout()->lineBoxes().deleteLineBoxes(); 3656 3656 3657 3657 for (auto& renderer : childrenOfType<RenderObject>(*this)) { … … 3664 3664 } 3665 3665 3666 m_ complexLineLayout = nullptr;3666 m_lineLayout = nullptr; 3667 3667 } 3668 3668 … … 3674 3674 setLineLayoutPath(ForceLineBoxesPath); 3675 3675 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(); 3689 3689 3690 3690 #if !ASSERT_DISABLED … … 3696 3696 LayoutUnit repaintLogicalTop; 3697 3697 LayoutUnit repaintLogicalBottom; 3698 if ( isPaginated) {3698 if (simpleLineLayout->isPaginated()) { 3699 3699 PaginatedLayoutStateMaintainer state(*this); 3700 m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);3700 complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); 3701 3701 // This matches relayoutToAvoidWidows. 3702 3702 if (shouldBreakAtLineToAvoidWidow()) 3703 m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);3703 complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); 3704 3704 // FIXME: This is needed as long as simple and normal line layout produce different line breakings. 3705 3705 repaint(); 3706 3706 } else 3707 m_complexLineLayout->layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom);3707 complexLineLayout.layoutLineBoxes(relayoutChildren, repaintLogicalTop, repaintLogicalBottom); 3708 3708 3709 3709 updateLogicalHeight(); -
trunk/Source/WebCore/rendering/RenderBlockFlow.h
r252716 r252868 73 73 void dirtyLinesFromChangedChild(RenderObject& child) final 74 74 { 75 if ( m_complexLineLayout)76 m_complexLineLayout->lineBoxes().dirtyLinesFromChangedChild(*this, child);75 if (complexLineLayout()) 76 complexLineLayout()->lineBoxes().dirtyLinesFromChangedChild(*this, child); 77 77 } 78 78 … … 333 333 LayoutPoint flipFloatForWritingModeForChild(const FloatingObject&, const LayoutPoint&) const; 334 334 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; } 337 337 338 338 bool hasLines() const; … … 355 355 356 356 const SimpleLineLayout::Layout* simpleLineLayout() const; 357 SimpleLineLayout::Layout* simpleLineLayout(); 358 const ComplexLineLayout* complexLineLayout() const; 359 ComplexLineLayout* complexLineLayout(); 360 357 361 void deleteLineBoxesBeforeSimpleLineLayout(); 358 362 void ensureLineBoxes(); … … 524 528 525 529 public: 526 ComplexLineLayout* complexLineLayout() { return m_complexLineLayout.get(); }527 528 530 virtual Optional<TextAlignMode> overrideTextAlignmentForLine(bool /* endsWithSoftBreak */) const { return { }; } 529 531 virtual void adjustInlineDirectionLineBounds(int /* expansionOpportunityCount */, float& /* logicalLeft */, float& /* logicalWidth */) const { } 530 532 531 533 private: 534 bool hasSimpleLineLayout() const; 535 bool hasComplexLineLayout() const; 536 532 537 void layoutSimpleLines(bool relayoutChildren, LayoutUnit& repaintLogicalTop, LayoutUnit& repaintLogicalBottom); 533 538 … … 568 573 std::unique_ptr<RenderBlockFlowRareData> m_rareBlockFlowData; 569 574 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; 575 private: 576 Variant<std::nullptr_t, std::unique_ptr<ComplexLineLayout>, Ref<SimpleLineLayout::Layout>> m_lineLayout; 573 577 574 578 friend class LineBreaker; … … 577 581 }; 578 582 583 inline bool RenderBlockFlow::hasComplexLineLayout() const 584 { 585 return WTF::holds_alternative<std::unique_ptr<ComplexLineLayout>>(m_lineLayout); 586 } 587 588 inline const ComplexLineLayout* RenderBlockFlow::complexLineLayout() const 589 { 590 return hasComplexLineLayout() ? WTF::get<std::unique_ptr<ComplexLineLayout>>(m_lineLayout).get() : nullptr; 591 } 592 593 inline ComplexLineLayout* RenderBlockFlow::complexLineLayout() 594 { 595 return hasComplexLineLayout() ? WTF::get<std::unique_ptr<ComplexLineLayout>>(m_lineLayout).get() : nullptr; 596 } 597 598 inline bool RenderBlockFlow::hasSimpleLineLayout() const 599 { 600 return WTF::holds_alternative<Ref<SimpleLineLayout::Layout>>(m_lineLayout); 601 } 602 579 603 inline const SimpleLineLayout::Layout* RenderBlockFlow::simpleLineLayout() const 580 604 { 581 ASSERT(lineLayoutPath() == SimpleLinesPath || !m_simpleLineLayout); 582 return m_simpleLineLayout.get(); 605 return hasSimpleLineLayout() ? WTF::get<Ref<SimpleLineLayout::Layout>>(m_lineLayout).ptr() : nullptr; 583 606 } 584 607 608 inline SimpleLineLayout::Layout* RenderBlockFlow::simpleLineLayout() 609 { 610 return hasSimpleLineLayout() ? WTF::get<Ref<SimpleLineLayout::Layout>>(m_lineLayout).ptr() : nullptr; 611 } 612 585 613 } // namespace WebCore 586 614
Note: See TracChangeset
for help on using the changeset viewer.