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