Changeset 252534 in webkit


Ignore:
Timestamp:
Nov 17, 2019 2:30:18 PM (4 years ago)
Author:
Alan Bujtas
Message:

[LFC] Move layout state initialization out of LayoutContext
https://bugs.webkit.org/show_bug.cgi?id=204285
<rdar://problem/57262858>

Reviewed by Antti Koivisto.

Move layout initialization to FrameViewLayoutContext::layoutUsingFormattingContext. This is now pretty close to
what the final initialization will look like.

  • layout/LayoutContext.cpp:

(WebCore::Layout::initializeLayoutState): Deleted.
(WebCore::Layout::LayoutContext::runLayout): Deleted.
(WebCore::Layout::LayoutContext::runLayoutAndVerify): Deleted.
(WebCore::Layout::LayoutContext::createLayoutState): Deleted.

  • layout/LayoutContext.h:

(WebCore::Layout::LayoutContext::layoutState):

  • layout/LayoutState.cpp:

(WebCore::Layout::LayoutState::LayoutState):

  • layout/LayoutState.h:

(WebCore::Layout::LayoutState::root const):
(WebCore::Layout::LayoutState::rootRenderer const):
(WebCore::Layout::LayoutState::setQuirksMode):
(WebCore::Layout::LayoutState::layoutBoxForRenderer const): Deleted.

  • layout/layouttree/LayoutTreeBuilder.cpp:

(WebCore::Layout::LayoutTreeContent::LayoutTreeContent):
(WebCore::Layout::TreeBuilder::buildLayoutTree):
(WebCore::Layout::TreeBuilder::buildTree):
(WebCore::Layout::TreeBuilder::createLayoutBox):
(WebCore::Layout::printLayoutTreeForLiveDocuments):

  • layout/layouttree/LayoutTreeBuilder.h:

(WebCore::Layout::LayoutTreeContent::rootLayoutBox const):
(WebCore::Layout::LayoutTreeContent::rootLayoutBox):
(WebCore::Layout::LayoutTreeContent::rootRenderer const):
(WebCore::Layout::LayoutTreeContent::layoutBoxForRenderer):
(WebCore::Layout::LayoutTreeContent::addLayoutBoxForRenderer):

  • page/FrameViewLayoutContext.cpp:

(WebCore::FrameViewLayoutContext::layoutUsingFormattingContext):
(WebCore::FrameViewLayoutContext::invalidateLayoutTreeContent):

  • page/FrameViewLayoutContext.h:

(WebCore::FrameViewLayoutContext::layoutTreeContent const):

  • rendering/updating/RenderTreeUpdater.cpp:

(WebCore::RenderTreeUpdater::updateRendererStyle):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252533 r252534  
     12019-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
    1462019-11-17  Zalan Bujtas  <zalan@apple.com>
    247
  • trunk/Source/WebCore/layout/LayoutContext.cpp

    r252533 r252534  
    110110}
    111111
    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 NDEBUG
    138     LayoutContext::verifyAndOutputMismatchingLayoutTree(layoutState);
    139 #endif
    140 }
    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 
    149112void LayoutContext::paint(const LayoutState& layoutState, GraphicsContext& context, const IntRect& dirtyRect)
    150113{
  • trunk/Source/WebCore/layout/LayoutContext.h

    r252533 r252534  
    4949// subsequent layouts (subtree layout). A non-initial, subtree layout could be initiated on multiple formatting contexts.
    5050// 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.
    5251class LayoutContext {
    5352    WTF_MAKE_ISO_ALLOCATED(LayoutContext);
    5453public:
    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 
    6054    LayoutContext(LayoutState&);
    6155    void layout(const LayoutSize& rootContentBoxSize, InvalidationState&);
     
    6357    static std::unique_ptr<FormattingContext> createFormattingContext(const Container& formattingContextRoot, LayoutState&);
    6458
     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
    6566private:
    6667    void layoutFormattingContextSubtree(const Container&, InvalidationState&);
    6768    LayoutState& layoutState() { return m_layoutState; }
    68 
    69     // For testing purposes only
    70 #ifndef NDEBUG
    71     static void verifyAndOutputMismatchingLayoutTree(const LayoutState&);
    72 #endif
    73     static void runLayout(const LayoutSize& rootContentBoxSize, LayoutState&);
    7469
    7570    LayoutState& m_layoutState;
  • trunk/Source/WebCore/layout/LayoutState.cpp

    r252482 r252534  
    3939WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState);
    4040
    41 LayoutState::LayoutState(LayoutTreeContent&& layoutTreeContent)
    42     : m_layoutTreeContent(WTFMove(layoutTreeContent))
     41LayoutState::LayoutState(const LayoutTreeContent& layoutTreeContent)
     42    : m_layoutTreeContent(makeWeakPtr(layoutTreeContent))
    4343{
    4444    // 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());
    4656}
    4757
  • trunk/Source/WebCore/layout/LayoutState.h

    r252487 r252534  
    5050    WTF_MAKE_ISO_ALLOCATED(LayoutState);
    5151public:
    52     LayoutState(LayoutTreeContent&&);
     52    LayoutState(const LayoutTreeContent&);
    5353    ~LayoutState();
    5454
     
    6868
    6969    enum class QuirksMode { No, Limited, Yes };
    70     void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; }
    7170    bool inQuirksMode() const { return m_quirksMode == QuirksMode::Yes; }
    7271    bool inLimitedQuirksMode() const { return m_quirksMode == QuirksMode::Limited; }
    7372    bool inNoQuirksMode() const { return m_quirksMode == QuirksMode::No; }
    7473
    75     const Container& root() const { return *m_layoutTreeContent.rootLayoutBox; }
     74    const Container& root() const { return m_layoutTreeContent->rootLayoutBox(); }
    7675#ifndef NDEBUG
    77     const RenderBox& rootRenderer() const { return m_layoutTreeContent.rootRenderer; }
     76    const RenderBox& rootRenderer() const { return m_layoutTreeContent->rootRenderer(); }
    7877#endif
    79     Box* layoutBoxForRenderer(const RenderObject& renderer) const { return m_layoutTreeContent.renderObjectToLayoutBox.get(&renderer); }
    8078
    8179private:
     80    void setQuirksMode(QuirksMode quirksMode) { m_quirksMode = quirksMode; }
     81
    8282    HashMap<const Container*, std::unique_ptr<FormattingState>> m_formattingStates;
    8383#ifndef NDEBUG
     
    8787    QuirksMode m_quirksMode { QuirksMode::No };
    8888
    89     // FIXME: Figure out the ownership model for the layout tree.
    90     LayoutTreeContent m_layoutTreeContent;
     89    WeakPtr<const LayoutTreeContent> m_layoutTreeContent;
    9190};
    9291
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.cpp

    r252533 r252534  
    5555#include "RenderTableCell.h"
    5656#include "RenderView.h"
     57#include <wtf/IsoMallocInlines.h>
    5758#include <wtf/text/TextStream.h>
    5859
    5960namespace WebCore {
    6061namespace Layout {
     62
     63WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutTreeContent);
     64LayoutTreeContent::LayoutTreeContent(const RenderBox& rootRenderer, std::unique_ptr<Container> rootLayoutBox)
     65    : m_rootRenderer(rootRenderer)
     66    , m_rootLayoutBox(WTFMove(rootLayoutBox))
     67{
     68}
    6169
    6270static void appendChild(Container& parent, Box& newChild)
     
    103111}
    104112
    105 LayoutTreeContent TreeBuilder::buildLayoutTree(const RenderView& renderView)
     113std::unique_ptr<Layout::LayoutTreeContent> TreeBuilder::buildLayoutTree(const RenderView& renderView)
    106114{
    107115    PhaseScope scope(Phase::Type::TreeBuilding);
     
    111119    style.setLogicalHeight(Length(renderView.height(), Fixed));
    112120
    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();
    115123    return layoutTreeContent;
    116 }
    117 
    118 LayoutTreeContent::LayoutTreeContent(const RenderBox& rootRenderer, std::unique_ptr<Container> rootLayoutBox)
    119     : rootRenderer(rootRenderer)
    120     , rootLayoutBox(WTFMove(rootLayoutBox))
    121 {
    122124}
    123125
     
    129131void TreeBuilder::buildTree()
    130132{
    131     buildSubTree(m_layoutTreeContent.rootRenderer, *m_layoutTreeContent.rootLayoutBox);
     133    buildSubTree(m_layoutTreeContent.rootRenderer(), m_layoutTreeContent.rootLayoutBox());
    132134}
    133135
     
    232234            childLayoutBox->setIsAnonymous();
    233235    }
    234     m_layoutTreeContent.renderObjectToLayoutBox.add(&childRenderer, childLayoutBox.get());
     236    m_layoutTreeContent.addLayoutBoxForRenderer(childRenderer, *childLayoutBox);
    235237    return childLayoutBox;
    236238}
     
    418420        // FIXME: Need to find a way to output geometry without layout context.
    419421        auto& renderView = *document->renderView();
    420         auto layoutState = 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 };
    422424
    423425        auto& layoutRoot = layoutState.root();
  • trunk/Source/WebCore/layout/layouttree/LayoutTreeBuilder.h

    r252482 r252534  
    2828#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    2929
     30#include <wtf/IsoMalloc.h>
     31#include <wtf/WeakPtr.h>
     32
    3033namespace WebCore {
    3134
     
    4144class LayoutState;
    4245
    43 struct LayoutTreeContent {
     46class LayoutTreeContent : public CanMakeWeakPtr<LayoutTreeContent> {
     47    WTF_MAKE_ISO_ALLOCATED(LayoutTreeContent);
     48public:
    4449    LayoutTreeContent(const RenderBox&, std::unique_ptr<Container>);
    4550
    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; }
    4854
    4955    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
     59private:
     60    const RenderBox& m_rootRenderer;
     61    std::unique_ptr<Container> m_rootLayoutBox;
     62    RenderObjectToLayoutBoxMap m_renderObjectToLayoutBox;
    5163};
    5264
    5365class TreeBuilder {
    5466public:
    55     static LayoutTreeContent buildLayoutTree(const RenderView&);
     67    static std::unique_ptr<Layout::LayoutTreeContent> buildLayoutTree(const RenderView&);
    5668
    5769private:
  • trunk/Source/WebCore/page/FrameViewLayoutContext.cpp

    r252533 r252534  
    4141#include "Settings.h"
    4242#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
     43#include "InvalidationContext.h"
     44#include "InvalidationState.h"
    4345#include "LayoutContext.h"
    4446#include "LayoutState.h"
     47#include "LayoutTreeBuilder.h"
    4548#endif
    4649
     
    5659    if (!RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextEnabled())
    5760        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    }
    5867    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
     82void FrameViewLayoutContext::invalidateLayoutTreeContent()
     83{
     84    m_layoutTreeContent = nullptr;
     85}
    6286#endif
    6387
  • trunk/Source/WebCore/page/FrameViewLayoutContext.h

    r252487 r252534  
    4646namespace Layout {
    4747class LayoutState;
     48class LayoutTreeContent;
    4849}
    4950#endif
     
    118119#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    119120    const Layout::LayoutState* layoutFormattingState() const { return m_layoutState.get(); }
     121    Layout::LayoutTreeContent* layoutTreeContent() const { return m_layoutTreeContent.get(); }
     122    void invalidateLayoutTreeContent();
    120123#endif
    121124
     
    190193#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
    191194    std::unique_ptr<Layout::LayoutState> m_layoutState;
     195    std::unique_ptr<Layout::LayoutTreeContent> m_layoutTreeContent;
    192196#endif
    193197};
  • trunk/Source/WebCore/rendering/updating/RenderTreeUpdater.cpp

    r252487 r252534  
    300300        if (!m_document.view() || m_document.view()->layoutContext().layoutFormattingState())
    301301            return;
    302         if (auto* layoutBox = m_document.view()->layoutContext().layoutFormattingState()->layoutBoxForRenderer(renderer))
     302        if (auto* layoutBox = m_document.view()->layoutContext().layoutTreeContent()->layoutBoxForRenderer(renderer))
    303303            layoutBox->updateStyle(newStyle);
    304304    }
Note: See TracChangeset for help on using the changeset viewer.