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

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

Issue 2465983002: Rename "paint invalidation rect" etc. to "visual rect". (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/ObjectPaintInvalidator.h" 5 #include "core/paint/ObjectPaintInvalidator.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/frame/LocalFrame.h" 8 #include "core/frame/LocalFrame.h"
9 #include "core/layout/LayoutBlockFlow.h" 9 #include "core/layout/LayoutBlockFlow.h"
10 #include "core/layout/LayoutView.h" 10 #include "core/layout/LayoutView.h"
11 #include "core/layout/api/LayoutPartItem.h" 11 #include "core/layout/api/LayoutPartItem.h"
12 #include "core/layout/compositing/CompositedLayerMapping.h" 12 #include "core/layout/compositing/CompositedLayerMapping.h"
13 #include "core/paint/PaintInvalidator.h" 13 #include "core/paint/PaintInvalidator.h"
14 #include "core/paint/PaintLayer.h" 14 #include "core/paint/PaintLayer.h"
15 #include "platform/HostWindow.h" 15 #include "platform/HostWindow.h"
16 #include "platform/graphics/GraphicsLayer.h" 16 #include "platform/graphics/GraphicsLayer.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 static bool gDisablePaintInvalidationStateAsserts = false; 20 static bool gDisablePaintInvalidationStateAsserts = false;
21 21
22 typedef HashMap<const LayoutObject*, LayoutRect> SelectionPaintInvalidationMap; 22 typedef HashMap<const LayoutObject*, LayoutRect> SelectionVisualRectMap;
23 static SelectionPaintInvalidationMap& selectionPaintInvalidationMap() { 23 static SelectionVisualRectMap& selectionVisualRectMap() {
24 DEFINE_STATIC_LOCAL(SelectionPaintInvalidationMap, map, ()); 24 DEFINE_STATIC_LOCAL(SelectionVisualRectMap, map, ());
25 return map; 25 return map;
26 } 26 }
27 27
28 static void setPreviousSelectionPaintInvalidationRect( 28 static void setPreviousSelectionVisualRect(const LayoutObject& object,
29 const LayoutObject& object, 29 const LayoutRect& rect) {
30 const LayoutRect& rect) {
31 if (rect.isEmpty()) 30 if (rect.isEmpty())
32 selectionPaintInvalidationMap().remove(&object); 31 selectionVisualRectMap().remove(&object);
33 else 32 else
34 selectionPaintInvalidationMap().set(&object, rect); 33 selectionVisualRectMap().set(&object, rect);
35 } 34 }
36 35
37 void ObjectPaintInvalidator::objectWillBeDestroyed(const LayoutObject& object) { 36 void ObjectPaintInvalidator::objectWillBeDestroyed(const LayoutObject& object) {
38 selectionPaintInvalidationMap().remove(&object); 37 selectionVisualRectMap().remove(&object);
39 } 38 }
40 39
41 // TODO(trchen): Use std::function<void, LayoutObject&> when available. 40 // TODO(trchen): Use std::function<void, LayoutObject&> when available.
42 template <typename LayoutObjectTraversalFunctor> 41 template <typename LayoutObjectTraversalFunctor>
43 void traverseNonCompositingDescendantsInPaintOrder( 42 void traverseNonCompositingDescendantsInPaintOrder(
44 const LayoutObject&, 43 const LayoutObject&,
45 const LayoutObjectTraversalFunctor&); 44 const LayoutObjectTraversalFunctor&);
46 45
47 template <typename LayoutObjectTraversalFunctor> 46 template <typename LayoutObjectTraversalFunctor>
48 void traverseNonCompositingDescendantsBelongingToAncestorPaintInvalidationContai ner( 47 void traverseNonCompositingDescendantsBelongingToAncestorPaintInvalidationContai ner(
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 traverseNonCompositingDescendantsInPaintOrder( 118 traverseNonCompositingDescendantsInPaintOrder(
120 m_object, [reason](const LayoutObject& object) { 119 m_object, [reason](const LayoutObject& object) {
121 if (object.hasLayer() && 120 if (object.hasLayer() &&
122 toLayoutBoxModelObject(object).hasSelfPaintingLayer()) 121 toLayoutBoxModelObject(object).hasSelfPaintingLayer())
123 toLayoutBoxModelObject(object).layer()->setNeedsRepaint(); 122 toLayoutBoxModelObject(object).layer()->setNeedsRepaint();
124 object.invalidateDisplayItemClients(reason); 123 object.invalidateDisplayItemClients(reason);
125 }); 124 });
126 } 125 }
127 126
128 DISABLE_CFI_PERF 127 DISABLE_CFI_PERF
129 void ObjectPaintInvalidator::invalidatePaintOfPreviousPaintInvalidationRect( 128 void ObjectPaintInvalidator::invalidatePaintOfPreviousVisualRect(
130 const LayoutBoxModelObject& paintInvalidationContainer, 129 const LayoutBoxModelObject& paintInvalidationContainer,
131 PaintInvalidationReason reason) { 130 PaintInvalidationReason reason) {
132 // It's caller's responsibility to ensure enclosingSelfPaintingLayer's 131 // It's caller's responsibility to ensure enclosingSelfPaintingLayer's
133 // needsRepaint is set. Don't set the flag here because getting 132 // needsRepaint is set. Don't set the flag here because getting
134 // enclosingSelfPaintLayer has cost and the caller can use various ways (e.g. 133 // enclosingSelfPaintLayer has cost and the caller can use various ways (e.g.
135 // PaintInvalidatinState::enclosingSelfPaintingLayer()) to reduce the cost. 134 // PaintInvalidatinState::enclosingSelfPaintingLayer()) to reduce the cost.
136 DCHECK(!m_object.paintingLayer() || m_object.paintingLayer()->needsRepaint()); 135 DCHECK(!m_object.paintingLayer() || m_object.paintingLayer()->needsRepaint());
137 136
138 // These disablers are valid because we want to use the current 137 // These disablers are valid because we want to use the current
139 // compositing/invalidation status. 138 // compositing/invalidation status.
140 DisablePaintInvalidationStateAsserts invalidationDisabler; 139 DisablePaintInvalidationStateAsserts invalidationDisabler;
141 DisableCompositingQueryAsserts compositingDisabler; 140 DisableCompositingQueryAsserts compositingDisabler;
142 141
143 LayoutRect invalidationRect = m_object.previousPaintInvalidationRect(); 142 LayoutRect invalidationRect = m_object.previousVisualRect();
144 invalidatePaintUsingContainer(paintInvalidationContainer, invalidationRect, 143 invalidatePaintUsingContainer(paintInvalidationContainer, invalidationRect,
145 reason); 144 reason);
146 m_object.invalidateDisplayItemClients(reason); 145 m_object.invalidateDisplayItemClients(reason);
147 146
148 // This method may be used to invalidate paint of an object changing paint 147 // This method may be used to invalidate paint of an object changing paint
149 // invalidation container. Clear previous paint invalidation rect on the 148 // invalidation container. Clear previous visual rect on the original paint
150 // original paint invalidation container to avoid under-invalidation if the 149 // invalidation container to avoid under-invalidation if the visual rect on
151 // new paint invalidation rect on the new paint invalidation container happens 150 // the new paint invalidation container happens to be the same as the old one.
152 // to be the same as the old one. 151 m_object.getMutableForPainting().clearPreviousVisualRects();
153 m_object.getMutableForPainting().clearPreviousPaintInvalidationRects();
154 } 152 }
155 153
156 void ObjectPaintInvalidator:: 154 void ObjectPaintInvalidator::
157 invalidatePaintIncludingNonCompositingDescendants() { 155 invalidatePaintIncludingNonCompositingDescendants() {
158 // Since we're only painting non-composited layers, we know that they all 156 // Since we're only painting non-composited layers, we know that they all
159 // share the same paintInvalidationContainer. 157 // share the same paintInvalidationContainer.
160 const LayoutBoxModelObject& paintInvalidationContainer = 158 const LayoutBoxModelObject& paintInvalidationContainer =
161 m_object.containerForPaintInvalidation(); 159 m_object.containerForPaintInvalidation();
162 traverseNonCompositingDescendantsInPaintOrder( 160 traverseNonCompositingDescendantsInPaintOrder(
163 m_object, [&paintInvalidationContainer](const LayoutObject& object) { 161 m_object, [&paintInvalidationContainer](const LayoutObject& object) {
164 if (object.hasLayer()) 162 if (object.hasLayer())
165 toLayoutBoxModelObject(object).layer()->setNeedsRepaint(); 163 toLayoutBoxModelObject(object).layer()->setNeedsRepaint();
166 ObjectPaintInvalidator(object) 164 ObjectPaintInvalidator(object).invalidatePaintOfPreviousVisualRect(
167 .invalidatePaintOfPreviousPaintInvalidationRect( 165 paintInvalidationContainer, PaintInvalidationSubtree);
168 paintInvalidationContainer, PaintInvalidationSubtree);
169 }); 166 });
170 } 167 }
171 168
172 void ObjectPaintInvalidator:: 169 void ObjectPaintInvalidator::
173 invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal( 170 invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal(
174 const LayoutBoxModelObject& paintInvalidationContainer) { 171 const LayoutBoxModelObject& paintInvalidationContainer) {
175 invalidatePaintOfPreviousPaintInvalidationRect(paintInvalidationContainer, 172 invalidatePaintOfPreviousVisualRect(paintInvalidationContainer,
176 PaintInvalidationSubtree); 173 PaintInvalidationSubtree);
177 for (LayoutObject* child = m_object.slowFirstChild(); child; 174 for (LayoutObject* child = m_object.slowFirstChild(); child;
178 child = child->nextSibling()) { 175 child = child->nextSibling()) {
179 if (!child->hasLayer() || 176 if (!child->hasLayer() ||
180 !toLayoutBoxModelObject(child)->layer()->isSelfPaintingLayer()) 177 !toLayoutBoxModelObject(child)->layer()->isSelfPaintingLayer())
181 ObjectPaintInvalidator(*child) 178 ObjectPaintInvalidator(*child)
182 .invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal( 179 .invalidatePaintIncludingNonSelfPaintingLayerDescendantsInternal(
183 paintInvalidationContainer); 180 paintInvalidationContainer);
184 } 181 }
185 } 182 }
186 183
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 return dirtyRectOnBacking; 365 return dirtyRectOnBacking;
369 } 366 }
370 367
371 void ObjectPaintInvalidator::slowSetPaintingLayerNeedsRepaint() { 368 void ObjectPaintInvalidator::slowSetPaintingLayerNeedsRepaint() {
372 if (PaintLayer* paintingLayer = m_object.paintingLayer()) 369 if (PaintLayer* paintingLayer = m_object.paintingLayer())
373 paintingLayer->setNeedsRepaint(); 370 paintingLayer->setNeedsRepaint();
374 } 371 }
375 372
376 void ObjectPaintInvalidatorWithContext::fullyInvalidatePaint( 373 void ObjectPaintInvalidatorWithContext::fullyInvalidatePaint(
377 PaintInvalidationReason reason, 374 PaintInvalidationReason reason,
378 const LayoutRect& oldBounds, 375 const LayoutRect& oldVisualRect,
379 const LayoutRect& newBounds) { 376 const LayoutRect& newVisualRect) {
380 // The following logic avoids invalidating twice if one set of bounds contains 377 // The following logic avoids invalidating twice if one set of bounds contains
381 // the other. 378 // the other.
382 if (!newBounds.contains(oldBounds)) { 379 if (!newVisualRect.contains(oldVisualRect)) {
383 LayoutRect invalidationRect = oldBounds; 380 LayoutRect invalidationRect = oldVisualRect;
384 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer, 381 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer,
385 invalidationRect, reason); 382 invalidationRect, reason);
386 383
387 if (invalidationRect.contains(newBounds)) 384 if (invalidationRect.contains(newVisualRect))
388 return; 385 return;
389 } 386 }
390 387
391 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer, 388 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer,
392 newBounds, reason); 389 newVisualRect, reason);
393 } 390 }
394 391
395 PaintInvalidationReason 392 PaintInvalidationReason
396 ObjectPaintInvalidatorWithContext::computePaintInvalidationReason() { 393 ObjectPaintInvalidatorWithContext::computePaintInvalidationReason() {
397 // This is before any early return to ensure the background obscuration status 394 // This is before any early return to ensure the background obscuration status
398 // is saved. 395 // is saved.
399 bool backgroundObscurationChanged = false; 396 bool backgroundObscurationChanged = false;
400 bool backgroundObscured = m_object.backgroundIsKnownToBeObscured(); 397 bool backgroundObscured = m_object.backgroundIsKnownToBeObscured();
401 if (backgroundObscured != m_object.previousBackgroundObscured()) { 398 if (backgroundObscured != m_object.previousBackgroundObscured()) {
402 m_object.getMutableForPainting().setPreviousBackgroundObscured( 399 m_object.getMutableForPainting().setPreviousBackgroundObscured(
403 backgroundObscured); 400 backgroundObscured);
404 backgroundObscurationChanged = true; 401 backgroundObscurationChanged = true;
405 } 402 }
406 403
407 if (m_context.forcedSubtreeInvalidationFlags & 404 if (m_context.forcedSubtreeInvalidationFlags &
408 PaintInvalidatorContext::ForcedSubtreeFullInvalidation) 405 PaintInvalidatorContext::ForcedSubtreeFullInvalidation)
409 return PaintInvalidationSubtree; 406 return PaintInvalidationSubtree;
410 407
411 if (m_object.shouldDoFullPaintInvalidation()) 408 if (m_object.shouldDoFullPaintInvalidation())
412 return m_object.fullPaintInvalidationReason(); 409 return m_object.fullPaintInvalidationReason();
413 410
414 if (m_context.oldBounds.isEmpty() && m_context.newBounds.isEmpty()) 411 if (m_context.oldVisualRect.isEmpty() && m_context.newVisualRect.isEmpty())
415 return PaintInvalidationNone; 412 return PaintInvalidationNone;
416 413
417 if (backgroundObscurationChanged) 414 if (backgroundObscurationChanged)
418 return PaintInvalidationBackgroundObscurationChange; 415 return PaintInvalidationBackgroundObscurationChange;
419 416
420 if (m_object.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) 417 if (m_object.paintedOutputOfObjectHasNoEffectRegardlessOfSize())
421 return PaintInvalidationNone; 418 return PaintInvalidationNone;
422 419
423 const ComputedStyle& style = m_object.styleRef(); 420 const ComputedStyle& style = m_object.styleRef();
424 421
425 // The outline may change shape because of position change of descendants. For 422 // The outline may change shape because of position change of descendants. For
426 // simplicity, just force full paint invalidation if this object is marked for 423 // simplicity, just force full paint invalidation if this object is marked for
427 // checking paint invalidation for any reason. 424 // checking paint invalidation for any reason.
428 // TODO(wangxianzhu): Optimize this. 425 // TODO(wangxianzhu): Optimize this.
429 if (style.hasOutline()) 426 if (style.hasOutline())
430 return PaintInvalidationOutline; 427 return PaintInvalidationOutline;
431 428
432 // If the size is zero on one of our bounds then we know we're going to have 429 // If the size is zero on one of our bounds then we know we're going to have
433 // to do a full invalidation of either old bounds or new bounds. 430 // to do a full invalidation of either old bounds or new bounds.
434 if (m_context.oldBounds.isEmpty()) 431 if (m_context.oldVisualRect.isEmpty())
435 return PaintInvalidationBecameVisible; 432 return PaintInvalidationBecameVisible;
436 if (m_context.newBounds.isEmpty()) 433 if (m_context.newVisualRect.isEmpty())
437 return PaintInvalidationBecameInvisible; 434 return PaintInvalidationBecameInvisible;
438 435
439 // If we shifted, we don't know the exact reason so we are conservative and 436 // If we shifted, we don't know the exact reason so we are conservative and
440 // trigger a full invalidation. Shifting could be caused by some layout 437 // trigger a full invalidation. Shifting could be caused by some layout
441 // property (left / top) or some in-flow layoutObject inserted / removed 438 // property (left / top) or some in-flow layoutObject inserted / removed
442 // before us in the tree. 439 // before us in the tree.
443 if (m_context.newBounds.location() != m_context.oldBounds.location()) 440 if (m_context.newVisualRect.location() != m_context.oldVisualRect.location())
444 return PaintInvalidationBoundsChange; 441 return PaintInvalidationBoundsChange;
445 442
446 if (m_context.newLocation != m_context.oldLocation) 443 if (m_context.newLocation != m_context.oldLocation)
447 return PaintInvalidationLocationChange; 444 return PaintInvalidationLocationChange;
448 445
449 // Incremental invalidation is only applicable to LayoutBoxes. Return 446 // Incremental invalidation is only applicable to LayoutBoxes. Return
450 // PaintInvalidationIncremental no matter if oldBounds and newBounds are equal 447 // PaintInvalidationIncremental no matter if oldVisualRect and newVisualRect
448 // are equal
451 // because a LayoutBox may need paint invalidation if its border box changes. 449 // because a LayoutBox may need paint invalidation if its border box changes.
452 if (m_object.isBox()) 450 if (m_object.isBox())
453 return PaintInvalidationIncremental; 451 return PaintInvalidationIncremental;
454 452
455 if (m_context.oldBounds != m_context.newBounds) 453 if (m_context.oldVisualRect != m_context.newVisualRect)
456 return PaintInvalidationBoundsChange; 454 return PaintInvalidationBoundsChange;
457 455
458 return PaintInvalidationNone; 456 return PaintInvalidationNone;
459 } 457 }
460 458
461 void ObjectPaintInvalidatorWithContext::invalidateSelectionIfNeeded( 459 void ObjectPaintInvalidatorWithContext::invalidateSelectionIfNeeded(
462 PaintInvalidationReason reason) { 460 PaintInvalidationReason reason) {
463 // Update selection rect when we are doing full invalidation (in case that the 461 // Update selection rect when we are doing full invalidation (in case that the
464 // object is moved, composite status changed, etc.) or 462 // object is moved, composite status changed, etc.) or
465 // shouldInvalidationSelection is set (in case that the selection itself 463 // shouldInvalidationSelection is set (in case that the selection itself
466 // changed). 464 // changed).
467 bool fullInvalidation = isImmediateFullPaintInvalidationReason(reason); 465 bool fullInvalidation = isImmediateFullPaintInvalidationReason(reason);
468 if (!fullInvalidation && !m_object.shouldInvalidateSelection()) 466 if (!fullInvalidation && !m_object.shouldInvalidateSelection())
469 return; 467 return;
470 468
471 LayoutRect oldSelectionRect = selectionPaintInvalidationMap().get(&m_object); 469 LayoutRect oldSelectionRect = selectionVisualRectMap().get(&m_object);
472 LayoutRect newSelectionRect = m_object.localSelectionRect(); 470 LayoutRect newSelectionRect = m_object.localSelectionRect();
473 if (!newSelectionRect.isEmpty()) { 471 if (!newSelectionRect.isEmpty()) {
474 m_context.mapLocalRectToPaintInvalidationBacking(m_object, 472 m_context.mapLocalRectToPaintInvalidationBacking(m_object,
475 newSelectionRect); 473 newSelectionRect);
476 newSelectionRect.move(m_object.scrollAdjustmentForPaintInvalidation( 474 newSelectionRect.move(m_object.scrollAdjustmentForPaintInvalidation(
477 *m_context.paintInvalidationContainer)); 475 *m_context.paintInvalidationContainer));
478 } 476 }
479 477
480 setPreviousSelectionPaintInvalidationRect(m_object, newSelectionRect); 478 setPreviousSelectionVisualRect(m_object, newSelectionRect);
481 479
482 if (!fullInvalidation) { 480 if (!fullInvalidation) {
483 fullyInvalidatePaint(PaintInvalidationSelection, oldSelectionRect, 481 fullyInvalidatePaint(PaintInvalidationSelection, oldSelectionRect,
484 newSelectionRect); 482 newSelectionRect);
485 m_context.paintingLayer->setNeedsRepaint(); 483 m_context.paintingLayer->setNeedsRepaint();
486 m_object.invalidateDisplayItemClients(PaintInvalidationSelection); 484 m_object.invalidateDisplayItemClients(PaintInvalidationSelection);
487 } 485 }
488 } 486 }
489 487
490 PaintInvalidationReason 488 PaintInvalidationReason
(...skipping 15 matching lines...) Expand all
506 if (m_context.forcedSubtreeInvalidationFlags & 504 if (m_context.forcedSubtreeInvalidationFlags &
507 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking) { 505 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking) {
508 reason = PaintInvalidationLocationChange; 506 reason = PaintInvalidationLocationChange;
509 break; 507 break;
510 } 508 }
511 return PaintInvalidationNone; 509 return PaintInvalidationNone;
512 case PaintInvalidationDelayedFull: 510 case PaintInvalidationDelayedFull:
513 return PaintInvalidationDelayedFull; 511 return PaintInvalidationDelayedFull;
514 default: 512 default:
515 DCHECK(isImmediateFullPaintInvalidationReason(reason)); 513 DCHECK(isImmediateFullPaintInvalidationReason(reason));
516 fullyInvalidatePaint(reason, m_context.oldBounds, m_context.newBounds); 514 fullyInvalidatePaint(reason, m_context.oldVisualRect,
515 m_context.newVisualRect);
517 } 516 }
518 517
519 m_context.paintingLayer->setNeedsRepaint(); 518 m_context.paintingLayer->setNeedsRepaint();
520 m_object.invalidateDisplayItemClients(reason); 519 m_object.invalidateDisplayItemClients(reason);
521 return reason; 520 return reason;
522 } 521 }
523 522
524 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts() 523 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts()
525 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {} 524 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {}
526 525
527 } // namespace blink 526 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698