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"
33 #include "TiledBackingStore.h"
34 #include "TiledBackingStoreClient.h"
35 #include "TransformationMatrix.h"
36 #if USE(GRAPHICS_SURFACE)
37 #include "GraphicsSurfaceToken.h"
39 #include <wtf/text/StringHash.h>
41 #if USE(COORDINATED_GRAPHICS)
44 class CoordinatedGraphicsLayer;
45 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 bool paintToSurface(const IntSize&, CoordinatedSurface::Flags, uint32_t& atlasID, IntPoint&, CoordinatedSurface::Client*) = 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 FloatRect&) override;
88 virtual void setContentsTilePhase(const FloatPoint&) override;
89 virtual void setContentsTileSize(const FloatSize&) override;
90 virtual void setContentsToImage(Image*) override;
91 virtual void setContentsToSolidColor(const Color&) override;
92 virtual void setShowDebugBorder(bool) override;
93 virtual void setShowRepaintCounter(bool) override;
94 virtual bool shouldDirectlyCompositeImage(Image*) const override;
95 virtual void setContentsToCanvas(PlatformLayer*) override;
96 virtual void setMaskLayer(GraphicsLayer*) override;
97 virtual void setReplicatedByLayer(GraphicsLayer*) override;
98 virtual void setNeedsDisplay() override;
99 virtual void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
100 virtual void setContentsNeedsDisplay() override;
101 virtual void deviceOrPageScaleFactorChanged() override;
102 virtual void flushCompositingState(const FloatRect&) override;
103 virtual void flushCompositingStateForThisLayerOnly() override;
104 #if ENABLE(CSS_FILTERS)
105 virtual bool setFilters(const FilterOperations&) override;
107 virtual bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
108 virtual void pauseAnimation(const String&, double) override;
109 virtual void removeAnimation(const String&) override;
110 virtual void suspendAnimations(double time) override;
111 virtual void resumeAnimations() override;
112 virtual bool usesContentsLayer() const override { return m_canvasPlatformLayer || m_compositedImage; }
114 void syncPendingStateChangesIncludingSubLayers();
115 void updateContentBuffersIncludingSubLayers();
117 FloatPoint computePositionRelativeToBase();
118 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
120 void setVisibleContentRectTrajectoryVector(const FloatPoint&);
122 void setScrollableArea(ScrollableArea*);
123 bool isScrollable() const { return !!m_scrollableArea; }
124 void commitScrollOffset(const IntSize&);
126 CoordinatedLayerID id() const;
128 void setFixedToViewport(bool isFixed);
130 IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
132 // TiledBackingStoreClient
133 virtual void tiledBackingStorePaintBegin() override;
134 virtual void tiledBackingStorePaint(GraphicsContext*, const IntRect&) override;
135 virtual void tiledBackingStorePaintEnd(const Vector<IntRect>& paintedArea) override;
136 virtual void tiledBackingStoreHasPendingTileCreation() override;
137 virtual IntRect tiledBackingStoreContentsRect() override;
138 virtual IntRect tiledBackingStoreVisibleRect() override;
139 virtual Color tiledBackingStoreBackgroundColor() const override;
141 // CoordinatedTileClient
142 virtual void createTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
143 virtual void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
144 virtual void removeTile(uint32_t tileID) override;
145 virtual bool paintToSurface(const IntSize&, uint32_t& /* atlasID */, IntPoint&, CoordinatedSurface::Client*) override;
147 void setCoordinator(CoordinatedGraphicsLayerClient*);
149 void setNeedsVisibleRectAdjustment();
150 void purgeBackingStores();
152 static void setShouldSupportContentsTiling(bool);
153 CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively();
156 #if USE(GRAPHICS_SURFACE)
157 enum PendingCanvasOperation {
160 DestroyCanvas = 0x02,
162 CreateAndSyncCanvas = CreateCanvas | SyncCanvas,
163 RecreateCanvas = CreateAndSyncCanvas | DestroyCanvas
167 void destroyCanvasIfNeeded();
168 void createCanvasIfNeeded();
171 virtual void setDebugBorder(const Color&, float width) override;
173 bool fixedToViewport() const { return m_fixedToViewport; }
175 void didChangeLayerState();
176 void didChangeAnimations();
177 void didChangeGeometry();
178 void didChangeChildren();
179 #if ENABLE(CSS_FILTERS)
180 void didChangeFilters();
182 void didChangeImageBacking();
184 void resetLayerState();
185 void syncLayerState();
186 void syncAnimations();
188 #if ENABLE(CSS_FILTERS)
191 void syncImageBacking();
192 void computeTransformedVisibleRect();
193 void updateContentBuffers();
195 void createBackingStore();
196 void releaseImageBackingIfNeeded();
198 bool notifyFlushRequired();
200 // CoordinatedImageBacking::Host
201 virtual bool imageBackingVisible() override;
202 bool shouldHaveBackingStore() const;
203 bool selfOrAncestorHasActiveTransformAnimation() const;
204 bool selfOrAncestorHaveNonAffineTransforms();
205 void adjustContentsScale();
207 void setShouldUpdateVisibleRect();
208 float effectiveContentsScale();
210 void animationStartedTimerFired(Timer<CoordinatedGraphicsLayer>*);
212 CoordinatedLayerID m_id;
213 CoordinatedGraphicsLayerState m_layerState;
214 GraphicsLayerTransform m_layerTransform;
215 TransformationMatrix m_cachedInverseTransform;
216 FloatSize m_pixelAlignmentOffset;
217 FloatSize m_adjustedSize;
218 FloatPoint m_adjustedPosition;
219 FloatPoint3D m_adjustedAnchorPoint;
224 bool m_shouldUpdateVisibleRect: 1;
225 bool m_shouldSyncLayerState: 1;
226 bool m_shouldSyncChildren: 1;
227 bool m_shouldSyncFilters: 1;
228 bool m_shouldSyncImageBacking: 1;
229 bool m_shouldSyncAnimations: 1;
230 bool m_fixedToViewport : 1;
231 bool m_movingVisibleRect : 1;
232 bool m_pendingContentsScaleAdjustment : 1;
233 bool m_pendingVisibleRectAdjustment : 1;
234 #if USE(GRAPHICS_SURFACE)
235 bool m_isValidCanvas : 1;
236 unsigned m_pendingCanvasOperation : 3;
239 CoordinatedGraphicsLayerClient* m_coordinator;
240 std::unique_ptr<TiledBackingStore> m_mainBackingStore;
241 std::unique_ptr<TiledBackingStore> m_previousBackingStore;
243 RefPtr<Image> m_compositedImage;
244 NativeImagePtr m_compositedNativeImagePtr;
245 RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
247 PlatformLayer* m_canvasPlatformLayer;
248 #if USE(GRAPHICS_SURFACE)
249 IntSize m_canvasSize;
250 GraphicsSurfaceToken m_canvasToken;
252 Timer<CoordinatedGraphicsLayer> m_animationStartedTimer;
253 GraphicsLayerAnimations m_animations;
254 double m_lastAnimationStartTime;
256 ScrollableArea* m_scrollableArea;
259 CoordinatedGraphicsLayer* toCoordinatedGraphicsLayer(GraphicsLayer*);
261 } // namespace WebCore
262 #endif // USE(COORDINATED_GRAPHICS)
264 #endif // CoordinatedGraphicsLayer_h