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