| 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/layout/LayoutBlockFlow.h" | 7 #include "core/layout/LayoutBlockFlow.h" |
| 8 #include "core/paint/PaintInvalidator.h" | 8 #include "core/paint/PaintInvalidator.h" |
| 9 #include "core/paint/PaintLayer.h" | 9 #include "core/paint/PaintLayer.h" |
| 10 | 10 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 m_object.getMutableForPainting().setPreviousBackgroundObscured(backgroun
dObscured); | 79 m_object.getMutableForPainting().setPreviousBackgroundObscured(backgroun
dObscured); |
| 80 backgroundObscurationChanged = true; | 80 backgroundObscurationChanged = true; |
| 81 } | 81 } |
| 82 | 82 |
| 83 if (m_context.forcedSubtreeInvalidationFlags & PaintInvalidatorContext::Forc
edSubtreeFullInvalidation) | 83 if (m_context.forcedSubtreeInvalidationFlags & PaintInvalidatorContext::Forc
edSubtreeFullInvalidation) |
| 84 return PaintInvalidationSubtree; | 84 return PaintInvalidationSubtree; |
| 85 | 85 |
| 86 if (m_object.shouldDoFullPaintInvalidation()) | 86 if (m_object.shouldDoFullPaintInvalidation()) |
| 87 return m_object.fullPaintInvalidationReason(); | 87 return m_object.fullPaintInvalidationReason(); |
| 88 | 88 |
| 89 if (m_context.oldBounds.isEmpty() && m_context.newBounds.isEmpty()) |
| 90 return PaintInvalidationNone; |
| 91 |
| 89 if (backgroundObscurationChanged) | 92 if (backgroundObscurationChanged) |
| 90 return PaintInvalidationBackgroundObscurationChange; | 93 return PaintInvalidationBackgroundObscurationChange; |
| 91 | 94 |
| 92 if (m_object.paintedOutputOfObjectHasNoEffect()) | 95 if (m_object.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) |
| 93 return PaintInvalidationNone; | 96 return PaintInvalidationNone; |
| 94 | 97 |
| 95 const ComputedStyle& style = m_object.styleRef(); | 98 const ComputedStyle& style = m_object.styleRef(); |
| 96 | 99 |
| 97 // The outline may change shape because of position change of descendants. F
or simplicity, | 100 // The outline may change shape because of position change of descendants. F
or simplicity, |
| 98 // just force full paint invalidation if this object is marked for checking
paint invalidation | 101 // just force full paint invalidation if this object is marked for checking
paint invalidation |
| 99 // for any reason. | 102 // for any reason. |
| 100 // TODO(wangxianzhu): Optimize this. | 103 // TODO(wangxianzhu): Optimize this. |
| 101 if (style.hasOutline()) | 104 if (style.hasOutline()) |
| 102 return PaintInvalidationOutline; | 105 return PaintInvalidationOutline; |
| 103 | 106 |
| 104 bool locationChanged = m_context.newLocation != m_context.oldLocation; | 107 bool locationChanged = m_context.newLocation != m_context.oldLocation; |
| 105 | 108 |
| 106 // If the bounds are the same then we know that none of the statements below | 109 // If the bounds are the same then we know that none of the statements below |
| 107 // can match, so we can early out. | 110 // can match, so we can early out. |
| 108 if (m_context.oldBounds == m_context.newBounds) | 111 if (m_context.oldBounds == m_context.newBounds) |
| 109 return locationChanged && !m_context.oldBounds.isEmpty() ? PaintInvalida
tionLocationChange : PaintInvalidationNone; | 112 return locationChanged ? PaintInvalidationLocationChange : PaintInvalida
tionProbablyNone; |
| 110 | |
| 111 // If we shifted, we don't know the exact reason so we are conservative and
trigger a full invalidation. Shifting could | |
| 112 // be caused by some layout property (left / top) or some in-flow layoutObje
ct inserted / removed before us in the tree. | |
| 113 if (m_context.newBounds.location() != m_context.oldBounds.location()) | |
| 114 return PaintInvalidationBoundsChange; | |
| 115 | 113 |
| 116 // If the size is zero on one of our bounds then we know we're going to have | 114 // If the size is zero on one of our bounds then we know we're going to have |
| 117 // to do a full invalidation of either old bounds or new bounds. | 115 // to do a full invalidation of either old bounds or new bounds. |
| 118 if (m_context.oldBounds.isEmpty()) | 116 if (m_context.oldBounds.isEmpty()) |
| 119 return PaintInvalidationBecameVisible; | 117 return PaintInvalidationBecameVisible; |
| 120 if (m_context.newBounds.isEmpty()) | 118 if (m_context.newBounds.isEmpty()) |
| 121 return PaintInvalidationBecameInvisible; | 119 return PaintInvalidationBecameInvisible; |
| 122 | 120 |
| 121 // If we shifted, we don't know the exact reason so we are conservative and
trigger a full invalidation. Shifting could |
| 122 // be caused by some layout property (left / top) or some in-flow layoutObje
ct inserted / removed before us in the tree. |
| 123 if (m_context.newBounds.location() != m_context.oldBounds.location()) |
| 124 return PaintInvalidationBoundsChange; |
| 125 |
| 123 if (locationChanged) | 126 if (locationChanged) |
| 124 return PaintInvalidationLocationChange; | 127 return PaintInvalidationLocationChange; |
| 125 | 128 |
| 126 return PaintInvalidationIncremental; | 129 return PaintInvalidationIncremental; |
| 127 } | 130 } |
| 128 | 131 |
| 129 void ObjectPaintInvalidator::invalidateSelectionIfNeeded(PaintInvalidationReason
reason) | 132 void ObjectPaintInvalidator::invalidateSelectionIfNeeded(PaintInvalidationReason
reason) |
| 130 { | 133 { |
| 131 // Update selection rect when we are doing full invalidation (in case that t
he object is moved, | 134 // Update selection rect when we are doing full invalidation (in case that t
he object is moved, |
| 132 // composite status changed, etc.) or shouldInvalidationSelection is set (in
case that the | 135 // composite status changed, etc.) or shouldInvalidationSelection is set (in
case that the |
| 133 // selection itself changed). | 136 // selection itself changed). |
| 134 bool fullInvalidation = isFullPaintInvalidationReason(reason); | 137 bool fullInvalidation = isImmediateFullPaintInvalidationReason(reason); |
| 135 if (!fullInvalidation && !m_object.shouldInvalidateSelection()) | 138 if (!fullInvalidation && !m_object.shouldInvalidateSelection()) |
| 136 return; | 139 return; |
| 137 | 140 |
| 138 LayoutRect oldSelectionRect = selectionPaintInvalidationMap().get(&m_object)
; | 141 LayoutRect oldSelectionRect = selectionPaintInvalidationMap().get(&m_object)
; |
| 139 LayoutRect newSelectionRect = m_object.localSelectionRect(); | 142 LayoutRect newSelectionRect = m_object.localSelectionRect(); |
| 140 if (!newSelectionRect.isEmpty()) | 143 if (!newSelectionRect.isEmpty()) |
| 141 m_context.mapLocalRectToPaintInvalidationBacking(m_object, newSelectionR
ect); | 144 m_context.mapLocalRectToPaintInvalidationBacking(m_object, newSelectionR
ect); |
| 142 | 145 |
| 143 newSelectionRect.move(m_object.scrollAdjustmentForPaintInvalidation(*m_conte
xt.paintInvalidationContainer)); | 146 newSelectionRect.move(m_object.scrollAdjustmentForPaintInvalidation(*m_conte
xt.paintInvalidationContainer)); |
| 144 | 147 |
| 145 setPreviousSelectionPaintInvalidationRect(m_object, newSelectionRect); | 148 setPreviousSelectionPaintInvalidationRect(m_object, newSelectionRect); |
| 146 | 149 |
| 147 if (!fullInvalidation) { | 150 if (!fullInvalidation) { |
| 148 fullyInvalidatePaint(PaintInvalidationSelection, oldSelectionRect, newSe
lectionRect); | 151 fullyInvalidatePaint(PaintInvalidationSelection, oldSelectionRect, newSe
lectionRect); |
| 149 m_context.paintingLayer->setNeedsRepaint(); | 152 m_context.paintingLayer->setNeedsRepaint(); |
| 150 m_object.invalidateDisplayItemClients(PaintInvalidationSelection); | 153 m_object.invalidateDisplayItemClients(PaintInvalidationSelection); |
| 151 } | 154 } |
| 152 } | 155 } |
| 153 | 156 |
| 154 PaintInvalidationReason ObjectPaintInvalidator::invalidatePaintIfNeededWithCompu
tedReason(PaintInvalidationReason reason) | 157 PaintInvalidationReason ObjectPaintInvalidator::invalidatePaintIfNeededWithCompu
tedReason(PaintInvalidationReason reason) |
| 155 { | 158 { |
| 156 // We need to invalidate the selection before checking for whether we are do
ing a full invalidation. | 159 // We need to invalidate the selection before checking for whether we are do
ing a full invalidation. |
| 157 // This is because we need to update the previous selection rect regardless. | 160 // This is because we need to update the previous selection rect regardless. |
| 158 invalidateSelectionIfNeeded(reason); | 161 invalidateSelectionIfNeeded(reason); |
| 159 | 162 |
| 160 switch (reason) { | 163 switch (reason) { |
| 161 case PaintInvalidationNone: | 164 case PaintInvalidationNone: |
| 165 case PaintInvalidationProbablyNone: |
| 162 // TODO(trchen): Currently we don't keep track of paint offset of layout
objects. | 166 // TODO(trchen): Currently we don't keep track of paint offset of layout
objects. |
| 163 // There are corner cases that the display items need to be invalidated
for paint offset | 167 // There are corner cases that the display items need to be invalidated
for paint offset |
| 164 // mutation, but incurs no pixel difference (i.e. bounds stay the same)
so no rect-based | 168 // mutation, but incurs no pixel difference (i.e. bounds stay the same)
so no rect-based |
| 165 // invalidation is issued. See crbug.com/508383 and crbug.com/515977. | 169 // invalidation is issued. See crbug.com/508383 and crbug.com/515977. |
| 166 // This is a workaround to force display items to update paint offset. | 170 // This is a workaround to force display items to update paint offset. |
| 167 if (m_context.forcedSubtreeInvalidationFlags & PaintInvalidatorContext::
ForcedSubtreeInvalidationChecking) { | 171 if (m_context.forcedSubtreeInvalidationFlags & PaintInvalidatorContext::
ForcedSubtreeInvalidationChecking) { |
| 168 reason = PaintInvalidationLocationChange; | 172 reason = PaintInvalidationLocationChange; |
| 169 break; | 173 break; |
| 170 } | 174 } |
| 171 return PaintInvalidationNone; | 175 return PaintInvalidationNone; |
| 172 case PaintInvalidationIncremental: | 176 case PaintInvalidationIncremental: |
| 173 incrementallyInvalidatePaint(); | 177 incrementallyInvalidatePaint(); |
| 174 break; | 178 break; |
| 175 case PaintInvalidationDelayedFull: | 179 case PaintInvalidationDelayedFull: |
| 176 return PaintInvalidationDelayedFull; | 180 return PaintInvalidationDelayedFull; |
| 177 default: | 181 default: |
| 178 DCHECK(isFullPaintInvalidationReason(reason)); | 182 DCHECK(isImmediateFullPaintInvalidationReason(reason)); |
| 179 fullyInvalidatePaint(reason, m_context.oldBounds, m_context.newBounds); | 183 fullyInvalidatePaint(reason, m_context.oldBounds, m_context.newBounds); |
| 180 } | 184 } |
| 181 | 185 |
| 182 m_context.paintingLayer->setNeedsRepaint(); | 186 m_context.paintingLayer->setNeedsRepaint(); |
| 183 m_object.invalidateDisplayItemClients(reason); | 187 m_object.invalidateDisplayItemClients(reason); |
| 184 return reason; | 188 return reason; |
| 185 } | 189 } |
| 186 | 190 |
| 187 } // namespace blink | 191 } // namespace blink |
| OLD | NEW |