| 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 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 struct PrePaintTreeWalkContext { | 16 struct PrePaintTreeWalkContext { |
| 17 PrePaintTreeWalkContext() : paintInvalidatorContext(treeBuilderContext) {} | 17 PrePaintTreeWalkContext() : paintInvalidatorContext(treeBuilderContext) {} |
| 18 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) | 18 PrePaintTreeWalkContext(const PrePaintTreeWalkContext& parentContext) |
| 19 : treeBuilderContext(parentContext.treeBuilderContext), | 19 : treeBuilderContext(parentContext.treeBuilderContext), |
| 20 paintInvalidatorContext(treeBuilderContext, | 20 paintInvalidatorContext(treeBuilderContext, |
| 21 parentContext.paintInvalidatorContext) {} | 21 parentContext.paintInvalidatorContext) {} |
| 22 | 22 |
| 23 bool needToUpdatePaintPropertySubtree = false; |
| 23 PaintPropertyTreeBuilderContext treeBuilderContext; | 24 PaintPropertyTreeBuilderContext treeBuilderContext; |
| 24 PaintInvalidatorContext paintInvalidatorContext; | 25 PaintInvalidatorContext paintInvalidatorContext; |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 void PrePaintTreeWalk::walk(FrameView& rootFrame) { | 28 void PrePaintTreeWalk::walk(FrameView& rootFrame) { |
| 28 DCHECK(rootFrame.frame().document()->lifecycle().state() == | 29 DCHECK(rootFrame.frame().document()->lifecycle().state() == |
| 29 DocumentLifecycle::InPrePaint); | 30 DocumentLifecycle::InPrePaint); |
| 30 | 31 |
| 31 PrePaintTreeWalkContext initialContext; | 32 PrePaintTreeWalkContext initialContext; |
| 32 initialContext.treeBuilderContext = | 33 initialContext.treeBuilderContext = |
| 33 m_propertyTreeBuilder.setupInitialContext(); | 34 m_propertyTreeBuilder.setupInitialContext(); |
| 34 walk(rootFrame, initialContext); | 35 walk(rootFrame, initialContext); |
| 35 m_paintInvalidator.processPendingDelayedPaintInvalidations(); | 36 m_paintInvalidator.processPendingDelayedPaintInvalidations(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void PrePaintTreeWalk::walk(FrameView& frameView, | 39 void PrePaintTreeWalk::walk(FrameView& frameView, |
| 39 const PrePaintTreeWalkContext& context) { | 40 const PrePaintTreeWalkContext& context) { |
| 40 if (frameView.shouldThrottleRendering()) | 41 if (frameView.shouldThrottleRendering()) |
| 41 return; | 42 return; |
| 42 | 43 |
| 43 PrePaintTreeWalkContext localContext(context); | 44 PrePaintTreeWalkContext localContext(context); |
| 44 m_propertyTreeBuilder.updateFramePropertiesAndContext( | 45 |
| 45 frameView, localContext.treeBuilderContext); | 46 // Check whether we need to update the paint property trees. |
| 47 if (!localContext.needToUpdatePaintPropertySubtree) { |
| 48 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) { |
| 49 // forcedSubtreeInvalidationFlags will be true if locations have changed |
| 50 // which will affect paint properties (e.g., PaintOffset). |
| 51 localContext.needToUpdatePaintPropertySubtree = true; |
| 52 } else if (frameView.needsPaintPropertyUpdate()) { |
| 53 localContext.needToUpdatePaintPropertySubtree = true; |
| 54 } |
| 55 } |
| 56 // Paint properties can depend on their ancestor properties so ensure the |
| 57 // entire subtree is rebuilt on any changes. |
| 58 // TODO(pdr): Add additional granularity to the needs update approach such as |
| 59 // the ability to do local updates that don't change the subtree. |
| 60 if (localContext.needToUpdatePaintPropertySubtree) |
| 61 frameView.setNeedsPaintPropertyUpdate(); |
| 62 |
| 63 m_propertyTreeBuilder.updateProperties(frameView, |
| 64 localContext.treeBuilderContext); |
| 46 | 65 |
| 47 m_paintInvalidator.invalidatePaintIfNeeded( | 66 m_paintInvalidator.invalidatePaintIfNeeded( |
| 48 frameView, localContext.paintInvalidatorContext); | 67 frameView, localContext.paintInvalidatorContext); |
| 49 | 68 |
| 50 if (LayoutView* layoutView = frameView.layoutView()) | 69 if (LayoutView* layoutView = frameView.layoutView()) |
| 51 walk(*layoutView, localContext); | 70 walk(*layoutView, localContext); |
| 52 | 71 |
| 53 #if DCHECK_IS_ON() | 72 #if DCHECK_IS_ON() |
| 54 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags(); | 73 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags(); |
| 55 #endif | 74 #endif |
| 75 |
| 76 frameView.clearNeedsPaintPropertyUpdate(); |
| 56 } | 77 } |
| 57 | 78 |
| 58 void PrePaintTreeWalk::walk(const LayoutObject& object, | 79 void PrePaintTreeWalk::walk(const LayoutObject& object, |
| 59 const PrePaintTreeWalkContext& context) { | 80 const PrePaintTreeWalkContext& context) { |
| 60 PrePaintTreeWalkContext localContext(context); | 81 PrePaintTreeWalkContext localContext(context); |
| 61 | 82 |
| 83 // Check whether we need to update the paint property trees. |
| 84 if (!localContext.needToUpdatePaintPropertySubtree) { |
| 85 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags) { |
| 86 // forcedSubtreeInvalidationFlags will be true if locations have changed |
| 87 // which will affect paint properties (e.g., PaintOffset). |
| 88 localContext.needToUpdatePaintPropertySubtree = true; |
| 89 } else if (object.needsPaintPropertyUpdate()) { |
| 90 localContext.needToUpdatePaintPropertySubtree = true; |
| 91 } else if (object.mayNeedPaintInvalidation()) { |
| 92 // mayNeedpaintInvalidation will be true when locations change which will |
| 93 // affect paint properties (e.g., PaintOffset). |
| 94 localContext.needToUpdatePaintPropertySubtree = true; |
| 95 } else if (object.shouldDoFullPaintInvalidation()) { |
| 96 // shouldDoFullPaintInvalidation will be true when locations or overflow |
| 97 // changes which will affect paint properties (e.g., PaintOffset, scroll). |
| 98 localContext.needToUpdatePaintPropertySubtree = true; |
| 99 } |
| 100 } |
| 101 |
| 102 // Paint properties can depend on their ancestor properties so ensure the |
| 103 // entire subtree is rebuilt on any changes. |
| 104 // TODO(pdr): Add additional granularity to the needs update approach such as |
| 105 // the ability to do local updates that don't change the subtree. |
| 106 if (localContext.needToUpdatePaintPropertySubtree) |
| 107 object.getMutableForPainting().setNeedsPaintPropertyUpdate(); |
| 108 |
| 109 // TODO(pdr): Ensure multi column works with incremental property tree |
| 110 // construction. |
| 62 if (object.isLayoutMultiColumnSpannerPlaceholder()) { | 111 if (object.isLayoutMultiColumnSpannerPlaceholder()) { |
| 63 // Walk multi-column spanner as if it replaces the placeholder. | 112 // Walk multi-column spanner as if it replaces the placeholder. |
| 64 // Set the flag so that the tree builder can specially handle out-of-flow | 113 // Set the flag so that the tree builder can specially handle out-of-flow |
| 65 // positioned descendants if their containers are between the multi-column | 114 // positioned descendants if their containers are between the multi-column |
| 66 // container and the spanner. See PaintPropertyTreeBuilder for details. | 115 // container and the spanner. See PaintPropertyTreeBuilder for details. |
| 67 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; | 116 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; |
| 68 walk(*toLayoutMultiColumnSpannerPlaceholder(object) | 117 walk(*toLayoutMultiColumnSpannerPlaceholder(object) |
| 69 .layoutObjectInFlowThread(), | 118 .layoutObjectInFlowThread(), |
| 70 localContext); | 119 localContext); |
| 71 object.getMutableForPainting().clearPaintInvalidationFlags(); | 120 object.getMutableForPainting().clearPaintInvalidationFlags(); |
| 72 return; | 121 return; |
| 73 } | 122 } |
| 74 | 123 |
| 75 m_propertyTreeBuilder.updatePropertiesAndContextForSelf( | 124 m_propertyTreeBuilder.updatePropertiesForSelf( |
| 76 object, localContext.treeBuilderContext); | 125 object, localContext.treeBuilderContext); |
| 77 m_paintInvalidator.invalidatePaintIfNeeded( | 126 m_paintInvalidator.invalidatePaintIfNeeded( |
| 78 object, localContext.paintInvalidatorContext); | 127 object, localContext.paintInvalidatorContext); |
| 79 m_propertyTreeBuilder.updatePropertiesAndContextForChildren( | 128 m_propertyTreeBuilder.updatePropertiesForChildren( |
| 80 object, localContext.treeBuilderContext); | 129 object, localContext.treeBuilderContext); |
| 81 | 130 |
| 82 for (const LayoutObject* child = object.slowFirstChild(); child; | 131 for (const LayoutObject* child = object.slowFirstChild(); child; |
| 83 child = child->nextSibling()) { | 132 child = child->nextSibling()) { |
| 84 // Column spanners are walked through their placeholders. See above. | 133 // Column spanners are walked through their placeholders. See above. |
| 85 if (child->isColumnSpanAll()) | 134 if (child->isColumnSpanAll()) |
| 86 continue; | 135 continue; |
| 87 walk(*child, localContext); | 136 walk(*child, localContext); |
| 88 } | 137 } |
| 89 | 138 |
| 90 if (object.isLayoutPart()) { | 139 if (object.isLayoutPart()) { |
| 91 const LayoutPart& layoutPart = toLayoutPart(object); | 140 const LayoutPart& layoutPart = toLayoutPart(object); |
| 92 Widget* widget = layoutPart.widget(); | 141 Widget* widget = layoutPart.widget(); |
| 93 if (widget && widget->isFrameView()) { | 142 if (widget && widget->isFrameView()) { |
| 94 localContext.treeBuilderContext.current.paintOffset += | 143 localContext.treeBuilderContext.current.paintOffset += |
| 95 layoutPart.replacedContentRect().location() - | 144 layoutPart.replacedContentRect().location() - |
| 96 widget->frameRect().location(); | 145 widget->frameRect().location(); |
| 97 localContext.treeBuilderContext.current.paintOffset = | 146 localContext.treeBuilderContext.current.paintOffset = |
| 98 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); | 147 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); |
| 99 walk(*toFrameView(widget), localContext); | 148 walk(*toFrameView(widget), localContext); |
| 100 } | 149 } |
| 101 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). | 150 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). |
| 102 } | 151 } |
| 152 |
| 103 object.getMutableForPainting().clearPaintInvalidationFlags(); | 153 object.getMutableForPainting().clearPaintInvalidationFlags(); |
| 154 object.getMutableForPainting().clearNeedsPaintPropertyUpdate(); |
| 104 } | 155 } |
| 105 | 156 |
| 106 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |