| 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/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/layout/compositing/CompositedLayerMapping.h" | 9 #include "core/layout/compositing/CompositedLayerMapping.h" |
| 10 #include "core/paint/ObjectPaintInvalidator.h" | 10 #include "core/paint/ObjectPaintInvalidator.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 const ComputedStyle& style = m_box.styleRef(); | 118 const ComputedStyle& style = m_box.styleRef(); |
| 119 | 119 |
| 120 if ((style.backgroundLayers().thisOrNextLayersUseContentBox() || | 120 if ((style.backgroundLayers().thisOrNextLayersUseContentBox() || |
| 121 style.maskLayers().thisOrNextLayersUseContentBox() || | 121 style.maskLayers().thisOrNextLayersUseContentBox() || |
| 122 style.boxSizing() == EBoxSizing::kBorderBox) && | 122 style.boxSizing() == EBoxSizing::kBorderBox) && |
| 123 previousContentBoxRect() != m_box.contentBoxRect()) | 123 previousContentBoxRect() != m_box.contentBoxRect()) |
| 124 return PaintInvalidationContentBoxChange; | 124 return PaintInvalidationContentBoxChange; |
| 125 | 125 |
| 126 LayoutSize oldBorderBoxSize = previousBorderBoxSize(); | 126 LayoutSize oldBorderBoxSize = |
| 127 previousBorderBoxSize(m_box, m_context.oldVisualRect.size()); |
| 127 LayoutSize newBorderBoxSize = m_box.size(); | 128 LayoutSize newBorderBoxSize = m_box.size(); |
| 128 bool borderBoxChanged = oldBorderBoxSize != newBorderBoxSize; | 129 bool borderBoxChanged = oldBorderBoxSize != newBorderBoxSize; |
| 129 if (!borderBoxChanged && m_context.oldVisualRect == m_context.newVisualRect) | 130 if (!borderBoxChanged && m_context.oldVisualRect == m_context.newVisualRect) |
| 130 return PaintInvalidationNone; | 131 return PaintInvalidationNone; |
| 131 | 132 |
| 132 // If either border box changed or bounds changed, and old or new border box | 133 // If either border box changed or bounds changed, and old or new border box |
| 133 // doesn't equal old or new bounds, incremental invalidation is not | 134 // doesn't equal old or new bounds, incremental invalidation is not |
| 134 // applicable. This captures the following cases: | 135 // applicable. This captures the following cases: |
| 135 // - pixel snapping of paint invalidation bounds, | 136 // - pixel snapping of paint invalidation bounds, |
| 136 // - scale, rotate, skew etc. transforms, | 137 // - scale, rotate, skew etc. transforms, |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 273 |
| 273 PaintInvalidationReason reason = computePaintInvalidationReason(); | 274 PaintInvalidationReason reason = computePaintInvalidationReason(); |
| 274 if (reason == PaintInvalidationIncremental) { | 275 if (reason == PaintInvalidationIncremental) { |
| 275 bool invalidated; | 276 bool invalidated; |
| 276 if (m_box.isLayoutView() && | 277 if (m_box.isLayoutView() && |
| 277 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 278 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
| 278 invalidated = incrementallyInvalidatePaint( | 279 invalidated = incrementallyInvalidatePaint( |
| 279 reason, m_context.oldVisualRect, m_context.newVisualRect); | 280 reason, m_context.oldVisualRect, m_context.newVisualRect); |
| 280 } else { | 281 } else { |
| 281 invalidated = incrementallyInvalidatePaint( | 282 invalidated = incrementallyInvalidatePaint( |
| 282 reason, LayoutRect(m_context.oldLocation, previousBorderBoxSize()), | 283 reason, LayoutRect(m_context.oldLocation, |
| 284 previousBorderBoxSize( |
| 285 m_box, m_context.oldVisualRect.size())), |
| 283 LayoutRect(m_context.newLocation, m_box.size())); | 286 LayoutRect(m_context.newLocation, m_box.size())); |
| 284 } | 287 } |
| 285 if (invalidated) { | 288 if (invalidated) { |
| 286 m_context.paintingLayer->setNeedsRepaint(); | 289 m_context.paintingLayer->setNeedsRepaint(); |
| 287 m_box.invalidateDisplayItemClients(reason); | 290 m_box.invalidateDisplayItemClients(reason); |
| 288 } else { | 291 } else { |
| 289 reason = PaintInvalidationNone; | 292 reason = PaintInvalidationNone; |
| 290 } | 293 } |
| 291 | 294 |
| 292 // Though we have done incremental invalidation, we still need to call | 295 // Though we have done incremental invalidation, we still need to call |
| (...skipping 12 matching lines...) Expand all Loading... |
| 305 area->invalidatePaintOfScrollControlsIfNeeded(m_context); | 308 area->invalidatePaintOfScrollControlsIfNeeded(m_context); |
| 306 | 309 |
| 307 // This is for the next invalidatePaintIfNeeded so must be at the end. | 310 // This is for the next invalidatePaintIfNeeded so must be at the end. |
| 308 savePreviousBoxGeometriesIfNeeded(); | 311 savePreviousBoxGeometriesIfNeeded(); |
| 309 | 312 |
| 310 return reason; | 313 return reason; |
| 311 } | 314 } |
| 312 | 315 |
| 313 bool BoxPaintInvalidator::needsToSavePreviousBoxGeometries() { | 316 bool BoxPaintInvalidator::needsToSavePreviousBoxGeometries() { |
| 314 LayoutSize paintInvalidationSize = m_context.newVisualRect.size(); | 317 LayoutSize paintInvalidationSize = m_context.newVisualRect.size(); |
| 315 // Don't save old box Geometries if the paint rect is empty because we'll | |
| 316 // full invalidate once the paint rect becomes non-empty. | |
| 317 if (paintInvalidationSize.isEmpty()) | |
| 318 return false; | |
| 319 | 318 |
| 320 if (m_box.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) | 319 // The shortcuts doesn't apply to HTML element. ViewPaintInvalidator needs to |
| 321 return false; | 320 // know its previous border box size even if it has visibility:hidden (causing |
| 321 // empty paintInvalidationSize) or has no painted output. |
| 322 if (!m_box.node() || !m_box.node()->isHTMLElement()) { |
| 323 // Don't save old box geometries if the paint rect is empty because we'll |
| 324 // fully invalidate once the paint rect becomes non-empty. |
| 325 if (paintInvalidationSize.isEmpty()) |
| 326 return false; |
| 327 |
| 328 if (m_box.paintedOutputOfObjectHasNoEffectRegardlessOfSize()) |
| 329 return false; |
| 330 } |
| 322 | 331 |
| 323 const ComputedStyle& style = m_box.styleRef(); | 332 const ComputedStyle& style = m_box.styleRef(); |
| 324 | 333 |
| 325 // If we use border-box sizing we need to track changes in the size of the | 334 // If we use border-box sizing we need to track changes in the size of the |
| 326 // content box. | 335 // content box. |
| 327 if (style.boxSizing() == EBoxSizing::kBorderBox) | 336 if (style.boxSizing() == EBoxSizing::kBorderBox) |
| 328 return true; | 337 return true; |
| 329 | 338 |
| 330 // No need to save old border box size if we can use size of the old paint | 339 // No need to save old border box size if we can use size of the old paint |
| 331 // rect as the old border box size in the next invalidation. | 340 // rect as the old border box size in the next invalidation. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 353 } | 362 } |
| 354 return; | 363 return; |
| 355 } | 364 } |
| 356 | 365 |
| 357 PreviousBoxGeometries geometries = {m_box.size(), m_box.contentBoxRect(), | 366 PreviousBoxGeometries geometries = {m_box.size(), m_box.contentBoxRect(), |
| 358 m_box.layoutOverflowRect()}; | 367 m_box.layoutOverflowRect()}; |
| 359 previousBoxGeometriesMap().set(&m_box, geometries); | 368 previousBoxGeometriesMap().set(&m_box, geometries); |
| 360 m_box.getMutableForPainting().setHasPreviousBoxGeometries(true); | 369 m_box.getMutableForPainting().setHasPreviousBoxGeometries(true); |
| 361 } | 370 } |
| 362 | 371 |
| 363 LayoutSize BoxPaintInvalidator::previousBorderBoxSize() { | 372 LayoutSize BoxPaintInvalidator::previousBorderBoxSize( |
| 364 DCHECK(m_box.hasPreviousBoxGeometries() == | 373 const LayoutBox& box, |
| 365 previousBoxGeometriesMap().contains(&m_box)); | 374 const LayoutSize& defaultSize) { |
| 366 if (m_box.hasPreviousBoxGeometries()) | 375 DCHECK(box.hasPreviousBoxGeometries() == |
| 367 return previousBoxGeometriesMap().get(&m_box).borderBoxSize; | 376 previousBoxGeometriesMap().contains(&box)); |
| 368 | 377 if (box.hasPreviousBoxGeometries()) |
| 369 // We didn't save the old border box size because it was the same as the size | 378 return previousBoxGeometriesMap().get(&box).borderBoxSize; |
| 370 // of oldVisualRect. | 379 return defaultSize; |
| 371 return m_context.oldVisualRect.size(); | |
| 372 } | 380 } |
| 373 | 381 |
| 374 LayoutRect BoxPaintInvalidator::previousContentBoxRect() { | 382 LayoutRect BoxPaintInvalidator::previousContentBoxRect() { |
| 375 DCHECK(m_box.hasPreviousBoxGeometries() == | 383 DCHECK(m_box.hasPreviousBoxGeometries() == |
| 376 previousBoxGeometriesMap().contains(&m_box)); | 384 previousBoxGeometriesMap().contains(&m_box)); |
| 377 return m_box.hasPreviousBoxGeometries() | 385 return m_box.hasPreviousBoxGeometries() |
| 378 ? previousBoxGeometriesMap().get(&m_box).contentBoxRect | 386 ? previousBoxGeometriesMap().get(&m_box).contentBoxRect |
| 379 : LayoutRect(); | 387 : LayoutRect(); |
| 380 } | 388 } |
| 381 | 389 |
| 382 LayoutRect BoxPaintInvalidator::previousLayoutOverflowRect() { | 390 LayoutRect BoxPaintInvalidator::previousLayoutOverflowRect() { |
| 383 DCHECK(m_box.hasPreviousBoxGeometries() == | 391 DCHECK(m_box.hasPreviousBoxGeometries() == |
| 384 previousBoxGeometriesMap().contains(&m_box)); | 392 previousBoxGeometriesMap().contains(&m_box)); |
| 385 return m_box.hasPreviousBoxGeometries() | 393 return m_box.hasPreviousBoxGeometries() |
| 386 ? previousBoxGeometriesMap().get(&m_box).layoutOverflowRect | 394 ? previousBoxGeometriesMap().get(&m_box).layoutOverflowRect |
| 387 : LayoutRect(); | 395 : LayoutRect(); |
| 388 } | 396 } |
| 389 | 397 |
| 390 } // namespace blink | 398 } // namespace blink |
| OLD | NEW |