Changeset 252534 in webkit
- Timestamp:
- Nov 17, 2019 2:30:18 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r252533 r252534 1 2019-11-17 Zalan Bujtas <zalan@apple.com> 2 3 [LFC] Move layout state initialization out of LayoutContext 4 https://bugs.webkit.org/show_bug.cgi?id=204285 5 <rdar://problem/57262858> 6 7 Reviewed by Antti Koivisto. 8 9 Move layout initialization to FrameViewLayoutContext::layoutUsingFormattingContext. This is now pretty close to 10 what the final initialization will look like. 11 12 * layout/LayoutContext.cpp: 13 (WebCore::Layout::initializeLayoutState): Deleted. 14 (WebCore::Layout::LayoutContext::runLayout): Deleted. 15 (WebCore::Layout::LayoutContext::runLayoutAndVerify): Deleted. 16 (WebCore::Layout::LayoutContext::createLayoutState): Deleted. 17 * layout/LayoutContext.h: 18 (WebCore::Layout::LayoutContext::layoutState): 19 * layout/LayoutState.cpp: 20 (WebCore::Layout::LayoutState::LayoutState): 21 * layout/LayoutState.h: 22 (WebCore::Layout::LayoutState::root const): 23 (WebCore::Layout::LayoutState::rootRenderer const): 24 (WebCore::Layout::LayoutState::setQuirksMode): 25 (WebCore::Layout::LayoutState::layoutBoxForRenderer const): Deleted. 26 * layout/layouttree/LayoutTreeBuilder.cpp: 27 (WebCore::Layout::LayoutTreeContent::LayoutTreeContent): 28 (WebCore::Layout::TreeBuilder::buildLayoutTree): 29 (WebCore::Layout::TreeBuilder::buildTree): 30 (WebCore::Layout::TreeBuilder::createLayoutBox): 31 (WebCore::Layout::printLayoutTreeForLiveDocuments): 32 * layout/layouttree/LayoutTreeBuilder.h: 33 (WebCore::Layout::LayoutTreeContent::rootLayoutBox const): 34 (WebCore::Layout::LayoutTreeContent::rootLayoutBox): 35 (WebCore::Layout::LayoutTreeContent::rootRenderer const): 36 (WebCore::Layout::LayoutTreeContent::layoutBoxForRenderer): 37 (WebCore::Layout::LayoutTreeContent::addLayoutBoxForRenderer): 38 * page/FrameViewLayoutContext.cpp: 39 (WebCore::FrameViewLayoutContext::layoutUsingFormattingContext): 40 (WebCore::FrameViewLayoutContext::invalidateLayoutTreeContent): 41 * page/FrameViewLayoutContext.h: 42 (WebCore::FrameViewLayoutContext::layoutTreeContent const): 43 * rendering/updating/RenderTreeUpdater.cpp: 44 (WebCore::RenderTreeUpdater::updateRendererStyle): 45 1 46 2019-11-17 Zalan Bujtas <zalan@apple.com> 2 47 -
trunk/Source/WebCore/layout/LayoutContext.cpp
r252533 r252534 110 110 } 111 111 112 static void initializeLayoutState(LayoutState& layoutState, const RenderView& renderView)113 {114 auto quirksMode = [&] {115 auto& document = renderView.document();116 if (document.inLimitedQuirksMode())117 return LayoutState::QuirksMode::Limited;118 if (document.inQuirksMode())119 return LayoutState::QuirksMode::Yes;120 return LayoutState::QuirksMode::No;121 };122 layoutState.setQuirksMode(quirksMode());123 }124 125 void LayoutContext::runLayout(const LayoutSize& rootContentBoxSize, LayoutState& layoutState)126 {127 auto invalidationState = InvalidationState { };128 auto invalidationContext = InvalidationContext { invalidationState };129 invalidationContext.styleChanged(*layoutState.root().firstChild(), StyleDifference::Layout);130 131 LayoutContext(layoutState).layout(rootContentBoxSize, invalidationState);132 }133 134 void LayoutContext::runLayoutAndVerify(const LayoutSize& rootContentBoxSize, LayoutState& layoutState)135 {136 runLayout(rootContentBoxSize, layoutState);137 #ifndef NDEBUG138 LayoutContext::verifyAndOutputMismatchingLayoutTree(layoutState);139 #endif140 }141 142 std::unique_ptr<LayoutState> LayoutContext::createLayoutState(const RenderView& renderView)143 {144 auto layoutState = makeUnique<LayoutState>(TreeBuilder::buildLayoutTree(renderView));145 initializeLayoutState(*layoutState, renderView);146 return layoutState;147 }148 149 112 void LayoutContext::paint(const LayoutState& layoutState, GraphicsContext& context, const IntRect& dirtyRect) 150 113 { -
trunk/Source/WebCore/layout/LayoutContext.h
r252533 r252534 49 49 // subsequent layouts (subtree layout). A non-initial, subtree layout could be initiated on multiple formatting contexts. 50 50 // Each formatting context has an entry point for layout, which potenitally means multiple entry points per layout frame. 51 // LayoutState holds the formatting states. They cache formatting context specific data to enable performant incremental layouts.52 51 class LayoutContext { 53 52 WTF_MAKE_ISO_ALLOCATED(LayoutContext); 54 53 public: 55 // FIXME: These are temporary entry points for LFC layout.56 static std::unique_ptr<LayoutState> createLayoutState(const RenderView&);57 static void runLayoutAndVerify(const LayoutSize& rootContentBoxSize, LayoutState&);58 static void paint(const LayoutState&, GraphicsContext&, const IntRect& dirtyRect);59 60 54 LayoutContext(LayoutState&); 61 55 void layout(const LayoutSize& rootContentBoxSize, InvalidationState&); … … 63 57 static std::unique_ptr<FormattingContext> createFormattingContext(const Container& formattingContextRoot, LayoutState&); 64 58 59 // FIXME: This is temporary. 60 static void paint(const LayoutState&, GraphicsContext&, const IntRect& dirtyRect); 61 #ifndef NDEBUG 62 // For testing purposes only 63 static void verifyAndOutputMismatchingLayoutTree(const LayoutState&); 64 #endif 65 65 66 private: 66 67 void layoutFormattingContextSubtree(const Container&, InvalidationState&); 67 68 LayoutState& layoutState() { return m_layoutState; } 68 69 // For testing purposes only70 #ifndef NDEBUG71 static void verifyAndOutputMismatchingLayoutTree(const LayoutState&);72 #endif73 static void runLayout(const LayoutSize& rootContentBoxSize, LayoutState&);74 69 75 70 LayoutState& m_layoutState; -
trunk/Source/WebCore/layout/LayoutState.cpp
r252482 r252534 39 39 WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState); 40 40 41 LayoutState::LayoutState( LayoutTreeContent&& layoutTreeContent)42 : m_layoutTreeContent( WTFMove(layoutTreeContent))41 LayoutState::LayoutState(const LayoutTreeContent& layoutTreeContent) 42 : m_layoutTreeContent(makeWeakPtr(layoutTreeContent)) 43 43 { 44 44 // It makes absolutely no sense to construct a dedicated layout state for a non-formatting context root (layout would be a no-op). 45 ASSERT(m_layoutTreeContent.rootLayoutBox->establishesFormattingContext()); 45 ASSERT(m_layoutTreeContent->rootLayoutBox().establishesFormattingContext()); 46 47 auto quirksMode = [&] { 48 auto& document = m_layoutTreeContent->rootRenderer().document(); 49 if (document.inLimitedQuirksMode()) 50 return LayoutState::QuirksMode::Limited; 51 if (document.inQuirksMode()) 52 return LayoutState::QuirksMode::Yes; 53 return LayoutState::QuirksMode::No; 54 }; 55 setQuirksMode(quirksMode()); 46 56 } 47 57 -
trunk/Source/WebCore/layout/LayoutState.h
r252487 r252534 50 50 WTF_MAKE_ISO_ALLOCATED(LayoutState); 51 51 public: 52 LayoutState( LayoutTreeContent&&);52 LayoutState(const LayoutTreeContent&); 53 53 ~LayoutState(); 54 54 … … 68 68 69 69 enum class QuirksMode { No, Limited, Yes }; 70 void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; }71 70 bool inQuirksMode() const { return m_quirksMode == QuirksMode::Yes; } 72 71 bool inLimitedQuirksMode() const { return m_quirksMode == QuirksMode::Limited; } 73 72 bool inNoQuirksMode() const { return m_quirksMode == QuirksMode::No; } 74 73 75 const Container& root() const { return *m_layoutTreeContent.rootLayoutBox; }74 const Container& root() const { return m_layoutTreeContent->rootLayoutBox(); } 76 75 #ifndef NDEBUG 77 const RenderBox& rootRenderer() const { return m_layoutTreeContent .rootRenderer; }76 const RenderBox& rootRenderer() const { return m_layoutTreeContent->rootRenderer(); } 78 77 #endif 79 Box* layoutBoxForRenderer(const RenderObject& renderer) const { return m_layoutTreeContent.renderObjectToLayoutBox.get(&renderer); }80 78 81 79 private: 80 void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; } 81 82 82 HashMap<const Container*, std::unique_ptr<FormattingState>> m_formattingStates; 83 83 #ifndef NDEBUG … … 87 87 QuirksMode m_quirksMode { QuirksMode::No }; 88 88 89 // FIXME: Figure out the ownership model for the layout tree. 90 LayoutTreeContent m_layoutTreeContent; 89 WeakPtr<const LayoutTreeContent> m_layoutTreeContent; 91 90 }; 92 91 -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp
r252533 r252534 55 55 #include "RenderTableCell.h" 56 56 #include "RenderView.h" 57 #include <wtf/IsoMallocInlines.h> 57 58 #include <wtf/text/TextStream.h> 58 59 59 60 namespace WebCore { 60 61 namespace Layout { 62 63 WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutTreeContent); 64 LayoutTreeContent::LayoutTreeContent(const RenderBox& rootRenderer, std::unique_ptr<Container> rootLayoutBox) 65 : m_rootRenderer(rootRenderer) 66 , m_rootLayoutBox(WTFMove(rootLayoutBox)) 67 { 68 } 61 69 62 70 static void appendChild(Container& parent, Box& newChild) … … 103 111 } 104 112 105 LayoutTreeContentTreeBuilder::buildLayoutTree(const RenderView& renderView)113 std::unique_ptr<Layout::LayoutTreeContent> TreeBuilder::buildLayoutTree(const RenderView& renderView) 106 114 { 107 115 PhaseScope scope(Phase::Type::TreeBuilding); … … 111 119 style.setLogicalHeight(Length(renderView.height(), Fixed)); 112 120 113 auto layoutTreeContent = LayoutTreeContent { renderView, makeUnique<Container>(WTF::nullopt, WTFMove(style)) };114 TreeBuilder( layoutTreeContent).buildTree();121 auto layoutTreeContent = makeUnique<LayoutTreeContent>(renderView, makeUnique<Container>(WTF::nullopt, WTFMove(style))); 122 TreeBuilder(*layoutTreeContent).buildTree(); 115 123 return layoutTreeContent; 116 }117 118 LayoutTreeContent::LayoutTreeContent(const RenderBox& rootRenderer, std::unique_ptr<Container> rootLayoutBox)119 : rootRenderer(rootRenderer)120 , rootLayoutBox(WTFMove(rootLayoutBox))121 {122 124 } 123 125 … … 129 131 void TreeBuilder::buildTree() 130 132 { 131 buildSubTree(m_layoutTreeContent.rootRenderer , *m_layoutTreeContent.rootLayoutBox);133 buildSubTree(m_layoutTreeContent.rootRenderer(), m_layoutTreeContent.rootLayoutBox()); 132 134 } 133 135 … … 232 234 childLayoutBox->setIsAnonymous(); 233 235 } 234 m_layoutTreeContent. renderObjectToLayoutBox.add(&childRenderer, childLayoutBox.get());236 m_layoutTreeContent.addLayoutBoxForRenderer(childRenderer, *childLayoutBox); 235 237 return childLayoutBox; 236 238 } … … 418 420 // FIXME: Need to find a way to output geometry without layout context. 419 421 auto& renderView = *document->renderView(); 420 auto layout State = LayoutState { TreeBuilder::buildLayoutTree(renderView) };421 layoutState.setQuirksMode(renderView.document().inLimitedQuirksMode() ? LayoutState::QuirksMode::Limited : (renderView.document().inQuirksMode() ? LayoutState::QuirksMode::Yes : LayoutState::QuirksMode::No));422 auto layoutTreeContent = TreeBuilder::buildLayoutTree(renderView); 423 auto layoutState = LayoutState { *layoutTreeContent }; 422 424 423 425 auto& layoutRoot = layoutState.root(); -
trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h
r252482 r252534 28 28 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 29 29 30 #include <wtf/IsoMalloc.h> 31 #include <wtf/WeakPtr.h> 32 30 33 namespace WebCore { 31 34 … … 41 44 class LayoutState; 42 45 43 struct LayoutTreeContent { 46 class LayoutTreeContent : public CanMakeWeakPtr<LayoutTreeContent> { 47 WTF_MAKE_ISO_ALLOCATED(LayoutTreeContent); 48 public: 44 49 LayoutTreeContent(const RenderBox&, std::unique_ptr<Container>); 45 50 46 const RenderBox& rootRenderer; 47 std::unique_ptr<Container> rootLayoutBox; 51 const Container& rootLayoutBox() const { return *m_rootLayoutBox; } 52 Container& rootLayoutBox() { return *m_rootLayoutBox; } 53 const RenderBox& rootRenderer() const { return m_rootRenderer; } 48 54 49 55 using RenderObjectToLayoutBoxMap = HashMap<const RenderObject*, Box*>; 50 RenderObjectToLayoutBoxMap renderObjectToLayoutBox; 56 Box* layoutBoxForRenderer(const RenderObject& renderer) { return m_renderObjectToLayoutBox.get(&renderer); } 57 void addLayoutBoxForRenderer(const RenderObject& renderer, Box& layoutBox) { m_renderObjectToLayoutBox.add(&renderer, &layoutBox); } 58 59 private: 60 const RenderBox& m_rootRenderer; 61 std::unique_ptr<Container> m_rootLayoutBox; 62 RenderObjectToLayoutBoxMap m_renderObjectToLayoutBox; 51 63 }; 52 64 53 65 class TreeBuilder { 54 66 public: 55 static LayoutTreeContentbuildLayoutTree(const RenderView&);67 static std::unique_ptr<Layout::LayoutTreeContent> buildLayoutTree(const RenderView&); 56 68 57 69 private: -
trunk/Source/WebCore/page/FrameViewLayoutContext.cpp
r252533 r252534 41 41 #include "Settings.h" 42 42 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 43 #include "InvalidationContext.h" 44 #include "InvalidationState.h" 43 45 #include "LayoutContext.h" 44 46 #include "LayoutState.h" 47 #include "LayoutTreeBuilder.h" 45 48 #endif 46 49 … … 56 59 if (!RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled()) 57 60 return; 61 62 if (!m_layoutTreeContent) { 63 m_layoutTreeContent = Layout::TreeBuilder::buildLayoutTree(*renderView()); 64 // FIXME: New layout tree requires a new state for now. 65 m_layoutState = nullptr; 66 } 58 67 if (!m_layoutState) 59 m_layoutState = Layout::LayoutContext::createLayoutState(*renderView()); 60 Layout::LayoutContext::runLayoutAndVerify(renderView()->size(), *m_layoutState); 61 } 68 m_layoutState = makeUnique<Layout::LayoutState>(*m_layoutTreeContent); 69 70 // FIXME: This is not the real invalidation yet. 71 auto invalidationState = Layout::InvalidationState { }; 72 auto invalidationContext = Layout::InvalidationContext { invalidationState }; 73 invalidationContext.styleChanged(*m_layoutState->root().firstChild(), StyleDifference::Layout); 74 75 auto layoutContext = Layout::LayoutContext { *m_layoutState }; 76 layoutContext.layout(renderView()->size(), invalidationState); 77 #ifndef NDEBUG 78 Layout::LayoutContext::verifyAndOutputMismatchingLayoutTree(*m_layoutState); 79 #endif 80 } 81 82 void FrameViewLayoutContext::invalidateLayoutTreeContent() 83 { 84 m_layoutTreeContent = nullptr; 85 } 62 86 #endif 63 87 -
trunk/Source/WebCore/page/FrameViewLayoutContext.h
r252487 r252534 46 46 namespace Layout { 47 47 class LayoutState; 48 class LayoutTreeContent; 48 49 } 49 50 #endif … … 118 119 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 119 120 const Layout::LayoutState* layoutFormattingState() const { return m_layoutState.get(); } 121 Layout::LayoutTreeContent* layoutTreeContent() const { return m_layoutTreeContent.get(); } 122 void invalidateLayoutTreeContent(); 120 123 #endif 121 124 … … 190 193 #if ENABLE(LAYOUT_FORMATTING_CONTEXT) 191 194 std::unique_ptr<Layout::LayoutState> m_layoutState; 195 std::unique_ptr<Layout::LayoutTreeContent> m_layoutTreeContent; 192 196 #endif 193 197 }; -
trunk/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp
r252487 r252534 300 300 if (!m_document.view() || m_document.view()->layoutContext().layoutFormattingState()) 301 301 return; 302 if (auto* layoutBox = m_document.view()->layoutContext().layout FormattingState()->layoutBoxForRenderer(renderer))302 if (auto* layoutBox = m_document.view()->layoutContext().layoutTreeContent()->layoutBoxForRenderer(renderer)) 303 303 layoutBox->updateStyle(newStyle); 304 304 }
Note: See TracChangeset
for help on using the changeset viewer.