Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: third_party/WebKit/Source/core/paint/PrePaintTreeWalk.cpp

Issue 2404213004: Implement incremental paint property tree rebuilding (Closed)
Patch Set: Cleanup needsUpdate finder construction, tighten reasons for updating a property subtree, misc clea… Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/paint/PrePaintTreeWalk.h" 5 #include "core/paint/PrePaintTreeWalk.h"
6 6
7 #include "core/dom/DocumentLifecycle.h" 7 #include "core/dom/DocumentLifecycle.h"
8 #include "core/frame/FrameView.h" 8 #include "core/frame/FrameView.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/layout/LayoutMultiColumnSpannerPlaceholder.h" 10 #include "core/layout/LayoutMultiColumnSpannerPlaceholder.h"
11 #include "core/layout/LayoutPart.h" 11 #include "core/layout/LayoutPart.h"
12 #include "core/layout/LayoutView.h" 12 #include "core/layout/LayoutView.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 struct PrePaintTreeWalkContext { 16 struct PrePaintTreeWalkContext {
17 PrePaintTreeWalkContext() : paintInvalidatorContext(treeBuilderContext) {} 17 PrePaintTreeWalkContext() : paintInvalidatorContext(treeBuilderContext) {}
18 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) 18 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext)
19 : treeBuilderContext(parentContext.treeBuilderContext), 19 : treeBuilderContext(parentContext.treeBuilderContext),
20 paintInvalidatorContext(treeBuilderContext, 20 paintInvalidatorContext(treeBuilderContext,
21 parentContext.paintInvalidatorContext) {} 21 parentContext.paintInvalidatorContext) {}
22 22
23 bool needToUpdatePaintPropertySubtree = false;
23 PaintPropertyTreeBuilderContext treeBuilderContext; 24 PaintPropertyTreeBuilderContext treeBuilderContext;
24 PaintInvalidatorContext paintInvalidatorContext; 25 PaintInvalidatorContext paintInvalidatorContext;
25 }; 26 };
26 27
27 void PrePaintTreeWalk::walk(FrameView& rootFrame) { 28 void PrePaintTreeWalk::walk(FrameView& rootFrame) {
28 DCHECK(rootFrame.frame().document()->lifecycle().state() == 29 DCHECK(rootFrame.frame().document()->lifecycle().state() ==
29 DocumentLifecycle::InPrePaint); 30 DocumentLifecycle::InPrePaint);
30 31
31 PrePaintTreeWalkContext initialContext; 32 PrePaintTreeWalkContext initialContext;
32 initialContext.treeBuilderContext = 33 initialContext.treeBuilderContext =
33 m_propertyTreeBuilder.setupInitialContext(); 34 m_propertyTreeBuilder.setupInitialContext();
34 walk(rootFrame, initialContext); 35 walk(rootFrame, initialContext);
35 m_paintInvalidator.processPendingDelayedPaintInvalidations(); 36 m_paintInvalidator.processPendingDelayedPaintInvalidations();
36 } 37 }
37 38
38 void PrePaintTreeWalk::walk(FrameView& frameView, 39 void PrePaintTreeWalk::walk(FrameView& frameView,
39 const PrePaintTreeWalkContext& context) { 40 const PrePaintTreeWalkContext& context) {
40 if (frameView.shouldThrottleRendering()) 41 if (frameView.shouldThrottleRendering())
41 return; 42 return;
42 43
43 PrePaintTreeWalkContext localContext(context); 44 PrePaintTreeWalkContext localContext(context);
44 m_propertyTreeBuilder.buildTreeNodes(frameView, 45
45 localContext.treeBuilderContext); 46 // Check whether we need to update the paint property trees.
47 if (!localContext.needToUpdatePaintPropertySubtree) {
48 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) {
49 // forcedSubtreeInvalidationFlags will be true if locations have changed
50 // which will affect paint properties (e.g., PaintOffset).
51 localContext.needToUpdatePaintPropertySubtree = true;
52 } else if (frameView.needsPaintPropertyUpdate()) {
53 localContext.needToUpdatePaintPropertySubtree = true;
54 }
55 }
56 // Paint properties can depend on their ancestor properties so ensure the
57 // entire subtree is rebuilt on any changes.
58 // TODO(pdr): Add additional granularity to the needs update approach such as
59 // the ability to do local updates that don't change the subtree.
60 if (localContext.needToUpdatePaintPropertySubtree)
61 frameView.setNeedsPaintPropertyUpdate();
62
63 m_propertyTreeBuilder.updateProperties(frameView,
64 localContext.treeBuilderContext);
46 65
47 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) { 66 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) {
48 m_paintInvalidator.invalidatePaintIfNeeded( 67 m_paintInvalidator.invalidatePaintIfNeeded(
49 frameView, localContext.paintInvalidatorContext); 68 frameView, localContext.paintInvalidatorContext);
50 } 69 }
51 70
52 if (LayoutView* layoutView = frameView.layoutView()) 71 if (LayoutView* layoutView = frameView.layoutView())
53 walk(*layoutView, localContext); 72 walk(*layoutView, localContext);
54 73
55 #if DCHECK_IS_ON() 74 #if DCHECK_IS_ON()
56 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) 75 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled())
57 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags(); 76 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags();
58 #endif 77 #endif
78
79 frameView.clearNeedsPaintPropertyUpdate();
59 } 80 }
60 81
61 void PrePaintTreeWalk::walk(const LayoutObject& object, 82 void PrePaintTreeWalk::walk(const LayoutObject& object,
62 const PrePaintTreeWalkContext& context) { 83 const PrePaintTreeWalkContext& context) {
63 PrePaintTreeWalkContext localContext(context); 84 PrePaintTreeWalkContext localContext(context);
64 85
86 // Check whether we need to update the paint property trees.
87 if (!localContext.needToUpdatePaintPropertySubtree) {
88 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) {
89 // forcedSubtreeInvalidationFlags will be true if locations have changed
90 // which will affect paint properties (e.g., PaintOffset).
91 localContext.needToUpdatePaintPropertySubtree = true;
92 } else if (object.needsPaintPropertyUpdate()) {
93 localContext.needToUpdatePaintPropertySubtree = true;
94 } else if (object.mayNeedPaintInvalidation()) {
95 // mayNeedpaintInvalidation will be true when locations change which will
96 // affect paint properties (e.g., PaintOffset).
97 localContext.needToUpdatePaintPropertySubtree = true;
98 } else if (object.shouldDoFullPaintInvalidation()) {
99 // shouldDoFullPaintInvalidation will be true when locations or overflow
100 // changes which will affect paint properties (e.g., PaintOffset, scroll).
101 localContext.needToUpdatePaintPropertySubtree = true;
102 }
103 }
104
105 // Paint properties can depend on their ancestor properties so ensure the
106 // entire subtree is rebuilt on any changes.
107 // TODO(pdr): Add additional granularity to the needs update approach such as
108 // the ability to do local updates that don't change the subtree.
109 if (localContext.needToUpdatePaintPropertySubtree)
110 object.getMutableForPainting().setNeedsPaintPropertyUpdate();
111
112 // TODO(pdr): Ensure multi column works with incremental property tree
113 // construction.
65 if (object.isLayoutMultiColumnSpannerPlaceholder()) { 114 if (object.isLayoutMultiColumnSpannerPlaceholder()) {
66 // Walk multi-column spanner as if it replaces the placeholder. 115 // Walk multi-column spanner as if it replaces the placeholder.
67 // Set the flag so that the tree builder can specially handle out-of-flow 116 // Set the flag so that the tree builder can specially handle out-of-flow
68 // positioned descendants if their containers are between the multi-column 117 // positioned descendants if their containers are between the multi-column
69 // container and the spanner. See PaintPropertyTreeBuilder for details. 118 // container and the spanner. See PaintPropertyTreeBuilder for details.
70 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; 119 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true;
71 object.getMutableForPainting().clearPaintInvalidationFlags(); 120 object.getMutableForPainting().clearPaintInvalidationFlags();
72 walk(*toLayoutMultiColumnSpannerPlaceholder(object) 121 walk(*toLayoutMultiColumnSpannerPlaceholder(object)
73 .layoutObjectInFlowThread(), 122 .layoutObjectInFlowThread(),
74 localContext); 123 localContext);
75 return; 124 return;
76 } 125 }
77 126
78 m_propertyTreeBuilder.buildTreeNodesForSelf(object, 127 m_propertyTreeBuilder.updatePropertiesForSelf(
79 localContext.treeBuilderContext); 128 object, localContext.treeBuilderContext);
129
80 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) 130 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled())
81 m_paintInvalidator.invalidatePaintIfNeeded( 131 m_paintInvalidator.invalidatePaintIfNeeded(
82 object, localContext.paintInvalidatorContext); 132 object, localContext.paintInvalidatorContext);
83 m_propertyTreeBuilder.buildTreeNodesForChildren( 133
134 m_propertyTreeBuilder.updatePropertiesForChildren(
84 object, localContext.treeBuilderContext); 135 object, localContext.treeBuilderContext);
85 136
86 for (const LayoutObject* child = object.slowFirstChild(); child; 137 for (const LayoutObject* child = object.slowFirstChild(); child;
87 child = child->nextSibling()) { 138 child = child->nextSibling()) {
88 // Column spanners are walked through their placeholders. See above. 139 // Column spanners are walked through their placeholders. See above.
89 if (child->isColumnSpanAll()) 140 if (child->isColumnSpanAll())
90 continue; 141 continue;
91 walk(*child, localContext); 142 walk(*child, localContext);
92 } 143 }
93 144
94 if (object.isLayoutPart()) { 145 if (object.isLayoutPart()) {
95 const LayoutPart& layoutPart = toLayoutPart(object); 146 const LayoutPart& layoutPart = toLayoutPart(object);
96 Widget* widget = layoutPart.widget(); 147 Widget* widget = layoutPart.widget();
97 if (widget && widget->isFrameView()) { 148 if (widget && widget->isFrameView()) {
98 localContext.treeBuilderContext.current.paintOffset += 149 localContext.treeBuilderContext.current.paintOffset +=
99 layoutPart.replacedContentRect().location() - 150 layoutPart.replacedContentRect().location() -
100 widget->frameRect().location(); 151 widget->frameRect().location();
101 localContext.treeBuilderContext.current.paintOffset = 152 localContext.treeBuilderContext.current.paintOffset =
102 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); 153 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset);
103 walk(*toFrameView(widget), localContext); 154 walk(*toFrameView(widget), localContext);
104 } 155 }
105 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). 156 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281).
106 } 157 }
158
159 object.getMutableForPainting().clearNeedsPaintPropertyUpdate();
107 } 160 }
108 161
109 } // namespace blink 162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698