| 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(GeometryMapper& geometryMapper) | 18 PrePaintTreeWalkContext(GeometryMapper& geometryMapper) |
| 19 : treeBuilderContext( | 19 : treeBuilderContext( |
| 20 WTF::wrapUnique(new PaintPropertyTreeBuilderContext)), | 20 WTF::wrapUnique(new PaintPropertyTreeBuilderContext)), |
| 21 paintInvalidatorContext(treeBuilderContext.get(), geometryMapper), | 21 paintInvalidatorContext(*treeBuilderContext, geometryMapper), |
| 22 ancestorOverflowPaintLayer(nullptr), | 22 ancestorOverflowPaintLayer(nullptr), |
| 23 ancestorTransformedOrRootPaintLayer(nullptr) {} | 23 ancestorTransformedOrRootPaintLayer(nullptr) {} |
| 24 | 24 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) |
| 25 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext, | 25 : treeBuilderContext(WTF::wrapUnique(new PaintPropertyTreeBuilderContext( |
| 26 bool needsTreeBuilderContext) | 26 *parentContext.treeBuilderContext))), |
| 27 : treeBuilderContext( | 27 paintInvalidatorContext(*treeBuilderContext, |
| 28 WTF::wrapUnique(needsTreeBuilderContext || DCHECK_IS_ON() | |
| 29 ? new PaintPropertyTreeBuilderContext( | |
| 30 *parentContext.treeBuilderContext) | |
| 31 : nullptr)), | |
| 32 paintInvalidatorContext(treeBuilderContext.get(), | |
| 33 parentContext.paintInvalidatorContext), | 28 parentContext.paintInvalidatorContext), |
| 34 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer), | 29 ancestorOverflowPaintLayer(parentContext.ancestorOverflowPaintLayer), |
| 35 ancestorTransformedOrRootPaintLayer( | 30 ancestorTransformedOrRootPaintLayer( |
| 36 parentContext.ancestorTransformedOrRootPaintLayer) { | 31 parentContext.ancestorTransformedOrRootPaintLayer) {} |
| 37 #if DCHECK_IS_ON() | |
| 38 if (needsTreeBuilderContext) | |
| 39 DCHECK(parentContext.treeBuilderContext->isActuallyNeeded); | |
| 40 treeBuilderContext->isActuallyNeeded = needsTreeBuilderContext; | |
| 41 #endif | |
| 42 } | |
| 43 | 32 |
| 44 // PaintPropertyTreeBuilderContext is large and can lead to stack overflows | 33 // PaintPropertyTreeBuilderContext is large and can lead to stack overflows |
| 45 // when recursion is deep so this context object is allocated on the heap. | 34 // when recursion is deep so this context object is allocated on the heap. |
| 46 // See: https://crbug.com/698653. | 35 // See: https://crbug.com/698653. |
| 47 std::unique_ptr<PaintPropertyTreeBuilderContext> treeBuilderContext; | 36 std::unique_ptr<PaintPropertyTreeBuilderContext> treeBuilderContext; |
| 48 | 37 |
| 49 PaintInvalidatorContext paintInvalidatorContext; | 38 PaintInvalidatorContext paintInvalidatorContext; |
| 50 | 39 |
| 51 // The ancestor in the PaintLayer tree which has overflow clip, or | 40 // The ancestor in the PaintLayer tree which has overflow clip, or |
| 52 // is the root layer. Note that it is tree ancestor, not containing | 41 // is the root layer. Note that it is tree ancestor, not containing |
| 53 // block or stacking ancestor. | 42 // block or stacking ancestor. |
| 54 PaintLayer* ancestorOverflowPaintLayer; | 43 PaintLayer* ancestorOverflowPaintLayer; |
| 55 PaintLayer* ancestorTransformedOrRootPaintLayer; | 44 PaintLayer* ancestorTransformedOrRootPaintLayer; |
| 56 }; | 45 }; |
| 57 | 46 |
| 58 void PrePaintTreeWalk::walk(FrameView& rootFrame) { | 47 void PrePaintTreeWalk::walk(FrameView& rootFrame) { |
| 59 DCHECK(rootFrame.frame().document()->lifecycle().state() == | 48 DCHECK(rootFrame.frame().document()->lifecycle().state() == |
| 60 DocumentLifecycle::InPrePaint); | 49 DocumentLifecycle::InPrePaint); |
| 61 | 50 |
| 62 PrePaintTreeWalkContext initialContext(m_geometryMapper); | 51 PrePaintTreeWalkContext initialContext(m_geometryMapper); |
| 63 initialContext.ancestorTransformedOrRootPaintLayer = | 52 initialContext.ancestorTransformedOrRootPaintLayer = |
| 64 rootFrame.layoutView()->layer(); | 53 rootFrame.layoutView()->layer(); |
| 65 | 54 |
| 66 // GeometryMapper depends on paint properties. | 55 // GeometryMapper depends on paint properties. |
| 67 if (needsTreeBuilderContextUpdate(rootFrame, initialContext)) | 56 if (rootFrame.needsPaintPropertyUpdate() || |
| 57 (rootFrame.layoutView() && |
| 58 !shouldEndWalkBefore(*rootFrame.layoutView(), initialContext))) |
| 68 m_geometryMapper.clearCache(); | 59 m_geometryMapper.clearCache(); |
| 69 | 60 |
| 70 walk(rootFrame, initialContext); | 61 walk(rootFrame, initialContext); |
| 71 m_paintInvalidator.processPendingDelayedPaintInvalidations(); | 62 m_paintInvalidator.processPendingDelayedPaintInvalidations(); |
| 72 } | 63 } |
| 73 | 64 |
| 74 void PrePaintTreeWalk::walk(FrameView& frameView, | 65 void PrePaintTreeWalk::walk(FrameView& frameView, |
| 75 const PrePaintTreeWalkContext& parentContext) { | 66 const PrePaintTreeWalkContext& parentContext) { |
| 76 if (frameView.shouldThrottleRendering()) { | 67 if (frameView.shouldThrottleRendering()) { |
| 77 // Skip the throttled frame. Will update it when it becomes unthrottled. | 68 // Skip the throttled frame. Will update it when it becomes unthrottled. |
| 78 return; | 69 return; |
| 79 } | 70 } |
| 80 | 71 |
| 81 bool needsTreeBuilderContextUpdate = | 72 PrePaintTreeWalkContext context(parentContext); |
| 82 this->needsTreeBuilderContextUpdate(frameView, parentContext); | |
| 83 PrePaintTreeWalkContext context(parentContext, needsTreeBuilderContextUpdate); | |
| 84 // ancestorOverflowLayer does not cross frame boundaries. | 73 // ancestorOverflowLayer does not cross frame boundaries. |
| 85 context.ancestorOverflowPaintLayer = nullptr; | 74 context.ancestorOverflowPaintLayer = nullptr; |
| 86 if (context.treeBuilderContext) { | 75 m_propertyTreeBuilder.updateProperties(frameView, |
| 87 m_propertyTreeBuilder.updateProperties(frameView, | 76 *context.treeBuilderContext); |
| 88 *context.treeBuilderContext); | |
| 89 } | |
| 90 m_paintInvalidator.invalidatePaintIfNeeded(frameView, | 77 m_paintInvalidator.invalidatePaintIfNeeded(frameView, |
| 91 context.paintInvalidatorContext); | 78 context.paintInvalidatorContext); |
| 92 | 79 |
| 93 if (LayoutView* view = frameView.layoutView()) { | 80 if (LayoutView* view = frameView.layoutView()) { |
| 94 walk(*view, context); | 81 walk(*view, context); |
| 95 #if DCHECK_IS_ON() | 82 #if DCHECK_IS_ON() |
| 96 view->assertSubtreeClearedPaintInvalidationFlags(); | 83 view->assertSubtreeClearedPaintInvalidationFlags(); |
| 97 #endif | 84 #endif |
| 98 } | 85 } |
| 99 frameView.clearNeedsPaintPropertyUpdate(); | 86 frameView.clearNeedsPaintPropertyUpdate(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 ClipRects* previousClipRects = paintLayer.previousPaintingClipRects(); | 217 ClipRects* previousClipRects = paintLayer.previousPaintingClipRects(); |
| 231 | 218 |
| 232 if (!previousClipRects || *clipRects != *previousClipRects) { | 219 if (!previousClipRects || *clipRects != *previousClipRects) { |
| 233 paintLayer.setNeedsRepaint(); | 220 paintLayer.setNeedsRepaint(); |
| 234 paintLayer.setPreviousPaintPhaseDescendantOutlinesEmpty(false); | 221 paintLayer.setPreviousPaintPhaseDescendantOutlinesEmpty(false); |
| 235 paintLayer.setPreviousPaintPhaseFloatEmpty(false); | 222 paintLayer.setPreviousPaintPhaseFloatEmpty(false); |
| 236 paintLayer.setPreviousPaintPhaseDescendantBlockBackgroundsEmpty(false); | 223 paintLayer.setPreviousPaintPhaseDescendantBlockBackgroundsEmpty(false); |
| 237 // All subsequences which are contained below this paintLayer must also | 224 // All subsequences which are contained below this paintLayer must also |
| 238 // be checked. | 225 // be checked. |
| 239 context.paintInvalidatorContext.forcedSubtreeInvalidationFlags |= | 226 context.paintInvalidatorContext.forcedSubtreeInvalidationFlags |= |
| 240 PaintInvalidatorContext::ForcedSubtreeVisualRectUpdate; | 227 PaintInvalidatorContext::ForcedSubtreeInvalidationRectUpdate; |
| 241 } | 228 } |
| 242 | 229 |
| 243 paintLayer.setPreviousPaintingClipRects(*clipRects); | 230 paintLayer.setPreviousPaintingClipRects(*clipRects); |
| 244 } | 231 } |
| 245 | 232 |
| 246 bool PrePaintTreeWalk::needsTreeBuilderContextUpdate( | 233 bool PrePaintTreeWalk::shouldEndWalkBefore( |
| 247 const FrameView& frameView, | 234 const LayoutObject& object, |
| 248 const PrePaintTreeWalkContext& context) { | 235 const PrePaintTreeWalkContext& context) { |
| 249 return frameView.needsPaintPropertyUpdate() || | 236 return !object.needsPaintPropertyUpdate() && |
| 250 (frameView.layoutView() && | 237 !object.descendantNeedsPaintPropertyUpdate() && |
| 251 needsTreeBuilderContextUpdate(*frameView.layoutView(), context)); | 238 !context.treeBuilderContext->forceSubtreeUpdate && |
| 252 } | 239 !context.paintInvalidatorContext.forcedSubtreeInvalidationFlags && |
| 253 | 240 !object.shouldCheckForPaintInvalidation(); |
| 254 bool PrePaintTreeWalk::needsTreeBuilderContextUpdate( | |
| 255 const LayoutObject& object, | |
| 256 const PrePaintTreeWalkContext& parentContext) { | |
| 257 return object.needsPaintPropertyUpdate() || | |
| 258 object.descendantNeedsPaintPropertyUpdate() || | |
| 259 (parentContext.treeBuilderContext && | |
| 260 parentContext.treeBuilderContext->forceSubtreeUpdate) || | |
| 261 // If the object needs visual rect update, we should update tree | |
| 262 // builder context which is needed by visual rect update. | |
| 263 parentContext.paintInvalidatorContext.needsVisualRectUpdate(object); | |
| 264 } | 241 } |
| 265 | 242 |
| 266 void PrePaintTreeWalk::walk(const LayoutObject& object, | 243 void PrePaintTreeWalk::walk(const LayoutObject& object, |
| 267 const PrePaintTreeWalkContext& parentContext) { | 244 const PrePaintTreeWalkContext& parentContext) { |
| 268 // Early out from the tree walk if possible. | 245 if (shouldEndWalkBefore(object, parentContext)) |
| 269 bool needsTreeBuilderContextUpdate = | |
| 270 this->needsTreeBuilderContextUpdate(object, parentContext); | |
| 271 if (!needsTreeBuilderContextUpdate && | |
| 272 !object.shouldCheckForPaintInvalidation()) | |
| 273 return; | 246 return; |
| 274 | 247 |
| 275 PrePaintTreeWalkContext context(parentContext, needsTreeBuilderContextUpdate); | 248 PrePaintTreeWalkContext context(parentContext); |
| 276 | 249 |
| 277 // This must happen before updatePropertiesForSelf, because the latter reads | 250 // This must happen before updatePropertiesForSelf, because the latter reads |
| 278 // some of the state computed here. | 251 // some of the state computed here. |
| 279 updateAuxiliaryObjectProperties(object, context); | 252 updateAuxiliaryObjectProperties(object, context); |
| 280 | 253 |
| 281 if (context.treeBuilderContext) { | 254 m_propertyTreeBuilder.updatePropertiesForSelf(object, |
| 282 DCHECK(context.treeBuilderContext); | 255 *context.treeBuilderContext); |
| 283 m_propertyTreeBuilder.updatePropertiesForSelf(object, | |
| 284 *context.treeBuilderContext); | |
| 285 } | |
| 286 | |
| 287 m_paintInvalidator.invalidatePaintIfNeeded(object, | 256 m_paintInvalidator.invalidatePaintIfNeeded(object, |
| 288 context.paintInvalidatorContext); | 257 context.paintInvalidatorContext); |
| 258 m_propertyTreeBuilder.updatePropertiesForChildren( |
| 259 object, *context.treeBuilderContext); |
| 289 | 260 |
| 290 if (context.treeBuilderContext) { | 261 invalidatePaintLayerOptimizationsIfNeeded(object, context); |
| 291 m_propertyTreeBuilder.updatePropertiesForChildren( | |
| 292 object, *context.treeBuilderContext); | |
| 293 invalidatePaintLayerOptimizationsIfNeeded(object, context); | |
| 294 } | |
| 295 | 262 |
| 296 for (const LayoutObject* child = object.slowFirstChild(); child; | 263 for (const LayoutObject* child = object.slowFirstChild(); child; |
| 297 child = child->nextSibling()) { | 264 child = child->nextSibling()) { |
| 298 if (child->isLayoutMultiColumnSpannerPlaceholder()) { | 265 if (child->isLayoutMultiColumnSpannerPlaceholder()) { |
| 299 child->getMutableForPainting().clearPaintFlags(); | 266 child->getMutableForPainting().clearPaintFlags(); |
| 300 continue; | 267 continue; |
| 301 } | 268 } |
| 302 walk(*child, context); | 269 walk(*child, context); |
| 303 } | 270 } |
| 304 | 271 |
| 305 if (object.isLayoutPart()) { | 272 if (object.isLayoutPart()) { |
| 306 const LayoutPart& layoutPart = toLayoutPart(object); | 273 const LayoutPart& layoutPart = toLayoutPart(object); |
| 307 FrameViewBase* frameViewBase = layoutPart.frameViewBase(); | 274 FrameViewBase* frameViewBase = layoutPart.frameViewBase(); |
| 308 if (frameViewBase && frameViewBase->isFrameView()) { | 275 if (frameViewBase && frameViewBase->isFrameView()) { |
| 309 if (context.treeBuilderContext) { | 276 context.treeBuilderContext->current.paintOffset += |
| 310 context.treeBuilderContext->current.paintOffset += | 277 layoutPart.replacedContentRect().location() - |
| 311 layoutPart.replacedContentRect().location() - | 278 frameViewBase->frameRect().location(); |
| 312 frameViewBase->frameRect().location(); | 279 context.treeBuilderContext->current.paintOffset = |
| 313 context.treeBuilderContext->current.paintOffset = | 280 roundedIntPoint(context.treeBuilderContext->current.paintOffset); |
| 314 roundedIntPoint(context.treeBuilderContext->current.paintOffset); | |
| 315 } | |
| 316 walk(*toFrameView(frameViewBase), context); | 281 walk(*toFrameView(frameViewBase), context); |
| 317 } | 282 } |
| 318 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). | 283 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). |
| 319 } | 284 } |
| 320 | 285 |
| 321 object.getMutableForPainting().clearPaintFlags(); | 286 object.getMutableForPainting().clearPaintFlags(); |
| 322 } | 287 } |
| 323 | 288 |
| 324 } // namespace blink | 289 } // namespace blink |
| OLD | NEW |