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 TextureMapperNode_h
21 #define TextureMapperNode_h
23 #include "FloatRect.h"
24 #include "GraphicsContext.h"
25 #include "GraphicsLayer.h"
27 #include "IntPointHash.h"
28 #include "TextureMapper.h"
30 #include "TransformOperations.h"
31 #include "TranslateTransformOperation.h"
32 #include "UnitBezier.h"
33 #include <wtf/CurrentTime.h>
34 #include <wtf/HashMap.h>
35 #include <wtf/RefCounted.h>
39 class TextureMapperPlatformLayer;
40 class TextureMapperNode;
41 class GraphicsLayerTextureMapper;
42 class TextureMapperSurfaceManager;
44 class TextureMapperPaintOptions {
46 BitmapTexture* surface;
47 TextureMapper* textureMapper;
48 TextureMapperSurfaceManager* surfaceManager;
52 TextureMapperPaintOptions() : surface(0), textureMapper(0), opacity(1.0), isSurface(false) { }
55 class TextureMapperAnimation : public RefCounted<TextureMapperAnimation> {
58 KeyframeValueList keyframes;
60 RefPtr<Animation> animation;
62 Vector<TransformOperation::OperationType> functionList;
66 TextureMapperAnimation(const KeyframeValueList&);
67 static PassRefPtr<TextureMapperAnimation> create(const KeyframeValueList& values) { return adoptRef(new TextureMapperAnimation(values)); }
70 class TextureMapperNode {
73 // This set of flags help us defer which properties of the layer have been
74 // modified by the compositor, so we can know what to look for in the next flush.
78 ParentChange = (1L << 0),
79 ChildrenChange = (1L << 1),
80 MaskLayerChange = (1L << 2),
81 PositionChange = (1L << 3),
83 AnchorPointChange = (1L << 4),
84 SizeChange = (1L << 5),
85 TransformChange = (1L << 6),
86 ContentChange = (1L << 7),
88 ContentsOrientationChange = (1L << 9),
89 OpacityChange = (1L << 10),
90 ContentsRectChange = (1L << 11),
92 Preserves3DChange = (1L << 12),
93 MasksToBoundsChange = (1L << 13),
94 DrawsContentChange = (1L << 14),
95 ContentsOpaqueChange = (1L << 15),
97 BackfaceVisibilityChange = (1L << 16),
98 ChildrenTransformChange = (1L << 17),
99 DisplayChange = (1L << 18),
100 BackgroundColorChange = (1L << 19),
102 ReplicaLayerChange = (1L << 20),
103 AnimationChange = (1L << 21)
107 TraverseDescendants = 1,
113 ExternallyManagedTiles
116 typedef HashMap<TextureMapperNode*, FloatRect> NodeRectMap;
118 // The compositor lets us special-case images and colors, so we try to do so.
119 enum ContentType { HTMLContentType, DirectImageContentType, ColorContentType, MediaContentType, Canvas3DContentType};
121 FloatRect needsDisplayRect;
123 Color backgroundColor;
125 ContentType contentType;
127 const TextureMapperPlatformLayer* media;
128 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
132 : needsDisplay(false)
133 , contentType(HTMLContentType)
136 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
144 : m_parent(0), m_effectTarget(0), m_opacity(1.0), m_surfaceManager(0), m_textureMapper(0) { }
146 virtual ~TextureMapperNode();
148 void syncCompositingState(GraphicsLayerTextureMapper*, int syncOptions = 0);
149 void syncCompositingState(GraphicsLayerTextureMapper*, TextureMapper*, int syncOptions = 0);
150 void syncAnimationsRecursively();
151 IntSize size() const { return IntSize(m_size.width(), m_size.height()); }
152 void setTransform(const TransformationMatrix&);
153 void setOpacity(float value) { m_opacity = value; }
154 void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; }
155 bool descendantsOrSelfHaveRunningAnimations() const;
159 #if USE(TILED_BACKING_STORE)
160 void setTileOwnership(TileOwnership ownership) { m_state.tileOwnership = ownership; }
161 int createContentsTile(float scale);
162 void removeContentsTile(int id);
163 void setContentsTileBackBuffer(int id, const IntRect& sourceRect, const IntRect& targetRect, void* bits, BitmapTexture::PixelFormat);
164 void setTileBackBufferTextureForDirectlyCompositedImage(int id, const IntRect& sourceRect, const FloatRect& targetRect, BitmapTexture*);
165 void clearAllDirectlyCompositedImageTiles();
166 bool collectVisibleContentsRects(NodeRectMap&, const FloatRect&);
167 void purgeNodeTexturesRecursive();
169 void setID(int id) { m_id = id; }
170 int id() const { return m_id; }
172 const TextureMapperPlatformLayer* media() const { return m_currentContent.media; }
174 #if ENABLE(TIZEN_WEBKIT2_TILED_AC)
175 bool collectVisibleContentRects(NodeRectMap&, const FloatRect&);
179 TextureMapperNode* rootLayer();
180 void computeAllTransforms();
181 void computeVisibleRect(const FloatRect& rootVisibleRect);
182 void computePerspectiveTransformIfNeeded();
183 void computeReplicaTransformIfNeeded();
184 void computeOverlapsIfNeeded();
185 void computeLocalTransformIfNeeded();
187 void swapContentsBuffers();
188 int countDescendantsWithContent() const;
189 FloatRect targetRectForTileRect(const FloatRect& totalTargetRect, const FloatRect& tileRect) const;
190 void invalidateViewport(const FloatRect&);
191 void notifyChange(ChangeMask);
192 void syncCompositingStateSelf(GraphicsLayerTextureMapper* graphicsLayer, TextureMapper* textureMapper);
194 static int compareGraphicsLayersZValue(const void* a, const void* b);
195 static void sortByZOrder(Vector<TextureMapperNode* >& array, int first, int last);
197 BitmapTexture* texture() { return m_ownedTiles.isEmpty() ? 0 : m_ownedTiles[0].texture.get(); }
199 void paintRecursive(TextureMapperPaintOptions);
200 bool paintReflection(const TextureMapperPaintOptions&, BitmapTexture* surface);
201 void paintSelf(const TextureMapperPaintOptions&);
202 void paintSelfAndChildren(const TextureMapperPaintOptions&, TextureMapperPaintOptions& optionsForDescendants);
203 void renderContent(TextureMapper*, GraphicsLayer*);
205 void syncAnimations(GraphicsLayerTextureMapper*);
206 void applyAnimation(const TextureMapperAnimation&, double runningTime);
207 void applyAnimationFrame(const TextureMapperAnimation&, const AnimationValue* from, const AnimationValue* to, float progress);
208 void applyOpacityAnimation(float fromOpacity, float toOpacity, double);
209 void applyTransformAnimation(const TextureMapperAnimation&, const TransformOperations* start, const TransformOperations* end, double);
210 bool hasOpacityAnimation() const;
211 bool hasTransformAnimation() const;
213 struct TransformData {
214 TransformationMatrix target;
215 TransformationMatrix replica;
216 TransformationMatrix forDescendants;
217 TransformationMatrix local;
218 TransformationMatrix base;
219 TransformationMatrix perspective;
224 TransformData m_transforms;
226 inline FloatRect targetRect() const
228 return m_currentContent.contentType == HTMLContentType ? entireRect() : m_state.contentsRect;
231 inline FloatRect entireRect() const
233 return FloatRect(0, 0, m_size.width(), m_size.height());
236 FloatSize contentSize() const
238 return m_currentContent.contentType == DirectImageContentType && m_currentContent.image ? m_currentContent.image->size() : m_size;
242 RefPtr<BitmapTexture> texture;
246 Vector<OwnedTile> m_ownedTiles;
248 #if USE(TILED_BACKING_STORE)
249 struct ExternallyManagedTileBuffer {
250 FloatRect sourceRect;
251 FloatRect targetRect;
252 RefPtr<BitmapTexture> texture;
255 struct ExternallyManagedTile {
256 bool isBackBufferUpdated;
257 bool isDirectlyCompositedImage;
259 ExternallyManagedTileBuffer frontBuffer;
260 ExternallyManagedTileBuffer backBuffer;
262 ExternallyManagedTile(float scale = 1.0)
263 : isBackBufferUpdated(false)
264 , isDirectlyCompositedImage(false)
270 HashMap<int, ExternallyManagedTile> m_externallyManagedTiles;
273 ContentData m_currentContent;
275 Vector<TextureMapperNode*> m_children;
276 TextureMapperNode* m_parent;
277 TextureMapperNode* m_effectTarget;
285 FloatPoint3D anchorPoint;
287 TransformationMatrix transform;
288 TransformationMatrix childrenTransform;
290 FloatRect contentsRect;
291 int descendantsWithContent;
292 TextureMapperNode* maskLayer;
293 TextureMapperNode* replicaLayer;
294 bool preserves3D : 1;
295 bool masksToBounds : 1;
296 bool drawsContent : 1;
297 bool contentsOpaque : 1;
298 bool backfaceVisibility : 1;
301 bool mightHaveOverlaps : 1;
305 #if USE(TILED_BACKING_STORE)
306 TileOwnership tileOwnership;
313 , masksToBounds(false)
314 , drawsContent(false)
315 , contentsOpaque(false)
316 , backfaceVisibility(false)
319 , mightHaveOverlaps(false)
320 , needsRepaint(false)
322 #if USE(TILED_BACKING_STORE)
323 , tileOwnership(OwnedTiles)
330 TextureMapperSurfaceManager* m_surfaceManager;
331 TextureMapper* m_textureMapper;
333 Vector<RefPtr<TextureMapperAnimation> > m_animations;
337 TextureMapperNode* toTextureMapperNode(GraphicsLayer*);
340 #endif // TextureMapperNode_h