Combine event and touch action regions into a single class
[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     static FloatRect adjustTiledLayerVisibleRect(TiledBacking*, const FloatRect& oldVisibleRect, const FloatRect& newVisibleRect, const FloatSize& oldSize, const FloatSize& newSize);
327
328     bool recursiveVisibleRectChangeRequiresFlush(const CommitState&, const TransformState&) const;
329     
330     bool isPageTiledBackingLayer() const { return type() == Type::PageTiledBacking; }
331
332     // Used to track the path down the tree for replica layers.
333     struct ReplicaState {
334         static const size_t maxReplicaDepth = 16;
335         enum ReplicaBranchType { ChildBranch = 0, ReplicaBranch = 1 };
336         ReplicaState(ReplicaBranchType firstBranch)
337             : m_replicaDepth(0)
338         {
339             push(firstBranch);
340         }
341         
342         // Called as we walk down the tree to build replicas.
343         void push(ReplicaBranchType branchType)
344         {
345             m_replicaBranches.append(branchType);
346             if (branchType == ReplicaBranch)
347                 ++m_replicaDepth;
348         }
349         
350         void setBranchType(ReplicaBranchType branchType)
351         {
352             ASSERT(!m_replicaBranches.isEmpty());
353
354             if (m_replicaBranches.last() != branchType) {
355                 if (branchType == ReplicaBranch)
356                     ++m_replicaDepth;
357                 else
358                     --m_replicaDepth;
359             }
360
361             m_replicaBranches.last() = branchType;
362         }
363
364         void pop()
365         {
366             if (m_replicaBranches.last() == ReplicaBranch)
367                 --m_replicaDepth;
368             m_replicaBranches.removeLast();
369         }
370         
371         size_t depth() const { return m_replicaBranches.size(); }
372         size_t replicaDepth() const { return m_replicaDepth; }
373
374         CloneID cloneID() const;        
375
376     private:
377         Vector<ReplicaBranchType> m_replicaBranches;
378         size_t m_replicaDepth;
379     };
380     RefPtr<PlatformCALayer>replicatedLayerRoot(ReplicaState&);
381
382     enum CloneLevel { RootCloneLevel, IntermediateCloneLevel };
383     RefPtr<PlatformCALayer> fetchCloneLayers(GraphicsLayer* replicaRoot, ReplicaState&, CloneLevel);
384     
385     Ref<PlatformCALayer> cloneLayer(PlatformCALayer *, CloneLevel);
386     RefPtr<PlatformCALayer> findOrMakeClone(CloneID, PlatformCALayer *, LayerMap&, CloneLevel);
387
388     void ensureCloneLayers(CloneID, RefPtr<PlatformCALayer>& primaryLayer, RefPtr<PlatformCALayer>& structuralLayer,
389         RefPtr<PlatformCALayer>& contentsLayer, RefPtr<PlatformCALayer>& contentsClippingLayer, RefPtr<PlatformCALayer>& contentsShapeMaskLayer,
390         RefPtr<PlatformCALayer>& shapeMaskLayer, RefPtr<PlatformCALayer>& backdropLayer, RefPtr<PlatformCALayer>& backdropClippingLayer,
391         CloneLevel);
392
393     bool hasCloneLayers() const { return !!m_layerClones; }
394     void removeCloneLayers();
395     FloatPoint positionForCloneRootLayer() const;
396
397     // All these "update" methods will be called inside a BEGIN_BLOCK_OBJC_EXCEPTIONS/END_BLOCK_OBJC_EXCEPTIONS block.
398     void updateNames();
399     void updateSublayerList(bool maxLayerDepthReached = false);
400     void updateGeometry(float pixelAlignmentScale, const FloatPoint& positionRelativeToBase);
401     void updateTransform();
402     void updateChildrenTransform();
403     void updateMasksToBounds();
404     void updateContentsVisibility();
405     void updateContentsOpaque(float pageScaleFactor);
406     void updateBackfaceVisibility();
407     bool updateStructuralLayer();
408     void updateDrawsContent();
409     void updateCoverage(const CommitState&);
410     void updateBackgroundColor();
411     void updateUserInteractionEnabled();
412
413     void updateContentsImage();
414     void updateContentsPlatformLayer();
415     void updateContentsColorLayer();
416     void updateContentsRects();
417     void updateMasksToBoundsRect();
418     void updateEventRegion();
419     void updateMaskLayer();
420     void updateReplicatedLayers();
421
422     void updateAnimations();
423     void updateContentsNeedsDisplay();
424     void updateAcceleratesDrawing();
425     void updateSupportsSubpixelAntialiasedText();
426     void updateDebugIndicators();
427     void updateTiles();
428     void updateContentsScale(float pageScaleFactor);
429     void updateCustomAppearance();
430
431     void updateOpacityOnLayer();
432     void updateFilters();
433     void updateBackdropFilters(CommitState&);
434     void updateBackdropFiltersRect();
435
436 #if ENABLE(CSS_COMPOSITING)
437     void updateBlendMode();
438 #endif
439
440     void updateShape();
441     void updateWindRule();
442
443     enum StructuralLayerPurpose {
444         NoStructuralLayer = 0,
445         StructuralLayerForPreserves3D,
446         StructuralLayerForReplicaFlattening,
447         StructuralLayerForBackdrop
448     };
449     bool ensureStructuralLayer(StructuralLayerPurpose);
450     StructuralLayerPurpose structuralLayerPurpose() const;
451     
452     void ensureLayerAnimations();
453
454     void setAnimationOnLayer(PlatformCAAnimation&, AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
455     bool removeCAAnimationFromLayer(AnimatedPropertyID, const String& animationName, int index, int subINdex);
456     void pauseCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
457     void seekCAAnimationOnLayer(AnimatedPropertyID, const String& animationName, int index, int subIndex, Seconds timeOffset);
458
459     enum MoveOrCopy { Move, Copy };
460     static void moveOrCopyLayerAnimation(MoveOrCopy, const String& animationIdentifier, PlatformCALayer *fromLayer, PlatformCALayer *toLayer);
461     void moveOrCopyAnimations(MoveOrCopy, PlatformCALayer* fromLayer, PlatformCALayer* toLayer);
462
463     void moveAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
464     {
465         moveOrCopyAnimations(Move, fromLayer, toLayer);
466     }
467     void copyAnimations(PlatformCALayer* fromLayer, PlatformCALayer* toLayer)
468     {
469         moveOrCopyAnimations(Copy, fromLayer, toLayer);
470     }
471
472     // This represents the animation of a single property. There may be multiple transform animations for
473     // a single transition or keyframe animation, so index is used to distinguish these.
474     struct LayerPropertyAnimation {
475         LayerPropertyAnimation(Ref<PlatformCAAnimation>&& caAnimation, const String& animationName, AnimatedPropertyID property, int index, int subIndex, Seconds timeOffset)
476             : m_animation(WTFMove(caAnimation))
477             , m_name(animationName)
478             , m_property(property)
479             , m_index(index)
480             , m_subIndex(subIndex)
481             , m_timeOffset(timeOffset)
482         { }
483
484         RefPtr<PlatformCAAnimation> m_animation;
485         String m_name;
486         AnimatedPropertyID m_property;
487         int m_index;
488         int m_subIndex;
489         Seconds m_timeOffset;
490     };
491
492     bool appendToUncommittedAnimations(const KeyframeValueList&, const TransformOperations*, const Animation*, const String& animationName, const FloatSize& boxSize, int animationIndex, Seconds timeOffset, bool isMatrixAnimation);
493     bool appendToUncommittedAnimations(const KeyframeValueList&, const FilterOperation*, const Animation*, const String& animationName, int animationIndex, Seconds timeOffset);
494     void appendToUncommittedAnimations(LayerPropertyAnimation&&);
495
496     enum LayerChange : uint64_t {
497         NoChange                                = 0,
498         NameChanged                             = 1LLU << 1,
499         ChildrenChanged                         = 1LLU << 2, // also used for content layer, and preserves-3d, and size if tiling changes?
500         GeometryChanged                         = 1LLU << 3,
501         TransformChanged                        = 1LLU << 4,
502         ChildrenTransformChanged                = 1LLU << 5,
503         Preserves3DChanged                      = 1LLU << 6,
504         MasksToBoundsChanged                    = 1LLU << 7,
505         DrawsContentChanged                     = 1LLU << 8,
506         BackgroundColorChanged                  = 1LLU << 9,
507         ContentsOpaqueChanged                   = 1LLU << 10,
508         BackfaceVisibilityChanged               = 1LLU << 11,
509         OpacityChanged                          = 1LLU << 12,
510         AnimationChanged                        = 1LLU << 13,
511         DirtyRectsChanged                       = 1LLU << 14,
512         ContentsImageChanged                    = 1LLU << 15,
513         ContentsPlatformLayerChanged            = 1LLU << 16,
514         ContentsColorLayerChanged               = 1LLU << 17,
515         ContentsRectsChanged                    = 1LLU << 18,
516         MasksToBoundsRectChanged                = 1LLU << 19,
517         MaskLayerChanged                        = 1LLU << 20,
518         ReplicatedLayerChanged                  = 1LLU << 21,
519         ContentsNeedsDisplay                    = 1LLU << 22,
520         AcceleratesDrawingChanged               = 1LLU << 23,
521         SupportsSubpixelAntialiasedTextChanged  = 1LLU << 24,
522         ContentsScaleChanged                    = 1LLU << 25,
523         ContentsVisibilityChanged               = 1LLU << 26,
524         CoverageRectChanged                     = 1LLU << 27,
525         FiltersChanged                          = 1LLU << 28,
526         BackdropFiltersChanged                  = 1LLU << 29,
527         BackdropFiltersRectChanged              = 1LLU << 30,
528         TilingAreaChanged                       = 1LLU << 31,
529         TilesAdded                              = 1LLU << 32,
530         DebugIndicatorsChanged                  = 1LLU << 33,
531         CustomAppearanceChanged                 = 1LLU << 34,
532         BlendModeChanged                        = 1LLU << 35,
533         ShapeChanged                            = 1LLU << 36,
534         WindRuleChanged                         = 1LLU << 37,
535         UserInteractionEnabledChanged           = 1LLU << 38,
536         NeedsComputeVisibleAndCoverageRect      = 1LLU << 39,
537         EventRegionChanged                      = 1LLU << 40,
538     };
539     typedef uint64_t LayerChangeFlags;
540     void addUncommittedChanges(LayerChangeFlags);
541     bool hasDescendantsWithUncommittedChanges() const { return m_hasDescendantsWithUncommittedChanges; }
542     void setHasDescendantsWithUncommittedChanges(bool);
543     enum ScheduleFlushOrNot { ScheduleFlush, DontScheduleFlush };
544     void noteLayerPropertyChanged(LayerChangeFlags, ScheduleFlushOrNot = ScheduleFlush);
545     void noteSublayersChanged(ScheduleFlushOrNot = ScheduleFlush);
546     void noteChangesForScaleSensitiveProperties();
547
548     bool hasDescendantsWithRunningTransformAnimations() const { return m_hasDescendantsWithRunningTransformAnimations; }
549     void setHasDescendantsWithRunningTransformAnimations(bool b) { m_hasDescendantsWithRunningTransformAnimations = b; }
550
551     void propagateLayerChangeToReplicas(ScheduleFlushOrNot = ScheduleFlush);
552
553     void repaintLayerDirtyRects();
554
555     enum Action { Remove, Pause, Seek };
556     struct AnimationProcessingAction {
557         AnimationProcessingAction(Action action = Remove, Seconds timeOffset = 0_s)
558             : action(action)
559             , timeOffset(timeOffset)
560         {
561         }
562         Action action;
563         Seconds timeOffset; // Only used for pause.
564     };
565     void addProcessingActionForAnimation(const String&, AnimationProcessingAction);
566
567 #if PLATFORM(WIN)
568     // 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.
569     LayerChangeFlags m_uncommittedChanges { 0 };
570 #else
571     LayerChangeFlags m_uncommittedChanges { CoverageRectChanged };
572 #endif
573
574     RefPtr<PlatformCALayer> m_layer; // The main layer
575     RefPtr<PlatformCALayer> m_structuralLayer; // A layer used for structural reasons, like preserves-3d or replica-flattening. Is the parent of m_layer.
576     RefPtr<PlatformCALayer> m_contentsClippingLayer; // A layer used to clip inner content
577     RefPtr<PlatformCALayer> m_shapeMaskLayer; // Used to clip with non-trivial corner radii.
578     RefPtr<PlatformCALayer> m_backdropClippingLayer; // Used to clip the backdrop layer with corner radii.
579     RefPtr<PlatformCALayer> m_contentsLayer; // A layer used for inner content, like image and video
580     RefPtr<PlatformCALayer> m_contentsShapeMaskLayer; // Used to clip the content layer with non-trivial corner radii.
581     RefPtr<PlatformCALayer> m_backdropLayer; // The layer used for backdrop rendering, if necessary.
582
583     // References to clones of our layers, for replicated layers.
584     struct LayerClones {
585         LayerMap primaryLayerClones;
586         LayerMap structuralLayerClones;
587         LayerMap contentsLayerClones;
588         LayerMap contentsClippingLayerClones;
589         LayerMap contentsShapeMaskLayerClones;
590         LayerMap shapeMaskLayerClones;
591         LayerMap backdropLayerClones;
592         LayerMap backdropClippingLayerClones;
593     };
594
595     std::unique_ptr<LayerClones> m_layerClones;
596
597 #ifdef VISIBLE_TILE_WASH
598     RefPtr<PlatformCALayer> m_visibleTileWashLayer;
599 #endif
600     FloatRect m_visibleRect;
601     FloatRect m_previousCommittedVisibleRect;
602     FloatRect m_coverageRect; // Area for which we should maintain backing store, in the coordinate space of this layer.
603     FloatSize m_sizeAtLastCoverageRectUpdate;
604     FloatSize m_pixelAlignmentOffset;
605
606     Color m_contentsSolidColor;
607
608     RetainPtr<CGImageRef> m_uncorrectedContentsImage;
609     RetainPtr<CGImageRef> m_pendingContentsImage;
610     
611     typedef HashMap<String, Vector<AnimationProcessingAction>> AnimationsToProcessMap;
612     typedef HashMap<String, Vector<LayerPropertyAnimation>> AnimationsMap;
613     struct LayerAnimations {
614         Vector<LayerPropertyAnimation> uncomittedAnimations;
615         AnimationsToProcessMap animationsToProcess;
616         AnimationsMap runningAnimations;
617     };
618     
619     std::unique_ptr<LayerAnimations> m_animations;
620
621     Vector<FloatRect> m_dirtyRects;
622
623     std::unique_ptr<DisplayList::DisplayList> m_displayList;
624
625     ContentsLayerPurpose m_contentsLayerPurpose { ContentsLayerPurpose::None };
626     bool m_isCommittingChanges { false };
627
628     bool m_needsFullRepaint : 1;
629     bool m_usingBackdropLayerType : 1;
630     bool m_isViewportConstrained : 1;
631     bool m_intersectsCoverageRect : 1;
632     bool m_hasEverPainted : 1;
633     bool m_hasDescendantsWithRunningTransformAnimations : 1;
634     bool m_hasDescendantsWithUncommittedChanges : 1;
635 };
636
637 } // namespace WebCore
638
639 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::GraphicsLayerCA, isGraphicsLayerCA())