[Texmap] LayoutTests/compositing/animation/state-at-end-event-transform-layer.html...
[WebKit-https.git] / Source / WebCore / platform / graphics / texmap / TextureMapperLayer.h
1 /*
2  Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3
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.
8
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.
13
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.
18  */
19
20 #ifndef TextureMapperLayer_h
21 #define TextureMapperLayer_h
22
23 #if USE(ACCELERATED_COMPOSITING)
24
25 #include "FilterOperations.h"
26 #include "FloatRect.h"
27 #include "GraphicsLayerAnimation.h"
28 #include "GraphicsLayerTransform.h"
29 #include "TextureMapper.h"
30 #include "TextureMapperBackingStore.h"
31
32 namespace WebCore {
33
34 class TextureMapperPaintOptions;
35 class TextureMapperPlatformLayer;
36
37 class TextureMapperLayer : public GraphicsLayerAnimation::Client {
38     WTF_MAKE_NONCOPYABLE(TextureMapperLayer);
39     WTF_MAKE_FAST_ALLOCATED;
40 public:
41     TextureMapperLayer()
42         : m_parent(0)
43         , m_effectTarget(0)
44         , m_contentsLayer(0)
45         , m_currentOpacity(1)
46         , m_centerZ(0)
47         , m_textureMapper(0)
48         , m_fixedToViewport(false)
49     { }
50
51     virtual ~TextureMapperLayer();
52
53     TextureMapper* textureMapper() const;
54     void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; }
55
56     void setChildren(const Vector<TextureMapperLayer*>&);
57     void setMaskLayer(TextureMapperLayer*);
58     void setReplicaLayer(TextureMapperLayer*);
59     void setPosition(const FloatPoint&);
60     void setSize(const FloatSize&);
61     void setAnchorPoint(const FloatPoint3D&);
62     void setPreserves3D(bool);
63     void setTransform(const TransformationMatrix&);
64     void setChildrenTransform(const TransformationMatrix&);
65     void setContentsRect(const IntRect&);
66     void setMasksToBounds(bool);
67     void setDrawsContent(bool);
68     void setContentsVisible(bool);
69     void setContentsOpaque(bool);
70     void setBackfaceVisibility(bool);
71     void setOpacity(float);
72     void setSolidColor(const Color&);
73 #if ENABLE(CSS_FILTERS)
74     void setFilters(const FilterOperations&);
75 #endif
76     void setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth, bool showRepaintCounter);
77     void setRepaintCount(int);
78     void setContentsLayer(TextureMapperPlatformLayer*);
79     void setAnimations(const GraphicsLayerAnimations&);
80     void setFixedToViewport(bool);
81     void setBackingStore(PassRefPtr<TextureMapperBackingStore>);
82
83     void syncAnimations();
84     bool descendantsOrSelfHaveRunningAnimations() const;
85
86     void paint();
87
88     void setScrollPositionDeltaIfNeeded(const FloatSize&);
89
90     void applyAnimationsRecursively();
91
92 private:
93     const TextureMapperLayer* rootLayer() const;
94     void computeTransformsRecursive();
95     IntRect intermediateSurfaceRect(const TransformationMatrix&);
96     IntRect intermediateSurfaceRect();
97
98     static int compareGraphicsLayersZValue(const void* a, const void* b);
99     static void sortByZOrder(Vector<TextureMapperLayer* >& array, int first, int last);
100
101     PassRefPtr<BitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; }
102     FloatPoint adjustedPosition() const { return m_state.pos + m_scrollPositionDelta; }
103     bool isAncestorFixedToViewport() const;
104
105     void addChild(TextureMapperLayer*);
106     void removeFromParent();
107     void removeAllChildren();
108
109     void paintRecursive(const TextureMapperPaintOptions&);
110     void paintSelf(const TextureMapperPaintOptions&);
111     void paintSelfAndChildren(const TextureMapperPaintOptions&);
112     void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
113
114     // GraphicsLayerAnimation::Client
115     virtual void setAnimatedTransform(const TransformationMatrix&) OVERRIDE;
116     virtual void setAnimatedOpacity(float) OVERRIDE;
117 #if ENABLE(CSS_FILTERS)
118     virtual void setAnimatedFilters(const FilterOperations&) OVERRIDE;
119 #endif
120
121     bool isVisible() const;
122     enum ContentsLayerCount {
123         NoLayersWithContent,
124         SingleLayerWithContents,
125         MultipleLayersWithContents
126     };
127
128     ContentsLayerCount countPotentialLayersWithContents() const;
129     bool shouldPaintToIntermediateSurface() const;
130
131     inline FloatRect layerRect() const
132     {
133         return FloatRect(FloatPoint::zero(), m_state.size);
134     }
135
136     Vector<TextureMapperLayer*> m_children;
137     TextureMapperLayer* m_parent;
138     TextureMapperLayer* m_effectTarget;
139     RefPtr<TextureMapperBackingStore> m_backingStore;
140     TextureMapperPlatformLayer* m_contentsLayer;
141     GraphicsLayerTransform m_currentTransform;
142     float m_currentOpacity;
143 #if ENABLE(CSS_FILTERS)
144     FilterOperations m_currentFilters;
145 #endif
146     float m_centerZ;
147
148     struct State {
149         FloatPoint pos;
150         FloatPoint3D anchorPoint;
151         FloatSize size;
152         TransformationMatrix transform;
153         TransformationMatrix childrenTransform;
154         float opacity;
155         FloatRect contentsRect;
156         TextureMapperLayer* maskLayer;
157         TextureMapperLayer* replicaLayer;
158         Color solidColor;
159 #if ENABLE(CSS_FILTERS)
160         FilterOperations filters;
161 #endif
162         Color debugBorderColor;
163         float debugBorderWidth;
164         int repaintCount;
165
166         bool preserves3D : 1;
167         bool masksToBounds : 1;
168         bool drawsContent : 1;
169         bool contentsVisible : 1;
170         bool contentsOpaque : 1;
171         bool backfaceVisibility : 1;
172         bool visible : 1;
173         bool showDebugBorders : 1;
174         bool showRepaintCounter : 1;
175
176         State()
177             : opacity(1)
178             , maskLayer(0)
179             , replicaLayer(0)
180             , debugBorderWidth(0)
181             , repaintCount(0)
182             , preserves3D(false)
183             , masksToBounds(false)
184             , drawsContent(false)
185             , contentsVisible(true)
186             , contentsOpaque(false)
187             , backfaceVisibility(true)
188             , visible(true)
189             , showDebugBorders(false)
190             , showRepaintCounter(false)
191         {
192         }
193     };
194
195     State m_state;
196     TextureMapper* m_textureMapper;
197     GraphicsLayerAnimations m_animations;
198     FloatSize m_scrollPositionDelta;
199     bool m_fixedToViewport;
200 };
201
202 }
203 #endif
204
205 #endif // TextureMapperLayer_h