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 "config.h" | 5 #include "config.h" |
6 #include "core/rendering/compositing/CompositingReasonFinder.h" | 6 #include "core/rendering/compositing/CompositingReasonFinder.h" |
7 | 7 |
8 #include "core/CSSPropertyNames.h" | 8 #include "core/CSSPropertyNames.h" |
9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 bool CompositingReasonFinder::isMainFrame() const | 42 bool CompositingReasonFinder::isMainFrame() const |
43 { | 43 { |
44 // FIXME: LocalFrame::isMainFrame() is probably better. | 44 // FIXME: LocalFrame::isMainFrame() is probably better. |
45 return !m_renderView.document().ownerElement(); | 45 return !m_renderView.document().ownerElement(); |
46 } | 46 } |
47 | 47 |
48 CompositingReasons CompositingReasonFinder::directReasons(const RenderLayer* lay
er) const | 48 CompositingReasons CompositingReasonFinder::directReasons(const RenderLayer* lay
er) const |
49 { | 49 { |
50 ASSERT(potentialCompositingReasonsFromStyle(layer->renderer()) == layer->pot
entialCompositingReasonsFromStyle()); | 50 ASSERT(potentialCompositingReasonsFromStyle(layer->renderer()) == layer->pot
entialCompositingReasonsFromStyle()); |
51 CompositingReasons styleDeterminedDirectCompositingReasons = layer->potentia
lCompositingReasonsFromStyle() & CompositingReasonComboAllDirectStyleDeterminedR
easons; | 51 CompositingReasons styleDeterminedDirectCompositingReasons = layer->potentia
lCompositingReasonsFromStyle() & CompositingReasonComboAllDirectStyleDeterminedR
easons; |
| 52 |
| 53 // Apply optimizations for scroll-blocks-on which require comparing style be
tween objects. |
| 54 if ((styleDeterminedDirectCompositingReasons & CompositingReasonScrollBlocks
On) && !requiresCompositingForScrollBlocksOn(layer->renderer())) |
| 55 styleDeterminedDirectCompositingReasons &= ~CompositingReasonScrollBlock
sOn; |
| 56 |
52 return styleDeterminedDirectCompositingReasons | nonStyleDeterminedDirectRea
sons(layer); | 57 return styleDeterminedDirectCompositingReasons | nonStyleDeterminedDirectRea
sons(layer); |
53 } | 58 } |
54 | 59 |
55 // This information doesn't appear to be incorporated into CompositingReasons. | 60 // This information doesn't appear to be incorporated into CompositingReasons. |
56 bool CompositingReasonFinder::requiresCompositingForScrollableFrame() const | 61 bool CompositingReasonFinder::requiresCompositingForScrollableFrame() const |
57 { | 62 { |
58 // Need this done first to determine overflow. | 63 // Need this done first to determine overflow. |
59 ASSERT(!m_renderView.needsLayout()); | 64 ASSERT(!m_renderView.needsLayout()); |
60 if (isMainFrame()) | 65 if (isMainFrame()) |
61 return false; | 66 return false; |
(...skipping 24 matching lines...) Expand all Loading... |
86 | 91 |
87 if (style->hasInlineTransform()) | 92 if (style->hasInlineTransform()) |
88 reasons |= CompositingReasonInlineTransform; | 93 reasons |= CompositingReasonInlineTransform; |
89 | 94 |
90 if (style->transformStyle3D() == TransformStyle3DPreserve3D) | 95 if (style->transformStyle3D() == TransformStyle3DPreserve3D) |
91 reasons |= CompositingReasonPreserve3DWith3DDescendants; | 96 reasons |= CompositingReasonPreserve3DWith3DDescendants; |
92 | 97 |
93 if (style->hasPerspective()) | 98 if (style->hasPerspective()) |
94 reasons |= CompositingReasonPerspectiveWith3DDescendants; | 99 reasons |= CompositingReasonPerspectiveWith3DDescendants; |
95 | 100 |
| 101 // Ignore scroll-blocks-on on the document element, because it will get prop
agated to |
| 102 // the RenderView (by Document::inheritHtmlAndBodyElementStyles) and we don'
t want to |
| 103 // create two composited layers. |
| 104 if (style->hasScrollBlocksOn() && !renderer->isDocumentElement()) |
| 105 reasons |= CompositingReasonScrollBlocksOn; |
| 106 |
96 // If the implementation of createsGroup changes, we need to be aware of tha
t in this part of code. | 107 // If the implementation of createsGroup changes, we need to be aware of tha
t in this part of code. |
97 ASSERT((renderer->isTransparent() || renderer->hasMask() || renderer->hasFil
ter() || style->hasBlendMode()) == renderer->createsGroup()); | 108 ASSERT((renderer->isTransparent() || renderer->hasMask() || renderer->hasFil
ter() || style->hasBlendMode()) == renderer->createsGroup()); |
98 | 109 |
99 if (style->hasMask()) | 110 if (style->hasMask()) |
100 reasons |= CompositingReasonMaskWithCompositedDescendants; | 111 reasons |= CompositingReasonMaskWithCompositedDescendants; |
101 | 112 |
102 if (style->hasFilter()) | 113 if (style->hasFilter()) |
103 reasons |= CompositingReasonFilterWithCompositedDescendants; | 114 reasons |= CompositingReasonFilterWithCompositedDescendants; |
104 | 115 |
105 // See RenderLayer::updateTransform for an explanation of why we check both. | 116 // See RenderLayer::updateTransform for an explanation of why we check both. |
106 if (renderer->hasTransformRelatedProperty() && style->hasTransform()) | 117 if (renderer->hasTransformRelatedProperty() && style->hasTransform()) |
107 reasons |= CompositingReasonTransformWithCompositedDescendants; | 118 reasons |= CompositingReasonTransformWithCompositedDescendants; |
108 | 119 |
109 if (renderer->isTransparent()) | 120 if (renderer->isTransparent()) |
110 reasons |= CompositingReasonOpacityWithCompositedDescendants; | 121 reasons |= CompositingReasonOpacityWithCompositedDescendants; |
111 | 122 |
112 if (style->hasBlendMode()) | 123 if (style->hasBlendMode()) |
113 reasons |= CompositingReasonBlendingWithCompositedDescendants; | 124 reasons |= CompositingReasonBlendingWithCompositedDescendants; |
114 | 125 |
115 if (renderer->hasReflection()) | 126 if (renderer->hasReflection()) |
116 reasons |= CompositingReasonReflectionWithCompositedDescendants; | 127 reasons |= CompositingReasonReflectionWithCompositedDescendants; |
117 | 128 |
118 ASSERT(!(reasons & ~CompositingReasonComboAllStyleDeterminedReasons)); | 129 ASSERT(!(reasons & ~CompositingReasonComboAllStyleDeterminedReasons)); |
119 return reasons; | 130 return reasons; |
120 } | 131 } |
121 | 132 |
122 bool CompositingReasonFinder::requiresCompositingForTransform(RenderObject* rend
erer) const | 133 bool CompositingReasonFinder::requiresCompositingForTransform(RenderObject* rend
erer) const |
123 { | 134 { |
124 // Note that we ask the renderer if it has a transform, because the style ma
y have transforms, | 135 // Note that we ask the renderer if it has a transform, because the style ma
y have transforms, |
125 // but the renderer may be an inline that doesn't suppport them. | 136 // but the renderer may be an inline that doesn't support them. |
126 return renderer->hasTransformRelatedProperty() && renderer->style()->transfo
rm().has3DOperation(); | 137 return renderer->hasTransformRelatedProperty() && renderer->style()->transfo
rm().has3DOperation(); |
127 } | 138 } |
128 | 139 |
129 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons(cons
t RenderLayer* layer) const | 140 CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons(cons
t RenderLayer* layer) const |
130 { | 141 { |
131 CompositingReasons directReasons = CompositingReasonNone; | 142 CompositingReasons directReasons = CompositingReasonNone; |
132 RenderObject* renderer = layer->renderer(); | 143 RenderObject* renderer = layer->renderer(); |
133 | 144 |
134 if (hasOverflowScrollTrigger()) { | 145 if (hasOverflowScrollTrigger()) { |
135 if (layer->clipParent()) | 146 if (layer->clipParent()) |
(...skipping 27 matching lines...) Expand all Loading... |
163 | 174 |
164 bool CompositingReasonFinder::requiresCompositingForPositionFixed(const RenderLa
yer* layer) const | 175 bool CompositingReasonFinder::requiresCompositingForPositionFixed(const RenderLa
yer* layer) const |
165 { | 176 { |
166 if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger)) | 177 if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger)) |
167 return false; | 178 return false; |
168 // Don't promote fixed position elements that are descendants of a non-view
container, e.g. transformed elements. | 179 // Don't promote fixed position elements that are descendants of a non-view
container, e.g. transformed elements. |
169 // They will stay fixed wrt the container rather than the enclosing frame. | 180 // They will stay fixed wrt the container rather than the enclosing frame. |
170 return layer->scrollsWithViewport() && m_renderView.frameView()->isScrollabl
e(); | 181 return layer->scrollsWithViewport() && m_renderView.frameView()->isScrollabl
e(); |
171 } | 182 } |
172 | 183 |
| 184 bool CompositingReasonFinder::requiresCompositingForScrollBlocksOn(const RenderO
bject* renderer) const |
| 185 { |
| 186 // Note that the other requires* functions run at RenderObject::styleDidChan
ge time and so can rely |
| 187 // only on the style of their object. This function runs at CompositingRequ
irementsUpdater::update |
| 188 // time, and so can consider the style of other objects. |
| 189 RenderStyle* style = renderer->style(); |
| 190 |
| 191 // We should only get here by CompositingReasonScrollBlocksOn being a potent
ial compositing reason. |
| 192 ASSERT(style->hasScrollBlocksOn() && !renderer->isDocumentElement()); |
| 193 |
| 194 // scroll-blocks-on style is propagated from the document element to the doc
ument. |
| 195 ASSERT(!renderer->isRenderView() |
| 196 || !renderer->document().documentElement() |
| 197 || !renderer->document().documentElement()->renderer() |
| 198 || renderer->document().documentElement()->renderer()->style()->scrollBl
ocksOn() == style->scrollBlocksOn()); |
| 199 |
| 200 // When a scroll occurs, it's the union of all bits set on the target elemen
t's containing block |
| 201 // chain that determines the behavior. Thus we really only need a new layer
if this object contains |
| 202 // additional bits from those set by all objects in it's containing block ch
ain. But determining |
| 203 // this fully is probably more expensive than it's worth. Instead we just h
ave fast-paths here for |
| 204 // the most common cases of unnecessary layer creation. |
| 205 // Optimizing this fully would avoid layer explosion in pathological cases l
ike '*' rules. |
| 206 // We could consider tracking the current state in CompositingRequirementsUp
dater::update. |
| 207 |
| 208 // Ensure iframes don't get composited when they require no more blocking th
an the root. |
| 209 if (renderer->isRenderView()) { |
| 210 if (const FrameView* parentFrame = toRenderView(renderer)->frameView()->
parentFrameView()) { |
| 211 if (const RenderView* parentRenderer = parentFrame->renderView()) { |
| 212 // Does this frame contain only blocks-on bits already present i
n the parent frame? |
| 213 if (!(style->scrollBlocksOn() & ~parentRenderer->style()->scroll
BlocksOn())) |
| 214 return false; |
| 215 } |
| 216 } |
| 217 } |
| 218 |
| 219 return true; |
173 } | 220 } |
| 221 |
| 222 } |
OLD | NEW |