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 "CoordinatedTile.h"
27 #include "FloatPoint3D.h"
28 #include "GraphicsLayer.h"
29 #include "GraphicsLayerAnimation.h"
30 #include "GraphicsLayerTransform.h"
34 #include "TiledBackingStore.h"
35 #include "TiledBackingStoreClient.h"
36 #include "TransformationMatrix.h"
37 #if USE(GRAPHICS_SURFACE)
38 #include "GraphicsSurfaceToken.h"
40 #include <wtf/text/StringHash.h>
42 #if USE(COORDINATED_GRAPHICS)
45 class CoordinatedGraphicsLayer;
46 class GraphicsLayerAnimations;
48 class CoordinatedGraphicsLayerClient {
50 virtual bool isFlushingLayerChanges() const = 0;
51 virtual FloatRect visibleContentsRect() const = 0;
52 virtual PassRefPtr<CoordinatedImageBacking> createImageBackingIfNeeded(Image*) = 0;
53 virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
54 virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&) = 0;
56 virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
59 class CoordinatedGraphicsLayer : public GraphicsLayer
60 , public TiledBackingStoreClient
61 , public CoordinatedImageBacking::Host
62 , public CoordinatedTileClient {
64 explicit CoordinatedGraphicsLayer(GraphicsLayerClient*);
65 virtual ~CoordinatedGraphicsLayer();
67 // Reimplementations from GraphicsLayer.h.
68 virtual bool setChildren(const Vector<GraphicsLayer*>&) OVERRIDE;
69 virtual void addChild(GraphicsLayer*) OVERRIDE;
70 virtual void addChildAtIndex(GraphicsLayer*, int) OVERRIDE;
71 virtual void addChildAbove(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
72 virtual void addChildBelow(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
73 virtual bool replaceChild(GraphicsLayer*, GraphicsLayer*) OVERRIDE;
74 virtual void removeFromParent() OVERRIDE;
75 virtual void setPosition(const FloatPoint&) OVERRIDE;
76 virtual void setAnchorPoint(const FloatPoint3D&) OVERRIDE;
77 virtual void setSize(const FloatSize&) OVERRIDE;
78 virtual void setTransform(const TransformationMatrix&) OVERRIDE;
79 virtual void setChildrenTransform(const TransformationMatrix&) OVERRIDE;
80 virtual void setPreserves3D(bool) OVERRIDE;
81 virtual void setMasksToBounds(bool) OVERRIDE;
82 virtual void setDrawsContent(bool) OVERRIDE;
83 virtual void setContentsVisible(bool) OVERRIDE;
84 virtual void setContentsOpaque(bool) OVERRIDE;
85 virtual void setBackfaceVisibility(bool) OVERRIDE;
86 virtual void setOpacity(float) OVERRIDE;
87 virtual void setContentsRect(const IntRect&) 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 setContentsToCanvas(PlatformLayer*) OVERRIDE;
94 virtual void setMaskLayer(GraphicsLayer*) OVERRIDE;
95 virtual void setReplicatedByLayer(GraphicsLayer*) OVERRIDE;
96 virtual void setNeedsDisplay() OVERRIDE;
97 virtual void setNeedsDisplayInRect(const FloatRect&) OVERRIDE;
98 virtual void setContentsNeedsDisplay() OVERRIDE;
99 virtual void deviceOrPageScaleFactorChanged() OVERRIDE;
100 virtual void flushCompositingState(const FloatRect&) OVERRIDE;
101 virtual void flushCompositingStateForThisLayerOnly() OVERRIDE;
102 #if ENABLE(CSS_FILTERS)
103 virtual bool setFilters(const FilterOperations&) OVERRIDE;
105 virtual bool addAnimation(const KeyframeValueList&, const IntSize&, const Animation*, const String&, double) OVERRIDE;
106 virtual void pauseAnimation(const String&, double) OVERRIDE;
107 virtual void removeAnimation(const String&) OVERRIDE;
108 virtual void suspendAnimations(double time) OVERRIDE;
109 virtual void resumeAnimations() OVERRIDE;
111 FloatPoint computePositionRelativeToBase();
112 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
114 void setVisibleContentRectTrajectoryVector(const FloatPoint&);
116 void setRootLayer(bool);
118 CoordinatedLayerID id() const;
120 void setFixedToViewport(bool isFixed);
122 IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
124 // TiledBackingStoreClient
125 virtual void tiledBackingStorePaintBegin() OVERRIDE;
126 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) OVERRIDE;
127 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea) OVERRIDE;
128 virtual void tiledBackingStoreHasPendingTileCreation() OVERRIDE;
129 virtual IntRect tiledBackingStoreContentsRect() OVERRIDE;
130 virtual IntRect tiledBackingStoreVisibleRect() OVERRIDE;
131 virtual Color tiledBackingStoreBackgroundColor() const OVERRIDE;
133 // CoordinatedTileClient
134 virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE;
135 virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) OVERRIDE;
136 virtual void removeTile(uint32_t tileID) OVERRIDE;
137 virtual PassOwnPtr<GraphicsContext> beginContentUpdate(const IntSize&, uint32_t& atlasID, IntPoint&) OVERRIDE;
139 void setCoordinator(CoordinatedGraphicsLayerClient*);
141 void setNeedsVisibleRectAdjustment();
142 void purgeBackingStores();
143 bool hasPendingVisibleChanges();
146 #if USE(GRAPHICS_SURFACE)
147 enum PendingCanvasOperation {
150 DestroyCanvas = 0x02,
152 CreateAndSyncCanvas = CreateCanvas | SyncCanvas,
153 RecreateCanvas = CreateAndSyncCanvas | DestroyCanvas
157 void destroyCanvasIfNeeded();
158 void createCanvasIfNeeded();
161 virtual void setDebugBorder(const Color&, float width) OVERRIDE;
163 bool fixedToViewport() const { return m_fixedToViewport; }
165 void didChangeLayerState();
166 void didChangeAnimations();
167 void didChangeGeometry();
168 void didChangeChildren();
169 #if ENABLE(CSS_FILTERS)
170 void didChangeFilters();
172 void didChangeImageBacking();
174 void resetLayerState();
175 void syncLayerState();
176 void syncAnimations();
178 #if ENABLE(CSS_FILTERS)
181 void syncImageBacking();
182 void computeTransformedVisibleRect();
183 void updateContentBuffers();
185 void createBackingStore();
186 void releaseImageBackingIfNeeded();
188 // CoordinatedImageBacking::Host
189 virtual bool imageBackingVisible() OVERRIDE;
190 bool shouldHaveBackingStore() const;
191 bool selfOrAncestorHasActiveTransformAnimation() const;
192 bool selfOrAncestorHaveNonAffineTransforms();
193 void adjustContentsScale();
195 void setShouldUpdateVisibleRect();
196 float effectiveContentsScale();
198 void animationStartedTimerFired(Timer<CoordinatedGraphicsLayer>*);
200 CoordinatedLayerID m_id;
201 CoordinatedGraphicsLayerState m_layerState;
202 GraphicsLayerTransform m_layerTransform;
203 TransformationMatrix m_cachedInverseTransform;
204 FloatSize m_pixelAlignmentOffset;
205 FloatSize m_adjustedSize;
206 FloatPoint m_adjustedPosition;
207 FloatPoint3D m_adjustedAnchorPoint;
212 bool m_shouldUpdateVisibleRect: 1;
213 bool m_shouldSyncLayerState: 1;
214 bool m_shouldSyncChildren: 1;
215 bool m_shouldSyncFilters: 1;
216 bool m_shouldSyncImageBacking: 1;
217 bool m_shouldSyncAnimations: 1;
218 bool m_fixedToViewport : 1;
219 bool m_movingVisibleRect : 1;
220 bool m_pendingContentsScaleAdjustment : 1;
221 bool m_pendingVisibleRectAdjustment : 1;
222 #if USE(GRAPHICS_SURFACE)
223 bool m_isValidCanvas : 1;
224 unsigned m_pendingCanvasOperation : 3;
227 CoordinatedGraphicsLayerClient* m_coordinator;
228 OwnPtr<TiledBackingStore> m_mainBackingStore;
229 OwnPtr<TiledBackingStore> m_previousBackingStore;
231 RefPtr<Image> m_compositedImage;
232 NativeImagePtr m_compositedNativeImagePtr;
233 RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
235 PlatformLayer* m_canvasPlatformLayer;
236 #if USE(GRAPHICS_SURFACE)
237 IntSize m_canvasSize;
238 GraphicsSurfaceToken m_canvasToken;
240 Timer<CoordinatedGraphicsLayer> m_animationStartedTimer;
241 GraphicsLayerAnimations m_animations;
242 double m_lastAnimationStartTime;
245 CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*);
247 } // namespace WebCore
248 #endif // USE(COORDINATED_GRAPHICS)
250 #endif // CoordinatedGraphicsLayer_h