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