f679b2c95370a3bfafafa78b1d0858fa0490092e
[WebKit-https.git] / Source / WebCore / platform / graphics / texmap / coordinated / CoordinatedGraphicsLayer.h
1 /*
2  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  Library General Public License for more details.
13
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB.  If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18  */
19
20
21 #ifndef CoordinatedGraphicsLayer_h
22 #define CoordinatedGraphicsLayer_h
23
24 #if USE(COORDINATED_GRAPHICS)
25
26 #include "CoordinatedGraphicsState.h"
27 #include "FloatPoint3D.h"
28 #include "GraphicsLayer.h"
29 #include "GraphicsLayerTransform.h"
30 #include "Image.h"
31 #include "IntSize.h"
32 #include "NicosiaBuffer.h"
33 #include "NicosiaPlatformLayer.h"
34 #include "TextureMapperAnimation.h"
35 #include "TransformationMatrix.h"
36 #include <wtf/text/StringHash.h>
37
38 namespace Nicosia {
39 class PaintingEngine;
40 }
41
42 namespace WebCore {
43 class CoordinatedGraphicsLayer;
44 class TextureMapperAnimations;
45
46 class CoordinatedGraphicsLayerClient {
47 public:
48     virtual bool isFlushingLayerChanges() const = 0;
49     virtual FloatRect visibleContentsRect() const = 0;
50     virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
51     virtual void attachLayer(CoordinatedGraphicsLayer*) = 0;
52     virtual Nicosia::PaintingEngine& paintingEngine() = 0;
53     virtual void syncLayerState() = 0;
54 };
55
56 class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer {
57 public:
58     explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
59     virtual ~CoordinatedGraphicsLayer();
60
61     // FIXME: Merge these two methods.
62     Nicosia::PlatformLayer::LayerID id() const;
63     PlatformLayerID primaryLayerID() const override;
64
65     // Reimplementations from GraphicsLayer.h.
66     bool setChildren(const Vector<GraphicsLayer*>&) override;
67     void addChild(GraphicsLayer*) override;
68     void addChildAtIndex(GraphicsLayer*, int) override;
69     void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
70     void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
71     bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
72     void removeFromParent() override;
73     void setPosition(const FloatPoint&) override;
74     void setAnchorPoint(const FloatPoint3D&) override;
75     void setSize(const FloatSize&) override;
76     void setTransform(const TransformationMatrix&) override;
77     void setChildrenTransform(const TransformationMatrix&) override;
78     void setPreserves3D(bool) override;
79     void setMasksToBounds(bool) override;
80     void setDrawsContent(bool) override;
81     void setContentsVisible(bool) override;
82     void setContentsOpaque(bool) override;
83     void setBackfaceVisibility(bool) override;
84     void setOpacity(float) override;
85     void setContentsRect(const FloatRect&) override;
86     void setContentsTilePhase(const FloatSize&) override;
87     void setContentsTileSize(const FloatSize&) override;
88     void setContentsToImage(Image*) override;
89     void setContentsToSolidColor(const Color&) override;
90     void setShowDebugBorder(bool) override;
91     void setShowRepaintCounter(bool) override;
92     bool shouldDirectlyCompositeImage(Image*) const override;
93     void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
94     void setMaskLayer(GraphicsLayer*) override;
95     void setReplicatedByLayer(GraphicsLayer*) override;
96     void setNeedsDisplay() override;
97     void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
98     void setContentsNeedsDisplay() override;
99     void deviceOrPageScaleFactorChanged() override;
100     void flushCompositingState(const FloatRect&) override;
101     void flushCompositingStateForThisLayerOnly() override;
102     bool setFilters(const FilterOperations&) override;
103     bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
104     void pauseAnimation(const String&, double) override;
105     void removeAnimation(const String&) override;
106     void suspendAnimations(MonotonicTime) override;
107     void resumeAnimations() override;
108     bool usesContentsLayer() const override;
109
110     void syncPendingStateChangesIncludingSubLayers();
111     void updateContentBuffersIncludingSubLayers();
112
113     FloatPoint computePositionRelativeToBase();
114     void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
115
116     IntRect transformedVisibleRect();
117
118     void setCoordinator(CoordinatedGraphicsLayerClient*);
119     void setCoordinatorIncludingSubLayersIfNeeded(CoordinatedGraphicsLayerClient*);
120
121     void setNeedsVisibleRectAdjustment();
122     void purgeBackingStores();
123
124     const RefPtr<Nicosia::CompositionLayer>& compositionLayer() const;
125
126 private:
127     bool isCoordinatedGraphicsLayer() const;
128
129     void updatePlatformLayer();
130
131     void setDebugBorder(const Color&, float width) override;
132
133     void didChangeAnimations();
134     void didChangeGeometry();
135     void didChangeChildren();
136     void didChangeFilters();
137     void didUpdateTileBuffers();
138
139     void computeTransformedVisibleRect();
140     void updateContentBuffers();
141
142     void notifyFlushRequired();
143
144     bool shouldHaveBackingStore() const;
145     bool selfOrAncestorHasActiveTransformAnimation() const;
146     bool selfOrAncestorHaveNonAffineTransforms();
147
148     void setShouldUpdateVisibleRect();
149     float effectiveContentsScale();
150
151     void animationStartedTimerFired();
152
153     bool filtersCanBeComposited(const FilterOperations&) const;
154
155     Nicosia::PlatformLayer::LayerID m_id;
156     GraphicsLayerTransform m_layerTransform;
157     TransformationMatrix m_cachedInverseTransform;
158     FloatSize m_pixelAlignmentOffset;
159     FloatSize m_adjustedSize;
160     FloatPoint m_adjustedPosition;
161     FloatPoint3D m_adjustedAnchorPoint;
162
163     Color m_solidColor;
164
165 #ifndef NDEBUG
166     bool m_isPurging;
167 #endif
168     bool m_shouldUpdateVisibleRect: 1;
169     bool m_shouldSyncLayerState: 1;
170     bool m_movingVisibleRect : 1;
171     bool m_pendingContentsScaleAdjustment : 1;
172     bool m_pendingVisibleRectAdjustment : 1;
173     bool m_shouldUpdatePlatformLayer : 1;
174
175     CoordinatedGraphicsLayerClient* m_coordinator;
176
177     struct {
178         bool completeLayer { false };
179         Vector<FloatRect, 32> rects;
180     } m_needsDisplay;
181
182     RefPtr<Image> m_compositedImage;
183     NativeImagePtr m_compositedNativeImagePtr;
184
185     Timer m_animationStartedTimer;
186     TextureMapperAnimations m_animations;
187     MonotonicTime m_lastAnimationStartTime;
188
189     struct {
190         RefPtr<Nicosia::CompositionLayer> layer;
191         Nicosia::CompositionLayer::LayerState::Delta delta;
192         Nicosia::CompositionLayer::LayerState::RepaintCounter repaintCounter;
193         Nicosia::CompositionLayer::LayerState::DebugBorder debugBorder;
194         bool performLayerSync { false };
195
196         RefPtr<Nicosia::BackingStore> backingStore;
197         RefPtr<Nicosia::ContentLayer> contentLayer;
198         RefPtr<Nicosia::ImageBacking> imageBacking;
199     } m_nicosia;
200 };
201
202 } // namespace WebCore
203
204 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer())
205
206 #endif // USE(COORDINATED_GRAPHICS)
207
208 #endif // CoordinatedGraphicsLayer_h