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.
20 #ifndef TextureMapperLayer_h
21 #define TextureMapperLayer_h
23 #if USE(ACCELERATED_COMPOSITING)
25 #include "FilterOperations.h"
26 #include "FloatRect.h"
27 #include "GraphicsLayerAnimation.h"
28 #include "GraphicsLayerTransform.h"
29 #include "TextureMapper.h"
30 #include "TextureMapperBackingStore.h"
35 class TextureMapperPaintOptions;
36 class TextureMapperPlatformLayer;
38 class TextureMapperLayer : public GraphicsLayerAnimation::Client {
39 WTF_MAKE_NONCOPYABLE(TextureMapperLayer);
40 WTF_MAKE_FAST_ALLOCATED;
43 class ScrollingClient {
45 virtual void commitScrollOffset(uint32_t layerID, const IntSize& offset) = 0;
55 , m_fixedToViewport(false)
58 , m_isScrollable(false)
59 , m_patternTransformDirty(false)
62 virtual ~TextureMapperLayer();
64 void setID(uint32_t id) { m_id = id; }
65 uint32_t id() { return m_id; }
67 const Vector<TextureMapperLayer*>& children() const { return m_children; }
68 TextureMapperLayer* findScrollableContentsLayerAt(const FloatPoint& pos);
70 void setScrollClient(ScrollingClient* scrollClient) { m_scrollClient = scrollClient; }
71 void scrollBy(const WebCore::FloatSize&);
73 void didCommitScrollOffset(const IntSize&);
74 void setIsScrollable(bool isScrollable) { m_isScrollable = isScrollable; }
75 bool isScrollable() const { return m_isScrollable; }
77 TextureMapper* textureMapper() const;
78 void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; }
80 void setChildren(const Vector<TextureMapperLayer*>&);
81 void setMaskLayer(TextureMapperLayer*);
82 void setReplicaLayer(TextureMapperLayer*);
83 void setPosition(const FloatPoint&);
84 void setSize(const FloatSize&);
85 void setAnchorPoint(const FloatPoint3D&);
86 void setPreserves3D(bool);
87 void setTransform(const TransformationMatrix&);
88 void setChildrenTransform(const TransformationMatrix&);
89 void setContentsRect(const IntRect&);
90 void setMasksToBounds(bool);
91 void setDrawsContent(bool);
92 bool drawsContent() const { return m_state.drawsContent; }
93 bool contentsAreVisible() const { return m_state.contentsVisible; }
94 FloatSize size() const { return m_state.size; }
95 float opacity() const { return m_state.opacity; }
96 TransformationMatrix transform() const { return m_state.transform; }
97 void setContentsVisible(bool);
98 void setContentsOpaque(bool);
99 void setBackfaceVisibility(bool);
100 void setOpacity(float);
101 void setSolidColor(const Color&);
102 void setContentsTileSize(const IntSize&);
103 void setContentsTilePhase(const IntPoint&);
104 #if ENABLE(CSS_FILTERS)
105 void setFilters(const FilterOperations&);
108 bool hasFilters() const
110 #if ENABLE(CSS_FILTERS)
111 return !m_currentFilters.isEmpty();
117 void setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth, bool showRepaintCounter);
118 bool isShowingRepaintCounter() const { return m_state.showRepaintCounter; }
119 void setRepaintCount(int);
120 void setContentsLayer(TextureMapperPlatformLayer*);
121 void setAnimations(const GraphicsLayerAnimations&);
122 void setFixedToViewport(bool);
123 bool fixedToViewport() const { return m_fixedToViewport; }
124 void setBackingStore(PassRefPtr<TextureMapperBackingStore>);
125 void setShouldMapBackingStoreToContentsRect(bool m) { m_state.shouldMapBackingStoreToContentsRect = m; }
127 void syncAnimations();
128 bool descendantsOrSelfHaveRunningAnimations() const;
132 void setScrollPositionDeltaIfNeeded(const FloatSize&);
134 void applyAnimationsRecursively();
135 void addChild(TextureMapperLayer*);
138 const TextureMapperLayer* rootLayer() const;
139 void computeTransformsRecursive();
141 static int compareGraphicsLayersZValue(const void* a, const void* b);
142 static void sortByZOrder(Vector<TextureMapperLayer* >& array);
144 PassRefPtr<BitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; }
145 FloatPoint adjustedPosition() const { return m_state.pos + m_scrollPositionDelta - m_userScrollOffset; }
146 bool isAncestorFixedToViewport() const;
147 TransformationMatrix replicaTransform();
148 void removeFromParent();
149 void removeAllChildren();
151 enum ResolveSelfOverlapMode {
152 ResolveSelfOverlapAlways = 0,
153 ResolveSelfOverlapIfNeeded
155 void computeOverlapRegions(Region& overlapRegion, Region& nonOverlapRegion, ResolveSelfOverlapMode);
157 void paintRecursive(const TextureMapperPaintOptions&);
158 void paintUsingOverlapRegions(const TextureMapperPaintOptions&);
159 PassRefPtr<BitmapTexture> paintIntoSurface(const TextureMapperPaintOptions&, const IntSize&);
160 void paintWithIntermediateSurface(const TextureMapperPaintOptions&, const IntRect&);
161 void paintSelf(const TextureMapperPaintOptions&);
162 void paintSelfAndChildren(const TextureMapperPaintOptions&);
163 void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
164 void applyMask(const TextureMapperPaintOptions&);
165 void computePatternTransformIfNeeded();
167 // GraphicsLayerAnimation::Client
168 virtual void setAnimatedTransform(const TransformationMatrix&) OVERRIDE;
169 virtual void setAnimatedOpacity(float) OVERRIDE;
170 #if ENABLE(CSS_FILTERS)
171 virtual void setAnimatedFilters(const FilterOperations&) OVERRIDE;
174 bool isVisible() const;
175 enum ContentsLayerCount {
177 SingleLayerWithContents,
178 MultipleLayersWithContents
181 bool shouldBlend() const;
183 inline FloatRect layerRect() const
185 return FloatRect(FloatPoint::zero(), m_state.size);
188 Vector<TextureMapperLayer*> m_children;
189 TextureMapperLayer* m_parent;
190 TextureMapperLayer* m_effectTarget;
191 RefPtr<TextureMapperBackingStore> m_backingStore;
192 TextureMapperPlatformLayer* m_contentsLayer;
193 GraphicsLayerTransform m_currentTransform;
194 float m_currentOpacity;
195 #if ENABLE(CSS_FILTERS)
196 FilterOperations m_currentFilters;
200 template<class HitTestCondition> TextureMapperLayer* hitTest(const FloatPoint&, HitTestCondition);
201 static bool scrollableLayerHitTestCondition(TextureMapperLayer*, const FloatPoint&);
203 FloatSize mapScrollOffset(const FloatSize&);
204 void commitScrollOffset(const FloatSize&);
208 FloatPoint3D anchorPoint;
210 TransformationMatrix transform;
211 TransformationMatrix childrenTransform;
213 FloatRect contentsRect;
214 IntSize contentsTileSize;
215 IntPoint contentsTilePhase;
216 TextureMapperLayer* maskLayer;
217 TextureMapperLayer* replicaLayer;
219 #if ENABLE(CSS_FILTERS)
220 FilterOperations filters;
222 Color debugBorderColor;
223 float debugBorderWidth;
226 bool preserves3D : 1;
227 bool masksToBounds : 1;
228 bool drawsContent : 1;
229 bool contentsVisible : 1;
230 bool contentsOpaque : 1;
231 bool backfaceVisibility : 1;
233 bool showDebugBorders : 1;
234 bool showRepaintCounter : 1;
235 bool shouldMapBackingStoreToContentsRect : 1;
241 , debugBorderWidth(0)
244 , masksToBounds(false)
245 , drawsContent(false)
246 , contentsVisible(true)
247 , contentsOpaque(false)
248 , backfaceVisibility(true)
250 , showDebugBorders(false)
251 , showRepaintCounter(false)
252 , shouldMapBackingStoreToContentsRect(false)
258 TextureMapper* m_textureMapper;
259 GraphicsLayerAnimations m_animations;
260 FloatSize m_scrollPositionDelta;
261 bool m_fixedToViewport;
263 ScrollingClient* m_scrollClient;
265 FloatSize m_userScrollOffset;
266 FloatSize m_accumulatedScrollOffsetFractionalPart;
267 TransformationMatrix m_patternTransform;
268 bool m_patternTransformDirty;
274 #endif // TextureMapperLayer_h