Stop using PassRefPtr in platform/graphics
[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 "CoordinatedImageBacking.h"
28 #include "FloatPoint3D.h"
29 #include "GraphicsLayer.h"
30 #include "GraphicsLayerTransform.h"
31 #include "Image.h"
32 #include "IntSize.h"
33 #include "TextureMapperAnimation.h"
34 #include "TextureMapperPlatformLayer.h"
35 #include "TiledBackingStore.h"
36 #include "TiledBackingStoreClient.h"
37 #include "TransformationMatrix.h"
38 #include <wtf/text/StringHash.h>
39
40 namespace WebCore {
41 class CoordinatedGraphicsLayer;
42 class TextureMapperAnimations;
43 class ScrollableArea;
44
45 class CoordinatedGraphicsLayerClient {
46 public:
47     virtual bool isFlushingLayerChanges() const = 0;
48     virtual FloatRect visibleContentsRect() const = 0;
49     virtual Ref<CoordinatedImageBacking> createImageBackingIfNeeded(Image&) = 0;
50     virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
51     virtual bool paintToSurface(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client&) = 0;
52
53     virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
54 };
55
56 class CoordinatedGraphicsLayer : public GraphicsLayer
57     , public TiledBackingStoreClient
58 #if USE(COORDINATED_GRAPHICS_THREADED)
59     , public TextureMapperPlatformLayer::Client
60 #endif
61     , public CoordinatedImageBacking::Host {
62 public:
63     explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
64     virtual ~CoordinatedGraphicsLayer();
65
66     PlatformLayerID primaryLayerID() const override { return id(); }
67
68     // Reimplementations from GraphicsLayer.h.
69     bool setChildren(const Vector<GraphicsLayer*>&) override;
70     void addChild(GraphicsLayer*) override;
71     void addChildAtIndex(GraphicsLayer*, int) override;
72     void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
73     void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
74     bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
75     void removeFromParent() override;
76     void setPosition(const FloatPoint&) override;
77     void setAnchorPoint(const FloatPoint3D&) override;
78     void setSize(const FloatSize&) override;
79     void setTransform(const TransformationMatrix&) override;
80     void setChildrenTransform(const TransformationMatrix&) override;
81     void setPreserves3D(bool) override;
82     void setMasksToBounds(bool) override;
83     void setDrawsContent(bool) override;
84     void setContentsVisible(bool) override;
85     void setContentsOpaque(bool) override;
86     void setBackfaceVisibility(bool) override;
87     void setOpacity(float) override;
88     void setContentsRect(const FloatRect&) override;
89     void setContentsTilePhase(const FloatSize&) override;
90     void setContentsTileSize(const FloatSize&) override;
91     void setContentsToImage(Image*) override;
92     void setContentsToSolidColor(const Color&) override;
93     void setShowDebugBorder(bool) override;
94     void setShowRepaintCounter(bool) override;
95     bool shouldDirectlyCompositeImage(Image*) const override;
96     void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
97     void setMaskLayer(GraphicsLayer*) override;
98     void setReplicatedByLayer(GraphicsLayer*) override;
99     void setNeedsDisplay() override;
100     void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
101     void setContentsNeedsDisplay() override;
102     void deviceOrPageScaleFactorChanged() override;
103     void flushCompositingState(const FloatRect&) override;
104     void flushCompositingStateForThisLayerOnly() override;
105     bool setFilters(const FilterOperations&) override;
106     bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
107     void pauseAnimation(const String&, double) override;
108     void removeAnimation(const String&) override;
109     void suspendAnimations(double time) override;
110     void resumeAnimations() override;
111     bool usesContentsLayer() const override { return m_platformLayer || m_compositedImage; }
112
113     void syncPendingStateChangesIncludingSubLayers();
114     void updateContentBuffersIncludingSubLayers();
115
116     FloatPoint computePositionRelativeToBase();
117     void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
118
119     void setVisibleContentRectTrajectoryVector(const FloatPoint&);
120
121     void setScrollableArea(ScrollableArea*);
122     bool isScrollable() const { return !!m_scrollableArea; }
123     void commitScrollOffset(const IntSize&);
124
125     CoordinatedLayerID id() const { return m_id; }
126
127     void setFixedToViewport(bool isFixed);
128
129     IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
130     IntRect transformedVisibleRect();
131
132     // TiledBackingStoreClient
133     void tiledBackingStorePaint(GraphicsContext&, const IntRect&) override;
134     void didUpdateTileBuffers() override;
135     void tiledBackingStoreHasPendingTileCreation() override;
136     void createTile(uint32_t tileID, float) override;
137     void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
138     void removeTile(uint32_t tileID) override;
139     bool paintToSurface(const IntSize&, uint32_t& /* atlasID */, IntPoint&, CoordinatedSurface::Client&) override;
140
141     void setCoordinator(CoordinatedGraphicsLayerClient*);
142
143     void setNeedsVisibleRectAdjustment();
144     void purgeBackingStores();
145
146     CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively();
147
148 private:
149     bool isCoordinatedGraphicsLayer() const override { return true; }
150
151     void syncPlatformLayer();
152     void updatePlatformLayer();
153 #if USE(COORDINATED_GRAPHICS_THREADED)
154     void platformLayerWillBeDestroyed() override;
155     void setPlatformLayerNeedsDisplay() override;
156 #endif
157
158     void setDebugBorder(const Color&, float width) override;
159
160     bool fixedToViewport() const { return m_fixedToViewport; }
161
162     void didChangeLayerState();
163     void didChangeAnimations();
164     void didChangeGeometry();
165     void didChangeChildren();
166     void didChangeFilters();
167     void didChangeImageBacking();
168
169     void resetLayerState();
170     void syncLayerState();
171     void syncAnimations();
172     void syncChildren();
173     void syncFilters();
174     void syncImageBacking();
175     void computeTransformedVisibleRect();
176     void updateContentBuffers();
177
178     void createBackingStore();
179     void releaseImageBackingIfNeeded();
180
181     void notifyFlushRequired();
182
183     // CoordinatedImageBacking::Host
184     bool imageBackingVisible() override;
185     bool shouldHaveBackingStore() const;
186     bool selfOrAncestorHasActiveTransformAnimation() const;
187     bool selfOrAncestorHaveNonAffineTransforms();
188     void adjustContentsScale();
189
190     void setShouldUpdateVisibleRect();
191     float effectiveContentsScale();
192
193     void animationStartedTimerFired();
194
195     bool filtersCanBeComposited(const FilterOperations&) const;
196
197     CoordinatedLayerID m_id;
198     CoordinatedGraphicsLayerState m_layerState;
199     GraphicsLayerTransform m_layerTransform;
200     TransformationMatrix m_cachedInverseTransform;
201     FloatSize m_pixelAlignmentOffset;
202     FloatSize m_adjustedSize;
203     FloatPoint m_adjustedPosition;
204     FloatPoint3D m_adjustedAnchorPoint;
205
206 #ifndef NDEBUG
207     bool m_isPurging;
208 #endif
209     bool m_shouldUpdateVisibleRect: 1;
210     bool m_shouldSyncLayerState: 1;
211     bool m_shouldSyncChildren: 1;
212     bool m_shouldSyncFilters: 1;
213     bool m_shouldSyncImageBacking: 1;
214     bool m_shouldSyncAnimations: 1;
215     bool m_fixedToViewport : 1;
216     bool m_movingVisibleRect : 1;
217     bool m_pendingContentsScaleAdjustment : 1;
218     bool m_pendingVisibleRectAdjustment : 1;
219 #if USE(COORDINATED_GRAPHICS_THREADED)
220     bool m_shouldSyncPlatformLayer : 1;
221     bool m_shouldUpdatePlatformLayer : 1;
222 #endif
223
224     CoordinatedGraphicsLayerClient* m_coordinator;
225     std::unique_ptr<TiledBackingStore> m_mainBackingStore;
226     std::unique_ptr<TiledBackingStore> m_previousBackingStore;
227
228     RefPtr<Image> m_compositedImage;
229     NativeImagePtr m_compositedNativeImagePtr;
230     RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
231
232     PlatformLayer* m_platformLayer;
233     Timer m_animationStartedTimer;
234     TextureMapperAnimations m_animations;
235     double m_lastAnimationStartTime { 0.0 };
236
237     ScrollableArea* m_scrollableArea;
238 };
239
240 } // namespace WebCore
241
242 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer())
243
244 #endif // USE(COORDINATED_GRAPHICS)
245
246 #endif // CoordinatedGraphicsLayer_h