OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/PrePaintTreeWalk.h" | 5 #include "core/paint/PrePaintTreeWalk.h" |
6 | 6 |
7 #include "core/dom/DocumentLifecycle.h" | 7 #include "core/dom/DocumentLifecycle.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/layout/LayoutMultiColumnSpannerPlaceholder.h" | 10 #include "core/layout/LayoutMultiColumnSpannerPlaceholder.h" |
11 #include "core/layout/LayoutPart.h" | 11 #include "core/layout/LayoutPart.h" |
12 #include "core/layout/LayoutView.h" | 12 #include "core/layout/LayoutView.h" |
13 #include "core/paint/PaintLayer.h" | 13 #include "core/paint/PaintLayer.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 struct PrePaintTreeWalkContext { | 17 struct PrePaintTreeWalkContext { |
18 PrePaintTreeWalkContext() | 18 PrePaintTreeWalkContext() |
19 : paintInvalidatorContext(treeBuilderContext), | 19 : paintInvalidatorContext(treeBuilderContext), |
20 ancestorOverflowPaintLayer(nullptr) {} | 20 ancestorOverflowPaintLayer(nullptr) {} |
21 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) | 21 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) |
22 : treeBuilderContext(parentContext.treeBuilderContext), | 22 : treeBuilderContext(parentContext.treeBuilderContext), |
23 paintInvalidatorContext(treeBuilderContext, | 23 paintInvalidatorContext(treeBuilderContext, |
24 parentContext.paintInvalidatorContext), | 24 parentContext.paintInvalidatorContext), |
25 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer) {} | 25 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer), |
| 26 ancestorTransformedOrRootPaintLayer( |
| 27 parentContext.ancestorTransformedOrRootPaintLayer) {} |
26 | 28 |
27 PaintPropertyTreeBuilderContext treeBuilderContext; | 29 PaintPropertyTreeBuilderContext treeBuilderContext; |
28 PaintInvalidatorContext paintInvalidatorContext; | 30 PaintInvalidatorContext paintInvalidatorContext; |
29 | 31 |
30 // The ancestor in the PaintLayer tree which has overflow clip, or | 32 // The ancestor in the PaintLayer tree which has overflow clip, or |
31 // is the root layer. Note that it is tree ancestor, not containing | 33 // is the root layer. Note that it is tree ancestor, not containing |
32 // block or stacking ancestor. | 34 // block or stacking ancestor. |
33 PaintLayer* ancestorOverflowPaintLayer; | 35 PaintLayer* ancestorOverflowPaintLayer; |
| 36 PaintLayer* ancestorTransformedOrRootPaintLayer; |
34 }; | 37 }; |
35 | 38 |
36 void PrePaintTreeWalk::walk(FrameView& rootFrame) { | 39 void PrePaintTreeWalk::walk(FrameView& rootFrame) { |
37 DCHECK(rootFrame.frame().document()->lifecycle().state() == | 40 DCHECK(rootFrame.frame().document()->lifecycle().state() == |
38 DocumentLifecycle::InPrePaint); | 41 DocumentLifecycle::InPrePaint); |
39 | 42 |
40 PrePaintTreeWalkContext initialContext; | 43 PrePaintTreeWalkContext initialContext; |
41 initialContext.treeBuilderContext = | 44 initialContext.treeBuilderContext = |
42 m_propertyTreeBuilder.setupInitialContext(); | 45 m_propertyTreeBuilder.setupInitialContext(); |
43 walk(rootFrame, initialContext); | 46 walk(rootFrame, initialContext); |
44 m_paintInvalidator.processPendingDelayedPaintInvalidations(); | 47 m_paintInvalidator.processPendingDelayedPaintInvalidations(); |
45 } | 48 } |
46 | 49 |
47 void PrePaintTreeWalk::walk(FrameView& frameView, | 50 void PrePaintTreeWalk::walk(FrameView& frameView, |
48 const PrePaintTreeWalkContext& parentContext) { | 51 const PrePaintTreeWalkContext& parentContext) { |
49 if (frameView.shouldThrottleRendering()) { | 52 if (frameView.shouldThrottleRendering()) { |
50 // Skip the throttled frame. Will update it when it becomes unthrottled. | 53 // Skip the throttled frame. Will update it when it becomes unthrottled. |
51 return; | 54 return; |
52 } | 55 } |
53 | 56 |
54 PrePaintTreeWalkContext context(parentContext); | 57 PrePaintTreeWalkContext context(parentContext); |
55 // ancestorOverflowLayer does not cross frame boundaries. | 58 // ancestorOverflowLayer does not cross frame boundaries. |
56 context.ancestorOverflowPaintLayer = nullptr; | 59 context.ancestorOverflowPaintLayer = nullptr; |
| 60 context.ancestorTransformedOrRootPaintLayer = frameView.layoutView()->layer(); |
57 m_propertyTreeBuilder.updateProperties(frameView, context.treeBuilderContext); | 61 m_propertyTreeBuilder.updateProperties(frameView, context.treeBuilderContext); |
58 m_paintInvalidator.invalidatePaintIfNeeded(frameView, | 62 m_paintInvalidator.invalidatePaintIfNeeded(frameView, |
59 context.paintInvalidatorContext); | 63 context.paintInvalidatorContext); |
60 | 64 |
61 if (LayoutView* view = frameView.layoutView()) { | 65 if (LayoutView* view = frameView.layoutView()) { |
62 walk(*view, context); | 66 walk(*view, context); |
63 #if DCHECK_IS_ON() | 67 #if DCHECK_IS_ON() |
64 view->assertSubtreeClearedPaintInvalidationFlags(); | 68 view->assertSubtreeClearedPaintInvalidationFlags(); |
65 #endif | 69 #endif |
66 } | 70 } |
(...skipping 15 matching lines...) Expand all Loading... |
82 // sticky layer position, so we need to update it again here. | 86 // sticky layer position, so we need to update it again here. |
83 // TODO(flackr): This should be refactored in the future to be clearer (i.e. | 87 // TODO(flackr): This should be refactored in the future to be clearer (i.e. |
84 // update layer position and ancestor inputs updates in the same walk). | 88 // update layer position and ancestor inputs updates in the same walk). |
85 paintLayer->updateLayerPosition(); | 89 paintLayer->updateLayerPosition(); |
86 } | 90 } |
87 | 91 |
88 if (paintLayer->isRootLayer() || object.hasOverflowClip()) | 92 if (paintLayer->isRootLayer() || object.hasOverflowClip()) |
89 context.ancestorOverflowPaintLayer = paintLayer; | 93 context.ancestorOverflowPaintLayer = paintLayer; |
90 } | 94 } |
91 | 95 |
| 96 // Returns whether |a| is an ancestor of or equal to |b|. |
| 97 static bool isAncestorOfOrEqualTo(const ClipPaintPropertyNode* a, |
| 98 const ClipPaintPropertyNode* b) { |
| 99 while (b && b != a) { |
| 100 b = b->parent(); |
| 101 } |
| 102 return b == a; |
| 103 } |
| 104 |
| 105 ClipRect PrePaintTreeWalk::clipRectForContext( |
| 106 const PaintPropertyTreeBuilderContext::ContainingBlockContext& context, |
| 107 const EffectPaintPropertyNode* effect, |
| 108 const PropertyTreeState& ancestorState, |
| 109 const LayoutPoint& ancestorPaintOffset, |
| 110 bool& hasClip) { |
| 111 // Only return a non-infinite clip if clips differ, or the "ancestor" state is |
| 112 // actually an ancestor clip. This ensures no accuracy issues due to |
| 113 // transforms applied to infinite rects. |
| 114 if (isAncestorOfOrEqualTo(context.clip, ancestorState.clip())) |
| 115 return ClipRect(LayoutRect(LayoutRect::infiniteIntRect())); |
| 116 |
| 117 hasClip = true; |
| 118 |
| 119 PropertyTreeState localState(context.transform, context.clip, effect); |
| 120 |
| 121 // TODO(chrishtr): remove need for this. |
| 122 LayoutRect localRect(LayoutRect::infiniteIntRect()); |
| 123 |
| 124 LayoutRect rect(m_geometryMapper.sourceToDestinationVisualRect( |
| 125 FloatRect(localRect), localState, ancestorState)); |
| 126 rect.moveBy(-ancestorPaintOffset); |
| 127 return rect; |
| 128 } |
| 129 |
| 130 void PrePaintTreeWalk::invalidatePaintLayerOptimizationsIfNeeded( |
| 131 const LayoutObject& object, |
| 132 const PaintLayer& ancestorTransformedOrRootPaintLayer, |
| 133 PaintPropertyTreeBuilderContext& context) { |
| 134 if (!object.hasLayer()) |
| 135 return; |
| 136 |
| 137 PaintLayer& paintLayer = *toLayoutBoxModelObject(object).layer(); |
| 138 PropertyTreeState ancestorState = |
| 139 *ancestorTransformedOrRootPaintLayer.layoutObject() |
| 140 ->paintProperties() |
| 141 ->localBorderBoxProperties(); |
| 142 |
| 143 #ifdef CHECK_CLIP_RECTS |
| 144 ShouldRespectOverflowClipType respectOverflowClip = RespectOverflowClip; |
| 145 #endif |
| 146 if (ancestorTransformedOrRootPaintLayer.compositingState() == |
| 147 PaintsIntoOwnBacking && |
| 148 ancestorTransformedOrRootPaintLayer.layoutObject() |
| 149 ->paintProperties() |
| 150 ->overflowClip()) { |
| 151 ancestorState.setClip(ancestorTransformedOrRootPaintLayer.layoutObject() |
| 152 ->paintProperties() |
| 153 ->overflowClip()); |
| 154 #ifdef CHECK_CLIP_RECTS |
| 155 respectOverflowClip = IgnoreOverflowClip; |
| 156 #endif |
| 157 } |
| 158 |
| 159 #ifdef CHECK_CLIP_RECTS |
| 160 ClipRects& oldClipRects = paintLayer.clipper().paintingClipRects( |
| 161 &ancestorTransformedOrRootPaintLayer, respectOverflowClip, LayoutSize()); |
| 162 #endif |
| 163 |
| 164 bool hasClip = false; |
| 165 RefPtr<ClipRects> clipRects = ClipRects::create(); |
| 166 clipRects->setOverflowClipRect(clipRectForContext( |
| 167 context.current, context.currentEffect, ancestorState, |
| 168 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(), |
| 169 hasClip)); |
| 170 #ifdef CHECK_CLIP_RECTS |
| 171 CHECK(!hasClip || |
| 172 clipRects->overflowClipRect() == oldClipRects.overflowClipRect()) |
| 173 << "rect= " << clipRects->overflowClipRect().toString(); |
| 174 #endif |
| 175 |
| 176 clipRects->setFixedClipRect(clipRectForContext( |
| 177 context.fixedPosition, context.currentEffect, ancestorState, |
| 178 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(), |
| 179 hasClip)); |
| 180 #ifdef CHECK_CLIP_RECTS |
| 181 CHECK(hasClip || clipRects->fixedClipRect() == oldClipRects.fixedClipRect()) |
| 182 << " fixed=" << clipRects->fixedClipRect().toString(); |
| 183 #endif |
| 184 |
| 185 clipRects->setPosClipRect(clipRectForContext( |
| 186 context.absolutePosition, context.currentEffect, ancestorState, |
| 187 ancestorTransformedOrRootPaintLayer.layoutObject()->paintOffset(), |
| 188 hasClip)); |
| 189 #ifdef CHECK_CLIP_RECTS |
| 190 CHECK(!hasClip || clipRects->posClipRect() == oldClipRects.posClipRect()) |
| 191 << " abs=" << clipRects->posClipRect().toString(); |
| 192 #endif |
| 193 |
| 194 ClipRects* previousClipRects = paintLayer.previousPaintingClipRects(); |
| 195 |
| 196 if (!previousClipRects || *clipRects != *previousClipRects) { |
| 197 paintLayer.setNeedsRepaint(); |
| 198 paintLayer.setPreviousPaintPhaseDescendantOutlinesEmpty(false); |
| 199 paintLayer.setPreviousPaintPhaseFloatEmpty(false); |
| 200 paintLayer.setPreviousPaintPhaseDescendantBlockBackgroundsEmpty(false); |
| 201 // All subsequences which are contained below this paintLayer must also |
| 202 // be checked. |
| 203 context.forceSubtreeUpdate = true; |
| 204 } |
| 205 |
| 206 paintLayer.setPreviousPaintingClipRects(*clipRects); |
| 207 } |
| 208 |
92 void PrePaintTreeWalk::walk(const LayoutObject& object, | 209 void PrePaintTreeWalk::walk(const LayoutObject& object, |
93 const PrePaintTreeWalkContext& parentContext) { | 210 const PrePaintTreeWalkContext& parentContext) { |
94 PrePaintTreeWalkContext context(parentContext); | 211 PrePaintTreeWalkContext context(parentContext); |
95 | 212 |
96 // This must happen before updateContextForBoxPosition, because the | 213 // This must happen before updateContextForBoxPosition, because the |
97 // latter reads some of the state computed uere. | 214 // latter reads some of the state computed uere. |
98 updateAuxiliaryObjectProperties(object, context); | 215 updateAuxiliaryObjectProperties(object, context); |
99 | 216 |
100 // Ensure the current context takes into account the box's position. This can | 217 // Ensure the current context takes into account the box's position. This can |
101 // force a subtree update due to paint offset changes and must precede any | 218 // force a subtree update due to paint offset changes and must precede any |
(...skipping 11 matching lines...) Expand all Loading... |
113 return; | 230 return; |
114 } | 231 } |
115 | 232 |
116 m_propertyTreeBuilder.updatePropertiesForSelf(object, | 233 m_propertyTreeBuilder.updatePropertiesForSelf(object, |
117 context.treeBuilderContext); | 234 context.treeBuilderContext); |
118 m_paintInvalidator.invalidatePaintIfNeeded(object, | 235 m_paintInvalidator.invalidatePaintIfNeeded(object, |
119 context.paintInvalidatorContext); | 236 context.paintInvalidatorContext); |
120 m_propertyTreeBuilder.updatePropertiesForChildren(object, | 237 m_propertyTreeBuilder.updatePropertiesForChildren(object, |
121 context.treeBuilderContext); | 238 context.treeBuilderContext); |
122 | 239 |
| 240 if (object.isBoxModelObject() && object.hasLayer()) { |
| 241 if (object.styleRef().hasTransform() || |
| 242 &object == context.paintInvalidatorContext.paintInvalidationContainer) { |
| 243 context.ancestorTransformedOrRootPaintLayer = |
| 244 toLayoutBoxModelObject(object).layer(); |
| 245 } |
| 246 } |
| 247 |
| 248 invalidatePaintLayerOptimizationsIfNeeded( |
| 249 object, *context.ancestorTransformedOrRootPaintLayer, |
| 250 context.treeBuilderContext); |
| 251 |
123 for (const LayoutObject* child = object.slowFirstChild(); child; | 252 for (const LayoutObject* child = object.slowFirstChild(); child; |
124 child = child->nextSibling()) { | 253 child = child->nextSibling()) { |
125 if (child->isLayoutMultiColumnSpannerPlaceholder()) { | 254 if (child->isLayoutMultiColumnSpannerPlaceholder()) { |
126 child->getMutableForPainting().clearPaintFlags(); | 255 child->getMutableForPainting().clearPaintFlags(); |
127 continue; | 256 continue; |
128 } | 257 } |
129 walk(*child, context); | 258 walk(*child, context); |
130 } | 259 } |
131 | 260 |
132 if (object.isLayoutPart()) { | 261 if (object.isLayoutPart()) { |
133 const LayoutPart& layoutPart = toLayoutPart(object); | 262 const LayoutPart& layoutPart = toLayoutPart(object); |
134 Widget* widget = layoutPart.widget(); | 263 Widget* widget = layoutPart.widget(); |
135 if (widget && widget->isFrameView()) { | 264 if (widget && widget->isFrameView()) { |
136 context.treeBuilderContext.current.paintOffset += | 265 context.treeBuilderContext.current.paintOffset += |
137 layoutPart.replacedContentRect().location() - | 266 layoutPart.replacedContentRect().location() - |
138 widget->frameRect().location(); | 267 widget->frameRect().location(); |
139 context.treeBuilderContext.current.paintOffset = | 268 context.treeBuilderContext.current.paintOffset = |
140 roundedIntPoint(context.treeBuilderContext.current.paintOffset); | 269 roundedIntPoint(context.treeBuilderContext.current.paintOffset); |
141 walk(*toFrameView(widget), context); | 270 walk(*toFrameView(widget), context); |
142 } | 271 } |
143 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). | 272 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). |
144 } | 273 } |
145 | 274 |
146 object.getMutableForPainting().clearPaintFlags(); | 275 object.getMutableForPainting().clearPaintFlags(); |
147 } | 276 } |
148 | 277 |
149 } // namespace blink | 278 } // namespace blink |
OLD | NEW |