• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CompositingReasons_h
6 #define CompositingReasons_h
7 
8 #include "platform/PlatformExport.h"
9 #include "wtf/MathExtras.h"
10 #include <stdint.h>
11 
12 namespace blink {
13 
14 const uint64_t CompositingReasonNone                                     = 0;
15 const uint64_t CompositingReasonAll                                      = ~static_cast<uint64_t>(0);
16 
17 // Intrinsic reasons that can be known right away by the layer
18 const uint64_t CompositingReason3DTransform                              = UINT64_C(1) << 0;
19 const uint64_t CompositingReasonVideo                                    = UINT64_C(1) << 1;
20 const uint64_t CompositingReasonCanvas                                   = UINT64_C(1) << 2;
21 const uint64_t CompositingReasonPlugin                                   = UINT64_C(1) << 3;
22 const uint64_t CompositingReasonIFrame                                   = UINT64_C(1) << 4;
23 const uint64_t CompositingReasonBackfaceVisibilityHidden                 = UINT64_C(1) << 5;
24 const uint64_t CompositingReasonActiveAnimation                          = UINT64_C(1) << 6;
25 const uint64_t CompositingReasonTransitionProperty                       = UINT64_C(1) << 7;
26 const uint64_t CompositingReasonPositionFixed                            = UINT64_C(1) << 8;
27 const uint64_t CompositingReasonOverflowScrollingTouch                   = UINT64_C(1) << 9;
28 const uint64_t CompositingReasonOverflowScrollingParent                  = UINT64_C(1) << 10;
29 const uint64_t CompositingReasonOutOfFlowClipping                        = UINT64_C(1) << 11;
30 const uint64_t CompositingReasonVideoOverlay                             = UINT64_C(1) << 12;
31 const uint64_t CompositingReasonWillChangeCompositingHint                = UINT64_C(1) << 13;
32 
33 // Overlap reasons that require knowing what's behind you in paint-order before knowing the answer
34 const uint64_t CompositingReasonAssumedOverlap                           = UINT64_C(1) << 14;
35 const uint64_t CompositingReasonOverlap                                  = UINT64_C(1) << 15;
36 const uint64_t CompositingReasonNegativeZIndexChildren                   = UINT64_C(1) << 16;
37 const uint64_t CompositingReasonScrollsWithRespectToSquashingLayer       = UINT64_C(1) << 17;
38 const uint64_t CompositingReasonSquashingSparsityExceeded                = UINT64_C(1) << 18;
39 const uint64_t CompositingReasonSquashingClippingContainerMismatch       = UINT64_C(1) << 19;
40 const uint64_t CompositingReasonSquashingOpacityAncestorMismatch         = UINT64_C(1) << 20;
41 const uint64_t CompositingReasonSquashingTransformAncestorMismatch       = UINT64_C(1) << 21;
42 const uint64_t CompositingReasonSquashingFilterMismatch                  = UINT64_C(1) << 22;
43 const uint64_t CompositingReasonSquashingWouldBreakPaintOrder            = UINT64_C(1) << 23;
44 const uint64_t CompositingReasonSquashingVideoIsDisallowed               = UINT64_C(1) << 24;
45 const uint64_t CompositingReasonSquashedLayerClipsCompositingDescendants = UINT64_C(1) << 25;
46 const uint64_t CompositingReasonSquashingRenderPartIsDisallowed          = UINT64_C(1) << 26;
47 const uint64_t CompositingReasonSquashingReflectionIsDisallowed          = UINT64_C(1) << 27;
48 const uint64_t CompositingReasonSquashingBlendingIsDisallowed            = UINT64_C(1) << 28;
49 
50 // Subtree reasons that require knowing what the status of your subtree is before knowing the answer
51 const uint64_t CompositingReasonTransformWithCompositedDescendants       = UINT64_C(1) << 29;
52 const uint64_t CompositingReasonOpacityWithCompositedDescendants         = UINT64_C(1) << 30;
53 const uint64_t CompositingReasonMaskWithCompositedDescendants            = UINT64_C(1) << 31;
54 const uint64_t CompositingReasonReflectionWithCompositedDescendants      = UINT64_C(1) << 32;
55 const uint64_t CompositingReasonFilterWithCompositedDescendants          = UINT64_C(1) << 33;
56 const uint64_t CompositingReasonBlendingWithCompositedDescendants        = UINT64_C(1) << 34;
57 const uint64_t CompositingReasonClipsCompositingDescendants              = UINT64_C(1) << 35;
58 const uint64_t CompositingReasonPerspectiveWith3DDescendants             = UINT64_C(1) << 36;
59 const uint64_t CompositingReasonPreserve3DWith3DDescendants              = UINT64_C(1) << 37;
60 const uint64_t CompositingReasonReflectionOfCompositedParent             = UINT64_C(1) << 38;
61 const uint64_t CompositingReasonIsolateCompositedDescendants             = UINT64_C(1) << 39;
62 
63 // The root layer is a special case that may be forced to be a layer, but also it needs to be
64 // a layer if anything else in the subtree is composited.
65 const uint64_t CompositingReasonRoot                                     = UINT64_C(1) << 40;
66 
67 // CompositedLayerMapping internal hierarchy reasons
68 const uint64_t CompositingReasonLayerForAncestorClip                     = UINT64_C(1) << 41;
69 const uint64_t CompositingReasonLayerForDescendantClip                   = UINT64_C(1) << 42;
70 const uint64_t CompositingReasonLayerForPerspective                      = UINT64_C(1) << 43;
71 const uint64_t CompositingReasonLayerForHorizontalScrollbar              = UINT64_C(1) << 44;
72 const uint64_t CompositingReasonLayerForVerticalScrollbar                = UINT64_C(1) << 45;
73 const uint64_t CompositingReasonLayerForOverflowControlsHost             = UINT64_C(1) << 46;
74 const uint64_t CompositingReasonLayerForScrollCorner                     = UINT64_C(1) << 47;
75 const uint64_t CompositingReasonLayerForScrollingContents                = UINT64_C(1) << 48;
76 const uint64_t CompositingReasonLayerForScrollingContainer               = UINT64_C(1) << 49;
77 const uint64_t CompositingReasonLayerForSquashingContents                = UINT64_C(1) << 50;
78 const uint64_t CompositingReasonLayerForSquashingContainer               = UINT64_C(1) << 51;
79 const uint64_t CompositingReasonLayerForForeground                       = UINT64_C(1) << 52;
80 const uint64_t CompositingReasonLayerForBackground                       = UINT64_C(1) << 53;
81 const uint64_t CompositingReasonLayerForMask                             = UINT64_C(1) << 54;
82 const uint64_t CompositingReasonLayerForClippingMask                     = UINT64_C(1) << 55;
83 const uint64_t CompositingReasonLayerForScrollingBlockSelection          = UINT64_C(1) << 56;
84 
85 // Composited elements with inline transforms trigger assumed overlap so that
86 // we can update their transforms quickly.
87 const uint64_t CompositingReasonInlineTransform                          = UINT64_C(1) << 57;
88 
89 // Various combinations of compositing reasons are defined here also, for more intutive and faster bitwise logic.
90 const uint64_t CompositingReasonComboAllDirectReasons =
91     CompositingReason3DTransform
92     | CompositingReasonVideo
93     | CompositingReasonCanvas
94     | CompositingReasonPlugin
95     | CompositingReasonIFrame
96     | CompositingReasonBackfaceVisibilityHidden
97     | CompositingReasonActiveAnimation
98     | CompositingReasonTransitionProperty
99     | CompositingReasonPositionFixed
100     | CompositingReasonOverflowScrollingTouch
101     | CompositingReasonOverflowScrollingParent
102     | CompositingReasonOutOfFlowClipping
103     | CompositingReasonVideoOverlay
104     | CompositingReasonWillChangeCompositingHint;
105 
106 const uint64_t CompositingReasonComboAllDirectStyleDeterminedReasons =
107     CompositingReason3DTransform
108     | CompositingReasonBackfaceVisibilityHidden
109     | CompositingReasonActiveAnimation
110     | CompositingReasonTransitionProperty
111     | CompositingReasonWillChangeCompositingHint;
112 
113 const uint64_t CompositingReasonComboCompositedDescendants =
114     CompositingReasonTransformWithCompositedDescendants
115     | CompositingReasonIsolateCompositedDescendants
116     | CompositingReasonOpacityWithCompositedDescendants
117     | CompositingReasonMaskWithCompositedDescendants
118     | CompositingReasonFilterWithCompositedDescendants
119     | CompositingReasonBlendingWithCompositedDescendants
120     | CompositingReasonReflectionWithCompositedDescendants
121     | CompositingReasonClipsCompositingDescendants;
122 
123 const uint64_t CompositingReasonCombo3DDescendants =
124     CompositingReasonPreserve3DWith3DDescendants
125     | CompositingReasonPerspectiveWith3DDescendants;
126 
127 const uint64_t CompositingReasonComboAllStyleDeterminedReasons =
128     CompositingReasonComboAllDirectStyleDeterminedReasons
129     | CompositingReasonComboCompositedDescendants
130     | CompositingReasonCombo3DDescendants
131     | CompositingReasonInlineTransform;
132 
133 const uint64_t CompositingReasonComboReasonsThatRequireOwnBacking =
134     CompositingReasonComboAllDirectReasons
135     | CompositingReasonOverlap
136     | CompositingReasonAssumedOverlap
137     | CompositingReasonNegativeZIndexChildren
138     | CompositingReasonScrollsWithRespectToSquashingLayer
139     | CompositingReasonSquashingSparsityExceeded
140     | CompositingReasonSquashingClippingContainerMismatch
141     | CompositingReasonSquashingOpacityAncestorMismatch
142     | CompositingReasonSquashingTransformAncestorMismatch
143     | CompositingReasonSquashingFilterMismatch
144     | CompositingReasonSquashingWouldBreakPaintOrder
145     | CompositingReasonSquashingVideoIsDisallowed
146     | CompositingReasonSquashedLayerClipsCompositingDescendants
147     | CompositingReasonSquashingRenderPartIsDisallowed
148     | CompositingReasonSquashingReflectionIsDisallowed
149     | CompositingReasonSquashingBlendingIsDisallowed
150     | CompositingReasonTransformWithCompositedDescendants
151     | CompositingReasonOpacityWithCompositedDescendants
152     | CompositingReasonMaskWithCompositedDescendants
153     | CompositingReasonFilterWithCompositedDescendants
154     | CompositingReasonBlendingWithCompositedDescendants
155     | CompositingReasonIsolateCompositedDescendants
156     | CompositingReasonPreserve3DWith3DDescendants; // preserve-3d has to create backing store to ensure that 3d-transformed elements intersect.
157 
158 const uint64_t CompositingReasonComboSquashableReasons =
159     CompositingReasonOverlap
160     | CompositingReasonAssumedOverlap
161     | CompositingReasonOverflowScrollingParent;
162 
163 typedef uint64_t CompositingReasons;
164 
165 // Any reasons other than overlap or assumed overlap will require the layer to be separately compositing.
requiresCompositing(CompositingReasons reasons)166 inline bool requiresCompositing(CompositingReasons reasons)
167 {
168     return reasons & ~CompositingReasonComboSquashableReasons;
169 }
170 
171 // If the layer has overlap or assumed overlap, but no other reasons, then it should be squashed.
requiresSquashing(CompositingReasons reasons)172 inline bool requiresSquashing(CompositingReasons reasons)
173 {
174     return !requiresCompositing(reasons) && (reasons & CompositingReasonComboSquashableReasons);
175 }
176 
177 struct CompositingReasonStringMap {
178     CompositingReasons reason;
179     const char* shortName;
180     const char* description;
181 };
182 
183 PLATFORM_EXPORT extern const CompositingReasonStringMap kCompositingReasonStringMap[];
184 PLATFORM_EXPORT extern size_t kNumberOfCompositingReasons;
185 
186 } // namespace blink
187 
188 #endif // CompositingReasons_h
189