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 | #include "FilterOperations.h" |
24 | #include "FloatRect.h" |
25 | #include "TextureMapper.h" |
26 | #include "TextureMapperAnimation.h" |
27 | #include "TextureMapperBackingStore.h" |
28 | #include <wtf/WeakPtr.h> |
29 | |
30 | namespace WebCore { |
31 | |
32 | class GraphicsLayer; |
33 | class Region; |
34 | class TextureMapperPaintOptions; |
35 | class TextureMapperPlatformLayer; |
36 | |
37 | class WEBCORE_EXPORT TextureMapperLayer : public CanMakeWeakPtr<TextureMapperLayer> { |
38 | WTF_MAKE_NONCOPYABLE(TextureMapperLayer); |
39 | WTF_MAKE_FAST_ALLOCATED; |
40 | public: |
41 | TextureMapperLayer(); |
42 | virtual ~TextureMapperLayer(); |
43 | |
44 | void setID(uint32_t id) { m_id = id; } |
45 | uint32_t id() { return m_id; } |
46 | |
47 | const Vector<TextureMapperLayer*>& children() const { return m_children; } |
48 | |
49 | TextureMapper* textureMapper() const { return rootLayer().m_textureMapper; } |
50 | void setTextureMapper(TextureMapper* texmap) { m_textureMapper = texmap; } |
51 | |
52 | #if !USE(COORDINATED_GRAPHICS) |
53 | void setChildren(const Vector<GraphicsLayer*>&); |
54 | #endif |
55 | void setChildren(const Vector<TextureMapperLayer*>&); |
56 | void setMaskLayer(TextureMapperLayer*); |
57 | void setReplicaLayer(TextureMapperLayer*); |
58 | void setPosition(const FloatPoint&); |
59 | void setSize(const FloatSize&); |
60 | void setAnchorPoint(const FloatPoint3D&); |
61 | void setPreserves3D(bool); |
62 | void setTransform(const TransformationMatrix&); |
63 | void setChildrenTransform(const TransformationMatrix&); |
64 | void setContentsRect(const FloatRect&); |
65 | void setMasksToBounds(bool); |
66 | void setDrawsContent(bool); |
67 | bool drawsContent() const { return m_state.drawsContent; } |
68 | bool contentsAreVisible() const { return m_state.contentsVisible; } |
69 | FloatSize size() const { return m_state.size; } |
70 | float opacity() const { return m_state.opacity; } |
71 | TransformationMatrix transform() const { return m_state.transform; } |
72 | void setContentsVisible(bool); |
73 | void setContentsOpaque(bool); |
74 | void setBackfaceVisibility(bool); |
75 | void setOpacity(float); |
76 | void setSolidColor(const Color&); |
77 | void setContentsTileSize(const FloatSize&); |
78 | void setContentsTilePhase(const FloatSize&); |
79 | void setFilters(const FilterOperations&); |
80 | |
81 | bool hasFilters() const |
82 | { |
83 | return !m_currentFilters.isEmpty(); |
84 | } |
85 | |
86 | void setDebugVisuals(bool showDebugBorders, const Color& debugBorderColor, float debugBorderWidth); |
87 | void setRepaintCounter(bool showRepaintCounter, int repaintCount); |
88 | void setContentsLayer(TextureMapperPlatformLayer*); |
89 | void setAnimations(const TextureMapperAnimations&); |
90 | void setBackingStore(TextureMapperBackingStore*); |
91 | |
92 | bool applyAnimationsRecursively(MonotonicTime); |
93 | bool syncAnimations(MonotonicTime); |
94 | bool descendantsOrSelfHaveRunningAnimations() const; |
95 | |
96 | void paint(); |
97 | |
98 | void addChild(TextureMapperLayer*); |
99 | |
100 | private: |
101 | const TextureMapperLayer& rootLayer() const |
102 | { |
103 | if (m_effectTarget) |
104 | return m_effectTarget->rootLayer(); |
105 | if (m_parent) |
106 | return m_parent->rootLayer(); |
107 | return *this; |
108 | } |
109 | void computeTransformsRecursive(); |
110 | |
111 | static void sortByZOrder(Vector<TextureMapperLayer* >& array); |
112 | |
113 | TransformationMatrix replicaTransform(); |
114 | void removeFromParent(); |
115 | void removeAllChildren(); |
116 | |
117 | enum ResolveSelfOverlapMode { |
118 | ResolveSelfOverlapAlways = 0, |
119 | ResolveSelfOverlapIfNeeded |
120 | }; |
121 | void computeOverlapRegions(Region& overlapRegion, Region& nonOverlapRegion, ResolveSelfOverlapMode); |
122 | |
123 | void paintRecursive(const TextureMapperPaintOptions&); |
124 | void paintUsingOverlapRegions(const TextureMapperPaintOptions&); |
125 | RefPtr<BitmapTexture> paintIntoSurface(const TextureMapperPaintOptions&, const IntSize&); |
126 | void paintWithIntermediateSurface(const TextureMapperPaintOptions&, const IntRect&); |
127 | void paintSelf(const TextureMapperPaintOptions&); |
128 | void paintSelfAndChildren(const TextureMapperPaintOptions&); |
129 | void paintSelfAndChildrenWithReplica(const TextureMapperPaintOptions&); |
130 | void applyMask(const TextureMapperPaintOptions&); |
131 | |
132 | bool isVisible() const; |
133 | |
134 | bool shouldBlend() 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 { nullptr }; |
143 | WeakPtr<TextureMapperLayer> m_effectTarget; |
144 | TextureMapperBackingStore* m_backingStore { nullptr }; |
145 | TextureMapperPlatformLayer* m_contentsLayer { nullptr }; |
146 | float m_currentOpacity { 1.0 }; |
147 | FilterOperations m_currentFilters; |
148 | float m_centerZ { 0 }; |
149 | |
150 | struct State { |
151 | FloatPoint pos; |
152 | FloatPoint3D anchorPoint; |
153 | FloatSize size; |
154 | TransformationMatrix transform; |
155 | TransformationMatrix childrenTransform; |
156 | float opacity; |
157 | FloatRect contentsRect; |
158 | FloatSize contentsTileSize; |
159 | FloatSize contentsTilePhase; |
160 | WeakPtr<TextureMapperLayer> maskLayer; |
161 | WeakPtr<TextureMapperLayer> replicaLayer; |
162 | Color solidColor; |
163 | FilterOperations filters; |
164 | Color debugBorderColor; |
165 | float debugBorderWidth; |
166 | int repaintCount; |
167 | |
168 | bool preserves3D : 1; |
169 | bool masksToBounds : 1; |
170 | bool drawsContent : 1; |
171 | bool contentsVisible : 1; |
172 | bool contentsOpaque : 1; |
173 | bool backfaceVisibility : 1; |
174 | bool visible : 1; |
175 | bool showDebugBorders : 1; |
176 | bool showRepaintCounter : 1; |
177 | |
178 | State() |
179 | : anchorPoint(0.5, 0.5, 0) |
180 | , opacity(1) |
181 | , debugBorderWidth(0) |
182 | , repaintCount(0) |
183 | , preserves3D(false) |
184 | , masksToBounds(false) |
185 | , drawsContent(false) |
186 | , contentsVisible(true) |
187 | , contentsOpaque(false) |
188 | , backfaceVisibility(true) |
189 | , visible(true) |
190 | , showDebugBorders(false) |
191 | , showRepaintCounter(false) |
192 | { |
193 | } |
194 | }; |
195 | |
196 | State m_state; |
197 | TextureMapper* m_textureMapper { nullptr }; |
198 | TextureMapperAnimations m_animations; |
199 | uint32_t m_id { 0 }; |
200 | |
201 | struct { |
202 | TransformationMatrix localTransform; |
203 | |
204 | TransformationMatrix combined; |
205 | TransformationMatrix combinedForChildren; |
206 | } m_layerTransforms; |
207 | }; |
208 | |
209 | } |
210 | |
211 | #endif // TextureMapperLayer_h |
212 | |