f6b72a325bb85be01f892c379c2b7076d16604e4
[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_shouldUpdateCurrentTransformFromGraphicsLayer(true)
48         , m_shouldUpdateCurrentOpacityFromGraphicsLayer(true)
49 #if ENABLE(CSS_FILTERS)
50         , m_shouldUpdateCurrentFiltersFromGraphicsLayer(true)
51 #endif
52         , m_textureMapper(0)
53         , m_fixedToViewport(false)
54     { }
55
56     virtual ~TextureMapperLayer();
57
58     TextureMapper* textureMapper() const;
59     void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; }
60
61     void setChildren(const Vector<TextureMapperLayer*>&);
62     void setMaskLayer(TextureMapperLayer*);
63     void setReplicaLayer(TextureMapperLayer*);
64     void setPosition(const FloatPoint&);
65     void setSize(const FloatSize&);
66     void setAnchorPoint(const FloatPoint3D&);
67     void setPreserves3D(bool);
68     void setTransform(const TransformationMatrix&);
69     void setChildrenTransform(const TransformationMatrix&);
70     void setContentsRect(const IntRect&);
71     void setMasksToBounds(bool);
72     void setDrawsContent(bool);
73     void setContentsVisible(bool);
74     void setContentsOpaque(bool);
75     void setBackfaceVisibility(bool);
76     void setOpacity(float);
77     void setSolidColor(const Color&);
78 #if ENABLE(CSS_FILTERS)
79     void setFilters(const FilterOperations&);
80 #endif
81     void setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth, bool showRepaintCounter);
82     void setRepaintCount(int);
83     void setContentsLayer(TextureMapperPlatformLayer*);
84     void setAnimations(const GraphicsLayerAnimations&);
85     void setFixedToViewport(bool);
86     void setBackingStore(PassRefPtr<TextureMapperBackingStore>);
87
88     void syncAnimations();
89     bool descendantsOrSelfHaveRunningAnimations() const;
90
91     void paint();
92
93     void setScrollPositionDeltaIfNeeded(const FloatSize&);
94
95     void applyAnimationsRecursively();
96
97 private:
98     const TextureMapperLayer* rootLayer() const;
99     void computeTransformsRecursive();
100     IntRect intermediateSurfaceRect(const TransformationMatrix&);
101     IntRect intermediateSurfaceRect();
102
103     static int compareGraphicsLayersZValue(const void* a, const void* b);
104     static void sortByZOrder(Vector<TextureMapperLayer* >& array, int first, int last);
105
106     PassRefPtr<BitmapTexture> texture() { return m_backingStore ? m_backingStore->texture() : 0; }
107     FloatPoint adjustedPosition() const { return m_state.pos + m_scrollPositionDelta; }
108     bool isAncestorFixedToViewport() const;
109
110     void addChild(TextureMapperLayer*);
111     void removeFromParent();
112     void removeAllChildren();
113
114     void paintRecursive(const TextureMapperPaintOptions&);
115     void paintSelf(const TextureMapperPaintOptions&);
116     void paintSelfAndChildren(const TextureMapperPaintOptions&);
117     void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&);
118
119     // GraphicsLayerAnimation::Client
120     virtual void setAnimatedTransform(const TransformationMatrix&) OVERRIDE;
121     virtual void setAnimatedOpacity(float) OVERRIDE;
122 #if ENABLE(CSS_FILTERS)
123     virtual void setAnimatedFilters(const FilterOperations&) OVERRIDE;
124 #endif
125
126     bool isVisible() const;
127     enum ContentsLayerCount {
128         NoLayersWithContent,
129         SingleLayerWithContents,
130         MultipleLayersWithContents
131     };
132
133     ContentsLayerCount countPotentialLayersWithContents() const;
134     bool shouldPaintToIntermediateSurface() const;
135
136     inline FloatRect layerRect() const
137     {
138         return FloatRect(FloatPoint::zero(), m_state.size);
139     }
140
141     Vector<TextureMapperLayer*> m_children;
142     TextureMapperLayer* m_parent;
143     TextureMapperLayer* m_effectTarget;
144     RefPtr<TextureMapperBackingStore> m_backingStore;
145     TextureMapperPlatformLayer* m_contentsLayer;
146     GraphicsLayerTransform m_currentTransform;
147     float m_currentOpacity;
148 #if ENABLE(CSS_FILTERS)
149     FilterOperations m_currentFilters;
150 #endif
151     float m_centerZ;
152     
153     bool m_shouldUpdateCurrentTransformFromGraphicsLayer;
154     bool m_shouldUpdateCurrentOpacityFromGraphicsLayer;
155 #if ENABLE(CSS_FILTERS)
156     bool m_shouldUpdateCurrentFiltersFromGraphicsLayer;
157 #endif
158
159     struct State {
160         FloatPoint pos;
161         FloatPoint3D anchorPoint;
162         FloatSize size;
163         TransformationMatrix transform;
164         TransformationMatrix childrenTransform;
165         float opacity;
166         FloatRect contentsRect;
167         TextureMapperLayer* maskLayer;
168         TextureMapperLayer* replicaLayer;
169         Color solidColor;
170 #if ENABLE(CSS_FILTERS)
171         FilterOperations filters;
172 #endif
173         Color debugBorderColor;
174         float debugBorderWidth;
175         int repaintCount;
176
177         bool preserves3D : 1;
178         bool masksToBounds : 1;
179         bool drawsContent : 1;
180         bool contentsVisible : 1;
181         bool contentsOpaque : 1;
182         bool backfaceVisibility : 1;
183         bool visible : 1;
184         bool showDebugBorders : 1;
185         bool showRepaintCounter : 1;
186
187         State()
188             : opacity(1)
189             , maskLayer(0)
190             , replicaLayer(0)
191             , debugBorderWidth(0)
192             , repaintCount(0)
193             , preserves3D(false)
194             , masksToBounds(false)
195             , drawsContent(false)
196             , contentsVisible(true)
197             , contentsOpaque(false)
198             , backfaceVisibility(true)
199             , visible(true)
200             , showDebugBorders(false)
201             , showRepaintCounter(false)
202         {
203         }
204     };
205
206     State m_state;
207     TextureMapper* m_textureMapper;
208     GraphicsLayerAnimations m_animations;
209     FloatSize m_scrollPositionDelta;
210     bool m_fixedToViewport;
211 };
212
213 }
214 #endif
215
216 #endif // TextureMapperLayer_h