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

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

Issue 2539693002: Early-out from the prepaint tree walk (Closed)
Patch Set: Do not force subtree updates for all paint invalidation reasons, add todo to track paint offset cha… Created 4 years 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;
24 PaintPropertyTreeBuilderContext treeBuilderContext; 23 PaintPropertyTreeBuilderContext treeBuilderContext;
25 PaintInvalidatorContext paintInvalidatorContext; 24 PaintInvalidatorContext paintInvalidatorContext;
26 }; 25 };
27 26
28 void PrePaintTreeWalk::walk(FrameView& rootFrame) { 27 void PrePaintTreeWalk::walk(FrameView& rootFrame) {
29 DCHECK(rootFrame.frame().document()->lifecycle().state() == 28 DCHECK(rootFrame.frame().document()->lifecycle().state() ==
30 DocumentLifecycle::InPrePaint); 29 DocumentLifecycle::InPrePaint);
31 30
32 PrePaintTreeWalkContext initialContext; 31 PrePaintTreeWalkContext initialContext;
33 initialContext.treeBuilderContext = 32 initialContext.treeBuilderContext =
34 m_propertyTreeBuilder.setupInitialContext(); 33 m_propertyTreeBuilder.setupInitialContext();
35 walk(rootFrame, initialContext); 34 walk(rootFrame, initialContext);
36 m_paintInvalidator.processPendingDelayedPaintInvalidations(); 35 m_paintInvalidator.processPendingDelayedPaintInvalidations();
37 } 36 }
38 37
39 void PrePaintTreeWalk::walk(FrameView& frameView, 38 PrePaintTreeWalk::DescendantsUpdated PrePaintTreeWalk::walk(
40 const PrePaintTreeWalkContext& context) { 39 FrameView& frameView,
40 const PrePaintTreeWalkContext& context) {
41 if (frameView.shouldThrottleRendering()) 41 if (frameView.shouldThrottleRendering())
42 return; 42 return NotFullyUpdated;
43
44 PrePaintTreeWalkContext localContext(context);
45 m_propertyTreeBuilder.updateProperties(frameView,
46 localContext.treeBuilderContext);
47 m_paintInvalidator.invalidatePaintIfNeeded(
48 frameView, localContext.paintInvalidatorContext);
49
50 LayoutView* view = frameView.layoutView();
51 auto descendantsUpdated = view ? walk(*view, localContext) : FullyUpdated;
52 if (descendantsUpdated) {
53 #if DCHECK_IS_ON()
54 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags();
55 #endif
56 // If descendants were not updated, do not clear flags. During the next
57 // PrePaintTreeWalk, these flags will be used again.
58 frameView.clearNeedsPaintPropertyUpdate();
59 }
60 return descendantsUpdated;
61 }
62
63 PrePaintTreeWalk::DescendantsUpdated PrePaintTreeWalk::walk(
64 const LayoutObject& object,
65 const PrePaintTreeWalkContext& context) {
66 // Early out from the treewalk if possible.
67 if (!object.needsPaintPropertyUpdate() &&
68 !object.descendantNeedsPaintPropertyUpdate() &&
69 !context.treeBuilderContext.forceSubtreeUpdate &&
70 !context.paintInvalidatorContext.forcedSubtreeInvalidationFlags &&
71 !object
72 .shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState()) {
73 return FullyUpdated;
74 }
43 75
44 PrePaintTreeWalkContext localContext(context); 76 PrePaintTreeWalkContext localContext(context);
45 77
46 // Check whether we need to update the paint property trees. 78 // TODO(pdr): These should be removable once paint offset changes mark an
47 if (!localContext.needToUpdatePaintPropertySubtree) { 79 // object as needing a paint property update. Below, we temporarily re-use
48 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) { 80 // paint invalidation flags to detect paint offset changes.
49 // forcedSubtreeInvalidationFlags will be true if locations have changed 81 if (localContext.paintInvalidatorContext.forcedSubtreeInvalidationFlags) {
50 // which will affect paint properties (e.g., PaintOffset). 82 // forcedSubtreeInvalidationFlags will be true if locations have changed
51 localContext.needToUpdatePaintPropertySubtree = true; 83 // which will affect paint properties (e.g., PaintOffset).
52 } else if (frameView.needsPaintPropertyUpdate()) { 84 localContext.treeBuilderContext.forceSubtreeUpdate = true;
53 localContext.needToUpdatePaintPropertySubtree = true; 85 } else if (object.shouldDoFullPaintInvalidation()) {
54 } 86 // shouldDoFullPaintInvalidation will be true when locations or overflow
87 // changes which will affect paint properties (e.g., PaintOffset, scroll).
88 object.getMutableForPainting().setNeedsPaintPropertyUpdate();
89 } else if (object.mayNeedPaintInvalidation()) {
90 // mayNeedpaintInvalidation will be true when locations change which will
91 // affect paint properties (e.g., PaintOffset).
92 object.getMutableForPainting().setNeedsPaintPropertyUpdate();
55 } 93 }
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);
65
66 m_paintInvalidator.invalidatePaintIfNeeded(
67 frameView, localContext.paintInvalidatorContext);
68
69 if (LayoutView* layoutView = frameView.layoutView())
70 walk(*layoutView, localContext);
71
72 #if DCHECK_IS_ON()
73 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags();
74 #endif
75
76 frameView.clearNeedsPaintPropertyUpdate();
77 }
78
79 void PrePaintTreeWalk::walk(const LayoutObject& object,
80 const PrePaintTreeWalkContext& context) {
81 PrePaintTreeWalkContext localContext(context);
82
83 // Check whether we need to update the paint property trees.
84 if (!localContext.needToUpdatePaintPropertySubtree) {
85 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) {
86 // forcedSubtreeInvalidationFlags will be true if locations have changed
87 // which will affect paint properties (e.g., PaintOffset).
88 localContext.needToUpdatePaintPropertySubtree = true;
89 } else if (object.needsPaintPropertyUpdate()) {
90 localContext.needToUpdatePaintPropertySubtree = true;
91 } else if (object.mayNeedPaintInvalidation()) {
92 // mayNeedpaintInvalidation will be true when locations change which will
93 // affect paint properties (e.g., PaintOffset).
94 localContext.needToUpdatePaintPropertySubtree = true;
95 } else if (object.shouldDoFullPaintInvalidation()) {
96 // shouldDoFullPaintInvalidation will be true when locations or overflow
97 // changes which will affect paint properties (e.g., PaintOffset, scroll).
98 localContext.needToUpdatePaintPropertySubtree = true;
99 }
100 }
101
102 // Paint properties can depend on their ancestor properties so ensure the
103 // entire subtree is rebuilt on any changes.
104 // TODO(pdr): Add additional granularity to the needs update approach such as
105 // the ability to do local updates that don't change the subtree.
106 if (localContext.needToUpdatePaintPropertySubtree)
107 object.getMutableForPainting().setNeedsPaintPropertyUpdate();
108 94
109 // TODO(pdr): Ensure multi column works with incremental property tree 95 // TODO(pdr): Ensure multi column works with incremental property tree
110 // construction. 96 // construction.
111 if (object.isLayoutMultiColumnSpannerPlaceholder()) { 97 if (object.isLayoutMultiColumnSpannerPlaceholder()) {
112 // Walk multi-column spanner as if it replaces the placeholder. 98 // Walk multi-column spanner as if it replaces the placeholder.
113 // Set the flag so that the tree builder can specially handle out-of-flow 99 // Set the flag so that the tree builder can specially handle out-of-flow
114 // positioned descendants if their containers are between the multi-column 100 // positioned descendants if their containers are between the multi-column
115 // container and the spanner. See PaintPropertyTreeBuilder for details. 101 // container and the spanner. See PaintPropertyTreeBuilder for details.
116 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; 102 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true;
117 walk(*toLayoutMultiColumnSpannerPlaceholder(object) 103 auto descendantsUpdated =
118 .layoutObjectInFlowThread(), 104 walk(*toLayoutMultiColumnSpannerPlaceholder(object)
119 localContext); 105 .layoutObjectInFlowThread(),
120 object.getMutableForPainting().clearPaintInvalidationFlags(); 106 localContext);
121 object.getMutableForPainting().clearNeedsPaintPropertyUpdate(); 107 if (descendantsUpdated) {
122 object.getMutableForPainting().clearDescendantNeedsPaintPropertyUpdate(); 108 // If descendants were not updated, do not clear flags. During the next
123 return; 109 // PrePaintTreeWalk, these flags will be used again.
110 object.getMutableForPainting().clearPaintInvalidationFlags();
111 object.getMutableForPainting().clearNeedsPaintPropertyUpdate();
112 object.getMutableForPainting().clearDescendantNeedsPaintPropertyUpdate();
113 }
114 return descendantsUpdated;
124 } 115 }
125 116
126 m_propertyTreeBuilder.updatePropertiesForSelf( 117 m_propertyTreeBuilder.updatePropertiesForSelf(
127 object, localContext.treeBuilderContext); 118 object, localContext.treeBuilderContext);
128 m_paintInvalidator.invalidatePaintIfNeeded( 119 m_paintInvalidator.invalidatePaintIfNeeded(
129 object, localContext.paintInvalidatorContext); 120 object, localContext.paintInvalidatorContext);
130 m_propertyTreeBuilder.updatePropertiesForChildren( 121 m_propertyTreeBuilder.updatePropertiesForChildren(
131 object, localContext.treeBuilderContext); 122 object, localContext.treeBuilderContext);
132 123
124 auto descendantsUpdated = FullyUpdated;
133 for (const LayoutObject* child = object.slowFirstChild(); child; 125 for (const LayoutObject* child = object.slowFirstChild(); child;
134 child = child->nextSibling()) { 126 child = child->nextSibling()) {
135 // Column spanners are walked through their placeholders. See above. 127 // Column spanners are walked through their placeholders. See above.
136 if (child->isColumnSpanAll()) 128 if (child->isColumnSpanAll())
137 continue; 129 continue;
138 walk(*child, localContext); 130 auto childUpdated = walk(*child, localContext);
131 if (!childUpdated)
132 descendantsUpdated = NotFullyUpdated;
139 } 133 }
140 134
141 if (object.isLayoutPart()) { 135 if (object.isLayoutPart()) {
142 const LayoutPart& layoutPart = toLayoutPart(object); 136 const LayoutPart& layoutPart = toLayoutPart(object);
143 Widget* widget = layoutPart.widget(); 137 Widget* widget = layoutPart.widget();
144 if (widget && widget->isFrameView()) { 138 if (widget && widget->isFrameView()) {
145 localContext.treeBuilderContext.current.paintOffset += 139 localContext.treeBuilderContext.current.paintOffset +=
146 layoutPart.replacedContentRect().location() - 140 layoutPart.replacedContentRect().location() -
147 widget->frameRect().location(); 141 widget->frameRect().location();
148 localContext.treeBuilderContext.current.paintOffset = 142 localContext.treeBuilderContext.current.paintOffset =
149 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); 143 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset);
150 walk(*toFrameView(widget), localContext); 144 auto frameUpdated = walk(*toFrameView(widget), localContext);
145 if (!frameUpdated)
146 descendantsUpdated = NotFullyUpdated;
151 } 147 }
152 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). 148 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281).
153 } 149 }
154 150
155 object.getMutableForPainting().clearPaintInvalidationFlags(); 151 if (descendantsUpdated) {
156 object.getMutableForPainting().clearNeedsPaintPropertyUpdate(); 152 // If descendants were not updated, do not clear flags. During the next
157 object.getMutableForPainting().clearDescendantNeedsPaintPropertyUpdate(); 153 // PrePaintTreeWalk, these flags will be used again.
154 object.getMutableForPainting().clearPaintInvalidationFlags();
155 object.getMutableForPainting().clearNeedsPaintPropertyUpdate();
156 object.getMutableForPainting().clearDescendantNeedsPaintPropertyUpdate();
157 }
158 return descendantsUpdated;
158 } 159 }
159 160
160 } // namespace blink 161 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698