REGRESSION (r183300): Fixed elements flash when scrolling
[WebKit-https.git] / Source / WebCore / platform / graphics / ca / GraphicsLayerCA.h
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24  */
25
26 #ifndef GraphicsLayerCA_h
27 #define GraphicsLayerCA_h
28
29 #include "GraphicsLayer.h"
30 #include "PlatformCAAnimation.h"
31 #include "PlatformCALayer.h"
32 #include "PlatformCALayerClient.h"
33 #include <wtf/HashMap.h>
34 #include <wtf/HashSet.h>
35 #include <wtf/RetainPtr.h>
36 #include <wtf/text/StringHash.h>
37
38 // Enable this to add a light red wash over the visible portion of Tiled Layers, as computed
39 // by flushCompositingState().
40 // #define VISIBLE_TILE_WASH
41
42 namespace WebCore {
43
44 class FloatRoundedRect;
45 class Image;
46 class TransformState;
47
48 class GraphicsLayerCA : public GraphicsLayer, public PlatformCALayerClient {
49 public:
50     // The width and height of a single tile in a tiled layer. Should be large enough to
51     // avoid lots of small tiles (and therefore lots of drawing callbacks), but small enough
52     // to keep the overall tile cost low.
53     static const int kTiledLayerTileSize = 512;
54
55     WEBCORE_EXPORT explicit GraphicsLayerCA(Type, GraphicsLayerClient&);
56     WEBCORE_EXPORT virtual ~GraphicsLayerCA();
57
58     WEBCORE_EXPORT virtual void initialize(Type) override;
59
60     WEBCORE_EXPORT virtual void setName(const String&) override;
61
62     WEBCORE_EXPORT virtual PlatformLayerID primaryLayerID() const override;
63
64     WEBCORE_EXPORT virtual PlatformLayer* platformLayer() const override;
65     PlatformCALayer* platformCALayer() const { return primaryLayer(); }
66
67     WEBCORE_EXPORT virtual bool setChildren(const Vector<GraphicsLayer*>&) override;
68     WEBCORE_EXPORT virtual void addChild(GraphicsLayer*) override;
69     WEBCORE_EXPORT virtual void addChildAtIndex(GraphicsLayer*, int index) override;
70     WEBCORE_EXPORT virtual void addChildAbove(GraphicsLayer*, GraphicsLayer* sibling) override;
71     WEBCORE_EXPORT virtual void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling) override;
72     WEBCORE_EXPORT virtual bool replaceChild(GraphicsLayer* oldChild, GraphicsLayer* newChild) override;
73
74     WEBCORE_EXPORT virtual void removeFromParent() override;
75
76     WEBCORE_EXPORT virtual void setMaskLayer(GraphicsLayer*) override;
77     WEBCORE_EXPORT virtual void setReplicatedLayer(GraphicsLayer*) override;
78
79     WEBCORE_EXPORT virtual void setPosition(const FloatPoint&) override;
80     WEBCORE_EXPORT virtual void setAnchorPoint(const FloatPoint3D&) override;
81     WEBCORE_EXPORT virtual void setSize(const FloatSize&) override;
82     WEBCORE_EXPORT virtual void setBoundsOrigin(const FloatPoint&) override;
83
84     WEBCORE_EXPORT virtual void setTransform(const TransformationMatrix&) override;
85
86     WEBCORE_EXPORT virtual void setChildrenTransform(const TransformationMatrix&) override;
87
88     WEBCORE_EXPORT virtual void setPreserves3D(bool) override;
89     WEBCORE_EXPORT virtual void setMasksToBounds(bool) override;
90     WEBCORE_EXPORT virtual void setDrawsContent(bool) override;
91     WEBCORE_EXPORT virtual void setContentsVisible(bool) override;
92     WEBCORE_EXPORT virtual void setAcceleratesDrawing(bool) override;
93
94     WEBCORE_EXPORT virtual void setBackgroundColor(const Color&) override;
95
96     WEBCORE_EXPORT virtual void setContentsOpaque(bool) override;
97     WEBCORE_EXPORT virtual void setBackfaceVisibility(bool) override;
98
99     // return true if we started an animation
100     WEBCORE_EXPORT virtual void setOpacity(float) override;
101
102     WEBCORE_EXPORT virtual bool setFilters(const FilterOperations&) override;
103     virtual bool filtersCanBeComposited(const FilterOperations&);
104
105     WEBCORE_EXPORT virtual bool setBackdropFilters(const FilterOperations&) override;
106
107 #if ENABLE(CSS_COMPOSITING)
108     WEBCORE_EXPORT virtual void setBlendMode(BlendMode) override;
109 #endif
110
111     WEBCORE_EXPORT virtual void setNeedsDisplay() override;
112     WEBCORE_EXPORT virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
113     WEBCORE_EXPORT virtual void setContentsNeedsDisplay() override;
114     
115     WEBCORE_EXPORT virtual void setContentsRect(const FloatRect&) override;
116     WEBCORE_EXPORT virtual void setContentsClippingRect(const FloatRoundedRect&) override;
117     WEBCORE_EXPORT virtual bool setMasksToBoundsRect(const FloatRoundedRect&) override;
118
119     WEBCORE_EXPORT virtual void setShapeLayerPath(const Path&) override;
120     WEBCORE_EXPORT virtual void setShapeLayerWindRule(WindRule) override;
121
122     WEBCORE_EXPORT virtual void suspendAnimations(double time) override;
123     WEBCORE_EXPORT virtual void resumeAnimations() override;
124
125     WEBCORE_EXPORT virtual bool addAnimation(const KeyframeValueList&, const FloatSize& boxSize, const Animation*, const String& animationName, double timeOffset) override;
126     WEBCORE_EXPORT virtual void pauseAnimation(const String& animationName, double timeOffset) override;
127     WEBCORE_EXPORT virtual void removeAnimation(const String& animationName) override;
128
129     WEBCORE_EXPORT virtual void setContentsToImage(Image*) override;
130 #if PLATFORM(IOS)
131     WEBCORE_EXPORT virtual PlatformLayer* contentsLayerForMedia() const override;
132 #endif
133     WEBCORE_EXPORT virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
134     WEBCORE_EXPORT virtual void setContentsToSolidColor(const Color&) override;
135
136     virtual bool usesContentsLayer() const override { return m_contentsLayerPurpose != NoContentsLayer; }
137     
138     WEBCORE_EXPORT virtual void setShowDebugBorder(bool) override;
139     WEBCORE_EXPORT virtual void setShowRepaintCounter(bool) override;
140
141     WEBCORE_EXPORT virtual void setDebugBackgroundColor(const Color&) override;
142     WEBCORE_EXPORT virtual void setDebugBorder(const Color&, float borderWidth) override;
143
144     WEBCORE_EXPORT virtual void setCustomAppearance(CustomAppearance) override;
145
146     WEBCORE_EXPORT virtual void deviceOrPageScaleFactorChanged() override;
147
148     virtual FloatSize pixelAlignmentOffset() const override { return m_pixelAlignmentOffset; }
149
150     struct CommitState {
151         int treeDepth { 0 };
152         bool ancestorHasTransformAnimation { false };
153         bool ancestorsAllowBackingStoreDetachment { true };
154     };
155     void recursiveCommitChanges(const CommitState&, const TransformState&, float pageScaleFactor = 1, const FloatPoint& positionRelativeToBase = FloatPoint(), bool affectedByPageScale = false);
156
157     WEBCORE_EXPORT virtual void flushCompositingState(const FloatRect&) override;
158     WEBCORE_EXPORT virtual void flushCompositingStateForThisLayerOnly() override;
159
160     WEBCORE_EXPORT virtual bool visibleRectChangeRequiresFlush(const FloatRect& visibleRect) const override;
161
162     WEBCORE_EXPORT virtual TiledBacking* tiledBacking() const override;
163
164 protected:
165     WEBCORE_EXPORT virtual void setOpacityInternal(float) override;
166     
167     WEBCORE_EXPORT bool animationCanBeAccelerated(const KeyframeValueList&, const Animation*) const;
168
169 private:
170     virtual bool isGraphicsLayerCA() const override { return true; }
171
172     WEBCORE_EXPORT virtual void willBeDestroyed() override;
173
174     // PlatformCALayerClient overrides
175     virtual void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) override { }
176     virtual bool platformCALayerRespondsToLayoutChanges() const override { return false; }
177
178     WEBCORE_EXPORT void platformCALayerAnimationStarted(const String& animationKey, CFTimeInterval beginTime) override;
179     WEBCORE_EXPORT void platformCALayerAnimationEnded(const String& animationKey) override;
180     virtual CompositingCoordinatesOrientation platformCALayerContentsOrientation() const override { return contentsOrientation(); }
181     WEBCORE_EXPORT virtual void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect& clip) override;
182     virtual bool platformCALayerShowDebugBorders() const override { return isShowingDebugBorder(); }
183     WEBCORE_EXPORT virtual bool platformCALayerShowRepaintCounter(PlatformCALayer*) const override;
184     virtual int platformCALayerIncrementRepaintCount(PlatformCALayer*) override { return incrementRepaintCount(); }
185
186     virtual bool platformCALayerContentsOpaque() const override { return contentsOpaque(); }
187     virtual bool platformCALayerDrawsContent() const override { return drawsContent(); }
188     virtual void platformCALayerLayerDidDisplay(PlatformCALayer* layer) override { return layerDidDisplay(layer); }
189     WEBCORE_EXPORT virtual void platformCALayerSetNeedsToRevalidateTiles() override;
190     WEBCORE_EXPORT virtual float platformCALayerDeviceScaleFactor() const override;
191     WEBCORE_EXPORT virtual float platformCALayerContentsScaleMultiplierForNewTiles(PlatformCALayer*) const override;
192     WEBCORE_EXPORT virtual bool platformCALayerShouldAggressivelyRetainTiles(PlatformCALayer*) const override;
193     WEBCORE_EXPORT virtual bool platformCALayerShouldTemporarilyRetainTileCohorts(PlatformCALayer*) const override;
194
195     virtual bool isCommittingChanges() const override { return m_isCommittingChanges; }
196
197     WEBCORE_EXPORT virtual void setAllowsBackingStoreDetachment(bool) override;
198     WEBCORE_EXPORT virtual bool allowsBackingStoreDetachment() const override { return m_allowsBackingStoreDetachment; }
199
200     WEBCORE_EXPORT virtual double backingStoreMemoryEstimate() const override;
201
202     WEBCORE_EXPORT virtual bool shouldRepaintOnSizeChange() const override;
203
204     WEBCORE_EXPORT void layerDidDisplay(PlatformCALayer*);
205
206     virtual PassRefPtr<PlatformCALayer> createPlatformCALayer(PlatformCALayer::LayerType, PlatformCALayerClient* owner);
207     virtual PassRefPtr<PlatformCALayer> createPlatformCALayer(PlatformLayer*, PlatformCALayerClient* owner);
208     virtual PassRefPtr<PlatformCAAnimation> createPlatformCAAnimation(PlatformCAAnimation::AnimationType, const String& keyPath);
209
210     PlatformCALayer* primaryLayer() const { return m_structuralLayer.get() ? m_structuralLayer.get() : m_layer.get(); }
211     PlatformCALayer* hostLayerForSublayers() const;
212     PlatformCALayer* layerForSuperlayer() const;
213     PlatformCALayer* animatedLayer(AnimatedPropertyID) const;
214
215     typedef String CloneID; // Identifier for a given clone, based on original/replica branching down the tree.
216     static bool isReplicatedRootClone(const CloneID& cloneID) { return cloneID[0U] & 1; }
217
218     typedef HashMap<CloneID, RefPtr<PlatformCALayer>> LayerMap;
219     LayerMap* primaryLayerClones() const { return m_structuralLayer.get() ? m_structuralLayerClones.get() : m_layerClones.get(); }
220     LayerMap* animatedLayerClones(AnimatedPropertyID) const;
221
222     bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, double timeOffset);
223     bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, double timeOffset, const FloatSize& boxSize);
224     bool createFilterAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, double timeOffset);
225
226     // Return autoreleased animation (use RetainPtr?)
227     PassRefPtr<PlatformCAAnimation> createBasicAnimation(const Animation*, const String& keyPath, bool additive);
228     PassRefPtr<PlatformCAAnimation> createKeyframeAnimation(const Animation*, const String&, bool additive);
229     void setupAnimation(PlatformCAAnimation*, const Animation*, bool additive);
230     
231     const TimingFunction* timingFunctionForAnimationValue(const AnimationValue&, const Animation&);
232     
233     bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
234     bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
235
236     bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
237     bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
238     
239     bool setFilterAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex);
240     bool setFilterAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex, FilterOperation::OperationType);
241
242     bool isRunningTransformAnimation() const;
243
244     bool animationIsRunning(const String& animationName) const
245     {
246         return m_runningAnimations.find(animationName) != m_runningAnimations.end();
247     }
248
249     void commitLayerChangesBeforeSublayers(CommitState&, float pageScaleFactor, const FloatPoint& positionRelativeToBase);
250     void commitLayerChangesAfterSublayers(CommitState&);
251
252     FloatPoint computePositionRelativeToBase(float& pageScale) const;
253
254     bool requiresTiledLayer(float pageScaleFactor) const;
255     void changeLayerTypeTo(PlatformCALayer::LayerType);
256
257     CompositingCoordinatesOrientation defaultContentsOrientation() const;
258
259     void setupContentsLayer(PlatformCALayer*);
260     PlatformCALayer* contentsLayer() const { return m_contentsLayer.get(); }
261
262     void updateClippingStrategy(PlatformCALayer&, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect&);
263
264     WEBCORE_EXPORT virtual void setReplicatedByLayer(GraphicsLayer*) override;
265
266     WEBCORE_EXPORT virtual bool canThrottleLayerFlush() const override;
267
268     WEBCORE_EXPORT virtual void getDebugBorderInfo(Color&, float& width) const override;
269     WEBCORE_EXPORT virtual void dumpAdditionalProperties(TextStream&, int indent, LayerTreeAsTextBehavior) const override;
270
271     void computePixelAlignment(float contentsScale, const FloatPoint& positionRelativeToBase,
272         FloatPoint& position, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset) const;
273
274     TransformationMatrix layerTransform(const FloatPoint& position, const TransformationMatrix* customTransform = 0) const;
275
276     enum ComputeVisibleRectFlag { RespectAnimatingTransforms = 1 << 0 };
277     typedef unsigned ComputeVisibleRectFlags;
278     
279     struct VisibleAndCoverageRects {
280         FloatRect visibleRect;
281         FloatRect coverageRect;
282         
283         VisibleAndCoverageRects(const FloatRect& visRect, const FloatRect& covRect)
284             : visibleRect(visRect)
285             , coverageRect(covRect)
286         {
287         }
288     };
289     
290     VisibleAndCoverageRects computeVisibleAndCoverageRect(TransformState&, bool accumulateTransform, ComputeVisibleRectFlags = RespectAnimatingTransforms) const;
291     bool adjustCoverageRect(VisibleAndCoverageRects&, const FloatRect& oldVisibleRect) const;
292
293     const FloatRect& visibleRect() const { return m_visibleRect; }
294     const FloatRect& coverageRect() const { return m_coverageRect; }
295
296     void setVisibleAndCoverageRects(const VisibleAndCoverageRects&, bool allowBackingStoreDetachment);
297     
298     static FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize);
299
300     bool recursiveVisibleRectChangeRequiresFlush(const TransformState&) const;
301     
302     bool isPageTiledBackingLayer() const { return type() == Type::PageTiledBacking; }
303
304     // Used to track the path down the tree for replica layers.
305     struct ReplicaState {
306         static const size_t maxReplicaDepth = 16;
307         enum ReplicaBranchType { ChildBranch = 0, ReplicaBranch = 1 };
308         ReplicaState(ReplicaBranchType firstBranch)
309             : m_replicaDepth(0)
310         {
311             push(firstBranch);
312         }
313         
314         // Called as we walk down the tree to build replicas.
315         void push(ReplicaBranchType branchType)
316         {
317             m_replicaBranches.append(branchType);
318             if (branchType == ReplicaBranch)
319                 ++m_replicaDepth;
320         }
321         
322         void setBranchType(ReplicaBranchType branchType)
323         {
324             ASSERT(!m_replicaBranches.isEmpty());
325
326             if (m_replicaBranches.last() != branchType) {
327                 if (branchType == ReplicaBranch)
328                     ++m_replicaDepth;
329                 else
330                     --m_replicaDepth;
331             }
332
333             m_replicaBranches.last() = branchType;
334         }
335
336         void pop()
337         {
338             if (m_replicaBranches.last() == ReplicaBranch)
339                 --m_replicaDepth;
340             m_replicaBranches.removeLast();
341         }
342         
343         size_t depth() const { return m_replicaBranches.size(); }
344         size_t replicaDepth() const { return m_replicaDepth; }
345
346         CloneID cloneID() const;        
347
348     private:
349         Vector<ReplicaBranchType> m_replicaBranches;
350         size_t m_replicaDepth;
351     };
352     PassRefPtr<PlatformCALayer>replicatedLayerRoot(ReplicaState&);
353
354     enum CloneLevel { RootCloneLevel, IntermediateCloneLevel };
355     PassRefPtr<PlatformCALayer> fetchCloneLayers(GraphicsLayer* replicaRoot, ReplicaState&, CloneLevel);
356     
357     PassRefPtr<PlatformCALayer> cloneLayer(PlatformCALayer *, CloneLevel);
358     PassRefPtr<PlatformCALayer> findOrMakeClone(CloneID, PlatformCALayer *, LayerMap*, CloneLevel);
359
360     void ensureCloneLayers(CloneID, RefPtr<PlatformCALayer>& primaryLayer, RefPtr<PlatformCALayer>& structuralLayer,
361         RefPtr<PlatformCALayer>& contentsLayer, RefPtr<PlatformCALayer>& contentsClippingLayer, RefPtr<PlatformCALayer>& contentsShapeMaskLayer, RefPtr<PlatformCALayer>& shapeMaskLayer, CloneLevel);
362
363     bool hasCloneLayers() const { return !!m_layerClones; }
364     void removeCloneLayers();
365     FloatPoint positionForCloneRootLayer() const;
366
367     // All these "update" methods will be called inside a BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS block.
368     void updateNames();
369     void updateSublayerList(bool maxLayerDepthReached = false);
370     void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
371     void updateTransform();
372     void updateChildrenTransform();
373     void updateMasksToBounds();
374     void updateContentsVisibility();
375     void updateContentsOpaque(float pageScaleFactor);
376     void updateBackfaceVisibility();
377     void updateStructuralLayer();
378     void updateDrawsContent();
379     void updateCoverage();
380     void updateBackgroundColor();
381
382     void updateContentsImage();
383     void updateContentsPlatformLayer();
384     void updateContentsColorLayer();
385     void updateContentsRects();
386     void updateMasksToBoundsRect();
387     void updateMaskLayer();
388     void updateReplicatedLayers();
389
390     void updateAnimations();
391     void updateContentsNeedsDisplay();
392     void updateAcceleratesDrawing();
393     void updateDebugBorder();
394     void updateTiles();
395     void updateContentsScale(float pageScaleFactor);
396     void updateCustomAppearance();
397
398     void updateOpacityOnLayer();
399     void updateFilters();
400     void updateBackdropFilters();
401
402 #if ENABLE(CSS_COMPOSITING)
403     void updateBlendMode();
404 #endif
405
406     void updateShape();
407     void updateWindRule();
408
409     enum StructuralLayerPurpose {
410         NoStructuralLayer = 0,
411         StructuralLayerForPreserves3D,
412         StructuralLayerForReplicaFlattening,
413         StructuralLayerForBackdrop
414     };
415     void ensureStructuralLayer(StructuralLayerPurpose);
416     StructuralLayerPurpose structuralLayerPurpose() const;
417
418     void setAnimationOnLayer(PlatformCAAnimation&, AnimatedPropertyID, const String& animationName, int index, int subIndex, double timeOffset);
419     bool removeCAAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index, int subINdex);
420     void pauseCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, double timeOffset);
421
422     enum MoveOrCopy { Move, Copy };
423     static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
424     void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
425
426     void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
427     {
428         moveOrCopyAnimations(Move, fromLayer, toLayer);
429     }
430     void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
431     {
432         moveOrCopyAnimations(Copy, fromLayer, toLayer);
433     }
434
435     bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const FloatSize& boxSize, int animationIndex, double timeOffset, bool isMatrixAnimation);
436     bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, double timeOffset);
437
438     enum LayerChange {
439         NoChange =                      0,
440         NameChanged =                   1LLU << 1,
441         ChildrenChanged =               1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
442         GeometryChanged =               1LLU << 3,
443         TransformChanged =              1LLU << 4,
444         ChildrenTransformChanged =      1LLU << 5,
445         Preserves3DChanged =            1LLU << 6,
446         MasksToBoundsChanged =          1LLU << 7,
447         DrawsContentChanged =           1LLU << 8,
448         BackgroundColorChanged =        1LLU << 9,
449         ContentsOpaqueChanged =         1LLU << 10,
450         BackfaceVisibilityChanged =     1LLU << 11,
451         OpacityChanged =                1LLU << 12,
452         AnimationChanged =              1LLU << 13,
453         DirtyRectsChanged =             1LLU << 14,
454         ContentsImageChanged =          1LLU << 15,
455         ContentsPlatformLayerChanged =  1LLU << 16,
456         ContentsColorLayerChanged =     1LLU << 17,
457         ContentsRectsChanged =          1LLU << 18,
458         MasksToBoundsRectChanged =      1LLU << 19,
459         MaskLayerChanged =              1LLU << 20,
460         ReplicatedLayerChanged =        1LLU << 21,
461         ContentsNeedsDisplay =          1LLU << 22,
462         AcceleratesDrawingChanged =     1LLU << 23,
463         ContentsScaleChanged =          1LLU << 24,
464         ContentsVisibilityChanged =     1LLU << 25,
465         CoverageRectChanged =           1LLU << 26,
466         FiltersChanged =                1LLU << 27,
467         BackdropFiltersChanged =        1LLU << 28,
468         TilingAreaChanged =             1LLU << 29,
469         TilesAdded =                    1LLU << 30,
470         DebugIndicatorsChanged =        1LLU << 31,
471         CustomAppearanceChanged =       1LLU << 32,
472         BlendModeChanged =              1LLU << 33,
473         ShapeChanged =                  1LLU << 34,
474         WindRuleChanged =               1LLU << 35,
475     };
476     typedef uint64_t LayerChangeFlags;
477     enum ScheduleFlushOrNot { ScheduleFlush, DontScheduleFlush };
478     void noteLayerPropertyChanged(LayerChangeFlags, ScheduleFlushOrNot = ScheduleFlush);
479     void noteSublayersChanged(ScheduleFlushOrNot = ScheduleFlush);
480     void noteChangesForScaleSensitiveProperties();
481
482     void propagateLayerChangeToReplicas(ScheduleFlushOrNot = ScheduleFlush);
483
484     void repaintLayerDirtyRects();
485
486     RefPtr<PlatformCALayer> m_layer; // The main layer
487     RefPtr<PlatformCALayer> m_structuralLayer; // A layer used for structural reasons, like preserves-3d or replica-flattening. Is the parent of m_layer.
488     RefPtr<PlatformCALayer> m_contentsClippingLayer; // A layer used to clip inner content
489     RefPtr<PlatformCALayer> m_shapeMaskLayer; // Used to clip with non-trivial corner radii.
490     RefPtr<PlatformCALayer> m_contentsLayer; // A layer used for inner content, like image and video
491     RefPtr<PlatformCALayer> m_contentsShapeMaskLayer; // Used to clip the content layer with non-trivial corner radii.
492     RefPtr<PlatformCALayer> m_backdropLayer; // The layer used for backdrop rendering, if necessary.
493
494     // References to clones of our layers, for replicated layers.
495     std::unique_ptr<LayerMap> m_layerClones;
496     std::unique_ptr<LayerMap> m_structuralLayerClones;
497     std::unique_ptr<LayerMap> m_contentsLayerClones;
498     std::unique_ptr<LayerMap> m_contentsClippingLayerClones;
499     std::unique_ptr<LayerMap> m_contentsShapeMaskLayerClones;
500     std::unique_ptr<LayerMap> m_shapeMaskLayerClones;
501
502 #ifdef VISIBLE_TILE_WASH
503     RefPtr<PlatformCALayer> m_visibleTileWashLayer;
504 #endif
505     FloatRect m_visibleRect;
506     FloatSize m_sizeAtLastCoverageRectUpdate;
507
508     FloatRect m_coverageRect; // Area for which we should maintain backing store, in the coordinate space of this layer.
509     
510     ContentsLayerPurpose m_contentsLayerPurpose { NoContentsLayer };
511     bool m_needsFullRepaint : 1;
512     bool m_usingBackdropLayerType : 1;
513     bool m_allowsBackingStoreDetachment : 1;
514     bool m_intersectsCoverageRect : 1;
515
516     Color m_contentsSolidColor;
517
518     RetainPtr<CGImageRef> m_uncorrectedContentsImage;
519     RetainPtr<CGImageRef> m_pendingContentsImage;
520     
521     // This represents the animation of a single property. There may be multiple transform animations for
522     // a single transition or keyframe animation, so index is used to distinguish these.
523     struct LayerPropertyAnimation {
524         LayerPropertyAnimation(PassRefPtr<PlatformCAAnimation> caAnimation, const String& animationName, AnimatedPropertyID property, int index, int subIndex, double timeOffset)
525             : m_animation(caAnimation)
526             , m_name(animationName)
527             , m_property(property)
528             , m_index(index)
529             , m_subIndex(subIndex)
530             , m_timeOffset(timeOffset)
531         { }
532
533         RefPtr<PlatformCAAnimation> m_animation;
534         String m_name;
535         AnimatedPropertyID m_property;
536         int m_index;
537         int m_subIndex;
538         double m_timeOffset;
539     };
540     
541     // Uncommitted transitions and animations.
542     Vector<LayerPropertyAnimation> m_uncomittedAnimations;
543     
544     enum Action { Remove, Pause };
545     struct AnimationProcessingAction {
546         AnimationProcessingAction(Action action = Remove, double timeOffset = 0)
547             : action(action)
548             , timeOffset(timeOffset)
549         {
550         }
551         Action action;
552         double timeOffset; // only used for pause
553     };
554     typedef HashMap<String, AnimationProcessingAction> AnimationsToProcessMap;
555     AnimationsToProcessMap m_animationsToProcess;
556
557     // Map of animation names to their associated lists of property animations, so we can remove/pause them.
558     typedef HashMap<String, Vector<LayerPropertyAnimation>> AnimationsMap;
559     AnimationsMap m_runningAnimations;
560
561     Vector<FloatRect> m_dirtyRects;
562
563     FloatSize m_pixelAlignmentOffset;
564
565     LayerChangeFlags m_uncommittedChanges { 0 };
566     bool m_isCommittingChanges { false };
567 };
568
569 } // namespace WebCore
570
571 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::GraphicsLayerCA, isGraphicsLayerCA())
572
573 #endif // GraphicsLayerCA_h