• 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 "wtf/MathExtras.h"
9 #include <stdint.h>
10 
11 namespace WebCore {
12 
13 const uint64_t CompositingReasonNone                                     = 0;
14 const uint64_t CompositingReasonAll                                      = ~static_cast<uint64_t>(0);
15 
16 // Intrinsic reasons that can be known right away by the layer
17 const uint64_t CompositingReason3DTransform                              = UINT64_C(1) << 0;
18 const uint64_t CompositingReasonVideo                                    = UINT64_C(1) << 1;
19 const uint64_t CompositingReasonCanvas                                   = UINT64_C(1) << 2;
20 const uint64_t CompositingReasonPlugin                                   = UINT64_C(1) << 3;
21 const uint64_t CompositingReasonIFrame                                   = UINT64_C(1) << 4;
22 const uint64_t CompositingReasonBackfaceVisibilityHidden                 = UINT64_C(1) << 5;
23 const uint64_t CompositingReasonActiveAnimation                          = UINT64_C(1) << 6;
24 const uint64_t CompositingReasonTransitionProperty                       = UINT64_C(1) << 7;
25 const uint64_t CompositingReasonFilters                                  = UINT64_C(1) << 8;
26 const uint64_t CompositingReasonPositionFixed                            = UINT64_C(1) << 9;
27 const uint64_t CompositingReasonOverflowScrollingTouch                   = UINT64_C(1) << 10;
28 const uint64_t CompositingReasonOverflowScrollingParent                  = UINT64_C(1) << 11;
29 const uint64_t CompositingReasonOutOfFlowClipping                        = UINT64_C(1) << 12;
30 const uint64_t CompositingReasonVideoOverlay                             = UINT64_C(1) << 13;
31 const uint64_t CompositingReasonWillChangeCompositingHint                = UINT64_C(1) << 14;
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) << 15;
35 const uint64_t CompositingReasonOverlap                                  = UINT64_C(1) << 16;
36 const uint64_t CompositingReasonNegativeZIndexChildren                   = UINT64_C(1) << 17;
37 const uint64_t CompositingReasonScrollsWithRespectToSquashingLayer       = UINT64_C(1) << 18;
38 const uint64_t CompositingReasonSquashingSparsityExceeded                = UINT64_C(1) << 19;
39 const uint64_t CompositingReasonSquashingClippingContainerMismatch       = UINT64_C(1) << 20;
40 const uint64_t CompositingReasonSquashingOpacityAncestorMismatch         = UINT64_C(1) << 21;
41 const uint64_t CompositingReasonSquashingTransformAncestorMismatch       = UINT64_C(1) << 22;
42 const uint64_t CompositingReasonSquashingFilterAncestorMismatch          = UINT64_C(1) << 23;
43 const uint64_t CompositingReasonSquashingWouldBreakPaintOrder            = UINT64_C(1) << 24;
44 const uint64_t CompositingReasonSquashingVideoIsDisallowed               = UINT64_C(1) << 25;
45 const uint64_t CompositingReasonSquashedLayerClipsCompositingDescendants = UINT64_C(1) << 26;
46 
47 // Subtree reasons that require knowing what the status of your subtree is before knowing the answer
48 const uint64_t CompositingReasonTransformWithCompositedDescendants       = UINT64_C(1) << 27;
49 const uint64_t CompositingReasonOpacityWithCompositedDescendants         = UINT64_C(1) << 28;
50 const uint64_t CompositingReasonMaskWithCompositedDescendants            = UINT64_C(1) << 29;
51 const uint64_t CompositingReasonReflectionWithCompositedDescendants      = UINT64_C(1) << 30;
52 const uint64_t CompositingReasonFilterWithCompositedDescendants          = UINT64_C(1) << 31;
53 const uint64_t CompositingReasonBlendingWithCompositedDescendants        = UINT64_C(1) << 32;
54 const uint64_t CompositingReasonClipsCompositingDescendants              = UINT64_C(1) << 33;
55 const uint64_t CompositingReasonPerspectiveWith3DDescendants             = UINT64_C(1) << 34;
56 const uint64_t CompositingReasonPreserve3DWith3DDescendants              = UINT64_C(1) << 35;
57 const uint64_t CompositingReasonReflectionOfCompositedParent             = UINT64_C(1) << 36;
58 const uint64_t CompositingReasonIsolateCompositedDescendants             = UINT64_C(1) << 37;
59 
60 // The root layer is a special case that may be forced to be a layer, but also it needs to be
61 // a layer if anything else in the subtree is composited.
62 const uint64_t CompositingReasonRoot                                     = UINT64_C(1) << 38;
63 
64 // CompositedLayerMapping internal hierarchy reasons
65 const uint64_t CompositingReasonLayerForAncestorClip                     = UINT64_C(1) << 39;
66 const uint64_t CompositingReasonLayerForDescendantClip                   = UINT64_C(1) << 40;
67 const uint64_t CompositingReasonLayerForPerspective                      = UINT64_C(1) << 41;
68 const uint64_t CompositingReasonLayerForHorizontalScrollbar              = UINT64_C(1) << 42;
69 const uint64_t CompositingReasonLayerForVerticalScrollbar                = UINT64_C(1) << 43;
70 const uint64_t CompositingReasonLayerForScrollCorner                     = UINT64_C(1) << 44;
71 const uint64_t CompositingReasonLayerForScrollingContents                = UINT64_C(1) << 45;
72 const uint64_t CompositingReasonLayerForScrollingContainer               = UINT64_C(1) << 46;
73 const uint64_t CompositingReasonLayerForSquashingContents                = UINT64_C(1) << 47;
74 const uint64_t CompositingReasonLayerForSquashingContainer               = UINT64_C(1) << 48;
75 const uint64_t CompositingReasonLayerForForeground                       = UINT64_C(1) << 49;
76 const uint64_t CompositingReasonLayerForBackground                       = UINT64_C(1) << 50;
77 const uint64_t CompositingReasonLayerForMask                             = UINT64_C(1) << 51;
78 const uint64_t CompositingReasonLayerForClippingMask                     = UINT64_C(1) << 52;
79 const uint64_t CompositingReasonLayerForScrollingBlockSelection          = UINT64_C(1) << 53;
80 
81 // Various combinations of compositing reasons are defined here also, for more intutive and faster bitwise logic.
82 const uint64_t CompositingReasonComboAllDirectReasons =
83     CompositingReason3DTransform
84     | CompositingReasonVideo
85     | CompositingReasonCanvas
86     | CompositingReasonPlugin
87     | CompositingReasonIFrame
88     | CompositingReasonBackfaceVisibilityHidden
89     | CompositingReasonActiveAnimation
90     | CompositingReasonTransitionProperty
91     | CompositingReasonFilters
92     | CompositingReasonPositionFixed
93     | CompositingReasonOverflowScrollingTouch
94     | CompositingReasonOverflowScrollingParent
95     | CompositingReasonOutOfFlowClipping
96     | CompositingReasonVideoOverlay
97     | CompositingReasonWillChangeCompositingHint;
98 
99 const uint64_t CompositingReasonComboAllStyleDeterminedReasons =
100     CompositingReason3DTransform
101     | CompositingReasonBackfaceVisibilityHidden
102     | CompositingReasonActiveAnimation
103     | CompositingReasonTransitionProperty
104     | CompositingReasonFilters
105     | CompositingReasonWillChangeCompositingHint;
106 
107 const uint64_t CompositingReasonComboReasonsThatRequireOwnBacking =
108     CompositingReasonComboAllDirectReasons
109     | CompositingReasonOverlap
110     | CompositingReasonAssumedOverlap
111     | CompositingReasonNegativeZIndexChildren
112     | CompositingReasonScrollsWithRespectToSquashingLayer
113     | CompositingReasonSquashingSparsityExceeded
114     | CompositingReasonSquashingClippingContainerMismatch
115     | CompositingReasonSquashingOpacityAncestorMismatch
116     | CompositingReasonSquashingTransformAncestorMismatch
117     | CompositingReasonSquashingFilterAncestorMismatch
118     | CompositingReasonSquashingWouldBreakPaintOrder
119     | CompositingReasonSquashingVideoIsDisallowed
120     | CompositingReasonSquashedLayerClipsCompositingDescendants
121     | CompositingReasonTransformWithCompositedDescendants
122     | CompositingReasonOpacityWithCompositedDescendants
123     | CompositingReasonMaskWithCompositedDescendants
124     | CompositingReasonFilterWithCompositedDescendants
125     | CompositingReasonBlendingWithCompositedDescendants
126     | CompositingReasonIsolateCompositedDescendants
127     | CompositingReasonPreserve3DWith3DDescendants; // preserve-3d has to create backing store to ensure that 3d-transformed elements intersect.
128 
129 const uint64_t CompositingReasonComboSquashableReasons =
130     CompositingReasonOverlap
131     | CompositingReasonAssumedOverlap
132     | CompositingReasonOverflowScrollingParent;
133 
134 typedef uint64_t CompositingReasons;
135 
136 // Any reasons other than overlap or assumed overlap will require the layer to be separately compositing.
requiresCompositing(CompositingReasons reasons)137 inline bool requiresCompositing(CompositingReasons reasons)
138 {
139     return reasons & ~CompositingReasonComboSquashableReasons;
140 }
141 
142 // If the layer has overlap or assumed overlap, but no other reasons, then it should be squashed.
requiresSquashing(CompositingReasons reasons)143 inline bool requiresSquashing(CompositingReasons reasons)
144 {
145     return !requiresCompositing(reasons) && (reasons & CompositingReasonComboSquashableReasons);
146 }
147 
148 struct CompositingReasonStringMap {
149     CompositingReasons reason;
150     const char* shortName;
151     const char* description;
152 };
153 
154 // FIXME: This static data shouldn't be in a header. When it's in the header
155 // it's copied into every compilation unit that includes the header.
156 static const CompositingReasonStringMap compositingReasonStringMap[] = {
157     { CompositingReasonNone,
158         "Unknown",
159         "No reason given" },
160     { CompositingReason3DTransform,
161         "transform3D",
162         "Has a 3d transform" },
163     { CompositingReasonVideo,
164         "video",
165         "Is an accelerated video" },
166     { CompositingReasonCanvas,
167         "canvas",
168         "Is an accelerated canvas" },
169     { CompositingReasonPlugin,
170         "plugin",
171         "Is an accelerated plugin" },
172     { CompositingReasonIFrame,
173         "iFrame",
174         "Is an accelerated iFrame" },
175     { CompositingReasonBackfaceVisibilityHidden,
176         "backfaceVisibilityHidden",
177         "Has backface-visibility: hidden" },
178     { CompositingReasonActiveAnimation,
179         "activeAnimation",
180         "Has an active accelerated animation or transition" },
181     { CompositingReasonTransitionProperty,
182         "transitionProperty",
183         "Has an acceleratable transition property (active or inactive)" },
184     { CompositingReasonFilters,
185         "filters",
186         "Has an accelerated filter" },
187     { CompositingReasonPositionFixed,
188         "positionFixed",
189         "Is fixed position" },
190     { 0, 0, 0 }, // Available.
191     { CompositingReasonOverflowScrollingTouch,
192         "overflowScrollingTouch",
193         "Is a scrollable overflow element" },
194     { CompositingReasonOverflowScrollingParent,
195         "overflowScrollingParent",
196         "Scroll parent is not an ancestor" },
197     { CompositingReasonOutOfFlowClipping,
198         "outOfFlowClipping",
199         "Has clipping ancestor" },
200     { CompositingReasonVideoOverlay,
201         "videoOverlay",
202         "Is overlay controls for video" },
203     { CompositingReasonWillChangeCompositingHint,
204         "willChange",
205         "Has a will-change compositing hint" },
206     { 0, 0, 0 }, // Available.
207     { CompositingReasonAssumedOverlap,
208         "assumedOverlap",
209         "Might overlap other composited content" },
210     { CompositingReasonOverlap,
211         "overlap",
212         "Overlaps other composited content" },
213     { CompositingReasonNegativeZIndexChildren,
214         "negativeZIndexChildren",
215         "Parent with composited negative z-index content" },
216     { CompositingReasonScrollsWithRespectToSquashingLayer,
217         "scrollsWithRespectToSquashingLayer",
218         "Cannot be squashed since this layer scrolls with respect to the squashing layer" },
219     { CompositingReasonSquashingSparsityExceeded,
220         "squashingSparsityExceeded",
221         "Cannot be squashed as the squashing layer would become too sparse" },
222     { CompositingReasonSquashingClippingContainerMismatch,
223         "squashingClippingContainerMismatch",
224         "Cannot be squashed because this layer has a different clipping container than the squashing layer" },
225     { CompositingReasonSquashingOpacityAncestorMismatch,
226         "squashingOpacityAncestorMismatch",
227         "Cannot be squashed because this layer has a different opacity ancestor than the squashing layer" },
228     { CompositingReasonSquashingTransformAncestorMismatch,
229         "squashingTransformAncestorMismatch",
230         "Cannot be squashed because this layer has a different transform ancestor than the squashing layer" },
231     { CompositingReasonSquashingFilterAncestorMismatch,
232         "squashingFilterAncestorMismatch",
233         "Cannot be squashed because this layer has a different filter ancestor than the squashing layer" },
234     { CompositingReasonSquashingWouldBreakPaintOrder,
235         "squashingWouldBreakPaintOrder",
236         "Cannot be squashed without breaking paint order" },
237     { CompositingReasonSquashingVideoIsDisallowed,
238         "squashingVideoIsDisallowed",
239         "Squashing video is not supported" },
240     { CompositingReasonSquashedLayerClipsCompositingDescendants,
241         "squashedLayerClipsCompositingDescendants",
242         "Squashing a layer that clips composited descendants is not supported." },
243     { CompositingReasonTransformWithCompositedDescendants,
244         "transformWithCompositedDescendants",
245         "Has a transform that needs to be known by compositor because of composited descendants" },
246     { CompositingReasonOpacityWithCompositedDescendants,
247         "opacityWithCompositedDescendants",
248         "Has opacity that needs to be applied by compositor because of composited descendants" },
249     { CompositingReasonMaskWithCompositedDescendants,
250         "maskWithCompositedDescendants",
251         "Has a mask that needs to be known by compositor because of composited descendants" },
252     { CompositingReasonReflectionWithCompositedDescendants,
253         "reflectionWithCompositedDescendants",
254         "Has a reflection that needs to be known by compositor because of composited descendants" },
255     { CompositingReasonFilterWithCompositedDescendants,
256         "filterWithCompositedDescendants",
257         "Has a filter effect that needs to be known by compositor because of composited descendants" },
258     { CompositingReasonBlendingWithCompositedDescendants,
259         "blendingWithCompositedDescendants",
260         "Has a blenidng effect that needs to be known by compositor because of composited descendants" },
261     { CompositingReasonClipsCompositingDescendants,
262         "clipsCompositingDescendants",
263         "Has a clip that needs to be known by compositor because of composited descendants" },
264     { CompositingReasonPerspectiveWith3DDescendants,
265         "perspectiveWith3DDescendants",
266         "Has a perspective transform that needs to be known by compositor because of 3d descendants" },
267     { CompositingReasonPreserve3DWith3DDescendants,
268         "preserve3DWith3DDescendants",
269         "Has a preserves-3d property that needs to be known by compositor because of 3d descendants" },
270     { CompositingReasonReflectionOfCompositedParent,
271         "reflectionOfCompositedParent",
272         "Is a reflection of a composited layer" },
273     { CompositingReasonIsolateCompositedDescendants,
274         "isolateCompositedDescendants",
275         "Should isolate descendants to apply a blend effect" },
276     { CompositingReasonRoot,
277         "root",
278         "Is the root layer" },
279     { CompositingReasonLayerForAncestorClip,
280         "layerForAncestorClip",
281         "Secondary layer, applies a clip due to a sibling in the compositing tree" },
282     { CompositingReasonLayerForDescendantClip,
283         "layerForDescendantClip",
284         "Secondary layer, to clip descendants of the owning layer" },
285     { CompositingReasonLayerForPerspective,
286         "layerForPerspective",
287         "Secondary layer, to house the perspective transform for all descendants" },
288     { CompositingReasonLayerForHorizontalScrollbar,
289         "layerForHorizontalScrollbar",
290         "Secondary layer, the horizontal scrollbar layer" },
291     { CompositingReasonLayerForVerticalScrollbar,
292         "layerForVerticalScrollbar",
293         "Secondary layer, the vertical scrollbar layer" },
294     { CompositingReasonLayerForScrollCorner,
295         "layerForScrollCorner",
296         "Secondary layer, the scroll corner layer" },
297     { CompositingReasonLayerForScrollingContents,
298         "layerForScrollingContents",
299         "Secondary layer, to house contents that can be scrolled" },
300     { CompositingReasonLayerForScrollingContainer,
301         "layerForScrollingContainer",
302         "Secondary layer, used to position the scolling contents while scrolling" },
303     { CompositingReasonLayerForSquashingContents,
304         "layerForSquashingContents",
305         "Secondary layer, home for a group of squashable content" },
306     { CompositingReasonLayerForSquashingContainer,
307         "layerForSquashingContainer",
308         "Secondary layer, no-op layer to place the squashing layer correctly in the composited layer tree" },
309     { CompositingReasonLayerForForeground,
310         "layerForForeground",
311         "Secondary layer, to contain any normal flow and positive z-index contents on top of a negative z-index layer" },
312     { CompositingReasonLayerForBackground,
313         "layerForBackground",
314         "Secondary layer, to contain acceleratable background content" },
315     { CompositingReasonLayerForMask,
316         "layerForMask",
317         "Secondary layer, to contain the mask contents" },
318     { CompositingReasonLayerForClippingMask,
319         "layerForClippingMask",
320         "Secondary layer, for clipping mask" },
321     { CompositingReasonLayerForScrollingBlockSelection,
322         "layerForScrollingBlockSelection",
323         "Secondary layer, to house block selection gaps for composited scrolling with no scrolling contents" },
324 };
325 
326 } // namespace WebCore
327 
328 #endif // CompositingReasons_h
329