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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 | 422 |
| 423 const ComputedStyle& style = m_object.styleRef(); | 423 const ComputedStyle& style = m_object.styleRef(); |
| 424 | 424 |
| 425 // The outline may change shape because of position change of descendants. For | 425 // 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 | 426 // simplicity, just force full paint invalidation if this object is marked for |
| 427 // checking paint invalidation for any reason. | 427 // checking paint invalidation for any reason. |
| 428 // TODO(wangxianzhu): Optimize this. | 428 // TODO(wangxianzhu): Optimize this. |
| 429 if (style.hasOutline()) | 429 if (style.hasOutline()) |
| 430 return PaintInvalidationOutline; | 430 return PaintInvalidationOutline; |
| 431 | 431 |
| 432 bool locationChanged = m_context.newLocation != m_context.oldLocation; | |
| 433 | |
| 434 // If the bounds are the same then we know that none of the statements below | |
| 435 // can match, so we can early out. However, we can't return | |
| 436 // PaintInvalidationNone even if !locationChagned, but conservatively return | |
| 437 // PaintInvalidationIncremental because we are not sure whether paint | |
| 438 // invalidation is actually needed just based on information known to | |
| 439 // LayoutObject. For example, a LayoutBox may need paint invalidation if | |
| 440 // border box changes. | |
| 441 if (m_context.oldBounds == m_context.newBounds) | |
| 442 return locationChanged ? PaintInvalidationLocationChange | |
| 443 : PaintInvalidationIncremental; | |
| 444 | |
| 445 // If the size is zero on one of our bounds then we know we're going to have | 432 // If the size is zero on one of our bounds then we know we're going to have |
| 446 // to do a full invalidation of either old bounds or new bounds. | 433 // to do a full invalidation of either old bounds or new bounds. |
| 447 if (m_context.oldBounds.isEmpty()) | 434 if (m_context.oldBounds.isEmpty()) |
| 448 return PaintInvalidationBecameVisible; | 435 return PaintInvalidationBecameVisible; |
| 449 if (m_context.newBounds.isEmpty()) | 436 if (m_context.newBounds.isEmpty()) |
| 450 return PaintInvalidationBecameInvisible; | 437 return PaintInvalidationBecameInvisible; |
| 451 | 438 |
| 452 // If we shifted, we don't know the exact reason so we are conservative and | 439 // If we shifted, we don't know the exact reason so we are conservative and |
| 453 // trigger a full invalidation. Shifting could be caused by some layout | 440 // trigger a full invalidation. Shifting could be caused by some layout |
| 454 // property (left / top) or some in-flow layoutObject inserted / removed | 441 // property (left / top) or some in-flow layoutObject inserted / removed |
| 455 // before us in the tree. | 442 // before us in the tree. |
| 456 if (m_context.newBounds.location() != m_context.oldBounds.location()) | 443 if (m_context.newBounds.location() != m_context.oldBounds.location()) |
| 457 return PaintInvalidationBoundsChange; | 444 return PaintInvalidationBoundsChange; |
| 458 | 445 |
| 459 if (locationChanged) | 446 if (m_context.newLocation != m_context.oldLocation) |
| 460 return PaintInvalidationLocationChange; | 447 return PaintInvalidationLocationChange; |
| 461 | 448 |
| 462 return PaintInvalidationIncremental; | 449 // Incremental invalidation is only applicable to LayoutBoxes. Return |
| 450 // PaintInvalidationIncremental no matter if oldBounds and newBounds are equal | |
| 451 // because a LayoutBox may need paint invalidation if its border box changes. | |
| 452 if (m_object.isBox()) | |
| 453 return PaintInvalidationIncremental; | |
| 454 | |
| 455 if (m_context.oldBounds != m_context.newBounds) | |
| 456 return PaintInvalidationBoundsChange; | |
| 457 | |
| 458 return PaintInvalidationNone; | |
| 463 } | 459 } |
| 464 | 460 |
| 465 void ObjectPaintInvalidatorWithContext::invalidateSelectionIfNeeded( | 461 void ObjectPaintInvalidatorWithContext::invalidateSelectionIfNeeded( |
| 466 PaintInvalidationReason reason) { | 462 PaintInvalidationReason reason) { |
| 467 // Update selection rect when we are doing full invalidation (in case that the | 463 // Update selection rect when we are doing full invalidation (in case that the |
| 468 // object is moved, composite status changed, etc.) or | 464 // object is moved, composite status changed, etc.) or |
| 469 // shouldInvalidationSelection is set (in case that the selection itself | 465 // shouldInvalidationSelection is set (in case that the selection itself |
| 470 // changed). | 466 // changed). |
| 471 bool fullInvalidation = isImmediateFullPaintInvalidationReason(reason); | 467 bool fullInvalidation = isImmediateFullPaintInvalidationReason(reason); |
| 472 if (!fullInvalidation && !m_object.shouldInvalidateSelection()) | 468 if (!fullInvalidation && !m_object.shouldInvalidateSelection()) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 492 } | 488 } |
| 493 | 489 |
| 494 PaintInvalidationReason | 490 PaintInvalidationReason |
| 495 ObjectPaintInvalidatorWithContext::invalidatePaintIfNeededWithComputedReason( | 491 ObjectPaintInvalidatorWithContext::invalidatePaintIfNeededWithComputedReason( |
| 496 PaintInvalidationReason reason) { | 492 PaintInvalidationReason reason) { |
| 497 // We need to invalidate the selection before checking for whether we are | 493 // We need to invalidate the selection before checking for whether we are |
| 498 // doing a full invalidation. This is because we need to update the previous | 494 // doing a full invalidation. This is because we need to update the previous |
| 499 // selection rect regardless. | 495 // selection rect regardless. |
| 500 invalidateSelectionIfNeeded(reason); | 496 invalidateSelectionIfNeeded(reason); |
| 501 | 497 |
| 502 if (reason == PaintInvalidationIncremental) { | |
| 503 reason = m_context.oldBounds == m_context.newBounds ? PaintInvalidationNone | |
| 504 : PaintInvalidationFull; | |
| 505 } | |
| 506 | |
|
Xianzhu
2016/10/24 18:23:49
There would be no change of test results and this
| |
| 507 switch (reason) { | 498 switch (reason) { |
| 508 case PaintInvalidationNone: | 499 case PaintInvalidationNone: |
| 509 // TODO(trchen): Currently we don't keep track of paint offset of layout | 500 // TODO(trchen): Currently we don't keep track of paint offset of layout |
| 510 // objects. There are corner cases that the display items need to be | 501 // objects. There are corner cases that the display items need to be |
| 511 // invalidated for paint offset mutation, but incurs no pixel difference | 502 // invalidated for paint offset mutation, but incurs no pixel difference |
| 512 // (i.e. bounds stay the same) so no rect-based invalidation is issued. | 503 // (i.e. bounds stay the same) so no rect-based invalidation is issued. |
| 513 // See crbug.com/508383 and crbug.com/515977. This is a workaround to | 504 // See crbug.com/508383 and crbug.com/515977. This is a workaround to |
| 514 // force display items to update paint offset. | 505 // force display items to update paint offset. |
| 515 if (m_context.forcedSubtreeInvalidationFlags & | 506 if (m_context.forcedSubtreeInvalidationFlags & |
| 516 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking) { | 507 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 527 | 518 |
| 528 m_context.paintingLayer->setNeedsRepaint(); | 519 m_context.paintingLayer->setNeedsRepaint(); |
| 529 m_object.invalidateDisplayItemClients(reason); | 520 m_object.invalidateDisplayItemClients(reason); |
| 530 return reason; | 521 return reason; |
| 531 } | 522 } |
| 532 | 523 |
| 533 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts() | 524 DisablePaintInvalidationStateAsserts::DisablePaintInvalidationStateAsserts() |
| 534 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {} | 525 : m_disabler(&gDisablePaintInvalidationStateAsserts, true) {} |
| 535 | 526 |
| 536 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |