Skip to content

Commit db8f4a6

Browse files
author
shawnsingh@chromium.org
committedOct 8, 2013
Make compositingState explicit (re-land #2 with bogus ASSERT removed)
A lot of code uses isComposited() and compositedLayerMapping() as booleans to check the compositing state of a RenderLayer or RenderObject. However, in the code there are actually 3 different states: (1) not composited (paints into CompositedLayerMapping of a composited ancestor) (2) paints into own CompositedLayerMapping (3) has its own CompositedLayerMapping but actually still paints into composited ancestor. Furthermore, upcoming changes to compositing will add a fourth state: (4) paints into a GraphicsLayer that is shared by a group of layers. This patch removes isComposited() boolean check, and replaces it with compositingState() that returns an enum. Most call sites outside of RenderLayer, CompositedLayerMapping, and RenderLayerCompositor have been updated to reflect what states they really intended to check for. Remaining call sites have been replaced with the compositedLayerMapping() accessor for now, which is exactly equivalent to the old isComposited() boolean, and those sites will be updated in follow-up patches. BUG=261605 R=jamesr@chromium.org, jchaffraix@chromium.org, vollick@chromium.org Review URL: https://codereview.chromium.org/24921002 git-svn-id: svn://svn.chromium.org/blink/trunk@159118 bbb929c8-8fbe-4397-9dbb-9b2b20218538
1 parent b6d574a commit db8f4a6

24 files changed

+192
-118
lines changed
 

‎Source/core/css/CSSComputedStyleDeclaration.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,8 @@ PassRefPtr<RenderStyle> CSSComputedStyleDeclaration::computeRenderStyle(CSSPrope
16161616
Node* styledNode = this->styledNode();
16171617
ASSERT(styledNode);
16181618
RenderObject* renderer = styledNode->renderer();
1619-
if (renderer && renderer->isComposited() && !RuntimeEnabledFeatures::webAnimationsCSSEnabled() && AnimationController::supportsAcceleratedAnimationOfProperty(propertyID)) {
1619+
if (renderer && renderer->compositingState() == PaintsIntoOwnBacking
1620+
&& !RuntimeEnabledFeatures::webAnimationsCSSEnabled() && AnimationController::supportsAcceleratedAnimationOfProperty(propertyID)) {
16201621
AnimationUpdateBlock animationUpdateBlock(renderer->animation());
16211622
if (m_pseudoElementSpecifier && !styledNode->isPseudoElement()) {
16221623
// FIXME: This cached pseudo style will only exist if the animation has been run at least once.

‎Source/core/inspector/InspectorLayerTreeAgent.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void InspectorLayerTreeAgent::getLayers(ErrorString* errorString, const int* nod
204204

205205
void InspectorLayerTreeAgent::buildLayerIdToNodeIdMap(ErrorString* errorString, RenderLayer* root, LayerIdToNodeIdMap& layerIdToNodeIdMap)
206206
{
207-
if (root->isComposited()) {
207+
if (root->compositedLayerMapping()) {
208208
if (Node* node = root->renderer()->generatingNode()) {
209209
GraphicsLayer* graphicsLayer = root->compositedLayerMapping()->childForSuperlayers();
210210
layerIdToNodeIdMap.set(graphicsLayer->platformLayer()->id(), idForNode(errorString, node));

‎Source/core/page/FrameView.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ void FrameView::updateCanBlitOnScrollRecursively()
12551255
bool FrameView::contentsInCompositedLayer() const
12561256
{
12571257
RenderView* renderView = this->renderView();
1258-
if (renderView && renderView->isComposited()) {
1258+
if (renderView && renderView->compositingState() == PaintsIntoOwnBacking) {
12591259
GraphicsLayer* layer = renderView->layer()->compositedLayerMapping()->mainGraphicsLayer();
12601260
if (layer && layer->drawsContent())
12611261
return true;
@@ -1372,10 +1372,10 @@ bool FrameView::scrollContentsFastPath(const IntSize& scrollDelta, const IntRect
13721372
ASSERT(renderer->hasLayer());
13731373
RenderLayer* layer = toRenderBoxModelObject(renderer)->layer();
13741374

1375-
// Composited layers may still actually paint into their ancestor.
1376-
// If that happens, the viewport constrained object needs to be
1377-
// repainted on scroll.
1378-
if (layer->isComposited() && !layer->compositedLayerMapping()->paintsIntoCompositedAncestor())
1375+
// Layers that paint into their ancestor or into a grouped backing will still need
1376+
// to apply a repaint invalidation. If the layer paints into its own backing, then
1377+
// it does not need repainting just to scroll.
1378+
if (layer->compositingState() == PaintsIntoOwnBacking)
13791379
continue;
13801380

13811381
if (layer->viewportConstrainedNotCompositedReason() == RenderLayer::NotCompositedForBoundsOutOfView

‎Source/core/page/animation/AnimationBase.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,9 @@ void AnimationBase::freezeAtTime(double t)
555555
else
556556
m_pauseTime = m_startTime + t - m_animation->delay();
557557

558-
// It is possible that m_isAccelerated is true and m_object->isComposited() is false, because of style change.
559-
if (m_object && m_object->isComposited() && isAccelerated())
558+
// It is possible that m_isAccelerated is true and m_object->compositingState() is NotComposited, because of style change.
559+
// So, both conditions need to be checked.
560+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking && isAccelerated())
560561
toRenderBoxModelObject(m_object)->suspendAnimations(m_pauseTime);
561562
}
562563

‎Source/core/page/animation/ImplicitAnimation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ void ImplicitAnimation::getAnimatedStyle(RefPtr<RenderStyle>& animatedStyle)
104104

105105
void ImplicitAnimation::startAnimation(double timeOffset)
106106
{
107-
if (m_object && m_object->isComposited())
107+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking)
108108
m_isAccelerated = toRenderBoxModelObject(m_object)->startTransition(timeOffset, m_animatingProperty, m_fromStyle.get(), m_toStyle.get());
109109
}
110110

@@ -113,7 +113,7 @@ void ImplicitAnimation::pauseAnimation(double timeOffset)
113113
if (!m_object)
114114
return;
115115

116-
if (m_object && m_object->isComposited() && isAccelerated())
116+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking && isAccelerated())
117117
toRenderBoxModelObject(m_object)->transitionPaused(timeOffset, m_animatingProperty);
118118

119119
// Restore the original (unanimated) style
@@ -123,7 +123,7 @@ void ImplicitAnimation::pauseAnimation(double timeOffset)
123123

124124
void ImplicitAnimation::endAnimation()
125125
{
126-
if (m_object && m_object->isComposited() && isAccelerated())
126+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking && isAccelerated())
127127
toRenderBoxModelObject(m_object)->transitionFinished(m_animatingProperty);
128128
m_isAccelerated = false;
129129
}

‎Source/core/page/animation/KeyframeAnimation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ bool KeyframeAnimation::hasAnimationForProperty(CSSPropertyID property) const
239239

240240
void KeyframeAnimation::startAnimation(double timeOffset)
241241
{
242-
if (m_object && m_object->isComposited())
242+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking)
243243
m_isAccelerated = toRenderBoxModelObject(m_object)->startAnimation(timeOffset, m_animation.get(), m_keyframes);
244244
}
245245

@@ -248,7 +248,7 @@ void KeyframeAnimation::pauseAnimation(double timeOffset)
248248
if (!m_object)
249249
return;
250250

251-
if (m_object && m_object->isComposited() && isAccelerated())
251+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking && isAccelerated())
252252
toRenderBoxModelObject(m_object)->animationPaused(timeOffset, m_keyframes.animationName());
253253

254254
// Restore the original (unanimated) style
@@ -261,7 +261,7 @@ void KeyframeAnimation::endAnimation()
261261
if (!m_object)
262262
return;
263263

264-
if (m_object && m_object->isComposited() && isAccelerated())
264+
if (m_object && m_object->compositingState() == PaintsIntoOwnBacking && isAccelerated())
265265
toRenderBoxModelObject(m_object)->animationFinished(m_keyframes.animationName());
266266
m_isAccelerated = false;
267267

‎Source/core/page/scrolling/ScrollingCoordinator.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static void clearPositionConstraintExceptForLayer(GraphicsLayer* layer, Graphics
159159

160160
static WebLayerPositionConstraint computePositionConstraint(const RenderLayer* layer)
161161
{
162-
ASSERT(layer->isComposited());
162+
ASSERT(layer->compositedLayerMapping());
163163
do {
164164
if (layer->renderer()->style()->position() == FixedPosition) {
165165
const RenderObject* fixedPositionObject = layer->renderer();
@@ -169,7 +169,10 @@ static WebLayerPositionConstraint computePositionConstraint(const RenderLayer* l
169169
}
170170

171171
layer = layer->parent();
172-
} while (layer && !layer->isComposited());
172+
173+
// Composited layers that inherit a fixed position state will be positioned with respect to the nearest compositedLayerMapping's GraphicsLayer.
174+
// So, once we find a layer that has its own compositedLayerMapping, we can stop searching for a fixed position RenderObject.
175+
} while (layer && layer->compositedLayerMapping());
173176
return WebLayerPositionConstraint();
174177
}
175178

@@ -806,12 +809,12 @@ bool ScrollingCoordinator::hasVisibleSlowRepaintViewportConstrainedObjects(Frame
806809
return true;
807810
RenderLayer* layer = toRenderBoxModelObject(viewportConstrainedObject)->layer();
808811
// Any explicit reason that a fixed position element is not composited shouldn't cause slow scrolling.
809-
if (!layer->isComposited() && layer->viewportConstrainedNotCompositedReason() == RenderLayer::NoNotCompositedReason)
812+
if (layer->compositingState() != PaintsIntoOwnBacking && layer->viewportConstrainedNotCompositedReason() == RenderLayer::NoNotCompositedReason)
810813
return true;
811814

812815
// Composited layers that actually paint into their enclosing ancestor
813816
// must also force main thread scrolling.
814-
if (layer->isComposited() && layer->compositedLayerMapping()->paintsIntoCompositedAncestor())
817+
if (layer->compositingState() == HasOwnBackingButPaintsIntoAncestor)
815818
return true;
816819
}
817820
return false;

‎Source/core/rendering/CompositedLayerMapping.cpp

+17-8
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ void CompositedLayerMapping::updateGraphicsLayerGeometry()
696696
m_backgroundLayer->setOffsetFromRenderer(m_graphicsLayer->offsetFromRenderer());
697697
}
698698

699-
if (m_owningLayer->reflectionLayer() && m_owningLayer->reflectionLayer()->isComposited()) {
699+
if (m_owningLayer->reflectionLayer() && m_owningLayer->reflectionLayer()->compositedLayerMapping()) {
700700
CompositedLayerMapping* reflectionCompositedLayerMapping = m_owningLayer->reflectionLayer()->compositedLayerMapping();
701701
reflectionCompositedLayerMapping->updateGraphicsLayerGeometry();
702702

@@ -1197,9 +1197,16 @@ float CompositedLayerMapping::compositingOpacity(float rendererOpacity) const
11971197
if (!curr->isStackingContainer())
11981198
continue;
11991199

1200-
// If we found a compositing layer, we want to compute opacity
1201-
// relative to it. So we can break here.
1202-
if (curr->isComposited())
1200+
// If we found a composited layer, regardless of whether it actually
1201+
// paints into it, we want to compute opacity relative to it. So we can
1202+
// break here.
1203+
//
1204+
// FIXME: with grouped backings, a composited descendant will have to
1205+
// continue past the grouped (squashed) layers that its parents may
1206+
// contribute to. This whole confusion can be avoided by specifying
1207+
// explicitly the composited ancestor where we would stop accumulating
1208+
// opacity.
1209+
if (curr->compositingState() == PaintsIntoOwnBacking || curr->compositingState() == HasOwnBackingButPaintsIntoAncestor)
12031210
break;
12041211

12051212
finalOpacity *= curr->renderer()->opacity();
@@ -1337,7 +1344,7 @@ static bool hasVisibleNonCompositingDescendant(RenderLayer* parent)
13371344
size_t listSize = normalFlowList->size();
13381345
for (size_t i = 0; i < listSize; ++i) {
13391346
RenderLayer* curLayer = normalFlowList->at(i);
1340-
if (!curLayer->isComposited()
1347+
if (!curLayer->compositedLayerMapping()
13411348
&& (curLayer->hasVisibleContent() || hasVisibleNonCompositingDescendant(curLayer)))
13421349
return true;
13431350
}
@@ -1352,7 +1359,7 @@ static bool hasVisibleNonCompositingDescendant(RenderLayer* parent)
13521359
size_t listSize = negZOrderList->size();
13531360
for (size_t i = 0; i < listSize; ++i) {
13541361
RenderLayer* curLayer = negZOrderList->at(i);
1355-
if (!curLayer->isComposited()
1362+
if (!curLayer->compositedLayerMapping()
13561363
&& (curLayer->hasVisibleContent() || hasVisibleNonCompositingDescendant(curLayer)))
13571364
return true;
13581365
}
@@ -1362,7 +1369,7 @@ static bool hasVisibleNonCompositingDescendant(RenderLayer* parent)
13621369
size_t listSize = posZOrderList->size();
13631370
for (size_t i = 0; i < listSize; ++i) {
13641371
RenderLayer* curLayer = posZOrderList->at(i);
1365-
if (!curLayer->isComposited()
1372+
if (!curLayer->compositedLayerMapping()
13661373
&& (curLayer->hasVisibleContent() || hasVisibleNonCompositingDescendant(curLayer)))
13671374
return true;
13681375
}
@@ -1372,7 +1379,9 @@ static bool hasVisibleNonCompositingDescendant(RenderLayer* parent)
13721379
return false;
13731380
}
13741381

1375-
// Conservative test for having no rendered children.
1382+
// FIXME: By name the implementation is correct. But the code that uses this function means something
1383+
// very slightly different - the implementation needs to also include composited descendants that
1384+
// don't paint into their own backing, and instead paint into this backing.
13761385
bool CompositedLayerMapping::hasVisibleNonCompositingDescendantLayers() const
13771386
{
13781387
return hasVisibleNonCompositingDescendant(m_owningLayer);
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2013 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef CompositingState_h
6+
#define CompositingState_h
7+
8+
namespace WebCore {
9+
10+
enum CompositingState {
11+
// The layer paints into its enclosing composited ancestor.
12+
NotComposited = 0,
13+
14+
// The layer is composited, but its contents still paint into enclosing composited ancestor.
15+
// In this state, repaint invalidations must be sent to the enclosing composited ancestor.
16+
// Typically this happens when a layer's properties need to be represented in the compositor
17+
// output data structures, but it doesn't actually have any other reasons to be composited.
18+
HasOwnBackingButPaintsIntoAncestor = 1,
19+
20+
PaintsIntoOwnBacking = 2,
21+
};
22+
23+
} // namespace WebCore
24+
25+
#endif // CompositingState_h

‎Source/core/rendering/RenderBox.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,8 @@ static bool isCandidateForOpaquenessTest(RenderBox* childBox)
12571257
if (!childBox->width() || !childBox->height())
12581258
return false;
12591259
if (RenderLayer* childLayer = childBox->layer()) {
1260-
if (childLayer->isComposited())
1260+
// FIXME: perhaps this could be less conservative?
1261+
if (childLayer->compositingState() != NotComposited)
12611262
return false;
12621263
// FIXME: Deal with z-index.
12631264
if (!childStyle->hasAutoZIndex())
@@ -1352,9 +1353,13 @@ void RenderBox::paintClippingMask(PaintInfo& paintInfo, const LayoutPoint& paint
13521353
if (!paintInfo.shouldPaintWithinRoot(this) || style()->visibility() != VISIBLE || paintInfo.phase != PaintPhaseClippingMask || paintInfo.context->paintingDisabled())
13531354
return;
13541355

1355-
if (!layer() || !layer()->isComposited())
1356+
if (!layer() || layer()->compositingState() != PaintsIntoOwnBacking)
13561357
return;
13571358

1359+
// We should never have this state in this function. A layer with a mask
1360+
// should have always created its own backing if it became composited.
1361+
ASSERT(layer()->compositingState() != HasOwnBackingButPaintsIntoAncestor);
1362+
13581363
LayoutRect paintRect = LayoutRect(paintOffset, size());
13591364
paintInfo.context->fillRect(pixelSnappedIntRect(paintRect), Color::black);
13601365
}

‎Source/core/rendering/RenderBoxModelObject.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -102,49 +102,49 @@ bool RenderBoxModelObject::hasAcceleratedCompositing() const
102102
bool RenderBoxModelObject::startTransition(double timeOffset, CSSPropertyID propertyId, const RenderStyle* fromStyle, const RenderStyle* toStyle)
103103
{
104104
ASSERT(hasLayer());
105-
ASSERT(isComposited());
105+
ASSERT(compositingState() == PaintsIntoOwnBacking);
106106
return layer()->compositedLayerMapping()->startTransition(timeOffset, propertyId, fromStyle, toStyle);
107107
}
108108

109109
void RenderBoxModelObject::transitionPaused(double timeOffset, CSSPropertyID propertyId)
110110
{
111111
ASSERT(hasLayer());
112-
ASSERT(isComposited());
112+
ASSERT(compositingState() == PaintsIntoOwnBacking);
113113
layer()->compositedLayerMapping()->transitionPaused(timeOffset, propertyId);
114114
}
115115

116116
void RenderBoxModelObject::transitionFinished(CSSPropertyID propertyId)
117117
{
118118
ASSERT(hasLayer());
119-
ASSERT(isComposited());
119+
ASSERT(compositingState() == PaintsIntoOwnBacking);
120120
layer()->compositedLayerMapping()->transitionFinished(propertyId);
121121
}
122122

123123
bool RenderBoxModelObject::startAnimation(double timeOffset, const CSSAnimationData* animation, const KeyframeList& keyframes)
124124
{
125125
ASSERT(hasLayer());
126-
ASSERT(isComposited());
126+
ASSERT(compositingState() == PaintsIntoOwnBacking);
127127
return layer()->compositedLayerMapping()->startAnimation(timeOffset, animation, keyframes);
128128
}
129129

130130
void RenderBoxModelObject::animationPaused(double timeOffset, const String& name)
131131
{
132132
ASSERT(hasLayer());
133-
ASSERT(isComposited());
133+
ASSERT(compositingState() == PaintsIntoOwnBacking);
134134
layer()->compositedLayerMapping()->animationPaused(timeOffset, name);
135135
}
136136

137137
void RenderBoxModelObject::animationFinished(const String& name)
138138
{
139139
ASSERT(hasLayer());
140-
ASSERT(isComposited());
140+
ASSERT(compositingState() == PaintsIntoOwnBacking);
141141
layer()->compositedLayerMapping()->animationFinished(name);
142142
}
143143

144144
void RenderBoxModelObject::suspendAnimations(double time)
145145
{
146146
ASSERT(hasLayer());
147-
ASSERT(isComposited());
147+
ASSERT(compositingState() == PaintsIntoOwnBacking);
148148
layer()->compositedLayerMapping()->suspendAnimations(time);
149149
}
150150

@@ -985,7 +985,7 @@ bool RenderBoxModelObject::fixedBackgroundPaintsInLocalCoordinates() const
985985
return false;
986986

987987
RenderLayer* rootLayer = view()->layer();
988-
if (!rootLayer || !rootLayer->isComposited())
988+
if (!rootLayer || rootLayer->compositingState() == NotComposited)
989989
return false;
990990

991991
return rootLayer->compositedLayerMapping()->backgroundLayerPaintsFixedRootBackground();

0 commit comments

Comments
 (0)
Please sign in to comment.