cc307fb492ec0ae37304163364b95af1cfa0399a
[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(MonotonicTime) 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 seekAnimation(const String& animationName, double timeOffset) override;
134     WEBCORE_EXPORT void removeAnimation(const String& animationName) override;
135
136     WEBCORE_EXPORT void setContentsToImage(Image*) override;
137 #if PLATFORM(IOS)
138     WEBCORE_EXPORT PlatformLayer* contentsLayerForMedia() const override;
139 #endif
140     WEBCORE_EXPORT void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
141     WEBCORE_EXPORT void setContentsToSolidColor(const Color&) override;
142
143     bool usesContentsLayer() const override { return m_contentsLayerPurpose != ContentsLayerPurpose::None; }
144     
145     WEBCORE_EXPORT void setShowDebugBorder(bool) override;
146     WEBCORE_EXPORT void setShowRepaintCounter(bool) override;
147
148     WEBCORE_EXPORT void setDebugBackgroundColor(const Color&) override;
149     WEBCORE_EXPORT void setDebugBorder(const Color&, float borderWidth) override;
150
151     WEBCORE_EXPORT void setCustomAppearance(CustomAppearance) override;
152
153     WEBCORE_EXPORT void deviceOrPageScaleFactorChanged() override;
154
155     FloatSize pixelAlignmentOffset() const override { return m_pixelAlignmentOffset; }
156
157     struct CommitState {
158         int treeDepth { 0 };
159         bool ancestorHadChanges { false };
160         bool ancestorHasTransformAnimation { false };
161         bool ancestorStartedOrEndedTransformAnimation { false };
162         bool ancestorWithTransformAnimationIntersectsCoverageRect { false };
163         bool ancestorIsViewportConstrained { false };
164     };
165     bool needsCommit(const CommitState&);
166     void recursiveCommitChanges(const CommitState&, const TransformState&, float pageScaleFactor = 1, const FloatPoint& positionRelativeToBase = FloatPoint(), bool affectedByPageScale = false);
167
168     WEBCORE_EXPORT void flushCompositingState(const FloatRect&) override;
169     WEBCORE_EXPORT void flushCompositingStateForThisLayerOnly() override;
170
171     WEBCORE_EXPORT bool visibleRectChangeRequiresFlush(const FloatRect& visibleRect) const override;
172
173     WEBCORE_EXPORT TiledBacking* tiledBacking() const override;
174
175 protected:
176     WEBCORE_EXPORT void setOpacityInternal(float) override;
177     
178     WEBCORE_EXPORT bool animationCanBeAccelerated(const KeyframeValueList&, const Animation*) const;
179
180 private:
181     bool isGraphicsLayerCA() const override { return true; }
182
183     WEBCORE_EXPORT void willBeDestroyed() override;
184
185     // PlatformCALayerClient overrides
186     void platformCALayerLayoutSublayersOfLayer(PlatformCALayer*) override { }
187     bool platformCALayerRespondsToLayoutChanges() const override { return false; }
188     WEBCORE_EXPORT void platformCALayerCustomSublayersChanged(PlatformCALayer*) override;
189
190     WEBCORE_EXPORT void platformCALayerAnimationStarted(const String& animationKey, MonotonicTime beginTime) override;
191     WEBCORE_EXPORT void platformCALayerAnimationEnded(const String& animationKey) override;
192     CompositingCoordinatesOrientation platformCALayerContentsOrientation() const override { return contentsOrientation(); }
193     WEBCORE_EXPORT void platformCALayerPaintContents(PlatformCALayer*, GraphicsContext&, const FloatRect& clip, GraphicsLayerPaintBehavior) override;
194     bool platformCALayerShowDebugBorders() const override { return isShowingDebugBorder(); }
195     WEBCORE_EXPORT bool platformCALayerShowRepaintCounter(PlatformCALayer*) const override;
196     int platformCALayerRepaintCount(PlatformCALayer*) const override { return repaintCount(); }
197     int platformCALayerIncrementRepaintCount(PlatformCALayer*) override { return incrementRepaintCount(); }
198
199     bool platformCALayerContentsOpaque() const override { return contentsOpaque(); }
200     bool platformCALayerDrawsContent() const override { return drawsContent(); }
201     void platformCALayerLayerDidDisplay(PlatformCALayer* layer) override { return layerDidDisplay(layer); }
202     WEBCORE_EXPORT void platformCALayerSetNeedsToRevalidateTiles() override;
203     WEBCORE_EXPORT float platformCALayerDeviceScaleFactor() const override;
204     WEBCORE_EXPORT float platformCALayerContentsScaleMultiplierForNewTiles(PlatformCALayer*) const override;
205     WEBCORE_EXPORT bool platformCALayerShouldAggressivelyRetainTiles(PlatformCALayer*) const override;
206     WEBCORE_EXPORT bool platformCALayerShouldTemporarilyRetainTileCohorts(PlatformCALayer*) const override;
207     WEBCORE_EXPORT bool platformCALayerUseGiantTiles() const override;
208     WEBCORE_EXPORT void platformCALayerLogFilledVisibleFreshTile(unsigned) override;
209
210     bool isCommittingChanges() const override { return m_isCommittingChanges; }
211     bool isUsingDisplayListDrawing(PlatformCALayer*) const override { return m_usesDisplayListDrawing; }
212
213     WEBCORE_EXPORT void setIsViewportConstrained(bool) override;
214     bool isViewportConstrained() const override { return m_isViewportConstrained; }
215
216     WEBCORE_EXPORT String displayListAsText(DisplayList::AsTextFlags) const override;
217
218     WEBCORE_EXPORT void setIsTrackingDisplayListReplay(bool) override;
219     WEBCORE_EXPORT String replayDisplayListAsText(DisplayList::AsTextFlags) const override;
220
221     WEBCORE_EXPORT double backingStoreMemoryEstimate() const override;
222
223     WEBCORE_EXPORT bool shouldRepaintOnSizeChange() const override;
224
225     WEBCORE_EXPORT void layerDidDisplay(PlatformCALayer*);
226
227     virtual Ref<PlatformCALayer> createPlatformCALayer(PlatformCALayer::LayerType, PlatformCALayerClient* owner);
228     virtual Ref<PlatformCALayer> createPlatformCALayer(PlatformLayer*, PlatformCALayerClient* owner);
229     virtual Ref<PlatformCAAnimation> createPlatformCAAnimation(PlatformCAAnimation::AnimationType, const String& keyPath);
230
231     PlatformCALayer* primaryLayer() const { return m_structuralLayer.get() ? m_structuralLayer.get() : m_layer.get(); }
232     PlatformCALayer* hostLayerForSublayers() const;
233     PlatformCALayer* layerForSuperlayer() const;
234     PlatformCALayer* animatedLayer(AnimatedPropertyID) const;
235
236     typedef String CloneID; // Identifier for a given clone, based on original/replica branching down the tree.
237     static bool isReplicatedRootClone(const CloneID& cloneID) { return cloneID[0U] & 1; }
238
239     typedef HashMap<CloneID, RefPtr<PlatformCALayer>> LayerMap;
240     LayerMap* primaryLayerClones() const;
241     LayerMap* animatedLayerClones(AnimatedPropertyID) const;
242     static void clearClones(LayerMap&);
243
244     bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset);
245     bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset, const FloatSize& boxSize);
246     bool createFilterAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset);
247
248     // Return autoreleased animation (use RetainPtr?)
249     Ref<PlatformCAAnimation> createBasicAnimation(const Animation*, const String& keyPath, bool additive);
250     Ref<PlatformCAAnimation> createKeyframeAnimation(const Animation*, const String&, bool additive);
251     Ref<PlatformCAAnimation> createSpringAnimation(const Animation*, const String&, bool additive);
252     void setupAnimation(PlatformCAAnimation*, const Animation*, bool additive);
253     
254     const TimingFunction& timingFunctionForAnimationValue(const AnimationValue&, const Animation&);
255     
256     bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
257     bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
258
259     bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
260     bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
261     
262     bool setFilterAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex);
263     bool setFilterAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex, FilterOperation::OperationType);
264
265     bool isRunningTransformAnimation() const;
266
267     WEBCORE_EXPORT bool backingStoreAttached() const override;
268     WEBCORE_EXPORT bool backingStoreAttachedForTesting() const override;
269
270     bool hasAnimations() const { return m_animations.get(); }
271     bool animationIsRunning(const String& animationName) const
272     {
273         return m_animations && m_animations->runningAnimations.contains(animationName);
274     }
275
276     void commitLayerChangesBeforeSublayers(CommitState&, float pageScaleFactor, const FloatPoint& positionRelativeToBase);
277     void commitLayerChangesAfterSublayers(CommitState&);
278
279     FloatPoint computePositionRelativeToBase(float& pageScale) const;
280
281     bool requiresTiledLayer(float pageScaleFactor) const;
282     void changeLayerTypeTo(PlatformCALayer::LayerType);
283
284     CompositingCoordinatesOrientation defaultContentsOrientation() const;
285
286     void setupContentsLayer(PlatformCALayer*);
287     PlatformCALayer* contentsLayer() const { return m_contentsLayer.get(); }
288
289     void updateClippingStrategy(PlatformCALayer&, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect&);
290
291     WEBCORE_EXPORT void setReplicatedByLayer(GraphicsLayer*) override;
292
293     WEBCORE_EXPORT bool canThrottleLayerFlush() const override;
294
295     WEBCORE_EXPORT void getDebugBorderInfo(Color&, float& width) const override;
296     WEBCORE_EXPORT void dumpAdditionalProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const override;
297
298     void computePixelAlignment(float contentsScale, const FloatPoint& positionRelativeToBase,
299         FloatPoint& position, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset) const;
300
301     TransformationMatrix layerTransform(const FloatPoint& position, const TransformationMatrix* customTransform = 0) const;
302
303     enum ComputeVisibleRectFlag { RespectAnimatingTransforms = 1 << 0 };
304     typedef unsigned ComputeVisibleRectFlags;
305     
306     struct VisibleAndCoverageRects {
307         FloatRect visibleRect;
308         FloatRect coverageRect;
309         TransformationMatrix animatingTransform;
310     };
311     
312     VisibleAndCoverageRects computeVisibleAndCoverageRect(TransformState&, bool accumulateTransform, ComputeVisibleRectFlags = RespectAnimatingTransforms) const;
313     bool adjustCoverageRect(VisibleAndCoverageRects&, const FloatRect& oldVisibleRect) const;
314
315     const FloatRect& visibleRect() const { return m_visibleRect; }
316     const FloatRect& coverageRect() const { return m_coverageRect; }
317
318     void setVisibleAndCoverageRects(const VisibleAndCoverageRects&, bool isViewportConstrained);
319     
320     static FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize);
321
322     bool recursiveVisibleRectChangeRequiresFlush(const CommitState&, const TransformState&) const;
323     
324     bool isPageTiledBackingLayer() const { return type() == Type::PageTiledBacking; }
325
326     // Used to track the path down the tree for replica layers.
327     struct ReplicaState {
328         static const size_t maxReplicaDepth = 16;
329         enum ReplicaBranchType { ChildBranch = 0, ReplicaBranch = 1 };
330         ReplicaState(ReplicaBranchType firstBranch)
331             : m_replicaDepth(0)
332         {
333             push(firstBranch);
334         }
335         
336         // Called as we walk down the tree to build replicas.
337         void push(ReplicaBranchType branchType)
338         {
339             m_replicaBranches.append(branchType);
340             if (branchType == ReplicaBranch)
341                 ++m_replicaDepth;
342         }
343         
344         void setBranchType(ReplicaBranchType branchType)
345         {
346             ASSERT(!m_replicaBranches.isEmpty());
347
348             if (m_replicaBranches.last() != branchType) {
349                 if (branchType == ReplicaBranch)
350                     ++m_replicaDepth;
351                 else
352                     --m_replicaDepth;
353             }
354
355             m_replicaBranches.last() = branchType;
356         }
357
358         void pop()
359         {
360             if (m_replicaBranches.last() == ReplicaBranch)
361                 --m_replicaDepth;
362             m_replicaBranches.removeLast();
363         }
364         
365         size_t depth() const { return m_replicaBranches.size(); }
366         size_t replicaDepth() const { return m_replicaDepth; }
367
368         CloneID cloneID() const;        
369
370     private:
371         Vector<ReplicaBranchType> m_replicaBranches;
372         size_t m_replicaDepth;
373     };
374     RefPtr<PlatformCALayer>replicatedLayerRoot(ReplicaState&);
375
376     enum CloneLevel { RootCloneLevel, IntermediateCloneLevel };
377     RefPtr<PlatformCALayer> fetchCloneLayers(GraphicsLayer* replicaRoot, ReplicaState&, CloneLevel);
378     
379     Ref<PlatformCALayer> cloneLayer(PlatformCALayer *, CloneLevel);
380     RefPtr<PlatformCALayer> findOrMakeClone(CloneID, PlatformCALayer *, LayerMap&, CloneLevel);
381
382     void ensureCloneLayers(CloneID, RefPtr<PlatformCALayer>& primaryLayer, RefPtr<PlatformCALayer>& structuralLayer,
383         RefPtr<PlatformCALayer>& contentsLayer, RefPtr<PlatformCALayer>& contentsClippingLayer, RefPtr<PlatformCALayer>& contentsShapeMaskLayer,
384         RefPtr<PlatformCALayer>& shapeMaskLayer, RefPtr<PlatformCALayer>& backdropLayer, RefPtr<PlatformCALayer>& backdropClippingLayer,
385         CloneLevel);
386
387     bool hasCloneLayers() const { return !!m_layerClones; }
388     void removeCloneLayers();
389     FloatPoint positionForCloneRootLayer() const;
390
391     // All these "update" methods will be called inside a BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS block.
392     void updateNames();
393     void updateSublayerList(bool maxLayerDepthReached = false);
394     void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
395     void updateTransform();
396     void updateChildrenTransform();
397     void updateMasksToBounds();
398     void updateContentsVisibility();
399     void updateContentsOpaque(float pageScaleFactor);
400     void updateBackfaceVisibility();
401     void updateStructuralLayer();
402     void updateDrawsContent();
403     void updateCoverage(const CommitState&);
404     void updateBackgroundColor();
405     void updateUserInteractionEnabled();
406
407     void updateContentsImage();
408     void updateContentsPlatformLayer();
409     void updateContentsColorLayer();
410     void updateContentsRects();
411     void updateMasksToBoundsRect();
412     void updateMaskLayer();
413     void updateReplicatedLayers();
414
415     void updateAnimations();
416     void updateContentsNeedsDisplay();
417     void updateAcceleratesDrawing();
418     void updateSupportsSubpixelAntialiasedText();
419     void updateDebugIndicators();
420     void updateTiles();
421     void updateContentsScale(float pageScaleFactor);
422     void updateCustomAppearance();
423
424     void updateOpacityOnLayer();
425     void updateFilters();
426     void updateBackdropFilters();
427     void updateBackdropFiltersRect();
428
429 #if ENABLE(CSS_COMPOSITING)
430     void updateBlendMode();
431 #endif
432
433     void updateShape();
434     void updateWindRule();
435
436     enum StructuralLayerPurpose {
437         NoStructuralLayer = 0,
438         StructuralLayerForPreserves3D,
439         StructuralLayerForReplicaFlattening,
440         StructuralLayerForBackdrop
441     };
442     void ensureStructuralLayer(StructuralLayerPurpose);
443     StructuralLayerPurpose structuralLayerPurpose() const;
444     
445     void ensureLayerAnimations();
446
447     void setAnimationOnLayer(PlatformCAAnimation&, AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
448     bool removeCAAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index, int subINdex);
449     void pauseCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
450     void seekCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
451
452     enum MoveOrCopy { Move, Copy };
453     static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
454     void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
455
456     void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
457     {
458         moveOrCopyAnimations(Move, fromLayer, toLayer);
459     }
460     void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
461     {
462         moveOrCopyAnimations(Copy, fromLayer, toLayer);
463     }
464
465     // This represents the animation of a single property. There may be multiple transform animations for
466     // a single transition or keyframe animation, so index is used to distinguish these.
467     struct LayerPropertyAnimation {
468         LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedPropertyID property, int index, int subIndex, Seconds timeOffset)
469             : m_animation(WTFMove(caAnimation))
470             , m_name(animationName)
471             , m_property(property)
472             , m_index(index)
473             , m_subIndex(subIndex)
474             , m_timeOffset(timeOffset)
475         { }
476
477         RefPtr<PlatformCAAnimation> m_animation;
478         String m_name;
479         AnimatedPropertyID m_property;
480         int m_index;
481         int m_subIndex;
482         Seconds m_timeOffset;
483     };
484
485     bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const FloatSize& boxSize, int animationIndex, Seconds timeOffset, bool isMatrixAnimation);
486     bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, Seconds timeOffset);
487     void appendToUncommittedAnimations(LayerPropertyAnimation&&);
488
489     enum LayerChange : uint64_t {
490         NoChange                                = 0,
491         NameChanged                             = 1LLU << 1,
492         ChildrenChanged                         = 1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
493         GeometryChanged                         = 1LLU << 3,
494         TransformChanged                        = 1LLU << 4,
495         ChildrenTransformChanged                = 1LLU << 5,
496         Preserves3DChanged                      = 1LLU << 6,
497         MasksToBoundsChanged                    = 1LLU << 7,
498         DrawsContentChanged                     = 1LLU << 8,
499         BackgroundColorChanged                  = 1LLU << 9,
500         ContentsOpaqueChanged                   = 1LLU << 10,
501         BackfaceVisibilityChanged               = 1LLU << 11,
502         OpacityChanged                          = 1LLU << 12,
503         AnimationChanged                        = 1LLU << 13,
504         DirtyRectsChanged                       = 1LLU << 14,
505         ContentsImageChanged                    = 1LLU << 15,
506         ContentsPlatformLayerChanged            = 1LLU << 16,
507         ContentsColorLayerChanged               = 1LLU << 17,
508         ContentsRectsChanged                    = 1LLU << 18,
509         MasksToBoundsRectChanged                = 1LLU << 19,
510         MaskLayerChanged                        = 1LLU << 20,
511         ReplicatedLayerChanged                  = 1LLU << 21,
512         ContentsNeedsDisplay                    = 1LLU << 22,
513         AcceleratesDrawingChanged               = 1LLU << 23,
514         SupportsSubpixelAntialiasedTextChanged  = 1LLU << 24,
515         ContentsScaleChanged                    = 1LLU << 25,
516         ContentsVisibilityChanged               = 1LLU << 26,
517         CoverageRectChanged                     = 1LLU << 27,
518         FiltersChanged                          = 1LLU << 28,
519         BackdropFiltersChanged                  = 1LLU << 29,
520         BackdropFiltersRectChanged              = 1LLU << 30,
521         TilingAreaChanged                       = 1LLU << 31,
522         TilesAdded                              = 1LLU << 32,
523         DebugIndicatorsChanged                  = 1LLU << 33,
524         CustomAppearanceChanged                 = 1LLU << 34,
525         BlendModeChanged                        = 1LLU << 35,
526         ShapeChanged                            = 1LLU << 36,
527         WindRuleChanged                         = 1LLU << 37,
528         UserInteractionEnabledChanged           = 1LLU << 38,
529         NeedsComputeVisibleAndCoverageRect      = 1LLU << 39,
530     };
531     typedef uint64_t LayerChangeFlags;
532     void addUncommittedChanges(LayerChangeFlags);
533     bool hasDescendantsWithUncommittedChanges() const { return m_hasDescendantsWithUncommittedChanges; }
534     void setHasDescendantsWithUncommittedChanges(bool);
535     enum ScheduleFlushOrNot { ScheduleFlush, DontScheduleFlush };
536     void noteLayerPropertyChanged(LayerChangeFlags, ScheduleFlushOrNot = ScheduleFlush);
537     void noteSublayersChanged(ScheduleFlushOrNot = ScheduleFlush);
538     void noteChangesForScaleSensitiveProperties();
539
540     bool hasDescendantsWithRunningTransformAnimations() const { return m_hasDescendantsWithRunningTransformAnimations; }
541     void setHasDescendantsWithRunningTransformAnimations(bool b) { m_hasDescendantsWithRunningTransformAnimations = b; }
542
543     void propagateLayerChangeToReplicas(ScheduleFlushOrNot = ScheduleFlush);
544
545     void repaintLayerDirtyRects();
546
547     enum Action { Remove, Pause, Seek };
548     struct AnimationProcessingAction {
549         AnimationProcessingAction(Action action = Remove, Seconds timeOffset = 0_s)
550             : action(action)
551             , timeOffset(timeOffset)
552         {
553         }
554         Action action;
555         Seconds timeOffset; // Only used for pause.
556     };
557     void addProcessingActionForAnimation(const String&, AnimationProcessingAction);
558
559 #if PLATFORM(WIN)
560     // 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.
561     LayerChangeFlags m_uncommittedChanges { 0 };
562 #else
563     LayerChangeFlags m_uncommittedChanges { CoverageRectChanged };
564 #endif
565
566     RefPtr<PlatformCALayer> m_layer; // The main layer
567     RefPtr<PlatformCALayer> m_structuralLayer; // A layer used for structural reasons, like preserves-3d or replica-flattening. Is the parent of m_layer.
568     RefPtr<PlatformCALayer> m_contentsClippingLayer; // A layer used to clip inner content
569     RefPtr<PlatformCALayer> m_shapeMaskLayer; // Used to clip with non-trivial corner radii.
570     RefPtr<PlatformCALayer> m_backdropClippingLayer; // Used to clip the backdrop layer with corner radii.
571     RefPtr<PlatformCALayer> m_contentsLayer; // A layer used for inner content, like image and video
572     RefPtr<PlatformCALayer> m_contentsShapeMaskLayer; // Used to clip the content layer with non-trivial corner radii.
573     RefPtr<PlatformCALayer> m_backdropLayer; // The layer used for backdrop rendering, if necessary.
574
575     // References to clones of our layers, for replicated layers.
576     struct LayerClones {
577         LayerMap primaryLayerClones;
578         LayerMap structuralLayerClones;
579         LayerMap contentsLayerClones;
580         LayerMap contentsClippingLayerClones;
581         LayerMap contentsShapeMaskLayerClones;
582         LayerMap shapeMaskLayerClones;
583         LayerMap backdropLayerClones;
584         LayerMap backdropClippingLayerClones;
585     };
586
587     std::unique_ptr<LayerClones> m_layerClones;
588
589 #ifdef VISIBLE_TILE_WASH
590     RefPtr<PlatformCALayer> m_visibleTileWashLayer;
591 #endif
592     FloatRect m_visibleRect;
593     FloatRect m_previousCommittedVisibleRect;
594     FloatRect m_coverageRect; // Area for which we should maintain backing store, in the coordinate space of this layer.
595     FloatSize m_sizeAtLastCoverageRectUpdate;
596     FloatSize m_pixelAlignmentOffset;
597
598     Color m_contentsSolidColor;
599
600     RetainPtr<CGImageRef> m_uncorrectedContentsImage;
601     RetainPtr<CGImageRef> m_pendingContentsImage;
602     
603     typedef HashMap<String, Vector<AnimationProcessingAction>> AnimationsToProcessMap;
604     typedef HashMap<String, Vector<LayerPropertyAnimation>> AnimationsMap;
605     struct LayerAnimations {
606         Vector<LayerPropertyAnimation> uncomittedAnimations;
607         AnimationsToProcessMap animationsToProcess;
608         AnimationsMap runningAnimations;
609     };
610     
611     std::unique_ptr<LayerAnimations> m_animations;
612
613     Vector<FloatRect> m_dirtyRects;
614
615     std::unique_ptr<DisplayList::DisplayList> m_displayList;
616
617     ContentsLayerPurpose m_contentsLayerPurpose { ContentsLayerPurpose::None };
618     bool m_isCommittingChanges { false };
619
620     bool m_needsFullRepaint : 1;
621     bool m_usingBackdropLayerType : 1;
622     bool m_isViewportConstrained : 1;
623     bool m_intersectsCoverageRect : 1;
624     bool m_hasEverPainted : 1;
625     bool m_hasDescendantsWithRunningTransformAnimations : 1;
626     bool m_hasDescendantsWithUncommittedChanges : 1;
627 };
628
629 } // namespace WebCore
630
631 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::GraphicsLayerCA, isGraphicsLayerCA())