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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 return LayoutRect(); | 49 return LayoutRect(); |
50 } | 50 } |
51 | 51 |
52 bool BoxPaintInvalidator::IncrementallyInvalidatePaint( | 52 bool BoxPaintInvalidator::IncrementallyInvalidatePaint( |
53 PaintInvalidationReason reason, | 53 PaintInvalidationReason reason, |
54 const LayoutRect& old_rect, | 54 const LayoutRect& old_rect, |
55 const LayoutRect& new_rect) { | 55 const LayoutRect& new_rect) { |
56 DCHECK(old_rect.Location() == new_rect.Location()); | 56 DCHECK(old_rect.Location() == new_rect.Location()); |
57 LayoutRect right_delta = ComputeRightDelta( | 57 LayoutRect right_delta = ComputeRightDelta( |
58 new_rect.Location(), old_rect.Size(), new_rect.Size(), | 58 new_rect.Location(), old_rect.Size(), new_rect.Size(), |
59 reason == kPaintInvalidationIncremental ? box_.BorderRight() | 59 reason == PaintInvalidationReason::kIncremental ? box_.BorderRight() |
60 : LayoutUnit()); | 60 : LayoutUnit()); |
61 LayoutRect bottom_delta = ComputeBottomDelta( | 61 LayoutRect bottom_delta = ComputeBottomDelta( |
62 new_rect.Location(), old_rect.Size(), new_rect.Size(), | 62 new_rect.Location(), old_rect.Size(), new_rect.Size(), |
63 reason == kPaintInvalidationIncremental ? box_.BorderBottom() | 63 reason == PaintInvalidationReason::kIncremental ? box_.BorderBottom() |
64 : LayoutUnit()); | 64 : LayoutUnit()); |
65 | 65 |
66 if (right_delta.IsEmpty() && bottom_delta.IsEmpty()) | 66 if (right_delta.IsEmpty() && bottom_delta.IsEmpty()) |
67 return false; | 67 return false; |
68 | 68 |
69 ObjectPaintInvalidatorWithContext object_paint_invalidator(box_, context_); | 69 ObjectPaintInvalidatorWithContext object_paint_invalidator(box_, context_); |
70 object_paint_invalidator.InvalidatePaintRectangleWithContext(right_delta, | 70 object_paint_invalidator.InvalidatePaintRectangleWithContext(right_delta, |
71 reason); | 71 reason); |
72 object_paint_invalidator.InvalidatePaintRectangleWithContext(bottom_delta, | 72 object_paint_invalidator.InvalidatePaintRectangleWithContext(bottom_delta, |
73 reason); | 73 reason); |
74 return true; | 74 return true; |
75 } | 75 } |
76 | 76 |
77 PaintInvalidationReason BoxPaintInvalidator::ComputePaintInvalidationReason() { | 77 PaintInvalidationReason BoxPaintInvalidator::ComputePaintInvalidationReason() { |
78 PaintInvalidationReason reason = | 78 PaintInvalidationReason reason = |
79 ObjectPaintInvalidatorWithContext(box_, context_) | 79 ObjectPaintInvalidatorWithContext(box_, context_) |
80 .ComputePaintInvalidationReason(); | 80 .ComputePaintInvalidationReason(); |
81 | 81 |
82 if (reason != kPaintInvalidationIncremental) | 82 if (reason != PaintInvalidationReason::kIncremental) |
83 return reason; | 83 return reason; |
84 | 84 |
85 if (box_.IsLayoutView()) { | 85 if (box_.IsLayoutView()) { |
86 const LayoutView& layout_view = ToLayoutView(box_); | 86 const LayoutView& layout_view = ToLayoutView(box_); |
87 // In normal compositing mode, root background doesn't need to be | 87 // In normal compositing mode, root background doesn't need to be |
88 // invalidated for box changes, because the background always covers the | 88 // invalidated for box changes, because the background always covers the |
89 // whole document rect and clipping is done by | 89 // whole document rect and clipping is done by |
90 // compositor()->m_containerLayer. Also the scrollbars are always | 90 // compositor()->m_containerLayer. Also the scrollbars are always |
91 // composited. There are no other box decoration on the LayoutView thus we | 91 // composited. There are no other box decoration on the LayoutView thus we |
92 // can safely exit here. | 92 // can safely exit here. |
93 if (layout_view.UsesCompositing() && | 93 if (layout_view.UsesCompositing() && |
94 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) | 94 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) |
95 return reason; | 95 return reason; |
96 } | 96 } |
97 | 97 |
98 const ComputedStyle& style = box_.StyleRef(); | 98 const ComputedStyle& style = box_.StyleRef(); |
99 | 99 |
100 if ((style.BackgroundLayers().ThisOrNextLayersUseContentBox() || | 100 if ((style.BackgroundLayers().ThisOrNextLayersUseContentBox() || |
101 style.MaskLayers().ThisOrNextLayersUseContentBox()) && | 101 style.MaskLayers().ThisOrNextLayersUseContentBox()) && |
102 box_.PreviousContentBoxSize() != box_.ContentBoxRect().Size()) | 102 box_.PreviousContentBoxSize() != box_.ContentBoxRect().Size()) |
103 return kPaintInvalidationContentBoxChange; | 103 return PaintInvalidationReason::kGeometry; |
104 | 104 |
105 LayoutSize old_border_box_size = box_.PreviousSize(); | 105 LayoutSize old_border_box_size = box_.PreviousSize(); |
106 LayoutSize new_border_box_size = box_.Size(); | 106 LayoutSize new_border_box_size = box_.Size(); |
107 bool border_box_changed = old_border_box_size != new_border_box_size; | 107 bool border_box_changed = old_border_box_size != new_border_box_size; |
108 if (!border_box_changed && context_.old_visual_rect == box_.VisualRect()) | 108 if (!border_box_changed && context_.old_visual_rect == box_.VisualRect()) |
109 return kPaintInvalidationNone; | 109 return PaintInvalidationReason::kNone; |
110 | 110 |
111 // If either border box changed or bounds changed, and old or new border box | 111 // If either border box changed or bounds changed, and old or new border box |
112 // doesn't equal old or new bounds, incremental invalidation is not | 112 // doesn't equal old or new bounds, incremental invalidation is not |
113 // applicable. This captures the following cases: | 113 // applicable. This captures the following cases: |
114 // - pixel snapping of paint invalidation bounds, | 114 // - pixel snapping of paint invalidation bounds, |
115 // - scale, rotate, skew etc. transforms, | 115 // - scale, rotate, skew etc. transforms, |
116 // - visual overflows. | 116 // - visual overflows. |
117 if (context_.old_visual_rect != | 117 if (context_.old_visual_rect != |
118 LayoutRect(context_.old_location, old_border_box_size) || | 118 LayoutRect(context_.old_location, old_border_box_size) || |
119 box_.VisualRect() != | 119 box_.VisualRect() != |
120 LayoutRect(context_.new_location, new_border_box_size)) { | 120 LayoutRect(context_.new_location, new_border_box_size)) { |
121 return border_box_changed ? kPaintInvalidationBorderBoxChange | 121 return PaintInvalidationReason::kGeometry; |
122 : kPaintInvalidationBoundsChange; | |
123 } | 122 } |
124 | 123 |
125 DCHECK(border_box_changed); | 124 DCHECK(border_box_changed); |
126 | 125 |
127 if (style.HasVisualOverflowingEffect() || style.HasAppearance() || | 126 if (style.HasVisualOverflowingEffect() || style.HasAppearance() || |
128 style.HasFilterInducingProperty() || style.HasMask()) | 127 style.HasFilterInducingProperty() || style.HasMask()) |
129 return kPaintInvalidationBorderBoxChange; | 128 return PaintInvalidationReason::kGeometry; |
130 | 129 |
131 if (style.HasBorderRadius()) | 130 if (style.HasBorderRadius()) |
132 return kPaintInvalidationBorderBoxChange; | 131 return PaintInvalidationReason::kGeometry; |
133 | 132 |
134 if (old_border_box_size.Width() != new_border_box_size.Width() && | 133 if (old_border_box_size.Width() != new_border_box_size.Width() && |
135 box_.MustInvalidateBackgroundOrBorderPaintOnWidthChange()) | 134 box_.MustInvalidateBackgroundOrBorderPaintOnWidthChange()) |
136 return kPaintInvalidationBorderBoxChange; | 135 return PaintInvalidationReason::kGeometry; |
137 if (old_border_box_size.Height() != new_border_box_size.Height() && | 136 if (old_border_box_size.Height() != new_border_box_size.Height() && |
138 box_.MustInvalidateBackgroundOrBorderPaintOnHeightChange()) | 137 box_.MustInvalidateBackgroundOrBorderPaintOnHeightChange()) |
139 return kPaintInvalidationBorderBoxChange; | 138 return PaintInvalidationReason::kGeometry; |
140 | 139 |
141 // Needs to repaint frame boundaries. | 140 // Needs to repaint frame boundaries. |
142 if (box_.IsFrameSet()) | 141 if (box_.IsFrameSet()) |
143 return kPaintInvalidationBorderBoxChange; | 142 return PaintInvalidationReason::kGeometry; |
144 | 143 |
145 // Needs to repaint column rules. | 144 // Needs to repaint column rules. |
146 if (box_.IsLayoutMultiColumnSet()) | 145 if (box_.IsLayoutMultiColumnSet()) |
147 return kPaintInvalidationBorderBoxChange; | 146 return PaintInvalidationReason::kGeometry; |
148 | 147 |
149 return kPaintInvalidationIncremental; | 148 return PaintInvalidationReason::kIncremental; |
150 } | 149 } |
151 | 150 |
152 bool BoxPaintInvalidator::BackgroundGeometryDependsOnLayoutOverflowRect() { | 151 bool BoxPaintInvalidator::BackgroundGeometryDependsOnLayoutOverflowRect() { |
153 return !box_.IsDocumentElement() && !box_.BackgroundStolenForBeingBody() && | 152 return !box_.IsDocumentElement() && !box_.BackgroundStolenForBeingBody() && |
154 box_.StyleRef() | 153 box_.StyleRef() |
155 .BackgroundLayers() | 154 .BackgroundLayers() |
156 .ThisOrNextLayersHaveLocalAttachment(); | 155 .ThisOrNextLayersHaveLocalAttachment(); |
157 } | 156 } |
158 | 157 |
159 // Background positioning in layout overflow rect doesn't mean it will | 158 // Background positioning in layout overflow rect doesn't mean it will |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // Check change of layout overflow for full or incremental invalidation. | 211 // Check change of layout overflow for full or incremental invalidation. |
213 if (new_layout_overflow == old_layout_overflow) | 212 if (new_layout_overflow == old_layout_overflow) |
214 return; | 213 return; |
215 bool should_fully_invalidate = | 214 bool should_fully_invalidate = |
216 ShouldFullyInvalidateBackgroundOnLayoutOverflowChange( | 215 ShouldFullyInvalidateBackgroundOnLayoutOverflowChange( |
217 old_layout_overflow, new_layout_overflow); | 216 old_layout_overflow, new_layout_overflow); |
218 if (!paints_onto_scrolling_contents_layer) { | 217 if (!paints_onto_scrolling_contents_layer) { |
219 if (should_fully_invalidate) { | 218 if (should_fully_invalidate) { |
220 box_.GetMutableForPainting() | 219 box_.GetMutableForPainting() |
221 .SetShouldDoFullPaintInvalidationWithoutGeometryChange( | 220 .SetShouldDoFullPaintInvalidationWithoutGeometryChange( |
222 kPaintInvalidationLayoutOverflowBoxChange); | 221 PaintInvalidationReason::kBackground); |
223 } | 222 } |
224 return; | 223 return; |
225 } | 224 } |
226 should_fully_invalidate_on_scrolling_contents_layer = | 225 should_fully_invalidate_on_scrolling_contents_layer = |
227 should_fully_invalidate; | 226 should_fully_invalidate; |
228 } | 227 } |
229 | 228 |
230 if (should_fully_invalidate_on_scrolling_contents_layer) { | 229 if (should_fully_invalidate_on_scrolling_contents_layer) { |
231 ObjectPaintInvalidatorWithContext(box_, context_) | 230 ObjectPaintInvalidatorWithContext(box_, context_) |
232 .FullyInvalidatePaint( | 231 .FullyInvalidatePaint( |
233 kPaintInvalidationBackgroundOnScrollingContentsLayer, | 232 PaintInvalidationReason::kBackgroundOnScrollingContentsLayer, |
234 old_layout_overflow, new_layout_overflow); | 233 old_layout_overflow, new_layout_overflow); |
235 } else { | 234 } else { |
236 IncrementallyInvalidatePaint( | 235 IncrementallyInvalidatePaint( |
237 kPaintInvalidationBackgroundOnScrollingContentsLayer, | 236 PaintInvalidationReason::kBackgroundOnScrollingContentsLayer, |
238 old_layout_overflow, new_layout_overflow); | 237 old_layout_overflow, new_layout_overflow); |
239 } | 238 } |
240 | 239 |
241 context_.painting_layer->SetNeedsRepaint(); | 240 context_.painting_layer->SetNeedsRepaint(); |
242 // Currently we use CompositedLayerMapping as the DisplayItemClient to paint | 241 // Currently we use CompositedLayerMapping as the DisplayItemClient to paint |
243 // background on the scrolling contents layer. | 242 // background on the scrolling contents layer. |
244 ObjectPaintInvalidator(box_).InvalidateDisplayItemClient( | 243 ObjectPaintInvalidator(box_).InvalidateDisplayItemClient( |
245 *box_.Layer()->GetCompositedLayerMapping()->ScrollingContentsLayer(), | 244 *box_.Layer()->GetCompositedLayerMapping()->ScrollingContentsLayer(), |
246 kPaintInvalidationBackgroundOnScrollingContentsLayer); | 245 PaintInvalidationReason::kBackgroundOnScrollingContentsLayer); |
247 } | 246 } |
248 | 247 |
249 PaintInvalidationReason BoxPaintInvalidator::InvalidatePaint() { | 248 PaintInvalidationReason BoxPaintInvalidator::InvalidatePaint() { |
250 InvalidateScrollingContentsBackgroundIfNeeded(); | 249 InvalidateScrollingContentsBackgroundIfNeeded(); |
251 | 250 |
252 PaintInvalidationReason reason = ComputePaintInvalidationReason(); | 251 PaintInvalidationReason reason = ComputePaintInvalidationReason(); |
253 if (reason == kPaintInvalidationIncremental) { | 252 if (reason == PaintInvalidationReason::kIncremental) { |
254 bool invalidated; | 253 bool invalidated; |
255 if (box_.IsLayoutView() && | 254 if (box_.IsLayoutView() && |
256 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { | 255 !RuntimeEnabledFeatures::rootLayerScrollingEnabled()) { |
257 invalidated = IncrementallyInvalidatePaint( | 256 invalidated = IncrementallyInvalidatePaint( |
258 reason, context_.old_visual_rect, box_.VisualRect()); | 257 reason, context_.old_visual_rect, box_.VisualRect()); |
259 } else { | 258 } else { |
260 invalidated = IncrementallyInvalidatePaint( | 259 invalidated = IncrementallyInvalidatePaint( |
261 reason, LayoutRect(context_.old_location, box_.PreviousSize()), | 260 reason, LayoutRect(context_.old_location, box_.PreviousSize()), |
262 LayoutRect(context_.new_location, box_.Size())); | 261 LayoutRect(context_.new_location, box_.Size())); |
263 } | 262 } |
264 if (invalidated) { | 263 if (invalidated) { |
265 context_.painting_layer->SetNeedsRepaint(); | 264 context_.painting_layer->SetNeedsRepaint(); |
266 box_.InvalidateDisplayItemClients(reason); | 265 box_.InvalidateDisplayItemClients(reason); |
267 } else { | 266 } else { |
268 reason = kPaintInvalidationNone; | 267 reason = PaintInvalidationReason::kNone; |
269 } | 268 } |
270 | 269 |
271 // Though we have done incremental invalidation, we still need to call | 270 // Though we have done incremental invalidation, we still need to call |
272 // ObjectPaintInvalidator with PaintInvalidationNone to do any other | 271 // ObjectPaintInvalidator with PaintInvalidationNone to do any other |
273 // required operations. | 272 // required operations. |
274 reason = std::max( | 273 reason = std::max(reason, ObjectPaintInvalidatorWithContext(box_, context_) |
275 reason, ObjectPaintInvalidatorWithContext(box_, context_) | 274 .InvalidatePaintWithComputedReason( |
276 .InvalidatePaintWithComputedReason(kPaintInvalidationNone)); | 275 PaintInvalidationReason::kNone)); |
277 } else { | 276 } else { |
278 reason = ObjectPaintInvalidatorWithContext(box_, context_) | 277 reason = ObjectPaintInvalidatorWithContext(box_, context_) |
279 .InvalidatePaintWithComputedReason(reason); | 278 .InvalidatePaintWithComputedReason(reason); |
280 } | 279 } |
281 | 280 |
282 if (PaintLayerScrollableArea* area = box_.GetScrollableArea()) | 281 if (PaintLayerScrollableArea* area = box_.GetScrollableArea()) |
283 area->InvalidatePaintOfScrollControlsIfNeeded(context_); | 282 area->InvalidatePaintOfScrollControlsIfNeeded(context_); |
284 | 283 |
285 // This is for the next invalidatePaintIfNeeded so must be at the end. | 284 // This is for the next invalidatePaintIfNeeded so must be at the end. |
286 SavePreviousBoxGeometriesIfNeeded(); | 285 SavePreviousBoxGeometriesIfNeeded(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 if (NeedsToSavePreviousContentBoxSizeOrLayoutOverflowRect()) { | 319 if (NeedsToSavePreviousContentBoxSizeOrLayoutOverflowRect()) { |
321 box_.GetMutableForPainting() | 320 box_.GetMutableForPainting() |
322 .SavePreviousContentBoxSizeAndLayoutOverflowRect(); | 321 .SavePreviousContentBoxSizeAndLayoutOverflowRect(); |
323 } else { | 322 } else { |
324 box_.GetMutableForPainting() | 323 box_.GetMutableForPainting() |
325 .ClearPreviousContentBoxSizeAndLayoutOverflowRect(); | 324 .ClearPreviousContentBoxSizeAndLayoutOverflowRect(); |
326 } | 325 } |
327 } | 326 } |
328 | 327 |
329 } // namespace blink | 328 } // namespace blink |
OLD | NEW |