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

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

Issue 2662313003: Invalidate subsequence caching & empty paint phases if clips changed. (Closed)
Patch Set: Created 3 years, 10 months 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
« no previous file with comments | « third_party/WebKit/Source/core/paint/PrePaintTreeWalk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "core/paint/PaintLayer.h" 13 #include "core/paint/PaintLayer.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 struct PrePaintTreeWalkContext { 17 struct PrePaintTreeWalkContext {
18 PrePaintTreeWalkContext() 18 PrePaintTreeWalkContext()
19 : paintInvalidatorContext(treeBuilderContext), 19 : paintInvalidatorContext(treeBuilderContext),
20 ancestorOverflowPaintLayer(nullptr) {} 20 ancestorOverflowPaintLayer(nullptr) {}
21 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) 21 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext)
22 : treeBuilderContext(parentContext.treeBuilderContext), 22 : treeBuilderContext(parentContext.treeBuilderContext),
23 paintInvalidatorContext(treeBuilderContext, 23 paintInvalidatorContext(treeBuilderContext,
24 parentContext.paintInvalidatorContext), 24 parentContext.paintInvalidatorContext),
25 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer) {} 25 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer),
26 ancestorTransformedOrRootPaintLayer(
27 parentContext.ancestorTransformedOrRootPaintLayer) {}
26 28
27 PaintPropertyTreeBuilderContext treeBuilderContext; 29 PaintPropertyTreeBuilderContext treeBuilderContext;
28 PaintInvalidatorContext paintInvalidatorContext; 30 PaintInvalidatorContext paintInvalidatorContext;
29 31
30 // The ancestor in the PaintLayer tree which has overflow clip, or 32 // The ancestor in the PaintLayer tree which has overflow clip, or
31 // is the root layer. Note that it is tree ancestor, not containing 33 // is the root layer. Note that it is tree ancestor, not containing
32 // block or stacking ancestor. 34 // block or stacking ancestor.
33 PaintLayer* ancestorOverflowPaintLayer; 35 PaintLayer* ancestorOverflowPaintLayer;
36 PaintLayer* ancestorTransformedOrRootPaintLayer;
34 }; 37 };
35 38
36 void PrePaintTreeWalk::walk(FrameView& rootFrame) { 39 void PrePaintTreeWalk::walk(FrameView& rootFrame) {
37 DCHECK(rootFrame.frame().document()->lifecycle().state() == 40 DCHECK(rootFrame.frame().document()->lifecycle().state() ==
38 DocumentLifecycle::InPrePaint); 41 DocumentLifecycle::InPrePaint);
39 42
40 PrePaintTreeWalkContext initialContext; 43 PrePaintTreeWalkContext initialContext;
41 initialContext.treeBuilderContext = 44 initialContext.treeBuilderContext =
42 m_propertyTreeBuilder.setupInitialContext(); 45 m_propertyTreeBuilder.setupInitialContext();
43 walk(rootFrame, initialContext); 46 walk(rootFrame, initialContext);
44 m_paintInvalidator.processPendingDelayedPaintInvalidations(); 47 m_paintInvalidator.processPendingDelayedPaintInvalidations();
45 } 48 }
46 49
47 void PrePaintTreeWalk::walk(FrameView& frameView, 50 void PrePaintTreeWalk::walk(FrameView& frameView,
48 const PrePaintTreeWalkContext& parentContext) { 51 const PrePaintTreeWalkContext& parentContext) {
49 if (frameView.shouldThrottleRendering()) { 52 if (frameView.shouldThrottleRendering()) {
50 // Skip the throttled frame. Will update it when it becomes unthrottled. 53 // Skip the throttled frame. Will update it when it becomes unthrottled.
51 return; 54 return;
52 } 55 }
53 56
54 PrePaintTreeWalkContext context(parentContext); 57 PrePaintTreeWalkContext context(parentContext);
55 // ancestorOverflowLayer does not cross frame boundaries. 58 // ancestorOverflowLayer does not cross frame
59 // boundaries.
56 context.ancestorOverflowPaintLayer = nullptr; 60 context.ancestorOverflowPaintLayer = nullptr;
61 context.ancestorTransformedOrRootPaintLayer = frameView.layoutView()->layer();
57 m_propertyTreeBuilder.updateProperties(frameView, context.treeBuilderContext); 62 m_propertyTreeBuilder.updateProperties(frameView, context.treeBuilderContext);
58 m_paintInvalidator.invalidatePaintIfNeeded(frameView, 63 m_paintInvalidator.invalidatePaintIfNeeded(frameView,
59 context.paintInvalidatorContext); 64 context.paintInvalidatorContext);
60 65
61 if (LayoutView* view = frameView.layoutView()) { 66 if (LayoutView* view = frameView.layoutView()) {
62 walk(*view, context); 67 walk(*view, context);
63 #if DCHECK_IS_ON() 68 #if DCHECK_IS_ON()
64 view->assertSubtreeClearedPaintInvalidationFlags(); 69 view->assertSubtreeClearedPaintInvalidationFlags();
65 #endif 70 #endif
66 } 71 }
(...skipping 15 matching lines...) Expand all
82 // sticky layer position, so we need to update it again here. 87 // sticky layer position, so we need to update it again here.
83 // TODO(flackr): This should be refactored in the future to be clearer (i.e. 88 // TODO(flackr): This should be refactored in the future to be clearer (i.e.
84 // update layer position and ancestor inputs updates in the same walk). 89 // update layer position and ancestor inputs updates in the same walk).
85 paintLayer->updateLayerPosition(); 90 paintLayer->updateLayerPosition();
86 } 91 }
87 92
88 if (paintLayer->isRootLayer() || object.hasOverflowClip()) 93 if (paintLayer->isRootLayer() || object.hasOverflowClip())
89 context.ancestorOverflowPaintLayer = paintLayer; 94 context.ancestorOverflowPaintLayer = paintLayer;
90 } 95 }
91 96
97 ClipRect PrePaintTreeWalk::clipRectForContext(
98 const PaintPropertyTreeBuilderContext::ContainingBlockContext& context,
99 const EffectPaintPropertyNode* effect,
100 const PropertyTreeState& ancestorState,
101 const LayoutPoint& ancestorPaintOffset,
102 bool& hasClip) {
103 // Only return a non-infinite clip if clips differ. This ensures
104 // no accuracy issues due to transforms applied to infinite rects.
105 if (GeometryMapper::lowestCommonAncestor(
106 context.clip, ancestorState.clip()) == context.clip)
107 return ClipRect(LayoutRect(LayoutRect::infiniteIntRect()));
108
109 hasClip = true;
110
111 PropertyTreeState localState(context.transform, context.clip, effect,
112 context.scroll);
113
114 // TODO(chrishtr): remove need for this.
115 LayoutRect localRect(LayoutRect::infiniteIntRect());
116
117 LayoutRect rect(m_geometryMapper.sourceToDestinationVisualRect(
118 FloatRect(localRect), localState, ancestorState));
119 rect.moveBy(-ancestorPaintOffset);
120 return rect;
121 }
122
123 void PrePaintTreeWalk::invalidatePaintLayerProperties(
124 const LayoutObject& object,
125 const PaintLayer& ancestorTransformedOrRootPaintLayer,
126 const PaintPropertyTreeBuilderContext& context) {
127 if (!object.hasLayer() || !object.isBoxModelObject())
128 return;
129
130 if (ancestorTransformedOrRootPaintLayer.layoutObject()->hasClip())
131 return;
132
133 PaintLayer& paintLayer = *toLayoutBoxModelObject(object).layer();
134 PropertyTreeState ancestorState =
135 *ancestorTransformedOrRootPaintLayer.layoutObject()
136 ->paintProperties()
137 ->localBorderBoxProperties();
138 ShouldRespectOverflowClipType respectOverflowClip = RespectOverflowClip;
139 if (ancestorTransformedOrRootPaintLayer.compositingState() ==
140 PaintsIntoOwnBacking &&
141 ancestorTransformedOrRootPaintLayer.layoutObject()
142 ->paintProperties()
143 ->overflowClip()) {
144 // Use contentsProperties because we are ignoring any overflow clip applied
145 // to ancestorTransformedOrRootPaintLayer.
146 ancestorState.setClip(ancestorTransformedOrRootPaintLayer.layoutObject()
147 ->paintProperties()
148 ->overflowClip());
149 respectOverflowClip = IgnoreOverflowClip;
150 }
151
152 #ifdef CHECK_CLIP_RECTS
153 ClipRects& oldClipRects = paintLayer.clipper().paintingClipRects(
154 &ancestorTransformedOrRootPaintLayer, respectOverflowClip, LayoutSize());
155 #endif
156
157 bool hasClip = false;
158 RefPtr<ClipRects> clipRects = ClipRects::create();
159 clipRects->setOverflowClipRect(clipRectForContext(
160 context.current, context.currentEffect, ancestorState,
161 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(),
162 hasClip));
163 #ifdef CHECK_CLIP_RECTS
164 CHECK(!hasClip ||
165 clipRects->overflowClipRect() == oldClipRects.overflowClipRect())
166 << "rect= " << clipRects->overflowClipRect().toString();
167 #endif
168
169 clipRects->setFixedClipRect(clipRectForContext(
170 context.fixedPosition, context.currentEffect, ancestorState,
171 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(),
172 hasClip));
173 #ifdef CHECK_CLIP_RECTS
174 CHECK(hasClip || clipRects->fixedClipRect() == oldClipRects.fixedClipRect())
175 << " fixed=" << clipRects->fixedClipRect().toString();
176 #endif
177
178 clipRects->setPosClipRect(clipRectForContext(
179 context.absolutePosition, context.currentEffect, ancestorState,
180 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(),
181 hasClip));
182 #ifdef CHECK_CLIP_RECTS
183 CHECK(!hasClip || clipRects->posClipRect() == oldClipRects.posClipRect())
184 << " abs=" << clipRects->posClipRect().toString();
185 #endif
186
187 ClipRects* previousClipRects = paintLayer.previousPaintingClipRects();
188
189 if (!previousClipRects || *clipRects != *previousClipRects) {
190 paintLayer.setNeedsRepaint();
191 paintLayer.setPreviousPaintPhaseDescendantOutlinesEmpty(false);
192 paintLayer.setPreviousPaintPhaseFloatEmpty(false);
193 paintLayer.setPreviousPaintPhaseDescendantBlockBackgroundsEmpty(false);
194 }
195
196 paintLayer.setPreviousPaintingClipRects(*clipRects);
197 }
198
92 void PrePaintTreeWalk::walk(const LayoutObject& object, 199 void PrePaintTreeWalk::walk(const LayoutObject& object,
93 const PrePaintTreeWalkContext& parentContext) { 200 const PrePaintTreeWalkContext& parentContext) {
94 PrePaintTreeWalkContext context(parentContext); 201 PrePaintTreeWalkContext context(parentContext);
95 202
96 // This must happen before updateContextForBoxPosition, because the 203 // This must happen before updateContextForBoxPosition, because the
97 // latter reads some of the state computed uere. 204 // latter reads some of the state computed uere.
98 updateAuxiliaryObjectProperties(object, context); 205 updateAuxiliaryObjectProperties(object, context);
99 206
100 // Ensure the current context takes into account the box's position. This can 207 // Ensure the current context takes into account the box's position. This can
101 // force a subtree update due to paint offset changes and must precede any 208 // force a subtree update due to paint offset changes and must precede any
(...skipping 11 matching lines...) Expand all
113 return; 220 return;
114 } 221 }
115 222
116 m_propertyTreeBuilder.updatePropertiesForSelf(object, 223 m_propertyTreeBuilder.updatePropertiesForSelf(object,
117 context.treeBuilderContext); 224 context.treeBuilderContext);
118 m_paintInvalidator.invalidatePaintIfNeeded(object, 225 m_paintInvalidator.invalidatePaintIfNeeded(object,
119 context.paintInvalidatorContext); 226 context.paintInvalidatorContext);
120 m_propertyTreeBuilder.updatePropertiesForChildren(object, 227 m_propertyTreeBuilder.updatePropertiesForChildren(object,
121 context.treeBuilderContext); 228 context.treeBuilderContext);
122 229
230 if (object.isBoxModelObject() && object.hasLayer()) {
231 if (object.styleRef().hasTransform() ||
232 &object == context.paintInvalidatorContext.paintInvalidationContainer) {
233 context.ancestorTransformedOrRootPaintLayer =
234 toLayoutBoxModelObject(object).layer();
235 }
236 }
237
238 invalidatePaintLayerProperties(object,
239 *context.ancestorTransformedOrRootPaintLayer,
240 context.treeBuilderContext);
241
123 for (const LayoutObject* child = object.slowFirstChild(); child; 242 for (const LayoutObject* child = object.slowFirstChild(); child;
124 child = child->nextSibling()) { 243 child = child->nextSibling()) {
125 if (child->isLayoutMultiColumnSpannerPlaceholder()) { 244 if (child->isLayoutMultiColumnSpannerPlaceholder()) {
126 child->getMutableForPainting().clearPaintFlags(); 245 child->getMutableForPainting().clearPaintFlags();
127 continue; 246 continue;
128 } 247 }
129 walk(*child, context); 248 walk(*child, context);
130 } 249 }
131 250
132 if (object.isLayoutPart()) { 251 if (object.isLayoutPart()) {
133 const LayoutPart& layoutPart = toLayoutPart(object); 252 const LayoutPart& layoutPart = toLayoutPart(object);
134 Widget* widget = layoutPart.widget(); 253 Widget* widget = layoutPart.widget();
135 if (widget && widget->isFrameView()) { 254 if (widget && widget->isFrameView()) {
136 context.treeBuilderContext.current.paintOffset += 255 context.treeBuilderContext.current.paintOffset +=
137 layoutPart.replacedContentRect().location() - 256 layoutPart.replacedContentRect().location() -
138 widget->frameRect().location(); 257 widget->frameRect().location();
139 context.treeBuilderContext.current.paintOffset = 258 context.treeBuilderContext.current.paintOffset =
140 roundedIntPoint(context.treeBuilderContext.current.paintOffset); 259 roundedIntPoint(context.treeBuilderContext.current.paintOffset);
141 walk(*toFrameView(widget), context); 260 walk(*toFrameView(widget), context);
142 } 261 }
143 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). 262 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281).
144 } 263 }
145 264
146 object.getMutableForPainting().clearPaintFlags(); 265 object.getMutableForPainting().clearPaintFlags();
147 } 266 }
148 267
149 } // namespace blink 268 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/PrePaintTreeWalk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698