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 25 matching lines...) Expand all Loading... |
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::mapLocalRectToBacking() when removing | 44 // PaintInvalidator::mapLocalRectToBacking() when removing |
45 // PaintInvalidationState. | 45 // PaintInvalidationState. |
46 static PaintInvalidationRectInBacking 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 // 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; | |
73 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { | 72 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) { |
74 // In SPv2, visual rects are in the space of their local transform node. | 73 // In SPv2, visual rects are in the space of their local transform node. |
75 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 74 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
76 // Use enclosingIntRect to ensure the final visual rect will cover the | 75 // Use enclosingIntRect to ensure the final visual rect will cover the |
77 // rect in source coordinates no matter if the painting will use pixel | 76 // rect in source coordinates no matter if the painting will use pixel |
78 // snapping. | 77 // snapping. |
79 result.rect = LayoutRect(enclosingIntRect(rect)); | 78 return LayoutRect(enclosingIntRect(rect)); |
80 if (FloatRect(result.rect) != rect) | |
81 result.coversExtraPixels = true; | |
82 return result; | |
83 } | 79 } |
84 | 80 |
| 81 LayoutRect result; |
85 if (context.forcedSubtreeInvalidationFlags & | 82 if (context.forcedSubtreeInvalidationFlags & |
86 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { | 83 PaintInvalidatorContext::ForcedSubtreeSlowPathRect) { |
87 result.rect = slowMapToVisualRectInAncestorSpace( | 84 result = slowMapToVisualRectInAncestorSpace( |
88 object, *context.paintInvalidationContainer, rect); | 85 object, *context.paintInvalidationContainer, rect); |
89 } else if (object == context.paintInvalidationContainer) { | 86 } else if (object == context.paintInvalidationContainer) { |
90 result.rect = LayoutRect(rect); | 87 result = LayoutRect(rect); |
91 } else { | 88 } else { |
92 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); | 89 rect.moveBy(FloatPoint(context.treeBuilderContext.current.paintOffset)); |
93 if ((!object.isSVG() || object.isSVGRoot()) && !rect.isEmpty()) { | 90 if ((!object.isSVG() || object.isSVGRoot()) && !rect.isEmpty()) { |
94 // Use enclosingIntRect to ensure the final visual rect will cover the | 91 // Use enclosingIntRect to ensure the final visual rect will cover the |
95 // rect in source coordinates no matter if the painting will use pixel | 92 // rect in source coordinates no matter if the painting will use pixel |
96 // snapping. | 93 // snapping. |
97 IntRect intRect = enclosingIntRect(rect); | 94 rect = enclosingIntRect(rect); |
98 if (FloatRect(intRect) != rect) { | |
99 result.coversExtraPixels = true; | |
100 rect = intRect; | |
101 } | |
102 } | 95 } |
103 | 96 |
104 PropertyTreeState currentTreeState( | 97 PropertyTreeState currentTreeState( |
105 context.treeBuilderContext.current.transform, | 98 context.treeBuilderContext.current.transform, |
106 context.treeBuilderContext.current.clip, | 99 context.treeBuilderContext.current.clip, |
107 context.treeBuilderContext.currentEffect, | 100 context.treeBuilderContext.currentEffect, |
108 context.treeBuilderContext.current.scroll); | 101 context.treeBuilderContext.current.scroll); |
109 const auto* containerPaintProperties = | 102 const auto* containerPaintProperties = |
110 context.paintInvalidationContainer->paintProperties(); | 103 context.paintInvalidationContainer->paintProperties(); |
111 auto containerContentsProperties = | 104 auto containerContentsProperties = |
112 containerPaintProperties->contentsProperties(); | 105 containerPaintProperties->contentsProperties(); |
113 | 106 |
114 // TODO(wangxianzhu): Set coversExtraPixels if there are any non-translate | |
115 // transforms. Currently this case is handled in BoxPaintInvalidator by | |
116 // checking transforms. | |
117 bool success = false; | 107 bool success = false; |
118 result.rect = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( | 108 result = LayoutRect(geometryMapper.mapToVisualRectInDestinationSpace( |
119 rect, currentTreeState, containerContentsProperties.propertyTreeState, | 109 rect, currentTreeState, containerContentsProperties.propertyTreeState, |
120 success)); | 110 success)); |
121 DCHECK(success); | 111 DCHECK(success); |
122 | 112 |
123 // Convert the result to the container's contents space. | 113 // Convert the result to the container's contents space. |
124 result.rect.moveBy(-containerContentsProperties.paintOffset); | 114 result.moveBy(-containerContentsProperties.paintOffset); |
125 } | 115 } |
126 | 116 |
127 if (object.adjustVisualRectForRasterEffects(result.rect)) | 117 object.adjustVisualRectForRasterEffects(result); |
128 result.coversExtraPixels = true; | |
129 | 118 |
130 if (context.paintInvalidationContainer->layer()->groupedMapping()) { | 119 if (context.paintInvalidationContainer->layer()->groupedMapping()) { |
131 PaintLayer::mapRectInPaintInvalidationContainerToBacking( | 120 PaintLayer::mapRectInPaintInvalidationContainerToBacking( |
132 *context.paintInvalidationContainer, result.rect); | 121 *context.paintInvalidationContainer, result); |
133 } | 122 } |
134 return result; | 123 return result; |
135 } | 124 } |
136 | 125 |
137 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( | 126 void PaintInvalidatorContext::mapLocalRectToPaintInvalidationBacking( |
138 const LayoutObject& object, | 127 const LayoutObject& object, |
139 LayoutRect& rect) const { | 128 LayoutRect& rect) const { |
140 GeometryMapper geometryMapper; | 129 GeometryMapper geometryMapper; |
141 rect = blink::mapLocalRectToPaintInvalidationBacking(geometryMapper, object, | 130 rect = blink::mapLocalRectToPaintInvalidationBacking(geometryMapper, object, |
142 FloatRect(rect), *this) | 131 FloatRect(rect), *this); |
143 .rect; | |
144 } | 132 } |
145 | 133 |
146 PaintInvalidationRectInBacking | 134 LayoutRect PaintInvalidator::mapLocalRectToPaintInvalidationBacking( |
147 PaintInvalidator::mapLocalRectToPaintInvalidationBacking( | |
148 const LayoutObject& object, | 135 const LayoutObject& object, |
149 const FloatRect& localRect, | 136 const FloatRect& localRect, |
150 const PaintInvalidatorContext& context) { | 137 const PaintInvalidatorContext& context) { |
151 return blink::mapLocalRectToPaintInvalidationBacking(m_geometryMapper, object, | 138 return blink::mapLocalRectToPaintInvalidationBacking(m_geometryMapper, object, |
152 localRect, context); | 139 localRect, context); |
153 } | 140 } |
154 | 141 |
155 PaintInvalidationRectInBacking | 142 LayoutRect PaintInvalidator::computePaintInvalidationRectInBacking( |
156 PaintInvalidator::computePaintInvalidationRectInBacking( | |
157 const LayoutObject& object, | 143 const LayoutObject& object, |
158 const PaintInvalidatorContext& context) { | 144 const PaintInvalidatorContext& context) { |
159 FloatRect localRect; | 145 FloatRect localRect; |
160 if (object.isSVG() && !object.isSVGRoot()) | 146 if (object.isSVG() && !object.isSVGRoot()) |
161 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); | 147 localRect = SVGLayoutSupport::localOverflowRectForPaintInvalidation(object); |
162 else | 148 else |
163 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); | 149 localRect = FloatRect(object.localOverflowRectForPaintInvalidation()); |
164 | 150 |
165 return mapLocalRectToPaintInvalidationBacking(object, localRect, context); | 151 return mapLocalRectToPaintInvalidationBacking(object, localRect, context); |
166 } | 152 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 context.forcedSubtreeInvalidationFlags |= | 315 context.forcedSubtreeInvalidationFlags |= |
330 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; | 316 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; |
331 | 317 |
332 // TODO(crbug.com/637313): This is temporary before we support filters in | 318 // TODO(crbug.com/637313): This is temporary before we support filters in |
333 // paint property tree. | 319 // paint property tree. |
334 // TODO(crbug.com/648274): This is a workaround for multi-column contents. | 320 // TODO(crbug.com/648274): This is a workaround for multi-column contents. |
335 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) | 321 if (object.hasFilterInducingProperty() || object.isLayoutFlowThread()) |
336 context.forcedSubtreeInvalidationFlags |= | 322 context.forcedSubtreeInvalidationFlags |= |
337 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; | 323 PaintInvalidatorContext::ForcedSubtreeSlowPathRect; |
338 | 324 |
339 context.oldBounds.rect = object.previousPaintInvalidationRect(); | 325 context.oldBounds = object.previousPaintInvalidationRect(); |
340 context.oldBounds.coversExtraPixels = | |
341 object.previousPaintInvalidationRectCoversExtraPixels(); | |
342 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); | 326 context.oldLocation = object.previousPositionFromPaintInvalidationBacking(); |
343 context.newBounds = computePaintInvalidationRectInBacking(object, context); | 327 context.newBounds = computePaintInvalidationRectInBacking(object, context); |
344 context.newLocation = | 328 context.newLocation = |
345 computeLocationFromPaintInvalidationBacking(object, context); | 329 computeLocationFromPaintInvalidationBacking(object, context); |
346 | 330 |
347 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( | 331 IntSize adjustment = object.scrollAdjustmentForPaintInvalidation( |
348 *context.paintInvalidationContainer); | 332 *context.paintInvalidationContainer); |
349 context.newLocation.move(adjustment); | 333 context.newLocation.move(adjustment); |
350 context.newBounds.rect.move(adjustment); | 334 context.newBounds.move(adjustment); |
351 | 335 |
352 object.getMutableForPainting().setPreviousPaintInvalidationRect( | 336 object.getMutableForPainting().setPreviousPaintInvalidationRect( |
353 context.newBounds.rect, context.newBounds.coversExtraPixels); | 337 context.newBounds); |
354 object.getMutableForPainting() | 338 object.getMutableForPainting() |
355 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); | 339 .setPreviousPositionFromPaintInvalidationBacking(context.newLocation); |
356 } | 340 } |
357 | 341 |
358 void PaintInvalidator::invalidatePaintIfNeeded( | 342 void PaintInvalidator::invalidatePaintIfNeeded( |
359 FrameView& frameView, | 343 FrameView& frameView, |
360 PaintInvalidatorContext& context) { | 344 PaintInvalidatorContext& context) { |
361 LayoutView* layoutView = frameView.layoutView(); | 345 LayoutView* layoutView = frameView.layoutView(); |
362 CHECK(layoutView); | 346 CHECK(layoutView); |
363 | 347 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // TODO(crbug.com/533277): This is a workaround for the bug. Remove when we | 434 // TODO(crbug.com/533277): This is a workaround for the bug. Remove when we |
451 // detect paint offset change. | 435 // detect paint offset change. |
452 if (reason != PaintInvalidationNone && | 436 if (reason != PaintInvalidationNone && |
453 hasPercentageTransform(object.styleRef())) | 437 hasPercentageTransform(object.styleRef())) |
454 context.forcedSubtreeInvalidationFlags |= | 438 context.forcedSubtreeInvalidationFlags |= |
455 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; | 439 PaintInvalidatorContext::ForcedSubtreeInvalidationChecking; |
456 | 440 |
457 // TODO(crbug.com/490725): This is a workaround for the bug, to force | 441 // TODO(crbug.com/490725): This is a workaround for the bug, to force |
458 // descendant to update paint invalidation rects on clipping change. | 442 // descendant to update paint invalidation rects on clipping change. |
459 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && | 443 if (!RuntimeEnabledFeatures::slimmingPaintV2Enabled() && |
460 context.oldBounds.rect != context.newBounds.rect | 444 context.oldBounds != context.newBounds |
461 // Note that isLayoutView() below becomes unnecessary after the launch of | 445 // Note that isLayoutView() below becomes unnecessary after the launch of |
462 // root layer scrolling. | 446 // root layer scrolling. |
463 && (object.hasOverflowClip() || object.isLayoutView()) && | 447 && (object.hasOverflowClip() || object.isLayoutView()) && |
464 !toLayoutBox(object).usesCompositedScrolling()) | 448 !toLayoutBox(object).usesCompositedScrolling()) |
465 context.forcedSubtreeInvalidationFlags |= | 449 context.forcedSubtreeInvalidationFlags |= |
466 PaintInvalidatorContext::ForcedSubtreeInvalidationRectUpdate; | 450 PaintInvalidatorContext::ForcedSubtreeInvalidationRectUpdate; |
467 | 451 |
468 object.getMutableForPainting().clearPaintInvalidationFlags(); | 452 object.getMutableForPainting().clearPaintInvalidationFlags(); |
469 } | 453 } |
470 | 454 |
471 void PaintInvalidator::processPendingDelayedPaintInvalidations() { | 455 void PaintInvalidator::processPendingDelayedPaintInvalidations() { |
472 for (auto target : m_pendingDelayedPaintInvalidations) | 456 for (auto target : m_pendingDelayedPaintInvalidations) |
473 target->getMutableForPainting().setShouldDoFullPaintInvalidation( | 457 target->getMutableForPainting().setShouldDoFullPaintInvalidation( |
474 PaintInvalidationDelayedFull); | 458 PaintInvalidationDelayedFull); |
475 } | 459 } |
476 | 460 |
477 } // namespace blink | 461 } // namespace blink |
OLD | NEW |