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 #if USE(COORDINATED_GRAPHICS)
26 #include "CoordinatedGraphicsState.h"
27 #include "CoordinatedImageBacking.h"
28 #include "FloatPoint3D.h"
29 #include "GraphicsLayer.h"
30 #include "GraphicsLayerTransform.h"
33 #include "NicosiaBuffer.h"
34 #include "TextureMapperAnimation.h"
35 #include "TiledBackingStore.h"
36 #include "TiledBackingStoreClient.h"
37 #include "TransformationMatrix.h"
38 #include <wtf/text/StringHash.h>
45 class CoordinatedGraphicsLayer;
46 class TextureMapperAnimations;
48 class CoordinatedGraphicsLayerClient {
50 virtual bool isFlushingLayerChanges() const = 0;
51 virtual FloatRect visibleContentsRect() const = 0;
52 virtual Ref<CoordinatedImageBacking> createImageBackingIfNeeded(Image&) = 0;
53 virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
54 virtual Nicosia::PaintingEngine& paintingEngine() = 0;
56 virtual void syncLayerState(CoordinatedLayerID, CoordinatedGraphicsLayerState&) = 0;
59 class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer
60 , public TiledBackingStoreClient
61 , public CoordinatedImageBacking::Host {
63 explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
64 virtual ~CoordinatedGraphicsLayer();
66 PlatformLayerID primaryLayerID() const override { return id(); }
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(MonotonicTime) override;
110 void resumeAnimations() override;
111 bool usesContentsLayer() const override { return m_platformLayer || m_compositedImage; }
113 void syncPendingStateChangesIncludingSubLayers();
114 void updateContentBuffersIncludingSubLayers();
116 FloatPoint computePositionRelativeToBase();
117 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
119 void setVisibleContentRectTrajectoryVector(const FloatPoint&);
121 CoordinatedLayerID id() const { return m_id; }
123 void setFixedToViewport(bool isFixed);
125 IntRect coverRect() const { return m_mainBackingStore ? m_mainBackingStore->mapToContents(m_mainBackingStore->coverRect()) : IntRect(); }
126 IntRect transformedVisibleRect();
128 // TiledBackingStoreClient
129 void tiledBackingStoreHasPendingTileCreation() override;
130 void createTile(uint32_t tileID, float) override;
131 void updateTile(uint32_t tileID, const SurfaceUpdateInfo&, const IntRect&) override;
132 void removeTile(uint32_t tileID) override;
134 void setCoordinator(CoordinatedGraphicsLayerClient*);
136 void setNeedsVisibleRectAdjustment();
137 void purgeBackingStores();
139 CoordinatedGraphicsLayer* findFirstDescendantWithContentsRecursively();
142 bool isCoordinatedGraphicsLayer() const override { return true; }
144 void syncPlatformLayer();
145 void updatePlatformLayer();
147 void setDebugBorder(const Color&, float width) override;
149 bool fixedToViewport() const { return m_fixedToViewport; }
151 void didChangeLayerState();
152 void didChangeAnimations();
153 void didChangeGeometry();
154 void didChangeChildren();
155 void didChangeFilters();
156 void didChangeImageBacking();
157 void didUpdateTileBuffers();
159 void resetLayerState();
160 void syncLayerState();
161 void syncAnimations();
164 void syncImageBacking();
165 void computeTransformedVisibleRect();
166 void updateContentBuffers();
168 void createBackingStore();
169 void releaseImageBackingIfNeeded();
171 void notifyFlushRequired();
173 // CoordinatedImageBacking::Host
174 bool imageBackingVisible() override;
175 bool shouldHaveBackingStore() const;
176 bool selfOrAncestorHasActiveTransformAnimation() const;
177 bool selfOrAncestorHaveNonAffineTransforms();
178 void adjustContentsScale();
180 void setShouldUpdateVisibleRect();
181 float effectiveContentsScale();
183 void animationStartedTimerFired();
185 bool filtersCanBeComposited(const FilterOperations&) const;
187 CoordinatedLayerID m_id;
188 CoordinatedGraphicsLayerState m_layerState;
189 GraphicsLayerTransform m_layerTransform;
190 TransformationMatrix m_cachedInverseTransform;
191 FloatSize m_pixelAlignmentOffset;
192 FloatSize m_adjustedSize;
193 FloatPoint m_adjustedPosition;
194 FloatPoint3D m_adjustedAnchorPoint;
199 bool m_shouldUpdateVisibleRect: 1;
200 bool m_shouldSyncLayerState: 1;
201 bool m_shouldSyncChildren: 1;
202 bool m_shouldSyncFilters: 1;
203 bool m_shouldSyncImageBacking: 1;
204 bool m_shouldSyncAnimations: 1;
205 bool m_fixedToViewport : 1;
206 bool m_movingVisibleRect : 1;
207 bool m_pendingContentsScaleAdjustment : 1;
208 bool m_pendingVisibleRectAdjustment : 1;
209 #if USE(COORDINATED_GRAPHICS_THREADED)
210 bool m_shouldSyncPlatformLayer : 1;
211 bool m_shouldUpdatePlatformLayer : 1;
214 CoordinatedGraphicsLayerClient* m_coordinator;
215 std::unique_ptr<TiledBackingStore> m_mainBackingStore;
216 std::unique_ptr<TiledBackingStore> m_previousBackingStore;
219 bool completeLayer { false };
220 Vector<FloatRect, 32> rects;
223 RefPtr<Image> m_compositedImage;
224 NativeImagePtr m_compositedNativeImagePtr;
225 RefPtr<CoordinatedImageBacking> m_coordinatedImageBacking;
227 PlatformLayer* m_platformLayer;
228 Timer m_animationStartedTimer;
229 TextureMapperAnimations m_animations;
230 MonotonicTime m_lastAnimationStartTime;
233 } // namespace WebCore
235 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer())
237 #endif // USE(COORDINATED_GRAPHICS)
239 #endif // CoordinatedGraphicsLayer_h