File: CompositingReasonFinder.cpp

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (223 lines) | stat: -rw-r--r-- 8,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "core/layout/compositing/CompositingReasonFinder.h"

#include "core/CSSPropertyNames.h"
#include "core/dom/Document.h"
#include "core/frame/FrameView.h"
#include "core/frame/Settings.h"
#include "core/layout/LayoutView.h"
#include "core/page/Page.h"
#include "core/paint/PaintLayer.h"

namespace blink {

CompositingReasonFinder::CompositingReasonFinder(LayoutView& layoutView)
    : m_layoutView(layoutView),
      m_compositingTriggers(
          static_cast<CompositingTriggerFlags>(AllCompositingTriggers)) {
  updateTriggers();
}

void CompositingReasonFinder::updateTriggers() {
  m_compositingTriggers = 0;

  Settings& settings = m_layoutView.document().page()->settings();
  if (settings.getPreferCompositingToLCDTextEnabled()) {
    m_compositingTriggers |= ScrollableInnerFrameTrigger;
    m_compositingTriggers |= OverflowScrollTrigger;
    m_compositingTriggers |= ViewportConstrainedPositionedTrigger;
  }
}

bool CompositingReasonFinder::isMainFrame() const {
  return m_layoutView.document().isInMainFrame();
}

CompositingReasons CompositingReasonFinder::directReasons(
    const PaintLayer* layer) const {
  if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
    return CompositingReasonNone;

  DCHECK_EQ(potentialCompositingReasonsFromStyle(layer->layoutObject()),
            layer->potentialCompositingReasonsFromStyle());
  CompositingReasons styleDeterminedDirectCompositingReasons =
      layer->potentialCompositingReasonsFromStyle() &
      CompositingReasonComboAllDirectStyleDeterminedReasons;

  return styleDeterminedDirectCompositingReasons |
         nonStyleDeterminedDirectReasons(layer);
}

// This information doesn't appear to be incorporated into CompositingReasons.
bool CompositingReasonFinder::requiresCompositingForScrollableFrame() const {
  // Need this done first to determine overflow.
  DCHECK(!m_layoutView.needsLayout());
  if (isMainFrame())
    return false;

  if (!(m_compositingTriggers & ScrollableInnerFrameTrigger))
    return false;

  return m_layoutView.frameView()->isScrollable();
}

CompositingReasons
CompositingReasonFinder::potentialCompositingReasonsFromStyle(
    LayoutObject* layoutObject) const {
  if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
    return CompositingReasonNone;

  CompositingReasons reasons = CompositingReasonNone;

  const ComputedStyle& style = layoutObject->styleRef();

  if (requiresCompositingForTransform(*layoutObject))
    reasons |= CompositingReason3DTransform;

  if (style.backfaceVisibility() == BackfaceVisibilityHidden)
    reasons |= CompositingReasonBackfaceVisibilityHidden;

  if (requiresCompositingForAnimation(style))
    reasons |= CompositingReasonActiveAnimation;

  if (style.hasWillChangeCompositingHint() &&
      !style.subtreeWillChangeContents())
    reasons |= CompositingReasonWillChangeCompositingHint;

  if (style.hasInlineTransform())
    reasons |= CompositingReasonInlineTransform;

  if (style.usedTransformStyle3D() == TransformStyle3DPreserve3D)
    reasons |= CompositingReasonPreserve3DWith3DDescendants;

  if (style.hasPerspective())
    reasons |= CompositingReasonPerspectiveWith3DDescendants;

  if (style.hasCompositorProxy())
    reasons |= CompositingReasonCompositorProxy;

  // If the implementation of createsGroup changes, we need to be aware of that
  // in this part of code.
  DCHECK((layoutObject->isTransparent() || layoutObject->hasMask() ||
          layoutObject->hasFilterInducingProperty() || style.hasBlendMode()) ==
         layoutObject->createsGroup());

  if (style.hasMask())
    reasons |= CompositingReasonMaskWithCompositedDescendants;

  if (style.hasFilterInducingProperty())
    reasons |= CompositingReasonFilterWithCompositedDescendants;

  if (style.hasBackdropFilter())
    reasons |= CompositingReasonBackdropFilter;

  // See Layer::updateTransform for an explanation of why we check both.
  if (layoutObject->hasTransformRelatedProperty() && style.hasTransform())
    reasons |= CompositingReasonTransformWithCompositedDescendants;

  if (layoutObject->isTransparent())
    reasons |= CompositingReasonOpacityWithCompositedDescendants;

  if (style.hasBlendMode())
    reasons |= CompositingReasonBlendingWithCompositedDescendants;

  if (layoutObject->hasReflection())
    reasons |= CompositingReasonReflectionWithCompositedDescendants;

  DCHECK(!(reasons & ~CompositingReasonComboAllStyleDeterminedReasons));
  return reasons;
}

bool CompositingReasonFinder::requiresCompositingForTransform(
    const LayoutObject& layoutObject) {
  // Note that we ask the layoutObject if it has a transform, because the style
  // may have transforms, but the layoutObject may be an inline that doesn't
  // support them.
  return layoutObject.hasTransformRelatedProperty() &&
         layoutObject.styleRef().has3DTransform();
}

CompositingReasons CompositingReasonFinder::nonStyleDeterminedDirectReasons(
    const PaintLayer* layer) const {
  CompositingReasons directReasons = CompositingReasonNone;
  LayoutObject* layoutObject = layer->layoutObject();

  if (m_compositingTriggers & OverflowScrollTrigger && layer->clipParent())
    directReasons |= CompositingReasonOutOfFlowClipping;

  if (layer->needsCompositedScrolling())
    directReasons |= CompositingReasonOverflowScrollingTouch;

  // Composite |layer| if it is inside of an ancestor scrolling layer, but that
  // scrolling layer is not on the stacking context ancestor chain of |layer|.
  // See the definition of the scrollParent property in Layer for more detail.
  if (const PaintLayer* scrollingAncestor = layer->ancestorScrollingLayer()) {
    if (scrollingAncestor->needsCompositedScrolling() && layer->scrollParent())
      directReasons |= CompositingReasonOverflowScrollingParent;
  }

  // TODO(flackr): Rename functions and variables to include sticky position
  // (i.e. ScrollDependentPosition rather than PositionFixed).
  if (requiresCompositingForScrollDependentPosition(layer))
    directReasons |= CompositingReasonScrollDependentPosition;

  directReasons |= layoutObject->additionalCompositingReasons();

  DCHECK(!(directReasons & CompositingReasonComboAllStyleDeterminedReasons));
  return directReasons;
}

bool CompositingReasonFinder::requiresCompositingForAnimation(
    const ComputedStyle& style) {
  if (style.subtreeWillChangeContents())
    return style.isRunningAnimationOnCompositor();

  return style.shouldCompositeForCurrentAnimations();
}

bool CompositingReasonFinder::requiresCompositingForEffectAnimation(
    const ComputedStyle& style) {
  if (style.subtreeWillChangeContents()) {
    return style.isRunningOpacityAnimationOnCompositor() ||
           style.isRunningFilterAnimationOnCompositor() ||
           style.isRunningBackdropFilterAnimationOnCompositor();
  }

  return style.hasCurrentOpacityAnimation() ||
         style.hasCurrentFilterAnimation() ||
         style.hasCurrentBackdropFilterAnimation();
}

bool CompositingReasonFinder::requiresCompositingForTransformAnimation(
    const ComputedStyle& style) {
  return style.subtreeWillChangeContents()
             ? style.isRunningTransformAnimationOnCompositor()
             : style.hasCurrentTransformAnimation();
}

bool CompositingReasonFinder::requiresCompositingForScrollDependentPosition(
    const PaintLayer* layer) const {
  if (layer->layoutObject()->style()->position() != FixedPosition &&
      layer->layoutObject()->style()->position() != StickyPosition)
    return false;

  if (!(m_compositingTriggers & ViewportConstrainedPositionedTrigger) &&
      (!RuntimeEnabledFeatures::compositeOpaqueFixedPositionEnabled() ||
       !layer->backgroundIsKnownToBeOpaqueInRect(
           LayoutRect(layer->boundingBoxForCompositing())) ||
       layer->compositesWithTransform() || layer->compositesWithOpacity())) {
    return false;
  }
  // Don't promote fixed position elements that are descendants of a non-view
  // container, e.g. transformed elements.  They will stay fixed wrt the
  // container rather than the enclosing frame.
  if (layer->sticksToViewport())
    return m_layoutView.frameView()->isScrollable();
  return layer->layoutObject()->style()->position() == StickyPosition &&
         layer->ancestorOverflowLayer()->scrollsOverflow();
}

}  // namespace blink