2 Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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.
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.
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.
21 #ifndef CoordinatedGraphicsLayer_h
22 #define CoordinatedGraphicsLayer_h
24 #include "CoordinatedGraphicsState.h"
25 #include "CoordinatedImageBacking.h"
26 #include "FloatPoint3D.h"
27 #include "GraphicsLayer.h"
28 #include "GraphicsLayerTransform.h"
31 #include "TextureMapperAnimation.h"
32 #include "TiledBackingStore.h"
33 #include "TiledBackingStoreClient.h"
34 #include "TransformationMatrix.h"
35 #if USE(GRAPHICS_SURFACE)
36 #include "GraphicsSurfaceToken.h"
38 #include <wtf/text/StringHash.h>
40 #if USE(COORDINATED_GRAPHICS)
43 class CoordinatedGraphicsLayer;
44 class TextureMapperAnimations;
47 class CoordinatedGraphicsLayerClient {
49 virtual bool isFlushingLayerChanges() const = 0;
50 virtual FloatRect visibleContentsRect() const = 0;
51 virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) = 0;
52 virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
53 virtual bool paintToSurface(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client*) = 0;
55 virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
58 class CoordinatedGraphicsLayer : public GraphicsLayer
59 , public TiledBackingStoreClient
60 , public CoordinatedImageBacking::Host {
62 explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
63 virtual ~CoordinatedGraphicsLayer();
65 // Reimplementations from GraphicsLayer.h.
66 virtual bool setChildren(const Vector<GraphicsLayer*>&) override;
67 virtual void addChild(GraphicsLayer*) override;
68 virtual void addChildAtIndex(GraphicsLayer*, int) override;
69 virtual void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
70 virtual void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
71 virtual bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
72 virtual void removeFromParent() override;
73 virtual void setPosition(const FloatPoint&) override;
74 virtual void setAnchorPoint(const FloatPoint3D&) override;
75 virtual void setSize(const FloatSize&) override;
76 virtual void setTransform(const TransformationMatrix&) override;
77 virtual void setChildrenTransform(const TransformationMatrix&) override;
78 virtual void setPreserves3D(bool) override;
79 virtual void setMasksToBounds(bool) override;
80 virtual void setDrawsContent(bool) override;
81 virtual void setContentsVisible(bool) override;
82 virtual void setContentsOpaque(bool) override;
83 virtual void setBackfaceVisibility(bool) override;
84 virtual void setOpacity(float) override;
85 virtual void setContentsRect(const FloatRect&) override;
86 virtual void setContentsTilePhase(const FloatSize&) override;
87 virtual void setContentsTileSize(const FloatSize&) override;
88 virtual void setContentsToImage(Image*) override;
89 virtual void setContentsToSolidColor(const Color&) override;
90 virtual void setShowDebugBorder(bool) override;
91 virtual void setShowRepaintCounter(bool) override;
92 virtual bool shouldDirectlyCompositeImage(Image*) const override;
93 virtual void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
94 virtual void setMaskLayer(GraphicsLayer*) override;
95 virtual void setReplicatedByLayer(GraphicsLayer*) override;
96 virtual void setNeedsDisplay() override;
97 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
98 virtual void setContentsNeedsDisplay() override;
99 virtual void deviceOrPageScaleFactorChanged() override;
100 virtual void flushCompositingState(const FloatRect&) override;
101 virtual void flushCompositingStateForThisLayerOnly() override;
102 virtual bool setFilters(const FilterOperations&) override;
103 virtual bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
104 virtual void pauseAnimation(const String&, double) override;
105 virtual void removeAnimation(const String&) override;
106 virtual void suspendAnimations(double time) override;
107 virtual void resumeAnimations() override;
108 virtual bool usesContentsLayer() const override { return m_platformLayer || m_compositedImage; }
110 void syncPendingStateChangesIncludingSubLayers();
111 void updateContentBuffersIncludingSubLayers();
113 FloatPoint computePositionRelativeToBase();
114 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
116 void setVisibleContentRectTrajectoryVector(const FloatPoint&);
118 void setScrollableArea(ScrollableArea*);
119 bool isScrollable() const { return !!m_scrollableArea; }
120 void commitScrollOffset(const IntSize&);
122 CoordinatedLayerID id() const;
124 void setFixedToViewport(bool isFixed);
126 IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
128 // TiledBackingStoreClient
129 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) override;
130 virtual void didUpdateTileBuffers() override;
131 virtual void tiledBackingStoreHasPendingTileCreation() override;
132 virtual IntRect tiledBackingStoreContentsRect() override;
133 virtual IntRect tiledBackingStoreVisibleRect() override;
134 virtual void createTile(uint32_t tileID, float) override;
135 virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
136 virtual void removeTile(uint32_t tileID) override;
137 virtual bool paintToSurface(const IntSize&, uint32_t& /* atlasID */, IntPoint&, CoordinatedSurface::Client*) override;
139 void setCoordinator(CoordinatedGraphicsLayerClient*);
141 void setNeedsVisibleRectAdjustment();
142 void purgeBackingStores();
144 CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively();
147 #if USE(GRAPHICS_SURFACE)
148 enum PendingPlatformLayerOperation {
150 CreatePlatformLayer = 0x01,
151 DestroyPlatformLayer = 0x02,
152 SyncPlatformLayer = 0x04,
153 CreateAndSyncPlatformLayer = CreatePlatformLayer | SyncPlatformLayer,
154 RecreatePlatformLayer = CreateAndSyncPlatformLayer | DestroyPlatformLayer
157 void syncPlatformLayer();
158 void destroyPlatformLayerIfNeeded();
159 void createPlatformLayerIfNeeded();
162 virtual void setDebugBorder(const Color&, float width) override;
164 bool fixedToViewport() const { return m_fixedToViewport; }
166 void didChangeLayerState();
167 void didChangeAnimations();
168 void didChangeGeometry();
169 void didChangeChildren();
170 void didChangeFilters();
171 void didChangeImageBacking();
173 void resetLayerState();
174 void syncLayerState();
175 void syncAnimations();
178 void syncImageBacking();
179 void computeTransformedVisibleRect();
180 void updateContentBuffers();
182 void createBackingStore();
183 void releaseImageBackingIfNeeded();
185 bool notifyFlushRequired();
187 // CoordinatedImageBacking::Host
188 virtual bool imageBackingVisible() override;
189 bool shouldHaveBackingStore() const;
190 bool selfOrAncestorHasActiveTransformAnimation() const;
191 bool selfOrAncestorHaveNonAffineTransforms();
192 void adjustContentsScale();
194 void setShouldUpdateVisibleRect();
195 float effectiveContentsScale();
197 void animationStartedTimerFired();
199 CoordinatedLayerID m_id;
200 CoordinatedGraphicsLayerState m_layerState;
201 GraphicsLayerTransform m_layerTransform;
202 TransformationMatrix m_cachedInverseTransform;
203 FloatSize m_pixelAlignmentOffset;
204 FloatSize m_adjustedSize;
205 FloatPoint m_adjustedPosition;
206 FloatPoint3D m_adjustedAnchorPoint;
211 bool m_shouldUpdateVisibleRect: 1;
212 bool m_shouldSyncLayerState: 1;
213 bool m_shouldSyncChildren: 1;
214 bool m_shouldSyncFilters: 1;
215 bool m_shouldSyncImageBacking: 1;
216 bool m_shouldSyncAnimations: 1;
217 bool m_fixedToViewport : 1;
218 bool m_movingVisibleRect : 1;
219 bool m_pendingContentsScaleAdjustment : 1;
220 bool m_pendingVisibleRectAdjustment : 1;
221 #if USE(GRAPHICS_SURFACE)
222 bool m_isValidPlatformLayer : 1;
223 unsigned m_pendingPlatformLayerOperation : 3;
226 CoordinatedGraphicsLayerClient* m_coordinator;
227 std::unique_ptr<TiledBackingStore> m_mainBackingStore;
228 std::unique_ptr<TiledBackingStore> m_previousBackingStore;
230 RefPtr<Image> m_compositedImage;
231 NativeImagePtr m_compositedNativeImagePtr;
232 RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
234 PlatformLayer* m_platformLayer;
235 #if USE(GRAPHICS_SURFACE)
236 IntSize m_platformLayerSize;
237 GraphicsSurfaceToken m_platformLayerToken;
239 Timer m_animationStartedTimer;
240 TextureMapperAnimations m_animations;
241 double m_lastAnimationStartTime;
243 ScrollableArea* m_scrollableArea;
246 CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*);
248 } // namespace WebCore
249 #endif // USE(COORDINATED_GRAPHICS)
251 #endif // CoordinatedGraphicsLayer_h