| 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/PaintInvalidator.h" | 5 #include "core/paint/PaintInvalidator.h" |
| 6 | 6 |
| 7 #include "core/editing/FrameSelection.h" | 7 #include "core/editing/FrameSelection.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 return result; | 40 return result; |
| 41 } | 41 } |
| 42 | 42 |
| 43 // TODO(wangxianzhu): Combine this into | 43 // TODO(wangxianzhu): Combine this into |
| 44 // PaintInvalidator::mapLocalRectToPaintInvalidationBacking() when removing | 44 // PaintInvalidator::mapLocalRectToPaintInvalidationBacking() when removing |
| 45 // PaintInvalidationState. | 45 // PaintInvalidationState. |
| 46 static LayoutRect mapLocalRectToPaintInvalidationBacking( | 46 static LayoutRect mapLocalRectToPaintInvalidationBacking( |
| 47 GeometryMapper& geometryMapper, | 47 GeometryMapper& geometryMapper, |
| 48 const LayoutObject& object, | 48 const LayoutObject& object, |
| 49 const FloatRect& localRect, | 49 const FloatRect& localRect, |
| 50 const PaintInvalidatorContext& context) { | 50 const PaintInvalidatorContext& context, |
| 51 bool& coversExtraPixels) { |
| 51 // TODO(wkorman): The flip below is required because visual rects are | 52 // TODO(wkorman): The flip below is required because visual rects are |
| 52 // currently in "physical coordinates with flipped block-flow direction" | 53 // currently in "physical coordinates with flipped block-flow direction" |
| 53 // (see LayoutBoxModelObject.h) but we need them to be in physical | 54 // (see LayoutBoxModelObject.h) but we need them to be in physical |
| 54 // coordinates. | 55 // coordinates. |
| 55 FloatRect rect = localRect; | 56 FloatRect rect = localRect; |
| 56 // Writing-mode flipping doesn't apply to non-root SVG. | 57 // Writing-mode flipping doesn't apply to non-root SVG. |
| 57 if (!object.isSVG() || object.isSVGRoot()) { | 58 if (!object.isSVG() || object.isSVGRoot()) { |
| 58 if (object.isBox()) { | 59 if (object.isBox()) { |
| 59 toLayoutBox(object).flipForWritingMode(rect); | 60 toLayoutBox(object).flipForWritingMode(rect); |
| 60 } else if (!(context.forcedSubtreeInvalidationFlags & | 61 } else if (!(context.forcedSubtreeInvalidationFlags & |
| 61 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { | 62 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { |
| 62 // For SPv2 and the GeometryMapper path, we also need to convert the rect | 63 // For SPv2 and the GeometryMapper path, we also need to convert the rect |
| 63 // for non-boxes into physical coordinates before applying paint offset. | 64 // for non-boxes into physical coordinates before applying paint offset. |
| 64 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires | 65 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires |
| 65 // physical coordinates for boxes, but "physical coordinates with flipped | 66 // physical coordinates for boxes, but "physical coordinates with flipped |
| 66 // block-flow direction" for non-boxes for which we don't need to flip.) | 67 // block-flow direction" for non-boxes for which we don't need to flip.) |
| 67 // TODO(wangxianzhu): Avoid containingBlock(). | 68 // TODO(wangxianzhu): Avoid containingBlock(). |
| 68 object.containingBlock()->flipForWritingMode(rect); | 69 object.containingBlock()->flipForWritingMode(rect); |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 73 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
| 73 // In SPv2, visual rects are in the space of their local transform node. | 74 // In SPv2, visual rects are in the space of their local transform node. |
| 74 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 75 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 76 // Use enclosingIntRect to ensure the final visual rect will cover the |
| 77 // rect in source coordinates no matter if the painting will use pixel |
| 78 // snapping. |
| 79 IntRect intRect = enclosingIntRect(rect); |
| 80 if (FloatRect(intRect) != rect) { |
| 81 coversExtraPixels = true; |
| 82 return LayoutRect(intRect); |
| 83 } |
| 75 return LayoutRect(rect); | 84 return LayoutRect(rect); |
| 76 } | 85 } |
| 77 | 86 |
| 78 LayoutRect result; | 87 LayoutRect result; |
| 79 if (context.forcedSubtreeInvalidationFlags & | 88 if (context.forcedSubtreeInvalidationFlags & |
| 80 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { | 89 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { |
| 81 result = slowMapToVisualRectInAncestorSpace( | 90 result = slowMapToVisualRectInAncestorSpace( |
| 82 object, *context.paintInvalidationContainer, rect); | 91 object, *context.paintInvalidationContainer, rect); |
| 83 } else if (object == context.paintInvalidationContainer) { | 92 } else if (object == context.paintInvalidationContainer) { |
| 84 result = LayoutRect(rect); | 93 result = LayoutRect(rect); |
| 85 } else { | 94 } else { |
| 86 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 95 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 96 if ((!object.isSVG() || object.isSVGRoot()) && !rect.isEmpty()) { |
| 97 // Use enclosingIntRect to ensure the final visual rect will cover the |
| 98 // rect in source coordinates no matter if the painting will use pixel |
| 99 // snapping. |
| 100 IntRect intRect = enclosingIntRect(rect); |
| 101 if (FloatRect(intRect) != rect) { |
| 102 coversExtraPixels = true; |
| 103 rect = intRect; |
| 104 } |
| 105 } |
| 87 | 106 |
| 88 PropertyTreeState currentTreeState( | 107 PropertyTreeState currentTreeState( |
| 89 context.treeBuilderContext.current.transform, | 108 context.treeBuilderContext.current.transform, |
| 90 context.treeBuilderContext.current.clip, | 109 context.treeBuilderContext.current.clip, |
| 91 context.treeBuilderContext.currentEffect, | 110 context.treeBuilderContext.currentEffect, |
| 92 context.treeBuilderContext.current.scroll); | 111 context.treeBuilderContext.current.scroll); |
| 93 const auto* containerPaintProperties = | 112 const auto* containerPaintProperties = |
| 94 context.paintInvalidationContainer->paintProperties(); | 113 context.paintInvalidationContainer->paintProperties(); |
| 95 auto containerContentsProperties = | 114 auto containerContentsProperties = |
| 96 containerPaintProperties->contentsProperties(); | 115 containerPaintProperties->contentsProperties(); |
| 97 | 116 |
| 117 // TODO(wangxianzhu): Set coversExtraPixels if there are any non-translate |
| 118 // transforms. Currently this case is handled in BoxPaintInvalidator by |
| 119 // checking transforms. |
| 98 bool success = false; | 120 bool success = false; |
| 99 result = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( | 121 result = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( |
| 100 rect, currentTreeState, containerContentsProperties.propertyTreeState, | 122 rect, currentTreeState, containerContentsProperties.propertyTreeState, |
| 101 success)); | 123 success)); |
| 102 DCHECK(success); | 124 DCHECK(success); |
| 103 | 125 |
| 104 // Convert the result to the container's contents space. | 126 // Convert the result to the container's contents space. |
| 105 result.moveBy(-containerContentsProperties.paintOffset); | 127 result.moveBy(-containerContentsProperties.paintOffset); |
| 106 } | 128 } |
| 107 | 129 |
| 108 if (context.paintInvalidationContainer->layer()->groupedMapping()) | 130 if (context.paintInvalidationContainer->layer()->groupedMapping()) |
| 109 PaintLayer::mapRectInPaintInvalidationContainerToBacking( | 131 PaintLayer::mapRectInPaintInvalidationContainerToBacking( |
| 110 *context.paintInvalidationContainer, result); | 132 *context.paintInvalidationContainer, result); |
| 111 return result; | 133 return result; |
| 112 } | 134 } |
| 113 | 135 |
| 114 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( | 136 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( |
| 115 const LayoutObject& object, | 137 const LayoutObject& object, |
| 116 LayoutRect& rect) const { | 138 LayoutRect& rect) const { |
| 117 GeometryMapper geometryMapper; | 139 GeometryMapper geometryMapper; |
| 118 rect = blink::mapLocalRectToPaintInvalidationBacking(geometryMapper, object, | 140 bool coversExtraPixels; |
| 119 FloatRect(rect), *this); | 141 rect = blink::mapLocalRectToPaintInvalidationBacking( |
| 142 geometryMapper, object, FloatRect(rect), *this, coversExtraPixels); |
| 120 } | 143 } |
| 121 | 144 |
| 122 LayoutRect PaintInvalidator::mapLocalRectToPaintInvalidationBacking( | 145 LayoutRect PaintInvalidator::mapLocalRectToPaintInvalidationBacking( |
| 123 const LayoutObject& object, | 146 const LayoutObject& object, |
| 124 const FloatRect& localRect, | 147 const FloatRect& localRect, |
| 125 const PaintInvalidatorContext& context) { | 148 const PaintInvalidatorContext& context, |
| 126 return blink::mapLocalRectToPaintInvalidationBacking(m_geometryMapper, object, | 149 bool& coversExtraPixels) { |
| 127 localRect, context); | 150 return blink::mapLocalRectToPaintInvalidationBacking( |
| 151 m_geometryMapper, object, localRect, context, coversExtraPixels); |
| 128 } | 152 } |
| 129 | 153 |
| 130 LayoutRect PaintInvalidator::computePaintInvalidationRectInBacking( | 154 LayoutRect PaintInvalidator::computePaintInvalidationRectInBacking( |
| 131 const LayoutObject& object, | 155 const LayoutObject& object, |
| 132 const PaintInvalidatorContext& context) { | 156 const PaintInvalidatorContext& context, |
| 157 bool& coversExtraPixels) { |
| 133 FloatRect localRect; | 158 FloatRect localRect; |
| 134 if (object.isSVG() && !object.isSVGRoot()) | 159 if (object.isSVG() && !object.isSVGRoot()) |
| 135 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); | 160 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); |
| 136 else | 161 else |
| 137 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); | 162 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); |
| 138 | 163 |
| 139 return mapLocalRectToPaintInvalidationBacking(object, localRect, context); | 164 return mapLocalRectToPaintInvalidationBacking(object, localRect, context, |
| 165 coversExtraPixels); |
| 140 } | 166 } |
| 141 | 167 |
| 142 LayoutPoint PaintInvalidator::computeLocationFromPaintInvalidationBacking( | 168 LayoutPoint PaintInvalidator::computeLocationFromPaintInvalidationBacking( |
| 143 const LayoutObject& object, | 169 const LayoutObject& object, |
| 144 const PaintInvalidatorContext& context) { | 170 const PaintInvalidatorContext& context) { |
| 145 FloatPoint point; | 171 FloatPoint point; |
| 146 if (object != context.paintInvalidationContainer) { | 172 if (object != context.paintInvalidationContainer) { |
| 147 point.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 173 point.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 148 | 174 |
| 149 PropertyTreeState currentTreeState( | 175 PropertyTreeState currentTreeState( |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; | 330 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; |
| 305 | 331 |
| 306 // TODO(crbug.com/637313): This is temporary before we support filters in | 332 // TODO(crbug.com/637313): This is temporary before we support filters in |
| 307 // paint property tree. | 333 // paint property tree. |
| 308 // TODO(crbug.com/648274): This is a workaround for multi-column contents. | 334 // TODO(crbug.com/648274): This is a workaround for multi-column contents. |
| 309 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) | 335 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) |
| 310 context.forcedSubtreeInvalidationFlags |= | 336 context.forcedSubtreeInvalidationFlags |= |
| 311 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; | 337 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; |
| 312 | 338 |
| 313 context.oldBounds = object.previousPaintInvalidationRect(); | 339 context.oldBounds = object.previousPaintInvalidationRect(); |
| 340 context.oldBoundsCoversExtraPixels = |
| 341 object.previousPaintInvalidationRectCoversExtraPixels(); |
| 314 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); | 342 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); |
| 315 context.newBounds = computePaintInvalidationRectInBacking(object, context); | 343 context.newBounds = computePaintInvalidationRectInBacking( |
| 344 object, context, context.newBoundsCoversExtraPixels); |
| 316 context.newLocation = | 345 context.newLocation = |
| 317 computeLocationFromPaintInvalidationBacking(object, context); | 346 computeLocationFromPaintInvalidationBacking(object, context); |
| 318 | 347 |
| 319 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( | 348 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( |
| 320 *context.paintInvalidationContainer); | 349 *context.paintInvalidationContainer); |
| 321 context.newLocation.move(adjustment); | 350 context.newLocation.move(adjustment); |
| 322 context.newBounds.move(adjustment); | 351 context.newBounds.move(adjustment); |
| 323 | 352 |
| 324 object.getMutableForPainting().setPreviousPaintInvalidationRect( | 353 object.getMutableForPainting().setPreviousPaintInvalidationRect( |
| 325 context.newBounds); | 354 context.newBounds, context.newBoundsCoversExtraPixels); |
| 326 object.getMutableForPainting() | 355 object.getMutableForPainting() |
| 327 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); | 356 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); |
| 328 } | 357 } |
| 329 | 358 |
| 330 void PaintInvalidator::invalidatePaintIfNeeded( | 359 void PaintInvalidator::invalidatePaintIfNeeded( |
| 331 FrameView& frameView, | 360 FrameView& frameView, |
| 332 PaintInvalidatorContext& context) { | 361 PaintInvalidatorContext& context) { |
| 333 LayoutView* layoutView = frameView.layoutView(); | 362 LayoutView* layoutView = frameView.layoutView(); |
| 334 CHECK(layoutView); | 363 CHECK(layoutView); |
| 335 | 364 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 object.getMutableForPainting().clearPaintInvalidationFlags(); | 469 object.getMutableForPainting().clearPaintInvalidationFlags(); |
| 441 } | 470 } |
| 442 | 471 |
| 443 void PaintInvalidator::processPendingDelayedPaintInvalidations() { | 472 void PaintInvalidator::processPendingDelayedPaintInvalidations() { |
| 444 for (auto target : m_pendingDelayedPaintInvalidations) | 473 for (auto target : m_pendingDelayedPaintInvalidations) |
| 445 target->getMutableForPainting().setShouldDoFullPaintInvalidation( | 474 target->getMutableForPainting().setShouldDoFullPaintInvalidation( |
| 446 PaintInvalidationDelayedFull); | 475 PaintInvalidationDelayedFull); |
| 447 } | 476 } |
| 448 | 477 |
| 449 } // namespace blink | 478 } // namespace blink |
| OLD | NEW |