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

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

Issue 2457023002: Replace coversExtraPixels with simpler logic (Closed)
Patch Set: - 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/BoxPaintInvalidator.h" 5 #include "core/paint/BoxPaintInvalidator.h"
6 6
7 #include "core/frame/Settings.h" 7 #include "core/frame/Settings.h"
8 #include "core/layout/LayoutView.h" 8 #include "core/layout/LayoutView.h"
9 #include "core/paint/ObjectPaintInvalidator.h" 9 #include "core/paint/ObjectPaintInvalidator.h"
10 #include "core/paint/PaintInvalidator.h" 10 #include "core/paint/PaintInvalidator.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 if (delta < 0) { 59 if (delta < 0) {
60 return LayoutRect(location.x(), 60 return LayoutRect(location.x(),
61 location.y() + newSize.height() - extraHeight, 61 location.y() + newSize.height() - extraHeight,
62 oldSize.width(), -delta + extraHeight); 62 oldSize.width(), -delta + extraHeight);
63 } 63 }
64 return LayoutRect(); 64 return LayoutRect();
65 } 65 }
66 66
67 bool BoxPaintInvalidator::incrementallyInvalidatePaint() { 67 bool BoxPaintInvalidator::incrementallyInvalidatePaint() {
68 const LayoutRect& oldRect = m_context.oldBounds.rect; 68 LayoutRect rightDelta;
69 const LayoutRect& newRect = m_context.newBounds.rect; 69 LayoutRect bottomDelta;
70 DCHECK(oldRect.location() == newRect.location()); 70 if (m_box.isLayoutView()) {
71 LayoutRect rightDelta = 71 // This corresponds to the special case in computePaintInvalidationReason()
72 computeRightDelta(newRect.location(), oldRect.size(), newRect.size(), 0); 72 // for LayoutView in non-rootLayerScrolling mode. In rootLayerScrolling
73 LayoutRect bottomDelta = 73 // mode, we'll do full paint invalidation (see crbug.com/660156).
74 computeBottomDelta(newRect.location(), oldRect.size(), newRect.size(), 0); 74 DCHECK(!RuntimeEnabledFeatures::rootLayerScrollingEnabled());
75 75 DCHECK(m_context.oldBounds.location() == m_context.newBounds.location());
76 if (m_box.styleRef().hasBorder() || m_box.styleRef().hasBackground()) { 76 rightDelta = computeRightDelta(m_context.newBounds.location(),
77 LayoutSize oldBorderBoxSize = computePreviousBorderBoxSize(oldRect.size()); 77 m_context.oldBounds.size(),
78 m_context.newBounds.size(), 0);
79 bottomDelta = computeBottomDelta(m_context.newBounds.location(),
80 m_context.oldBounds.size(),
81 m_context.newBounds.size(), 0);
82 } else {
83 LayoutSize oldBorderBoxSize =
84 computePreviousBorderBoxSize(m_context.oldBounds.size());
78 LayoutSize newBorderBoxSize = m_box.size(); 85 LayoutSize newBorderBoxSize = m_box.size();
79 DCHECK(m_context.oldLocation == m_context.newLocation); 86 DCHECK(m_context.oldLocation == m_context.newLocation);
80 rightDelta.unite(computeRightDelta(m_context.newLocation, oldBorderBoxSize, 87 rightDelta = computeRightDelta(m_context.newLocation, oldBorderBoxSize,
81 newBorderBoxSize, m_box.borderRight())); 88 newBorderBoxSize, m_box.borderRight());
82 bottomDelta.unite(computeBottomDelta(m_context.newLocation, 89 bottomDelta = computeBottomDelta(m_context.newLocation, oldBorderBoxSize,
83 oldBorderBoxSize, newBorderBoxSize, 90 newBorderBoxSize, m_box.borderBottom());
84 m_box.borderBottom()));
85 } 91 }
86 92
87 if (rightDelta.isEmpty() && bottomDelta.isEmpty()) 93 if (rightDelta.isEmpty() && bottomDelta.isEmpty())
88 return false; 94 return false;
89 95
90 invalidatePaintRectClippedByOldAndNewBounds(rightDelta); 96 ObjectPaintInvalidator objectPaintInvalidator(m_box);
91 invalidatePaintRectClippedByOldAndNewBounds(bottomDelta); 97 objectPaintInvalidator.invalidatePaintUsingContainer(
98 *m_context.paintInvalidationContainer, rightDelta,
99 PaintInvalidationIncremental);
100 objectPaintInvalidator.invalidatePaintUsingContainer(
101 *m_context.paintInvalidationContainer, bottomDelta,
102 PaintInvalidationIncremental);
92 return true; 103 return true;
93 } 104 }
94 105
95 void BoxPaintInvalidator::invalidatePaintRectClippedByOldAndNewBounds(
Xianzhu 2016/10/28 22:03:06 Now this is not needed because we incrementally in
96 const LayoutRect& rect) {
97 if (rect.isEmpty())
98 return;
99
100 ObjectPaintInvalidator objectPaintInvalidator(m_box);
101 LayoutRect rectClippedByOldBounds =
102 intersection(rect, m_context.oldBounds.rect);
103 LayoutRect rectClippedByNewBounds =
104 intersection(rect, m_context.newBounds.rect);
105 // Invalidate only once if the clipped rects equal.
106 if (rectClippedByOldBounds == rectClippedByNewBounds) {
107 objectPaintInvalidator.invalidatePaintUsingContainer(
108 *m_context.paintInvalidationContainer, rectClippedByOldBounds,
109 PaintInvalidationIncremental);
110 return;
111 }
112 // Invalidate the bigger one if one contains another. Otherwise invalidate
113 // both.
114 if (!rectClippedByNewBounds.contains(rectClippedByOldBounds))
115 objectPaintInvalidator.invalidatePaintUsingContainer(
116 *m_context.paintInvalidationContainer, rectClippedByOldBounds,
117 PaintInvalidationIncremental);
118 if (!rectClippedByOldBounds.contains(rectClippedByNewBounds))
119 objectPaintInvalidator.invalidatePaintUsingContainer(
120 *m_context.paintInvalidationContainer, rectClippedByNewBounds,
121 PaintInvalidationIncremental);
122 }
123
124 PaintInvalidationReason BoxPaintInvalidator::computePaintInvalidationReason() { 106 PaintInvalidationReason BoxPaintInvalidator::computePaintInvalidationReason() {
125 PaintInvalidationReason reason = 107 PaintInvalidationReason reason =
126 ObjectPaintInvalidatorWithContext(m_box, m_context) 108 ObjectPaintInvalidatorWithContext(m_box, m_context)
127 .computePaintInvalidationReason(); 109 .computePaintInvalidationReason();
128 110
129 if (isImmediateFullPaintInvalidationReason(reason) || 111 if (isImmediateFullPaintInvalidationReason(reason) ||
130 reason == PaintInvalidationNone) 112 reason == PaintInvalidationNone)
131 return reason; 113 return reason;
132 114
133 if (m_box.mayNeedPaintInvalidationAnimatedBackgroundImage() && 115 if (m_box.mayNeedPaintInvalidationAnimatedBackgroundImage() &&
134 !m_box.backgroundIsKnownToBeObscured()) 116 !m_box.backgroundIsKnownToBeObscured())
135 reason = PaintInvalidationDelayedFull; 117 reason = PaintInvalidationDelayedFull;
136 118
137 // If the current paint invalidation reason is PaintInvalidationDelayedFull, 119 // If the current paint invalidation reason is PaintInvalidationDelayedFull,
138 // then this paint invalidation can delayed if the LayoutBox in question is 120 // then this paint invalidation can delayed if the LayoutBox in question is
139 // not on-screen. The logic to decide whether this is appropriate exists at 121 // not on-screen. The logic to decide whether this is appropriate exists at
140 // the site of the original paint invalidation that chose 122 // the site of the original paint invalidation that chose
141 // PaintInvalidationDelayedFull. 123 // PaintInvalidationDelayedFull.
142 if (reason == PaintInvalidationDelayedFull) { 124 if (reason == PaintInvalidationDelayedFull) {
143 // Do regular full paint invalidation if the object is onscreen. 125 // Do regular full paint invalidation if the object is onscreen.
144 return m_box.intersectsVisibleViewport() ? PaintInvalidationFull 126 return m_box.intersectsVisibleViewport() ? PaintInvalidationFull
145 : PaintInvalidationDelayedFull; 127 : PaintInvalidationDelayedFull;
146 } 128 }
147 129
130 DCHECK(reason == PaintInvalidationIncremental);
131
148 if (m_box.isLayoutView()) { 132 if (m_box.isLayoutView()) {
149 const LayoutView& layoutView = toLayoutView(m_box); 133 const LayoutView& layoutView = toLayoutView(m_box);
150 // In normal compositing mode, root background doesn't need to be 134 // In normal compositing mode, root background doesn't need to be
151 // invalidated for box changes, because the background always covers the 135 // invalidated for box changes, because the background always covers the
152 // whole document rect and clipping is done by 136 // whole document rect and clipping is done by
153 // compositor()->m_containerLayer. Also the scrollbars are always 137 // compositor()->m_containerLayer. Also the scrollbars are always
154 // composited. There are no other box decoration on the LayoutView thus we 138 // composited. There are no other box decoration on the LayoutView thus we
155 // can safely exit here. 139 // can safely exit here.
156 if (layoutView.usesCompositing() && 140 if (layoutView.usesCompositing() &&
157 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) 141 !RuntimeEnabledFeatures::rootLayerScrollingEnabled())
158 return reason; 142 return reason;
159 } 143 }
160 144
161 if (reason == PaintInvalidationIncremental &&
162 m_context.oldBounds.rect != m_context.newBounds.rect) {
163 if (m_context.newBounds.coversExtraPixels ||
164 m_context.oldBounds.coversExtraPixels) {
165 // Incremental invalidation is not applicable because the difference
166 // between oldBounds and newBounds may not cover all changed pixels along
167 // the edges.
168 return PaintInvalidationBoundsChange;
169 }
170
171 // If the transform is not identity or translation, incremental invalidation
172 // is not applicable because the difference between oldBounds and newBounds
173 // doesn't cover all area needing invalidation.
174 // TODO(crbug.com/426111): Should also consider ancestor transforms
175 // since paintInvalidationContainer. Combine this logic into the above
176 // boundsCoversExtraPixels logic.
177 if (m_context.paintInvalidationContainer != m_box && m_box.hasLayer() &&
178 m_box.layer()->transform() &&
179 !m_box.layer()->transform()->isIdentityOrTranslation())
180 return PaintInvalidationBoundsChange;
181 }
182
183 const ComputedStyle& style = m_box.styleRef(); 145 const ComputedStyle& style = m_box.styleRef();
184 if (style.backgroundLayers().thisOrNextLayersUseContentBox() || 146 if (style.backgroundLayers().thisOrNextLayersUseContentBox() ||
185 style.maskLayers().thisOrNextLayersUseContentBox() || 147 style.maskLayers().thisOrNextLayersUseContentBox() ||
186 style.boxSizing() == BoxSizingBorderBox) { 148 style.boxSizing() == BoxSizingBorderBox) {
187 if (previousBoxSizesMap().get(&m_box).contentBoxRect != 149 if (previousBoxSizesMap().get(&m_box).contentBoxRect !=
188 m_box.contentBoxRect()) 150 m_box.contentBoxRect())
189 return PaintInvalidationContentBoxChange; 151 return PaintInvalidationContentBoxChange;
190 } 152 }
191 153
192 if (!style.hasBackground() && !style.hasBoxDecorations()) {
193 if (reason == PaintInvalidationIncremental &&
194 m_context.oldBounds.rect != m_context.newBounds.rect &&
195 m_box.hasNonCompositedScrollbars())
196 return PaintInvalidationBorderBoxChange;
197 return reason;
198 }
199
200 if (style.backgroundLayers().thisOrNextLayersHaveLocalAttachment()) { 154 if (style.backgroundLayers().thisOrNextLayersHaveLocalAttachment()) {
201 if (previousBoxSizesMap().get(&m_box).layoutOverflowRect != 155 if (previousBoxSizesMap().get(&m_box).layoutOverflowRect !=
202 m_box.layoutOverflowRect()) 156 m_box.layoutOverflowRect())
203 return PaintInvalidationLayoutOverflowBoxChange; 157 return PaintInvalidationLayoutOverflowBoxChange;
204 } 158 }
205 159
206 LayoutSize oldBorderBoxSize = 160 LayoutSize oldBorderBoxSize =
207 computePreviousBorderBoxSize(m_context.oldBounds.rect.size()); 161 computePreviousBorderBoxSize(m_context.oldBounds.size());
208 LayoutSize newBorderBoxSize = m_box.size(); 162 LayoutSize newBorderBoxSize = m_box.size();
163 bool borderBoxChanged = oldBorderBoxSize != newBorderBoxSize;
209 164
210 if (oldBorderBoxSize == newBorderBoxSize) 165 if (!borderBoxChanged && m_context.oldBounds == m_context.newBounds)
211 return reason; 166 return PaintInvalidationNone;
212 167
213 // See another hasNonCompositedScrollbars() callsite above. 168 // If either border box changed or bounds changed, and old or new border box
169 // doesn't equal old or new bounds, incremental invalidation is not
170 // applicable.
171 if (m_context.oldBounds !=
172 LayoutRect(m_context.oldLocation, oldBorderBoxSize) ||
173 m_context.newBounds !=
174 LayoutRect(m_context.newLocation, newBorderBoxSize)) {
175 return borderBoxChanged ? PaintInvalidationBorderBoxChange
176 : PaintInvalidationBoundsChange;
177 }
178
179 DCHECK(borderBoxChanged);
180
214 if (m_box.hasNonCompositedScrollbars()) 181 if (m_box.hasNonCompositedScrollbars())
215 return PaintInvalidationBorderBoxChange; 182 return PaintInvalidationBorderBoxChange;
216 183
217 if (style.hasVisualOverflowingEffect() || style.hasAppearance() || 184 if (style.hasVisualOverflowingEffect() || style.hasAppearance() ||
218 style.hasFilterInducingProperty() || style.resize() != RESIZE_NONE || 185 style.hasFilterInducingProperty() || style.resize() != RESIZE_NONE ||
219 style.hasMask()) 186 style.hasMask())
220 return PaintInvalidationBorderBoxChange; 187 return PaintInvalidationBorderBoxChange;
221 188
222 if (style.hasBorderRadius()) 189 if (style.hasBorderRadius())
223 return PaintInvalidationBorderBoxChange; 190 return PaintInvalidationBorderBoxChange;
224 191
225 if (oldBorderBoxSize.width() != newBorderBoxSize.width() && 192 if (oldBorderBoxSize.width() != newBorderBoxSize.width() &&
226 m_box.mustInvalidateBackgroundOrBorderPaintOnWidthChange()) 193 m_box.mustInvalidateBackgroundOrBorderPaintOnWidthChange())
227 return PaintInvalidationBorderBoxChange; 194 return PaintInvalidationBorderBoxChange;
228 if (oldBorderBoxSize.height() != newBorderBoxSize.height() && 195 if (oldBorderBoxSize.height() != newBorderBoxSize.height() &&
229 m_box.mustInvalidateBackgroundOrBorderPaintOnHeightChange()) 196 m_box.mustInvalidateBackgroundOrBorderPaintOnHeightChange())
230 return PaintInvalidationBorderBoxChange; 197 return PaintInvalidationBorderBoxChange;
231 198
232 return reason; 199 return PaintInvalidationIncremental;
233 } 200 }
234 201
235 PaintInvalidationReason BoxPaintInvalidator::invalidatePaintIfNeeded() { 202 PaintInvalidationReason BoxPaintInvalidator::invalidatePaintIfNeeded() {
236 PaintInvalidationReason reason = computePaintInvalidationReason(); 203 PaintInvalidationReason reason = computePaintInvalidationReason();
237 if (reason == PaintInvalidationIncremental) { 204 if (reason == PaintInvalidationIncremental) {
238 if (incrementallyInvalidatePaint()) { 205 if (incrementallyInvalidatePaint()) {
239 m_context.paintingLayer->setNeedsRepaint(); 206 m_context.paintingLayer->setNeedsRepaint();
240 m_box.invalidateDisplayItemClients(reason); 207 m_box.invalidateDisplayItemClients(reason);
241 } else { 208 } else {
242 reason = PaintInvalidationNone; 209 reason = PaintInvalidationNone;
(...skipping 13 matching lines...) Expand all
256 if (PaintLayerScrollableArea* area = m_box.getScrollableArea()) 223 if (PaintLayerScrollableArea* area = m_box.getScrollableArea())
257 area->invalidatePaintOfScrollControlsIfNeeded(m_context); 224 area->invalidatePaintOfScrollControlsIfNeeded(m_context);
258 225
259 // This is for the next invalidatePaintIfNeeded so must be at the end. 226 // This is for the next invalidatePaintIfNeeded so must be at the end.
260 savePreviousBoxSizesIfNeeded(); 227 savePreviousBoxSizesIfNeeded();
261 228
262 return reason; 229 return reason;
263 } 230 }
264 231
265 bool BoxPaintInvalidator::needsToSavePreviousBoxSizes() { 232 bool BoxPaintInvalidator::needsToSavePreviousBoxSizes() {
266 LayoutSize paintInvalidationSize = m_context.newBounds.rect.size(); 233 LayoutSize paintInvalidationSize = m_context.newBounds.size();
267 // Don't save old box sizes if the paint rect is empty because we'll 234 // Don't save old box sizes if the paint rect is empty because we'll
268 // full invalidate once the paint rect becomes non-empty. 235 // full invalidate once the paint rect becomes non-empty.
269 if (paintInvalidationSize.isEmpty()) 236 if (paintInvalidationSize.isEmpty())
270 return false; 237 return false;
271 238
239 if (m_box.paintedOutputOfObjectHasNoEffectRegardlessOfSize())
240 return false;
241
272 const ComputedStyle& style = m_box.styleRef(); 242 const ComputedStyle& style = m_box.styleRef();
273 243
274 // If we use border-box sizing we need to track changes in the size of the 244 // If we use border-box sizing we need to track changes in the size of the
275 // content box. 245 // content box.
276 if (style.boxSizing() == BoxSizingBorderBox) 246 if (style.boxSizing() == BoxSizingBorderBox)
277 return true; 247 return true;
278 248
279 // We need the old box sizes only when the box has background, decorations, or
280 // masks.
281 // Main LayoutView paints base background, thus interested in box size.
282 if (!m_box.isLayoutView() && !style.hasBackground() &&
283 !style.hasBoxDecorations() && !style.hasMask())
284 return false;
285
286 // No need to save old border box size if we can use size of the old paint 249 // No need to save old border box size if we can use size of the old paint
287 // rect as the old border box size in the next invalidation. 250 // rect as the old border box size in the next invalidation.
288 if (paintInvalidationSize != m_box.size()) 251 if (paintInvalidationSize != m_box.size())
289 return true; 252 return true;
290 253
291 // Background and mask layers can depend on other boxes than border box. See 254 // Background and mask layers can depend on other boxes than border box. See
292 // crbug.com/490533 255 // crbug.com/490533
293 if (style.backgroundLayers().thisOrNextLayersUseContentBox() || 256 if (style.backgroundLayers().thisOrNextLayersUseContentBox() ||
294 style.backgroundLayers().thisOrNextLayersHaveLocalAttachment() || 257 style.backgroundLayers().thisOrNextLayersHaveLocalAttachment() ||
295 style.maskLayers().thisOrNextLayersUseContentBox()) 258 style.maskLayers().thisOrNextLayersUseContentBox())
296 return true; 259 return true;
297 260
298 return false; 261 return false;
299 } 262 }
300 263
301 void BoxPaintInvalidator::savePreviousBoxSizesIfNeeded() { 264 void BoxPaintInvalidator::savePreviousBoxSizesIfNeeded() {
302 if (!needsToSavePreviousBoxSizes()) { 265 if (!needsToSavePreviousBoxSizes()) {
303 previousBoxSizesMap().remove(&m_box); 266 previousBoxSizesMap().remove(&m_box);
304 return; 267 return;
305 } 268 }
306 269
307 PreviousBoxSizes sizes = {m_box.size(), m_box.contentBoxRect(), 270 PreviousBoxSizes sizes = {m_box.size(), m_box.contentBoxRect(),
308 m_box.layoutOverflowRect()}; 271 m_box.layoutOverflowRect()};
309 previousBoxSizesMap().set(&m_box, sizes); 272 previousBoxSizesMap().set(&m_box, sizes);
310 } 273 }
311 274
312 LayoutSize BoxPaintInvalidator::computePreviousBorderBoxSize( 275 LayoutSize BoxPaintInvalidator::computePreviousBorderBoxSize(
313 const LayoutSize& previousBoundsSize) { 276 const LayoutSize& previousBoundsSize) {
314 // PreviousBorderBoxSize is only valid when there is background or box
315 // decorations.
316 DCHECK(m_box.styleRef().hasBackground() ||
317 m_box.styleRef().hasBoxDecorations());
318
319 auto it = previousBoxSizesMap().find(&m_box); 277 auto it = previousBoxSizesMap().find(&m_box);
320 if (it != previousBoxSizesMap().end()) 278 if (it != previousBoxSizesMap().end())
321 return it->value.borderBoxSize; 279 return it->value.borderBoxSize;
322 280
323 // We didn't save the old border box size because it was the same as the size 281 // We didn't save the old border box size because it was the same as the size
324 // of oldBounds. 282 // of oldBounds.
325 return previousBoundsSize; 283 return previousBoundsSize;
326 } 284 }
327 285
328 } // namespace blink 286 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698