| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/layout/compositing/CompositingReasonFinder.h" | 5 #include "core/layout/compositing/CompositingReasonFinder.h" |
| 6 | 6 |
| 7 #include "core/CSSPropertyNames.h" | 7 #include "core/CSSPropertyNames.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/FrameView.h" | 9 #include "core/frame/FrameView.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 return false; | 59 return false; |
| 60 | 60 |
| 61 if (!(m_compositingTriggers & ScrollableInnerFrameTrigger)) | 61 if (!(m_compositingTriggers & ScrollableInnerFrameTrigger)) |
| 62 return false; | 62 return false; |
| 63 | 63 |
| 64 return m_layoutView.frameView()->isScrollable(); | 64 return m_layoutView.frameView()->isScrollable(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 CompositingReasons | 67 CompositingReasons |
| 68 CompositingReasonFinder::potentialCompositingReasonsFromStyle( | 68 CompositingReasonFinder::potentialCompositingReasonsFromStyle( |
| 69 LayoutObject* layoutObject) const { | 69 LayoutObject& layoutObject) const { |
| 70 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) | 70 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) |
| 71 return CompositingReasonNone; | 71 return CompositingReasonNone; |
| 72 | 72 |
| 73 CompositingReasons reasons = CompositingReasonNone; | 73 CompositingReasons reasons = CompositingReasonNone; |
| 74 | 74 |
| 75 const ComputedStyle& style = layoutObject->styleRef(); | 75 const ComputedStyle& style = layoutObject.styleRef(); |
| 76 | 76 |
| 77 if (requiresCompositingForTransform(*layoutObject)) | 77 if (requiresCompositingForTransform(layoutObject)) |
| 78 reasons |= CompositingReason3DTransform; | 78 reasons |= CompositingReason3DTransform; |
| 79 | 79 |
| 80 if (style.backfaceVisibility() == BackfaceVisibilityHidden) | 80 if (style.backfaceVisibility() == BackfaceVisibilityHidden) |
| 81 reasons |= CompositingReasonBackfaceVisibilityHidden; | 81 reasons |= CompositingReasonBackfaceVisibilityHidden; |
| 82 | 82 |
| 83 if (requiresCompositingForAnimation(style)) | 83 if (requiresCompositingForAnimation(style)) |
| 84 reasons |= CompositingReasonActiveAnimation; | 84 reasons |= CompositingReasonActiveAnimation; |
| 85 | 85 |
| 86 if (style.hasWillChangeCompositingHint() && | 86 if (style.hasWillChangeCompositingHint() && |
| 87 !style.subtreeWillChangeContents()) | 87 !style.subtreeWillChangeContents()) |
| 88 reasons |= CompositingReasonWillChangeCompositingHint; | 88 reasons |= CompositingReasonWillChangeCompositingHint; |
| 89 | 89 |
| 90 if (style.hasInlineTransform()) | 90 if (style.hasInlineTransform()) |
| 91 reasons |= CompositingReasonInlineTransform; | 91 reasons |= CompositingReasonInlineTransform; |
| 92 | 92 |
| 93 if (style.usedTransformStyle3D() == TransformStyle3DPreserve3D) | 93 if (style.usedTransformStyle3D() == TransformStyle3DPreserve3D) |
| 94 reasons |= CompositingReasonPreserve3DWith3DDescendants; | 94 reasons |= CompositingReasonPreserve3DWith3DDescendants; |
| 95 | 95 |
| 96 if (style.hasPerspective()) | 96 if (style.hasPerspective()) |
| 97 reasons |= CompositingReasonPerspectiveWith3DDescendants; | 97 reasons |= CompositingReasonPerspectiveWith3DDescendants; |
| 98 | 98 |
| 99 if (style.hasCompositorProxy()) | 99 if (style.hasCompositorProxy()) |
| 100 reasons |= CompositingReasonCompositorProxy; | 100 reasons |= CompositingReasonCompositorProxy; |
| 101 | 101 |
| 102 // If the implementation of createsGroup changes, we need to be aware of that | 102 // If the implementation of createsGroup changes, we need to be aware of that |
| 103 // in this part of code. | 103 // in this part of code. |
| 104 DCHECK((layoutObject->isTransparent() || layoutObject->hasMask() || | 104 DCHECK((layoutObject.isTransparent() || layoutObject.hasMask() || |
| 105 layoutObject->hasFilterInducingProperty() || style.hasBlendMode()) == | 105 layoutObject.hasFilterInducingProperty() || style.hasBlendMode()) == |
| 106 layoutObject->createsGroup()); | 106 layoutObject.createsGroup()); |
| 107 | 107 |
| 108 if (style.hasMask()) | 108 if (style.hasMask()) |
| 109 reasons |= CompositingReasonMaskWithCompositedDescendants; | 109 reasons |= CompositingReasonMaskWithCompositedDescendants; |
| 110 | 110 |
| 111 if (style.hasFilterInducingProperty()) | 111 if (style.hasFilterInducingProperty()) |
| 112 reasons |= CompositingReasonFilterWithCompositedDescendants; | 112 reasons |= CompositingReasonFilterWithCompositedDescendants; |
| 113 | 113 |
| 114 if (style.hasBackdropFilter()) | 114 if (style.hasBackdropFilter()) |
| 115 reasons |= CompositingReasonBackdropFilter; | 115 reasons |= CompositingReasonBackdropFilter; |
| 116 | 116 |
| 117 // See Layer::updateTransform for an explanation of why we check both. | 117 // See Layer::updateTransform for an explanation of why we check both. |
| 118 if (layoutObject->hasTransformRelatedProperty() && style.hasTransform()) | 118 if (layoutObject.hasTransformRelatedProperty() && style.hasTransform()) |
| 119 reasons |= CompositingReasonTransformWithCompositedDescendants; | 119 reasons |= CompositingReasonTransformWithCompositedDescendants; |
| 120 | 120 |
| 121 if (layoutObject->isTransparent()) | 121 if (layoutObject.isTransparent()) |
| 122 reasons |= CompositingReasonOpacityWithCompositedDescendants; | 122 reasons |= CompositingReasonOpacityWithCompositedDescendants; |
| 123 | 123 |
| 124 if (style.hasBlendMode()) | 124 if (style.hasBlendMode()) |
| 125 reasons |= CompositingReasonBlendingWithCompositedDescendants; | 125 reasons |= CompositingReasonBlendingWithCompositedDescendants; |
| 126 | 126 |
| 127 if (layoutObject->hasReflection()) | 127 if (layoutObject.hasReflection()) |
| 128 reasons |= CompositingReasonReflectionWithCompositedDescendants; | 128 reasons |= CompositingReasonReflectionWithCompositedDescendants; |
| 129 | 129 |
| 130 DCHECK(!(reasons & ~CompositingReasonComboAllStyleDeterminedReasons)); | 130 DCHECK(!(reasons & ~CompositingReasonComboAllStyleDeterminedReasons)); |
| 131 return reasons; | 131 return reasons; |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool CompositingReasonFinder::requiresCompositingForTransform( | 134 bool CompositingReasonFinder::requiresCompositingForTransform( |
| 135 const LayoutObject& layoutObject) { | 135 const LayoutObject& layoutObject) { |
| 136 // Note that we ask the layoutObject if it has a transform, because the style | 136 // Note that we ask the layoutObject if it has a transform, because the style |
| 137 // may have transforms, but the layoutObject may be an inline that doesn't | 137 // may have transforms, but the layoutObject may be an inline that doesn't |
| 138 // support them. | 138 // support them. |
| 139 return layoutObject.hasTransformRelatedProperty() && | 139 return layoutObject.hasTransformRelatedProperty() && |
| 140 layoutObject.styleRef().has3DTransform(); | 140 layoutObject.styleRef().has3DTransform(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons( | 143 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons( |
| 144 const PaintLayer* layer) const { | 144 const PaintLayer* layer) const { |
| 145 CompositingReasons directReasons = CompositingReasonNone; | 145 CompositingReasons directReasons = CompositingReasonNone; |
| 146 LayoutObject* layoutObject = layer->layoutObject(); | 146 LayoutObject& layoutObject = layer->layoutObject(); |
| 147 | 147 |
| 148 if (m_compositingTriggers & OverflowScrollTrigger && layer->clipParent()) | 148 if (m_compositingTriggers & OverflowScrollTrigger && layer->clipParent()) |
| 149 directReasons |= CompositingReasonOutOfFlowClipping; | 149 directReasons |= CompositingReasonOutOfFlowClipping; |
| 150 | 150 |
| 151 if (layer->needsCompositedScrolling()) | 151 if (layer->needsCompositedScrolling()) |
| 152 directReasons |= CompositingReasonOverflowScrollingTouch; | 152 directReasons |= CompositingReasonOverflowScrollingTouch; |
| 153 | 153 |
| 154 // Composite |layer| if it is inside of an ancestor scrolling layer, but that | 154 // Composite |layer| if it is inside of an ancestor scrolling layer, but that |
| 155 // scrolling layer is not on the stacking context ancestor chain of |layer|. | 155 // scrolling layer is not on the stacking context ancestor chain of |layer|. |
| 156 // See the definition of the scrollParent property in Layer for more detail. | 156 // See the definition of the scrollParent property in Layer for more detail. |
| 157 if (const PaintLayer* scrollingAncestor = layer->ancestorScrollingLayer()) { | 157 if (const PaintLayer* scrollingAncestor = layer->ancestorScrollingLayer()) { |
| 158 if (scrollingAncestor->needsCompositedScrolling() && layer->scrollParent()) | 158 if (scrollingAncestor->needsCompositedScrolling() && layer->scrollParent()) |
| 159 directReasons |= CompositingReasonOverflowScrollingParent; | 159 directReasons |= CompositingReasonOverflowScrollingParent; |
| 160 } | 160 } |
| 161 | 161 |
| 162 // TODO(flackr): Rename functions and variables to include sticky position | 162 // TODO(flackr): Rename functions and variables to include sticky position |
| 163 // (i.e. ScrollDependentPosition rather than PositionFixed). | 163 // (i.e. ScrollDependentPosition rather than PositionFixed). |
| 164 if (requiresCompositingForScrollDependentPosition(layer)) | 164 if (requiresCompositingForScrollDependentPosition(layer)) |
| 165 directReasons |= CompositingReasonScrollDependentPosition; | 165 directReasons |= CompositingReasonScrollDependentPosition; |
| 166 | 166 |
| 167 directReasons |= layoutObject->additionalCompositingReasons(); | 167 directReasons |= layoutObject.additionalCompositingReasons(); |
| 168 | 168 |
| 169 DCHECK(!(directReasons & CompositingReasonComboAllStyleDeterminedReasons)); | 169 DCHECK(!(directReasons & CompositingReasonComboAllStyleDeterminedReasons)); |
| 170 return directReasons; | 170 return directReasons; |
| 171 } | 171 } |
| 172 | 172 |
| 173 bool CompositingReasonFinder::requiresCompositingForAnimation( | 173 bool CompositingReasonFinder::requiresCompositingForAnimation( |
| 174 const ComputedStyle& style) { | 174 const ComputedStyle& style) { |
| 175 if (style.subtreeWillChangeContents()) | 175 if (style.subtreeWillChangeContents()) |
| 176 return style.isRunningAnimationOnCompositor(); | 176 return style.isRunningAnimationOnCompositor(); |
| 177 | 177 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 208 | 208 |
| 209 bool CompositingReasonFinder::requiresCompositingForTransformAnimation( | 209 bool CompositingReasonFinder::requiresCompositingForTransformAnimation( |
| 210 const ComputedStyle& style) { | 210 const ComputedStyle& style) { |
| 211 return style.subtreeWillChangeContents() | 211 return style.subtreeWillChangeContents() |
| 212 ? style.isRunningTransformAnimationOnCompositor() | 212 ? style.isRunningTransformAnimationOnCompositor() |
| 213 : style.hasCurrentTransformAnimation(); | 213 : style.hasCurrentTransformAnimation(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 bool CompositingReasonFinder::requiresCompositingForScrollDependentPosition( | 216 bool CompositingReasonFinder::requiresCompositingForScrollDependentPosition( |
| 217 const PaintLayer* layer) const { | 217 const PaintLayer* layer) const { |
| 218 if (layer->layoutObject()->style()->position() != EPosition::kFixed && | 218 if (layer->layoutObject().style()->position() != EPosition::kFixed && |
| 219 layer->layoutObject()->style()->position() != EPosition::kSticky) | 219 layer->layoutObject().style()->position() != EPosition::kSticky) |
| 220 return false; | 220 return false; |
| 221 | 221 |
| 222 if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger) && | 222 if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger) && |
| 223 (!RuntimeEnabledFeatures::compositeOpaqueFixedPositionEnabled() || | 223 (!RuntimeEnabledFeatures::compositeOpaqueFixedPositionEnabled() || |
| 224 !layer->backgroundIsKnownToBeOpaqueInRect( | 224 !layer->backgroundIsKnownToBeOpaqueInRect( |
| 225 LayoutRect(layer->boundingBoxForCompositing())) || | 225 LayoutRect(layer->boundingBoxForCompositing())) || |
| 226 layer->compositesWithTransform() || layer->compositesWithOpacity())) { | 226 layer->compositesWithTransform() || layer->compositesWithOpacity())) { |
| 227 return false; | 227 return false; |
| 228 } | 228 } |
| 229 // Don't promote fixed position elements that are descendants of a non-view | 229 // Don't promote fixed position elements that are descendants of a non-view |
| 230 // container, e.g. transformed elements. They will stay fixed wrt the | 230 // container, e.g. transformed elements. They will stay fixed wrt the |
| 231 // container rather than the enclosing frame. | 231 // container rather than the enclosing frame. |
| 232 if (layer->sticksToViewport()) | 232 if (layer->sticksToViewport()) |
| 233 return m_layoutView.frameView()->isScrollable(); | 233 return m_layoutView.frameView()->isScrollable(); |
| 234 return layer->layoutObject()->style()->position() == EPosition::kSticky && | 234 return layer->layoutObject().style()->position() == EPosition::kSticky && |
| 235 layer->ancestorOverflowLayer()->scrollsOverflow(); | 235 layer->ancestorOverflowLayer()->scrollsOverflow(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 } // namespace blink | 238 } // namespace blink |
| OLD | NEW |