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 23 matching lines...) Expand all Loading... |
34 LayoutRect result(rect); | 34 LayoutRect result(rect); |
35 if (object.isLayoutView()) | 35 if (object.isLayoutView()) |
36 toLayoutView(object).mapToVisualRectInAncestorSpace( | 36 toLayoutView(object).mapToVisualRectInAncestorSpace( |
37 &ancestor, result, InputIsInFrameCoordinates, DefaultVisualRectFlags); | 37 &ancestor, result, InputIsInFrameCoordinates, DefaultVisualRectFlags); |
38 else | 38 else |
39 object.mapToVisualRectInAncestorSpace(&ancestor, result); | 39 object.mapToVisualRectInAncestorSpace(&ancestor, result); |
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::mapLocalRectToBacking() when removing |
45 // PaintInvalidationState. | 45 // PaintInvalidationState. |
46 static LayoutRect mapLocalRectToPaintInvalidationBacking( | 46 static PaintInvalidationRectInBacking 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 // TODO(wkorman): The flip below is required because visual rects are | 51 // TODO(wkorman): The flip below is required because visual rects are |
52 // currently in "physical coordinates with flipped block-flow direction" | 52 // currently in "physical coordinates with flipped block-flow direction" |
53 // (see LayoutBoxModelObject.h) but we need them to be in physical | 53 // (see LayoutBoxModelObject.h) but we need them to be in physical |
54 // coordinates. | 54 // coordinates. |
55 FloatRect rect = localRect; | 55 FloatRect rect = localRect; |
56 // Writing-mode flipping doesn't apply to non-root SVG. | 56 // Writing-mode flipping doesn't apply to non-root SVG. |
57 if (!object.isSVG() || object.isSVGRoot()) { | 57 if (!object.isSVG() || object.isSVGRoot()) { |
58 if (object.isBox()) { | 58 if (object.isBox()) { |
59 toLayoutBox(object).flipForWritingMode(rect); | 59 toLayoutBox(object).flipForWritingMode(rect); |
60 } else if (!(context.forcedSubtreeInvalidationFlags & | 60 } else if (!(context.forcedSubtreeInvalidationFlags & |
61 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { | 61 PaintInvalidatorContext::ForcedSubtreeSlowPathRect)) { |
62 // For SPv2 and the GeometryMapper path, we also need to convert the rect | 62 // For SPv2 and the GeometryMapper path, we also need to convert the rect |
63 // for non-boxes into physical coordinates before applying paint offset. | 63 // for non-boxes into physical coordinates before applying paint offset. |
64 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires | 64 // (Otherwise we'll call mapToVisualrectInAncestorSpace() which requires |
65 // physical coordinates for boxes, but "physical coordinates with flipped | 65 // physical coordinates for boxes, but "physical coordinates with flipped |
66 // block-flow direction" for non-boxes for which we don't need to flip.) | 66 // block-flow direction" for non-boxes for which we don't need to flip.) |
67 // TODO(wangxianzhu): Avoid containingBlock(). | 67 // TODO(wangxianzhu): Avoid containingBlock(). |
68 object.containingBlock()->flipForWritingMode(rect); | 68 object.containingBlock()->flipForWritingMode(rect); |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
| 72 PaintInvalidationRectInBacking result; |
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)); |
75 return LayoutRect(rect); | 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 result.rect = LayoutRect(enclosingIntRect(rect)); |
| 80 if (FloatRect(result.rect) != rect) |
| 81 result.coversExtraPixels = true; |
| 82 return result; |
76 } | 83 } |
77 | 84 |
78 LayoutRect result; | |
79 if (context.forcedSubtreeInvalidationFlags & | 85 if (context.forcedSubtreeInvalidationFlags & |
80 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { | 86 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { |
81 result = slowMapToVisualRectInAncestorSpace( | 87 result.rect = slowMapToVisualRectInAncestorSpace( |
82 object, *context.paintInvalidationContainer, rect); | 88 object, *context.paintInvalidationContainer, rect); |
83 } else if (object == context.paintInvalidationContainer) { | 89 } else if (object == context.paintInvalidationContainer) { |
84 result = LayoutRect(rect); | 90 result.rect = LayoutRect(rect); |
85 } else { | 91 } else { |
86 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 92 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
| 93 if ((!object.isSVG() || object.isSVGRoot()) && !rect.isEmpty()) { |
| 94 // Use enclosingIntRect to ensure the final visual rect will cover the |
| 95 // rect in source coordinates no matter if the painting will use pixel |
| 96 // snapping. |
| 97 IntRect intRect = enclosingIntRect(rect); |
| 98 if (FloatRect(intRect) != rect) { |
| 99 result.coversExtraPixels = true; |
| 100 rect = intRect; |
| 101 } |
| 102 } |
87 | 103 |
88 PropertyTreeState currentTreeState( | 104 PropertyTreeState currentTreeState( |
89 context.treeBuilderContext.current.transform, | 105 context.treeBuilderContext.current.transform, |
90 context.treeBuilderContext.current.clip, | 106 context.treeBuilderContext.current.clip, |
91 context.treeBuilderContext.currentEffect, | 107 context.treeBuilderContext.currentEffect, |
92 context.treeBuilderContext.current.scroll); | 108 context.treeBuilderContext.current.scroll); |
93 const auto* containerPaintProperties = | 109 const auto* containerPaintProperties = |
94 context.paintInvalidationContainer->paintProperties(); | 110 context.paintInvalidationContainer->paintProperties(); |
95 auto containerContentsProperties = | 111 auto containerContentsProperties = |
96 containerPaintProperties->contentsProperties(); | 112 containerPaintProperties->contentsProperties(); |
97 | 113 |
| 114 // TODO(wangxianzhu): Set coversExtraPixels if there are any non-translate |
| 115 // transforms. Currently this case is handled in BoxPaintInvalidator by |
| 116 // checking transforms. |
98 bool success = false; | 117 bool success = false; |
99 result = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( | 118 result.rect = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( |
100 rect, currentTreeState, containerContentsProperties.propertyTreeState, | 119 rect, currentTreeState, containerContentsProperties.propertyTreeState, |
101 success)); | 120 success)); |
102 DCHECK(success); | 121 DCHECK(success); |
103 | 122 |
104 // Convert the result to the container's contents space. | 123 // Convert the result to the container's contents space. |
105 result.moveBy(-containerContentsProperties.paintOffset); | 124 result.rect.moveBy(-containerContentsProperties.paintOffset); |
106 } | 125 } |
107 | 126 |
108 if (context.paintInvalidationContainer->layer()->groupedMapping()) | 127 if (context.paintInvalidationContainer->layer()->groupedMapping()) { |
109 PaintLayer::mapRectInPaintInvalidationContainerToBacking( | 128 PaintLayer::mapRectInPaintInvalidationContainerToBacking( |
110 *context.paintInvalidationContainer, result); | 129 *context.paintInvalidationContainer, result.rect); |
| 130 } |
111 return result; | 131 return result; |
112 } | 132 } |
113 | 133 |
114 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( | 134 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( |
115 const LayoutObject& object, | 135 const LayoutObject& object, |
116 LayoutRect& rect) const { | 136 LayoutRect& rect) const { |
117 GeometryMapper geometryMapper; | 137 GeometryMapper geometryMapper; |
118 rect = blink::mapLocalRectToPaintInvalidationBacking(geometryMapper, object, | 138 rect = blink::mapLocalRectToPaintInvalidationBacking(geometryMapper, object, |
119 FloatRect(rect), *this); | 139 FloatRect(rect), *this) |
| 140 .rect; |
120 } | 141 } |
121 | 142 |
122 LayoutRect PaintInvalidator::mapLocalRectToPaintInvalidationBacking( | 143 PaintInvalidationRectInBacking |
| 144 PaintInvalidator::mapLocalRectToPaintInvalidationBacking( |
123 const LayoutObject& object, | 145 const LayoutObject& object, |
124 const FloatRect& localRect, | 146 const FloatRect& localRect, |
125 const PaintInvalidatorContext& context) { | 147 const PaintInvalidatorContext& context) { |
126 return blink::mapLocalRectToPaintInvalidationBacking(m_geometryMapper, object, | 148 return blink::mapLocalRectToPaintInvalidationBacking(m_geometryMapper, object, |
127 localRect, context); | 149 localRect, context); |
128 } | 150 } |
129 | 151 |
130 LayoutRect PaintInvalidator::computePaintInvalidationRectInBacking( | 152 PaintInvalidationRectInBacking |
| 153 PaintInvalidator::computePaintInvalidationRectInBacking( |
131 const LayoutObject& object, | 154 const LayoutObject& object, |
132 const PaintInvalidatorContext& context) { | 155 const PaintInvalidatorContext& context) { |
133 FloatRect localRect; | 156 FloatRect localRect; |
134 if (object.isSVG() && !object.isSVGRoot()) | 157 if (object.isSVG() && !object.isSVGRoot()) |
135 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); | 158 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); |
136 else | 159 else |
137 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); | 160 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); |
138 | 161 |
139 return mapLocalRectToPaintInvalidationBacking(object, localRect, context); | 162 return mapLocalRectToPaintInvalidationBacking(object, localRect, context); |
140 } | 163 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 context.forcedSubtreeInvalidationFlags |= | 326 context.forcedSubtreeInvalidationFlags |= |
304 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; | 327 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; |
305 | 328 |
306 // TODO(crbug.com/637313): This is temporary before we support filters in | 329 // TODO(crbug.com/637313): This is temporary before we support filters in |
307 // paint property tree. | 330 // paint property tree. |
308 // TODO(crbug.com/648274): This is a workaround for multi-column contents. | 331 // TODO(crbug.com/648274): This is a workaround for multi-column contents. |
309 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) | 332 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) |
310 context.forcedSubtreeInvalidationFlags |= | 333 context.forcedSubtreeInvalidationFlags |= |
311 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; | 334 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; |
312 | 335 |
313 context.oldBounds = object.previousPaintInvalidationRect(); | 336 context.oldBounds.rect = object.previousPaintInvalidationRect(); |
| 337 context.oldBounds.coversExtraPixels = |
| 338 object.previousPaintInvalidationRectCoversExtraPixels(); |
314 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); | 339 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); |
315 context.newBounds = computePaintInvalidationRectInBacking(object, context); | 340 context.newBounds = computePaintInvalidationRectInBacking(object, context); |
316 context.newLocation = | 341 context.newLocation = |
317 computeLocationFromPaintInvalidationBacking(object, context); | 342 computeLocationFromPaintInvalidationBacking(object, context); |
318 | 343 |
319 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( | 344 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( |
320 *context.paintInvalidationContainer); | 345 *context.paintInvalidationContainer); |
321 context.newLocation.move(adjustment); | 346 context.newLocation.move(adjustment); |
322 context.newBounds.move(adjustment); | 347 context.newBounds.rect.move(adjustment); |
323 | 348 |
324 object.getMutableForPainting().setPreviousPaintInvalidationRect( | 349 object.getMutableForPainting().setPreviousPaintInvalidationRect( |
325 context.newBounds); | 350 context.newBounds.rect, context.newBounds.coversExtraPixels); |
326 object.getMutableForPainting() | 351 object.getMutableForPainting() |
327 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); | 352 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); |
328 } | 353 } |
329 | 354 |
330 void PaintInvalidator::invalidatePaintIfNeeded( | 355 void PaintInvalidator::invalidatePaintIfNeeded( |
331 FrameView& frameView, | 356 FrameView& frameView, |
332 PaintInvalidatorContext& context) { | 357 PaintInvalidatorContext& context) { |
333 LayoutView* layoutView = frameView.layoutView(); | 358 LayoutView* layoutView = frameView.layoutView(); |
334 CHECK(layoutView); | 359 CHECK(layoutView); |
335 | 360 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 // TODO(crbug.com/533277): This is a workaround for the bug. Remove when we | 447 // TODO(crbug.com/533277): This is a workaround for the bug. Remove when we |
423 // detect paint offset change. | 448 // detect paint offset change. |
424 if (reason != PaintInvalidationNone && | 449 if (reason != PaintInvalidationNone && |
425 hasPercentageTransform(object.styleRef())) | 450 hasPercentageTransform(object.styleRef())) |
426 context.forcedSubtreeInvalidationFlags |= | 451 context.forcedSubtreeInvalidationFlags |= |
427 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; | 452 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; |
428 | 453 |
429 // TODO(crbug.com/490725): This is a workaround for the bug, to force | 454 // TODO(crbug.com/490725): This is a workaround for the bug, to force |
430 // descendant to update paint invalidation rects on clipping change. | 455 // descendant to update paint invalidation rects on clipping change. |
431 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && | 456 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && |
432 context.oldBounds != context.newBounds | 457 context.oldBounds.rect != context.newBounds.rect |
433 // Note that isLayoutView() below becomes unnecessary after the launch of | 458 // Note that isLayoutView() below becomes unnecessary after the launch of |
434 // root layer scrolling. | 459 // root layer scrolling. |
435 && (object.hasOverflowClip() || object.isLayoutView()) && | 460 && (object.hasOverflowClip() || object.isLayoutView()) && |
436 !toLayoutBox(object).usesCompositedScrolling()) | 461 !toLayoutBox(object).usesCompositedScrolling()) |
437 context.forcedSubtreeInvalidationFlags |= | 462 context.forcedSubtreeInvalidationFlags |= |
438 PaintInvalidatorContext::ForcedSubtreeInvalidationRectUpdate; | 463 PaintInvalidatorContext::ForcedSubtreeInvalidationRectUpdate; |
439 | 464 |
440 object.getMutableForPainting().clearPaintInvalidationFlags(); | 465 object.getMutableForPainting().clearPaintInvalidationFlags(); |
441 } | 466 } |
442 | 467 |
443 void PaintInvalidator::processPendingDelayedPaintInvalidations() { | 468 void PaintInvalidator::processPendingDelayedPaintInvalidations() { |
444 for (auto target : m_pendingDelayedPaintInvalidations) | 469 for (auto target : m_pendingDelayedPaintInvalidations) |
445 target->getMutableForPainting().setShouldDoFullPaintInvalidation( | 470 target->getMutableForPainting().setShouldDoFullPaintInvalidation( |
446 PaintInvalidationDelayedFull); | 471 PaintInvalidationDelayedFull); |
447 } | 472 } |
448 | 473 |
449 } // namespace blink | 474 } // namespace blink |
OLD | NEW |