Title: [251638] trunk/Source/WebCore
Revision
251638
Author
[email protected]
Date
2019-10-26 12:16:18 -0700 (Sat, 26 Oct 2019)

Log Message

[LFC] Do not layout on every paint frame.
https://bugs.webkit.org/show_bug.cgi?id=203462
<rdar://problem/56646779>

Reviewed by Antti Koivisto.

This is in preparation for being able to run layout benchmarks.

* layout/LayoutContext.cpp:
(WebCore::Layout::LayoutContext::runLayoutAndVerify):
(WebCore::Layout::LayoutContext::paint):
(WebCore::Layout::LayoutContext::runLayoutAndPaint): Deleted.
* layout/LayoutContext.h:
* layout/LayoutState.cpp:
(WebCore::Layout::LayoutState::LayoutState):
* layout/LayoutState.h:
* layout/layouttree/LayoutTreeBuilder.cpp:
(WebCore::Layout::printLayoutTreeForLiveDocuments):
* page/FrameView.cpp:
(WebCore::FrameView::paintContents):
* page/FrameViewLayoutContext.cpp:
(WebCore::FrameViewLayoutContext::layoutUsingFormattingContext):
(WebCore::FrameViewLayoutContext::layout):
(WebCore::layoutUsingFormattingContext): Deleted.
* page/FrameViewLayoutContext.h:
(WebCore::FrameViewLayoutContext::initialLayoutState const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (251637 => 251638)


--- trunk/Source/WebCore/ChangeLog	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/ChangeLog	2019-10-26 19:16:18 UTC (rev 251638)
@@ -1,3 +1,32 @@
+2019-10-26  Zalan Bujtas  <[email protected]>
+
+        [LFC] Do not layout on every paint frame.
+        https://bugs.webkit.org/show_bug.cgi?id=203462
+        <rdar://problem/56646779>
+
+        Reviewed by Antti Koivisto.
+
+        This is in preparation for being able to run layout benchmarks.
+
+        * layout/LayoutContext.cpp:
+        (WebCore::Layout::LayoutContext::runLayoutAndVerify):
+        (WebCore::Layout::LayoutContext::paint):
+        (WebCore::Layout::LayoutContext::runLayoutAndPaint): Deleted.
+        * layout/LayoutContext.h:
+        * layout/LayoutState.cpp:
+        (WebCore::Layout::LayoutState::LayoutState):
+        * layout/LayoutState.h:
+        * layout/layouttree/LayoutTreeBuilder.cpp:
+        (WebCore::Layout::printLayoutTreeForLiveDocuments):
+        * page/FrameView.cpp:
+        (WebCore::FrameView::paintContents):
+        * page/FrameViewLayoutContext.cpp:
+        (WebCore::FrameViewLayoutContext::layoutUsingFormattingContext):
+        (WebCore::FrameViewLayoutContext::layout):
+        (WebCore::layoutUsingFormattingContext): Deleted.
+        * page/FrameViewLayoutContext.h:
+        (WebCore::FrameViewLayoutContext::initialLayoutState const):
+
 2019-10-26  Rob Buis  <[email protected]>
 
         Main implementation for lazy image loading

Modified: trunk/Source/WebCore/layout/LayoutContext.cpp (251637 => 251638)


--- trunk/Source/WebCore/layout/LayoutContext.cpp	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/layout/LayoutContext.cpp	2019-10-26 19:16:18 UTC (rev 251638)
@@ -161,21 +161,17 @@
     layoutContext.layout();
 }
 
-void LayoutContext::runLayoutAndVerify(const RenderView& renderView)
+std::unique_ptr<LayoutState> LayoutContext::runLayoutAndVerify(const RenderView& renderView)
 {
-    auto initialContainingBlock = TreeBuilder::createLayoutTree(renderView);
-    auto layoutState = LayoutState { *initialContainingBlock };
-    initializeLayoutState(layoutState, renderView);
-    runLayout(layoutState);
-    LayoutContext::verifyAndOutputMismatchingLayoutTree(layoutState, renderView);
+    auto layoutState = makeUnique<LayoutState>(TreeBuilder::createLayoutTree(renderView));
+    initializeLayoutState(*layoutState, renderView);
+    runLayout(*layoutState);
+    LayoutContext::verifyAndOutputMismatchingLayoutTree(*layoutState, renderView);
+    return layoutState;
 }
 
-void LayoutContext::runLayoutAndPaint(const RenderView& renderView, GraphicsContext& context)
+void LayoutContext::paint(const LayoutState& layoutState, GraphicsContext& context)
 {
-    auto initialContainingBlock = TreeBuilder::createLayoutTree(renderView);
-    auto layoutState = LayoutState { *initialContainingBlock };
-    initializeLayoutState(layoutState, renderView);
-    runLayout(layoutState);
     Display::Painter::paint(layoutState, context);
 }
 

Modified: trunk/Source/WebCore/layout/LayoutContext.h (251637 => 251638)


--- trunk/Source/WebCore/layout/LayoutContext.h	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/layout/LayoutContext.h	2019-10-26 19:16:18 UTC (rev 251638)
@@ -54,8 +54,8 @@
     WTF_MAKE_ISO_ALLOCATED(LayoutContext);
 public:
     // FIXME: These are temporary entry points for LFC layout.
-    static void runLayoutAndVerify(const RenderView&);
-    static void runLayoutAndPaint(const RenderView&, GraphicsContext&);
+    static std::unique_ptr<LayoutState> runLayoutAndVerify(const RenderView&);
+    static void paint(const LayoutState&, GraphicsContext&);
 
     LayoutContext(LayoutState&);
     void layout();

Modified: trunk/Source/WebCore/layout/LayoutState.cpp (251637 => 251638)


--- trunk/Source/WebCore/layout/LayoutState.cpp	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/layout/LayoutState.cpp	2019-10-26 19:16:18 UTC (rev 251638)
@@ -38,11 +38,11 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState);
 
-LayoutState::LayoutState(const Container& root)
-    : m_root(makeWeakPtr(root))
+LayoutState::LayoutState(std::unique_ptr<Container> root)
+    : m_root(WTFMove(root))
 {
     // It makes absolutely no sense to construct a dedicated layout state for a non-formatting context root (it would be a no-op).
-    ASSERT(root.establishesFormattingContext());
+    ASSERT(m_root->establishesFormattingContext());
 }
 
 LayoutState::~LayoutState() = default;

Modified: trunk/Source/WebCore/layout/LayoutState.h (251637 => 251638)


--- trunk/Source/WebCore/layout/LayoutState.h	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/layout/LayoutState.h	2019-10-26 19:16:18 UTC (rev 251638)
@@ -27,6 +27,7 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 
+#include "LayoutContainer.h"
 #include <wtf/HashMap.h>
 #include <wtf/HashSet.h>
 #include <wtf/IsoMalloc.h>
@@ -41,7 +42,6 @@
 namespace Layout {
 
 class Box;
-class Container;
 class FormattingContext;
 class FormattingState;
 
@@ -48,7 +48,7 @@
 class LayoutState {
     WTF_MAKE_ISO_ALLOCATED(LayoutState);
 public:
-    LayoutState(const Container& root);
+    LayoutState(std::unique_ptr<Container> root);
     ~LayoutState();
 
     FormattingState& createFormattingStateForFormattingRootIfNeeded(const Container& formattingContextRoot);
@@ -74,7 +74,8 @@
     const Container& root() const { return *m_root; }
 
 private:
-    WeakPtr<const Container> m_root;
+    // FIXME: Figure out the ownership model for the layout tree.
+    std::unique_ptr<Container> m_root;
     HashMap<const Container*, std::unique_ptr<FormattingState>> m_formattingStates;
 #ifndef NDEBUG
     HashSet<const FormattingContext*> m_formattingContextList;

Modified: trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp (251637 => 251638)


--- trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp	2019-10-26 19:16:18 UTC (rev 251638)
@@ -401,11 +401,10 @@
         fprintf(stderr, "%s\n", document->url().string().utf8().data());
         // FIXME: Need to find a way to output geometry without layout context.
         auto& renderView = *document->renderView();
-        auto initialContainingBlock = TreeBuilder::createLayoutTree(renderView);
-        auto layoutState = LayoutState { *initialContainingBlock };
+        auto layoutState = LayoutState { TreeBuilder::createLayoutTree(renderView) };
         layoutState.setQuirksMode(renderView.document().inLimitedQuirksMode() ? LayoutState::QuirksMode::Limited : (renderView.document().inQuirksMode() ? LayoutState::QuirksMode::Yes : LayoutState::QuirksMode::No));
         LayoutContext(layoutState).layout();
-        showLayoutTree(*initialContainingBlock, &layoutState);
+        showLayoutTree(layoutState.root(), &layoutState);
     }
 }
 #endif

Modified: trunk/Source/WebCore/page/FrameView.cpp (251637 => 251638)


--- trunk/Source/WebCore/page/FrameView.cpp	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/page/FrameView.cpp	2019-10-26 19:16:18 UTC (rev 251638)
@@ -4180,7 +4180,8 @@
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled()) {
-        Layout::LayoutContext::runLayoutAndPaint(*renderView, context);
+        if (auto* layoutState = layoutContext().initialLayoutState())
+            Layout::LayoutContext::paint(*layoutState, context);
         return;
     }
 #endif

Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.cpp (251637 => 251638)


--- trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.cpp	2019-10-26 19:16:18 UTC (rev 251638)
@@ -41,6 +41,7 @@
 #include "Settings.h"
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
 #include "LayoutContext.h"
+#include "LayoutState.h"
 #endif
 
 #include <wtf/SetForScope.h>
@@ -50,11 +51,11 @@
 namespace WebCore {
 
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-static void layoutUsingFormattingContext(const RenderView& renderView)
+void FrameViewLayoutContext::layoutUsingFormattingContext()
 {
     if (!RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled())
         return;
-    Layout::LayoutContext::runLayoutAndVerify(renderView);
+    m_initialLayoutState = Layout::LayoutContext::runLayoutAndVerify(*renderView());
 } 
 #endif
 
@@ -204,7 +205,7 @@
 #endif
         layoutRoot->layout();
 #if ENABLE(LAYOUT_FORMATTING_CONTEXT)
-        layoutUsingFormattingContext(*renderView());
+        layoutUsingFormattingContext();
 #endif
         ++m_layoutCount;
 #if ENABLE(TEXT_AUTOSIZING)

Modified: trunk/Source/WebCore/page/FrameViewLayoutContext.h (251637 => 251638)


--- trunk/Source/WebCore/page/FrameViewLayoutContext.h	2019-10-26 17:17:54 UTC (rev 251637)
+++ trunk/Source/WebCore/page/FrameViewLayoutContext.h	2019-10-26 19:16:18 UTC (rev 251638)
@@ -42,6 +42,11 @@
 class RenderElement;
 class RenderLayoutState;
 class RenderView;
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+namespace Layout {
+class LayoutState;
+}
+#endif
     
 class FrameViewLayoutContext {
 public:
@@ -110,6 +115,10 @@
 #endif
     using LayoutStateStack = Vector<std::unique_ptr<RenderLayoutState>>;
 
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    const Layout::LayoutState* initialLayoutState() const { return m_initialLayoutState.get(); }
+#endif
+
 private:
     friend class LayoutScope;
     friend class LayoutStateMaintainer;
@@ -150,6 +159,9 @@
     // These functions may only be accessed by LayoutStateMaintainer or LayoutStateDisabler.
     void disablePaintOffsetCache() { m_paintOffsetCacheDisableCount++; }
     void enablePaintOffsetCache() { ASSERT(m_paintOffsetCacheDisableCount > 0); m_paintOffsetCacheDisableCount--; }
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    void layoutUsingFormattingContext();
+#endif
 
     Frame& frame() const;
     FrameView& view() const;
@@ -175,6 +187,9 @@
     int m_layoutDisallowedCount { 0 };
     unsigned m_paintOffsetCacheDisableCount { 0 };
     LayoutStateStack m_layoutStateStack;
+#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
+    std::unique_ptr<Layout::LayoutState> m_initialLayoutState;
+#endif
 };
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to