Chromium Code Reviews| 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 needToRebuildPaintPropertyTrees = 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.buildTreeNodes(frameView, | 45 |
| 45 localContext.treeBuilderContext); | 46 // Check whether we need to rebuild the paint property trees. |
| 47 if (!localContext.needToRebuildPaintPropertyTrees) { | |
| 48 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags || | |
| 49 !frameView.paintPropertiesValid()) | |
| 50 localContext.needToRebuildPaintPropertyTrees = true; | |
| 51 } | |
| 52 if (localContext.needToRebuildPaintPropertyTrees) | |
| 53 frameView.setPaintPropertiesInvalid(); | |
| 54 | |
| 55 m_propertyTreeBuilder.updateProperties(frameView, | |
| 56 localContext.treeBuilderContext); | |
| 46 | 57 |
| 47 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) { | 58 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) { |
| 48 m_paintInvalidator.invalidatePaintIfNeeded( | 59 m_paintInvalidator.invalidatePaintIfNeeded( |
| 49 frameView, localContext.paintInvalidatorContext); | 60 frameView, localContext.paintInvalidatorContext); |
| 50 } | 61 } |
| 51 | 62 |
| 52 if (LayoutView* layoutView = frameView.layoutView()) | 63 if (LayoutView* layoutView = frameView.layoutView()) |
| 53 walk(*layoutView, localContext); | 64 walk(*layoutView, localContext); |
| 54 | 65 |
| 55 #if DCHECK_IS_ON() | 66 #if DCHECK_IS_ON() |
| 56 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) | 67 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 57 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags(); | 68 frameView.layoutView()->assertSubtreeClearedPaintInvalidationFlags(); |
| 58 #endif | 69 #endif |
| 70 | |
| 71 frameView.setPaintPropertiesValid(); | |
| 59 } | 72 } |
| 60 | 73 |
| 61 void PrePaintTreeWalk::walk(const LayoutObject& object, | 74 void PrePaintTreeWalk::walk(const LayoutObject& object, |
| 62 const PrePaintTreeWalkContext& context) { | 75 const PrePaintTreeWalkContext& context) { |
| 63 PrePaintTreeWalkContext localContext(context); | 76 PrePaintTreeWalkContext localContext(context); |
| 64 | 77 |
| 78 // Check whether we need to rebuild the paint property trees. | |
| 79 if (!localContext.needToRebuildPaintPropertyTrees) { | |
|
chrishtr
2016/10/21 22:03:09
Perhaps add a TODO somewhere about unifying the pa
| |
| 80 if (context.paintInvalidatorContext.forcedSubtreeInvalidationFlags || | |
| 81 !object.paintPropertiesValid() || | |
| 82 object | |
| 83 .shouldCheckForPaintInvalidationRegardlessOfPaintInvalidationState() ) | |
| 84 localContext.needToRebuildPaintPropertyTrees = true; | |
| 85 } | |
| 86 if (localContext.needToRebuildPaintPropertyTrees) | |
| 87 object.getMutableForPainting().setPaintPropertiesInvalid(); | |
| 88 | |
| 89 // TODO(pdr): Ensure multi column works with incremental property tree | |
| 90 // construction. | |
| 65 if (object.isLayoutMultiColumnSpannerPlaceholder()) { | 91 if (object.isLayoutMultiColumnSpannerPlaceholder()) { |
| 66 // Walk multi-column spanner as if it replaces the placeholder. | 92 // Walk multi-column spanner as if it replaces the placeholder. |
| 67 // Set the flag so that the tree builder can specially handle out-of-flow | 93 // Set the flag so that the tree builder can specially handle out-of-flow |
| 68 // positioned descendants if their containers are between the multi-column | 94 // positioned descendants if their containers are between the multi-column |
| 69 // container and the spanner. See PaintPropertyTreeBuilder for details. | 95 // container and the spanner. See PaintPropertyTreeBuilder for details. |
| 70 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; | 96 localContext.treeBuilderContext.isUnderMultiColumnSpanner = true; |
| 71 object.getMutableForPainting().clearPaintInvalidationFlags(); | 97 object.getMutableForPainting().clearPaintInvalidationFlags(); |
| 72 walk(*toLayoutMultiColumnSpannerPlaceholder(object) | 98 walk(*toLayoutMultiColumnSpannerPlaceholder(object) |
| 73 .layoutObjectInFlowThread(), | 99 .layoutObjectInFlowThread(), |
| 74 localContext); | 100 localContext); |
| 75 return; | 101 return; |
| 76 } | 102 } |
| 77 | 103 |
| 78 m_propertyTreeBuilder.buildTreeNodesForSelf(object, | 104 m_propertyTreeBuilder.updatePropertiesForSelf( |
| 79 localContext.treeBuilderContext); | 105 object, localContext.treeBuilderContext); |
| 106 | |
| 80 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) | 107 if (RuntimeEnabledFeatures::slimmingPaintInvalidationEnabled()) |
| 81 m_paintInvalidator.invalidatePaintIfNeeded( | 108 m_paintInvalidator.invalidatePaintIfNeeded( |
| 82 object, localContext.paintInvalidatorContext); | 109 object, localContext.paintInvalidatorContext); |
| 83 m_propertyTreeBuilder.buildTreeNodesForChildren( | 110 |
| 111 m_propertyTreeBuilder.updatePropertiesForChildren( | |
| 84 object, localContext.treeBuilderContext); | 112 object, localContext.treeBuilderContext); |
| 85 | 113 |
| 86 for (const LayoutObject* child = object.slowFirstChild(); child; | 114 for (const LayoutObject* child = object.slowFirstChild(); child; |
| 87 child = child->nextSibling()) { | 115 child = child->nextSibling()) { |
| 88 // Column spanners are walked through their placeholders. See above. | 116 // Column spanners are walked through their placeholders. See above. |
| 89 if (child->isColumnSpanAll()) | 117 if (child->isColumnSpanAll()) |
| 90 continue; | 118 continue; |
| 91 walk(*child, localContext); | 119 walk(*child, localContext); |
| 92 } | 120 } |
| 93 | 121 |
| 94 if (object.isLayoutPart()) { | 122 if (object.isLayoutPart()) { |
| 95 const LayoutPart& layoutPart = toLayoutPart(object); | 123 const LayoutPart& layoutPart = toLayoutPart(object); |
| 96 Widget* widget = layoutPart.widget(); | 124 Widget* widget = layoutPart.widget(); |
| 97 if (widget && widget->isFrameView()) { | 125 if (widget && widget->isFrameView()) { |
| 98 localContext.treeBuilderContext.current.paintOffset += | 126 localContext.treeBuilderContext.current.paintOffset += |
| 99 layoutPart.replacedContentRect().location() - | 127 layoutPart.replacedContentRect().location() - |
| 100 widget->frameRect().location(); | 128 widget->frameRect().location(); |
| 101 localContext.treeBuilderContext.current.paintOffset = | 129 localContext.treeBuilderContext.current.paintOffset = |
| 102 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); | 130 roundedIntPoint(localContext.treeBuilderContext.current.paintOffset); |
| 103 walk(*toFrameView(widget), localContext); | 131 walk(*toFrameView(widget), localContext); |
| 104 } | 132 } |
| 105 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). | 133 // TODO(pdr): Investigate RemoteFrameView (crbug.com/579281). |
| 106 } | 134 } |
| 135 | |
| 136 object.getMutableForPainting().setPaintPropertiesValid(); | |
| 107 } | 137 } |
| 108 | 138 |
| 109 } // namespace blink | 139 } // namespace blink |
| OLD | NEW |