REGRESSION (r230574): Interrupted hardware transitions don't behave correctly
[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 != NoContentsLayer; }
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 { return m_structuralLayer.get() ? m_structuralLayerClones.get() : m_layerClones.get(); }
241     LayerMap* animatedLayerClones(AnimatedPropertyID) const;
242
243     bool createAnimationFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset);
244     bool createTransformAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset, const FloatSize& boxSize);
245     bool createFilterAnimationsFromKeyframes(const KeyframeValueList&, const Animation*, const String& animationName, Seconds timeOffset);
246
247     // Return autoreleased animation (use RetainPtr?)
248     Ref<PlatformCAAnimation> createBasicAnimation(const Animation*, const String& keyPath, bool additive);
249     Ref<PlatformCAAnimation> createKeyframeAnimation(const Animation*, const String&, bool additive);
250     Ref<PlatformCAAnimation> createSpringAnimation(const Animation*, const String&, bool additive);
251     void setupAnimation(PlatformCAAnimation*, const Animation*, bool additive);
252     
253     const TimingFunction& timingFunctionForAnimationValue(const AnimationValue&, const Animation&);
254     
255     bool setAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
256     bool setAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*);
257
258     bool setTransformAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
259     bool setTransformAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, TransformOperation::OperationType, bool isMatrixAnimation, const FloatSize& boxSize);
260     
261     bool setFilterAnimationEndpoints(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex);
262     bool setFilterAnimationKeyframes(const KeyframeValueList&, const Animation*, PlatformCAAnimation*, int functionIndex, int internalFilterPropertyIndex, FilterOperation::OperationType);
263
264     bool isRunningTransformAnimation() const;
265
266     WEBCORE_EXPORT bool backingStoreAttached() const override;
267
268     bool animationIsRunning(const String& animationName) const
269     {
270         return m_runningAnimations.find(animationName) != m_runningAnimations.end();
271     }
272
273     void commitLayerChangesBeforeSublayers(CommitState&, float pageScaleFactor, const FloatPoint& positionRelativeToBase);
274     void commitLayerChangesAfterSublayers(CommitState&);
275
276     FloatPoint computePositionRelativeToBase(float& pageScale) const;
277
278     bool requiresTiledLayer(float pageScaleFactor) const;
279     void changeLayerTypeTo(PlatformCALayer::LayerType);
280
281     CompositingCoordinatesOrientation defaultContentsOrientation() const;
282
283     void setupContentsLayer(PlatformCALayer*);
284     PlatformCALayer* contentsLayer() const { return m_contentsLayer.get(); }
285
286     void updateClippingStrategy(PlatformCALayer&, RefPtr<PlatformCALayer>& shapeMaskLayer, const FloatRoundedRect&);
287
288     WEBCORE_EXPORT void setReplicatedByLayer(GraphicsLayer*) override;
289
290     WEBCORE_EXPORT bool canThrottleLayerFlush() const override;
291
292     WEBCORE_EXPORT void getDebugBorderInfo(Color&, float& width) const override;
293     WEBCORE_EXPORT void dumpAdditionalProperties(WTF::TextStream&, LayerTreeAsTextBehavior) const override;
294
295     void computePixelAlignment(float contentsScale, const FloatPoint& positionRelativeToBase,
296         FloatPoint& position, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset) const;
297
298     TransformationMatrix layerTransform(const FloatPoint& position, const TransformationMatrix* customTransform = 0) const;
299
300     enum ComputeVisibleRectFlag { RespectAnimatingTransforms = 1 << 0 };
301     typedef unsigned ComputeVisibleRectFlags;
302     
303     struct VisibleAndCoverageRects {
304         FloatRect visibleRect;
305         FloatRect coverageRect;
306         TransformationMatrix animatingTransform;
307     };
308     
309     VisibleAndCoverageRects computeVisibleAndCoverageRect(TransformState&, bool accumulateTransform, ComputeVisibleRectFlags = RespectAnimatingTransforms) const;
310     bool adjustCoverageRect(VisibleAndCoverageRects&, const FloatRect& oldVisibleRect) const;
311
312     const FloatRect& visibleRect() const { return m_visibleRect; }
313     const FloatRect& coverageRect() const { return m_coverageRect; }
314
315     void setVisibleAndCoverageRects(const VisibleAndCoverageRects&, bool isViewportConstrained);
316     
317     static FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize);
318
319     bool recursiveVisibleRectChangeRequiresFlush(const CommitState&, const TransformState&) const;
320     
321     bool isPageTiledBackingLayer() const { return type() == Type::PageTiledBacking; }
322
323     // Used to track the path down the tree for replica layers.
324     struct ReplicaState {
325         static const size_t maxReplicaDepth = 16;
326         enum ReplicaBranchType { ChildBranch = 0, ReplicaBranch = 1 };
327         ReplicaState(ReplicaBranchType firstBranch)
328             : m_replicaDepth(0)
329         {
330             push(firstBranch);
331         }
332         
333         // Called as we walk down the tree to build replicas.
334         void push(ReplicaBranchType branchType)
335         {
336             m_replicaBranches.append(branchType);
337             if (branchType == ReplicaBranch)
338                 ++m_replicaDepth;
339         }
340         
341         void setBranchType(ReplicaBranchType branchType)
342         {
343             ASSERT(!m_replicaBranches.isEmpty());
344
345             if (m_replicaBranches.last() != branchType) {
346                 if (branchType == ReplicaBranch)
347                     ++m_replicaDepth;
348                 else
349                     --m_replicaDepth;
350             }
351
352             m_replicaBranches.last() = branchType;
353         }
354
355         void pop()
356         {
357             if (m_replicaBranches.last() == ReplicaBranch)
358                 --m_replicaDepth;
359             m_replicaBranches.removeLast();
360         }
361         
362         size_t depth() const { return m_replicaBranches.size(); }
363         size_t replicaDepth() const { return m_replicaDepth; }
364
365         CloneID cloneID() const;        
366
367     private:
368         Vector<ReplicaBranchType> m_replicaBranches;
369         size_t m_replicaDepth;
370     };
371     RefPtr<PlatformCALayer>replicatedLayerRoot(ReplicaState&);
372
373     enum CloneLevel { RootCloneLevel, IntermediateCloneLevel };
374     RefPtr<PlatformCALayer> fetchCloneLayers(GraphicsLayer* replicaRoot, ReplicaState&, CloneLevel);
375     
376     Ref<PlatformCALayer> cloneLayer(PlatformCALayer *, CloneLevel);
377     RefPtr<PlatformCALayer> findOrMakeClone(CloneID, PlatformCALayer *, LayerMap*, CloneLevel);
378
379     void ensureCloneLayers(CloneID, RefPtr<PlatformCALayer>& primaryLayer, RefPtr<PlatformCALayer>& structuralLayer,
380         RefPtr<PlatformCALayer>& contentsLayer, RefPtr<PlatformCALayer>& contentsClippingLayer, RefPtr<PlatformCALayer>& contentsShapeMaskLayer,
381         RefPtr<PlatformCALayer>& shapeMaskLayer, RefPtr<PlatformCALayer>& backdropLayer, RefPtr<PlatformCALayer>& backdropClippingLayer,
382         CloneLevel);
383
384     static void clearClones(std::unique_ptr<LayerMap>&);
385
386     bool hasCloneLayers() const { return !!m_layerClones; }
387     void removeCloneLayers();
388     FloatPoint positionForCloneRootLayer() const;
389
390     // All these "update" methods will be called inside a BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS block.
391     void updateNames();
392     void updateSublayerList(bool maxLayerDepthReached = false);
393     void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
394     void updateTransform();
395     void updateChildrenTransform();
396     void updateMasksToBounds();
397     void updateContentsVisibility();
398     void updateContentsOpaque(float pageScaleFactor);
399     void updateBackfaceVisibility();
400     void updateStructuralLayer();
401     void updateDrawsContent();
402     void updateCoverage(const CommitState&);
403     void updateBackgroundColor();
404     void updateUserInteractionEnabled();
405
406     void updateContentsImage();
407     void updateContentsPlatformLayer();
408     void updateContentsColorLayer();
409     void updateContentsRects();
410     void updateMasksToBoundsRect();
411     void updateMaskLayer();
412     void updateReplicatedLayers();
413
414     void updateAnimations();
415     void updateContentsNeedsDisplay();
416     void updateAcceleratesDrawing();
417     void updateSupportsSubpixelAntialiasedText();
418     void updateDebugIndicators();
419     void updateTiles();
420     void updateContentsScale(float pageScaleFactor);
421     void updateCustomAppearance();
422
423     void updateOpacityOnLayer();
424     void updateFilters();
425     void updateBackdropFilters();
426     void updateBackdropFiltersRect();
427
428 #if ENABLE(CSS_COMPOSITING)
429     void updateBlendMode();
430 #endif
431
432     void updateShape();
433     void updateWindRule();
434
435     enum StructuralLayerPurpose {
436         NoStructuralLayer = 0,
437         StructuralLayerForPreserves3D,
438         StructuralLayerForReplicaFlattening,
439         StructuralLayerForBackdrop
440     };
441     void ensureStructuralLayer(StructuralLayerPurpose);
442     StructuralLayerPurpose structuralLayerPurpose() const;
443
444     void setAnimationOnLayer(PlatformCAAnimation&, AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
445     bool removeCAAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index, int subINdex);
446     void pauseCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
447     void seekCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
448
449     enum MoveOrCopy { Move, Copy };
450     static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
451     void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
452
453     void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
454     {
455         moveOrCopyAnimations(Move, fromLayer, toLayer);
456     }
457     void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
458     {
459         moveOrCopyAnimations(Copy, fromLayer, toLayer);
460     }
461
462     // This represents the animation of a single property. There may be multiple transform animations for
463     // a single transition or keyframe animation, so index is used to distinguish these.
464     struct LayerPropertyAnimation {
465         LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedPropertyID property, int index, int subIndex, Seconds timeOffset)
466             : m_animation(WTFMove(caAnimation))
467             , m_name(animationName)
468             , m_property(property)
469             , m_index(index)
470             , m_subIndex(subIndex)
471             , m_timeOffset(timeOffset)
472         { }
473
474         RefPtr<PlatformCAAnimation> m_animation;
475         String m_name;
476         AnimatedPropertyID m_property;
477         int m_index;
478         int m_subIndex;
479         Seconds m_timeOffset;
480     };
481
482     bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const FloatSize& boxSize, int animationIndex, Seconds timeOffset, bool isMatrixAnimation);
483     bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, Seconds timeOffset);
484     void appendToUncommittedAnimations(LayerPropertyAnimation&&);
485
486     enum LayerChange : uint64_t {
487         NoChange                                = 0,
488         NameChanged                             = 1LLU << 1,
489         ChildrenChanged                         = 1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
490         GeometryChanged                         = 1LLU << 3,
491         TransformChanged                        = 1LLU << 4,
492         ChildrenTransformChanged                = 1LLU << 5,
493         Preserves3DChanged                      = 1LLU << 6,
494         MasksToBoundsChanged                    = 1LLU << 7,
495         DrawsContentChanged                     = 1LLU << 8,
496         BackgroundColorChanged                  = 1LLU << 9,
497         ContentsOpaqueChanged                   = 1LLU << 10,
498         BackfaceVisibilityChanged               = 1LLU << 11,
499         OpacityChanged                          = 1LLU << 12,
500         AnimationChanged                        = 1LLU << 13,
501         DirtyRectsChanged                       = 1LLU << 14,
502         ContentsImageChanged                    = 1LLU << 15,
503         ContentsPlatformLayerChanged            = 1LLU << 16,
504         ContentsColorLayerChanged               = 1LLU << 17,
505         ContentsRectsChanged                    = 1LLU << 18,
506         MasksToBoundsRectChanged                = 1LLU << 19,
507         MaskLayerChanged                        = 1LLU << 20,
508         ReplicatedLayerChanged                  = 1LLU << 21,
509         ContentsNeedsDisplay                    = 1LLU << 22,
510         AcceleratesDrawingChanged               = 1LLU << 23,
511         SupportsSubpixelAntialiasedTextChanged  = 1LLU << 24,
512         ContentsScaleChanged                    = 1LLU << 25,
513         ContentsVisibilityChanged               = 1LLU << 26,
514         CoverageRectChanged                     = 1LLU << 27,
515         FiltersChanged                          = 1LLU << 28,
516         BackdropFiltersChanged                  = 1LLU << 29,
517         BackdropFiltersRectChanged              = 1LLU << 30,
518         TilingAreaChanged                       = 1LLU << 31,
519         TilesAdded                              = 1LLU << 32,
520         DebugIndicatorsChanged                  = 1LLU << 33,
521         CustomAppearanceChanged                 = 1LLU << 34,
522         BlendModeChanged                        = 1LLU << 35,
523         ShapeChanged                            = 1LLU << 36,
524         WindRuleChanged                         = 1LLU << 37,
525         UserInteractionEnabledChanged           = 1LLU << 38,
526         NeedsComputeVisibleAndCoverageRect      = 1LLU << 39,
527     };
528     typedef uint64_t LayerChangeFlags;
529     void addUncommittedChanges(LayerChangeFlags);
530     bool hasDescendantsWithUncommittedChanges() const { return m_hasDescendantsWithUncommittedChanges; }
531     void setHasDescendantsWithUncommittedChanges(bool);
532     enum ScheduleFlushOrNot { ScheduleFlush, DontScheduleFlush };
533     void noteLayerPropertyChanged(LayerChangeFlags, ScheduleFlushOrNot = ScheduleFlush);
534     void noteSublayersChanged(ScheduleFlushOrNot = ScheduleFlush);
535     void noteChangesForScaleSensitiveProperties();
536
537     bool hasDescendantsWithRunningTransformAnimations() const { return m_hasDescendantsWithRunningTransformAnimations; }
538     void setHasDescendantsWithRunningTransformAnimations(bool b) { m_hasDescendantsWithRunningTransformAnimations = b; }
539
540     void propagateLayerChangeToReplicas(ScheduleFlushOrNot = ScheduleFlush);
541
542     void repaintLayerDirtyRects();
543
544     enum Action { Remove, Pause, Seek };
545     struct AnimationProcessingAction {
546         AnimationProcessingAction(Action action = Remove, Seconds timeOffset = 0_s)
547             : action(action)
548             , timeOffset(timeOffset)
549         {
550         }
551         Action action;
552         Seconds timeOffset; // Only used for pause.
553     };
554     void addProcessingActionForAnimation(const String&, AnimationProcessingAction);
555
556     RefPtr<PlatformCALayer> m_layer; // The main layer
557     RefPtr<PlatformCALayer> m_structuralLayer; // A layer used for structural reasons, like preserves-3d or replica-flattening. Is the parent of m_layer.
558     RefPtr<PlatformCALayer> m_contentsClippingLayer; // A layer used to clip inner content
559     RefPtr<PlatformCALayer> m_shapeMaskLayer; // Used to clip with non-trivial corner radii.
560     RefPtr<PlatformCALayer> m_backdropClippingLayer; // Used to clip the backdrop layer with corner radii.
561     RefPtr<PlatformCALayer> m_contentsLayer; // A layer used for inner content, like image and video
562     RefPtr<PlatformCALayer> m_contentsShapeMaskLayer; // Used to clip the content layer with non-trivial corner radii.
563     RefPtr<PlatformCALayer> m_backdropLayer; // The layer used for backdrop rendering, if necessary.
564
565     // References to clones of our layers, for replicated layers.
566     std::unique_ptr<LayerMap> m_layerClones;
567     std::unique_ptr<LayerMap> m_structuralLayerClones;
568     std::unique_ptr<LayerMap> m_contentsLayerClones;
569     std::unique_ptr<LayerMap> m_contentsClippingLayerClones;
570     std::unique_ptr<LayerMap> m_contentsShapeMaskLayerClones;
571     std::unique_ptr<LayerMap> m_shapeMaskLayerClones;
572     std::unique_ptr<LayerMap> m_backdropLayerClones;
573     std::unique_ptr<LayerMap> m_backdropClippingLayerClones;
574
575 #ifdef VISIBLE_TILE_WASH
576     RefPtr<PlatformCALayer> m_visibleTileWashLayer;
577 #endif
578     FloatRect m_visibleRect;
579     FloatSize m_sizeAtLastCoverageRectUpdate;
580
581     FloatRect m_coverageRect; // Area for which we should maintain backing store, in the coordinate space of this layer.
582     
583     ContentsLayerPurpose m_contentsLayerPurpose { NoContentsLayer };
584     bool m_needsFullRepaint { false };
585     bool m_usingBackdropLayerType { false };
586     bool m_isViewportConstrained { false };
587     bool m_intersectsCoverageRect { false };
588     bool m_hasEverPainted { false };
589     bool m_hasDescendantsWithRunningTransformAnimations { false };
590
591     Color m_contentsSolidColor;
592
593     RetainPtr<CGImageRef> m_uncorrectedContentsImage;
594     RetainPtr<CGImageRef> m_pendingContentsImage;
595     
596     // Uncommitted transitions and animations.
597     Vector<LayerPropertyAnimation> m_uncomittedAnimations;
598     
599     typedef HashMap<String, Vector<AnimationProcessingAction>> AnimationsToProcessMap;
600     AnimationsToProcessMap m_animationsToProcess;
601
602     // Map of animation names to their associated lists of property animations, so we can remove/pause them.
603     typedef HashMap<String, Vector<LayerPropertyAnimation>> AnimationsMap;
604     AnimationsMap m_runningAnimations;
605
606     Vector<FloatRect> m_dirtyRects;
607
608     std::unique_ptr<DisplayList::DisplayList> m_displayList;
609
610     FloatSize m_pixelAlignmentOffset;
611
612 #if PLATFORM(WIN)
613     // 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.
614     LayerChangeFlags m_uncommittedChanges { 0 };
615 #else
616     LayerChangeFlags m_uncommittedChanges { CoverageRectChanged };
617 #endif
618     bool m_hasDescendantsWithUncommittedChanges { false };
619
620     bool m_isCommittingChanges { false };
621     FloatRect m_previousCommittedVisibleRect;
622 };
623
624 } // namespace WebCore
625
626 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::GraphicsLayerCA, isGraphicsLayerCA())