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 "FloatPoint3D.h"
28 #include "GraphicsLayer.h"
29 #include "GraphicsLayerTransform.h"
32 #include "NicosiaBuffer.h"
33 #include "NicosiaPlatformLayer.h"
34 #include "TextureMapperAnimation.h"
35 #include "TransformationMatrix.h"
36 #include <wtf/text/StringHash.h>
43 class CoordinatedGraphicsLayer;
44 class TextureMapperAnimations;
46 class CoordinatedGraphicsLayerClient {
48 virtual bool isFlushingLayerChanges() const = 0;
49 virtual FloatRect visibleContentsRect() const = 0;
50 virtual void detachLayer(CoordinatedGraphicsLayer*) = 0;
51 virtual void attachLayer(CoordinatedGraphicsLayer*) = 0;
52 virtual Nicosia::PaintingEngine& paintingEngine() = 0;
53 virtual void syncLayerState() = 0;
56 class WEBCORE_EXPORT CoordinatedGraphicsLayer : public GraphicsLayer {
58 explicit CoordinatedGraphicsLayer(Type, GraphicsLayerClient&);
59 virtual ~CoordinatedGraphicsLayer();
61 // FIXME: Merge these two methods.
62 Nicosia::PlatformLayer::LayerID id() const;
63 PlatformLayerID primaryLayerID() const override;
65 // Reimplementations from GraphicsLayer.h.
66 bool setChildren(const Vector<GraphicsLayer*>&) override;
67 void addChild(GraphicsLayer*) override;
68 void addChildAtIndex(GraphicsLayer*, int) override;
69 void addChildAbove(GraphicsLayer*, GraphicsLayer*) override;
70 void addChildBelow(GraphicsLayer*, GraphicsLayer*) override;
71 bool replaceChild(GraphicsLayer*, GraphicsLayer*) override;
72 void removeFromParent() override;
73 void setPosition(const FloatPoint&) override;
74 void setAnchorPoint(const FloatPoint3D&) override;
75 void setSize(const FloatSize&) override;
76 void setTransform(const TransformationMatrix&) override;
77 void setChildrenTransform(const TransformationMatrix&) override;
78 void setPreserves3D(bool) override;
79 void setMasksToBounds(bool) override;
80 void setDrawsContent(bool) override;
81 void setContentsVisible(bool) override;
82 void setContentsOpaque(bool) override;
83 void setBackfaceVisibility(bool) override;
84 void setOpacity(float) override;
85 void setContentsRect(const FloatRect&) override;
86 void setContentsTilePhase(const FloatSize&) override;
87 void setContentsTileSize(const FloatSize&) override;
88 void setContentsToImage(Image*) override;
89 void setContentsToSolidColor(const Color&) override;
90 void setShowDebugBorder(bool) override;
91 void setShowRepaintCounter(bool) override;
92 bool shouldDirectlyCompositeImage(Image*) const override;
93 void setContentsToPlatformLayer(PlatformLayer*, ContentsLayerPurpose) override;
94 void setMaskLayer(GraphicsLayer*) override;
95 void setReplicatedByLayer(GraphicsLayer*) override;
96 void setNeedsDisplay() override;
97 void setNeedsDisplayInRect(const FloatRect&, ShouldClipToLayer = ClipToLayer) override;
98 void setContentsNeedsDisplay() override;
99 void deviceOrPageScaleFactorChanged() override;
100 void flushCompositingState(const FloatRect&) override;
101 void flushCompositingStateForThisLayerOnly() override;
102 bool setFilters(const FilterOperations&) override;
103 bool addAnimation(const KeyframeValueList&, const FloatSize&, const Animation*, const String&, double) override;
104 void pauseAnimation(const String&, double) override;
105 void removeAnimation(const String&) override;
106 void suspendAnimations(MonotonicTime) override;
107 void resumeAnimations() override;
108 bool usesContentsLayer() const override;
110 void syncPendingStateChangesIncludingSubLayers();
111 void updateContentBuffersIncludingSubLayers();
113 FloatPoint computePositionRelativeToBase();
114 void computePixelAlignment(FloatPoint& position, FloatSize&, FloatPoint3D& anchorPoint, FloatSize& alignmentOffset);
116 IntRect transformedVisibleRect();
118 void setCoordinator(CoordinatedGraphicsLayerClient*);
119 void setCoordinatorIncludingSubLayersIfNeeded(CoordinatedGraphicsLayerClient*);
121 void setNeedsVisibleRectAdjustment();
122 void purgeBackingStores();
124 const RefPtr<Nicosia::CompositionLayer>& compositionLayer() const;
127 bool isCoordinatedGraphicsLayer() const;
129 void updatePlatformLayer();
131 void setDebugBorder(const Color&, float width) override;
133 void didChangeAnimations();
134 void didChangeGeometry();
135 void didChangeChildren();
136 void didChangeFilters();
137 void didUpdateTileBuffers();
139 void computeTransformedVisibleRect();
140 void updateContentBuffers();
142 void notifyFlushRequired();
144 bool shouldHaveBackingStore() const;
145 bool selfOrAncestorHasActiveTransformAnimation() const;
146 bool selfOrAncestorHaveNonAffineTransforms();
148 void setShouldUpdateVisibleRect();
149 float effectiveContentsScale();
151 void animationStartedTimerFired();
153 bool filtersCanBeComposited(const FilterOperations&) const;
155 Nicosia::PlatformLayer::LayerID m_id;
156 GraphicsLayerTransform m_layerTransform;
157 TransformationMatrix m_cachedInverseTransform;
158 FloatSize m_pixelAlignmentOffset;
159 FloatSize m_adjustedSize;
160 FloatPoint m_adjustedPosition;
161 FloatPoint3D m_adjustedAnchorPoint;
168 bool m_shouldUpdateVisibleRect: 1;
169 bool m_shouldSyncLayerState: 1;
170 bool m_movingVisibleRect : 1;
171 bool m_pendingContentsScaleAdjustment : 1;
172 bool m_pendingVisibleRectAdjustment : 1;
173 bool m_shouldUpdatePlatformLayer : 1;
175 CoordinatedGraphicsLayerClient* m_coordinator;
178 bool completeLayer { false };
179 Vector<FloatRect, 32> rects;
182 RefPtr<Image> m_compositedImage;
183 NativeImagePtr m_compositedNativeImagePtr;
185 Timer m_animationStartedTimer;
186 TextureMapperAnimations m_animations;
187 MonotonicTime m_lastAnimationStartTime;
190 RefPtr<Nicosia::CompositionLayer> layer;
191 Nicosia::CompositionLayer::LayerState::Delta delta;
192 Nicosia::CompositionLayer::LayerState::RepaintCounter repaintCounter;
193 Nicosia::CompositionLayer::LayerState::DebugBorder debugBorder;
194 bool performLayerSync { false };
196 RefPtr<Nicosia::BackingStore> backingStore;
197 RefPtr<Nicosia::ContentLayer> contentLayer;
198 RefPtr<Nicosia::ImageBacking> imageBacking;
202 } // namespace WebCore
204 SPECIALIZE_TYPE_TRAITS_GRAPHICSLAYER(WebCore::CoordinatedGraphicsLayer, isCoordinatedGraphicsLayer())
206 #endif // USE(COORDINATED_GRAPHICS)
208 #endif // CoordinatedGraphicsLayer_h