Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 | 27 |
| 28 static void setPreviousSelectionVisualRect(const LayoutObject& object, | 28 static void setPreviousSelectionVisualRect(const LayoutObject& object, |
| 29 const LayoutRect& rect) { | 29 const LayoutRect& rect) { |
| 30 if (rect.isEmpty()) | 30 if (rect.isEmpty()) |
| 31 selectionVisualRectMap().remove(&object); | 31 selectionVisualRectMap().remove(&object); |
| 32 else | 32 else |
| 33 selectionVisualRectMap().set(&object, rect); | 33 selectionVisualRectMap().set(&object, rect); |
| 34 } | 34 } |
| 35 | 35 |
| 36 typedef HashMap<const LayoutObject*, LayoutPoint> LocationInBackingMap; | |
| 37 static LocationInBackingMap& locationInBackingMap() { | |
| 38 DEFINE_STATIC_LOCAL(LocationInBackingMap, map, ()); | |
| 39 return map; | |
| 40 } | |
| 41 | |
| 36 void ObjectPaintInvalidator::objectWillBeDestroyed(const LayoutObject& object) { | 42 void ObjectPaintInvalidator::objectWillBeDestroyed(const LayoutObject& object) { |
| 37 selectionVisualRectMap().remove(&object); | 43 selectionVisualRectMap().remove(&object); |
| 44 locationInBackingMap().remove(&object); | |
| 38 } | 45 } |
| 39 | 46 |
| 40 // TODO(trchen): Use std::function<void, LayoutObject&> when available. | 47 // TODO(trchen): Use std::function<void, LayoutObject&> when available. |
| 41 template <typename LayoutObjectTraversalFunctor> | 48 template <typename LayoutObjectTraversalFunctor> |
| 42 void traverseNonCompositingDescendantsInPaintOrder( | 49 void traverseNonCompositingDescendantsInPaintOrder( |
| 43 const LayoutObject&, | 50 const LayoutObject&, |
| 44 const LayoutObjectTraversalFunctor&); | 51 const LayoutObjectTraversalFunctor&); |
| 45 | 52 |
| 46 template <typename LayoutObjectTraversalFunctor> | 53 template <typename LayoutObjectTraversalFunctor> |
| 47 void traverseNonCompositingDescendantsBelongingToAncestorPaintInvalidationContai ner( | 54 void traverseNonCompositingDescendantsBelongingToAncestorPaintInvalidationContai ner( |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 m_object.invalidateDisplayItemClients(PaintInvalidationRectangle); | 370 m_object.invalidateDisplayItemClients(PaintInvalidationRectangle); |
| 364 | 371 |
| 365 return dirtyRectOnBacking; | 372 return dirtyRectOnBacking; |
| 366 } | 373 } |
| 367 | 374 |
| 368 void ObjectPaintInvalidator::slowSetPaintingLayerNeedsRepaint() { | 375 void ObjectPaintInvalidator::slowSetPaintingLayerNeedsRepaint() { |
| 369 if (PaintLayer* paintingLayer = m_object.paintingLayer()) | 376 if (PaintLayer* paintingLayer = m_object.paintingLayer()) |
| 370 paintingLayer->setNeedsRepaint(); | 377 paintingLayer->setNeedsRepaint(); |
| 371 } | 378 } |
| 372 | 379 |
| 380 LayoutPoint ObjectPaintInvalidator::previousLocationInBacking() const { | |
| 381 // TODO(wangxianzhu): Use a bit in LayoutObject to indicate whether the object | |
| 382 // has previous location in the map to avoid unnecessary map lookup. | |
| 383 auto it = locationInBackingMap().find(&m_object); | |
|
chrishtr
2016/11/04 18:20:07
This lookup will be slow. How slow?
I think you s
Xianzhu
2016/11/04 19:11:03
Done.
| |
| 384 if (it == locationInBackingMap().end()) | |
| 385 return m_object.previousVisualRect().location(); | |
| 386 return it->value; | |
| 387 } | |
| 388 | |
| 389 void ObjectPaintInvalidator::setPreviousLocationInBacking( | |
| 390 const LayoutPoint& location) { | |
| 391 // TODO(wangxianzhu): Use a bit in LayoutObject to indicate whether the object | |
| 392 // has previous location in the map to avoid unnecessary map lookup. | |
| 393 if (location == m_object.previousVisualRect().location()) | |
| 394 locationInBackingMap().remove(&m_object); | |
| 395 else | |
| 396 locationInBackingMap().set(&m_object, location); | |
| 397 } | |
| 398 | |
| 373 void ObjectPaintInvalidatorWithContext::fullyInvalidatePaint( | 399 void ObjectPaintInvalidatorWithContext::fullyInvalidatePaint( |
| 374 PaintInvalidationReason reason, | 400 PaintInvalidationReason reason, |
| 375 const LayoutRect& oldVisualRect, | 401 const LayoutRect& oldVisualRect, |
| 376 const LayoutRect& newVisualRect) { | 402 const LayoutRect& newVisualRect) { |
| 377 // The following logic avoids invalidating twice if one set of bounds contains | 403 // The following logic avoids invalidating twice if one set of bounds contains |
| 378 // the other. | 404 // the other. |
| 379 if (!newVisualRect.contains(oldVisualRect)) { | 405 if (!newVisualRect.contains(oldVisualRect)) { |
| 380 LayoutRect invalidationRect = oldVisualRect; | 406 LayoutRect invalidationRect = oldVisualRect; |
| 381 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer, | 407 invalidatePaintUsingContainer(*m_context.paintInvalidationContainer, |
| 382 invalidationRect, reason); | 408 invalidationRect, reason); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 | 543 |
| 518 m_context.paintingLayer->setNeedsRepaint(); | 544 m_context.paintingLayer->setNeedsRepaint(); |
| 519 m_object.invalidateDisplayItemClients(reason); | 545 m_object.invalidateDisplayItemClients(reason); |
| 520 return reason; | 546 return reason; |
| 521 } | 547 } |
| 522 | 548 |
| 523 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts() | 549 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts() |
| 524 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {} | 550 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {} |
| 525 | 551 |
| 526 } // namespace blink | 552 } // namespace blink |
| OLD | NEW |