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