tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / efl / GraphicsLayerTexture.cpp
1 /*
2     Copyright (C) 2011 Samsung Electronics
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 #include "config.h"
21
22 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
23 #if USE(ACCELERATED_COMPOSITING)
24
25 #include "GraphicsLayerTexture.h"
26
27 #include "EflLayer.h"
28 #include "FloatRect.h"
29 #include "Logging.h"
30
31 #include <wtf/text/CString.h>
32
33 namespace WebCore {
34
35 PassOwnPtr<GraphicsLayer> GraphicsLayer::create(GraphicsLayerClient* client)
36 {
37     return adoptPtr(new GraphicsLayerTexture(client));
38 }
39
40 GraphicsLayerTexture::GraphicsLayerTexture(GraphicsLayerClient* client)
41     : GraphicsLayer(client)
42 {
43     LOG(AcceleratedCompositing, "Layer[%p/(nil)] GraphicsLayerTexture::%s() - CONSTRUCTOR\n", this, __func__);
44     m_platformLayer = EflLayer::create(this);
45     updateDebugIndicators();
46 }
47
48 GraphicsLayerTexture::~GraphicsLayerTexture()
49 {
50     LOG(AcceleratedCompositing, "Layer[%p/(nil)] GraphicsLayerTexture::%s() - DESTRUCTOR\n", this, __func__);
51     if (m_platformLayer)
52         m_platformLayer->setOwner(0);
53 }
54
55 void GraphicsLayerTexture::setName(const String & name)
56 {
57     String layerName = String::format("GraphicsLayerTexture[%p]", this) + name;
58     GraphicsLayer::setName(layerName);
59 }
60
61 bool GraphicsLayerTexture::setChildren(const Vector<GraphicsLayer*> & children)
62 {
63     bool b = GraphicsLayer::setChildren(children);
64     m_platformLayer->notifyChange();
65     return b;
66 }
67
68 void GraphicsLayerTexture::addChild(GraphicsLayer *child)
69 {
70     LOG(AcceleratedCompositing, "Layer[%p/%p] GraphicsLayerTexture::%s()\n", this, m_platformLayer.get(), __func__);
71     LOG(AcceleratedCompositing, "---> child: %p\n", child);
72     GraphicsLayer::addChild(child);
73     m_platformLayer->notifyChange();
74 }
75
76 void GraphicsLayerTexture::addChildAtIndex(GraphicsLayer *child, int index)
77 {
78     GraphicsLayer::addChildAtIndex(child, index);
79     m_platformLayer->notifyChange();
80 }
81
82 void GraphicsLayerTexture::addChildAbove(GraphicsLayer *child, GraphicsLayer *sibling)
83 {
84     GraphicsLayer::addChildAbove(child, sibling);
85     m_platformLayer->notifyChange();
86 }
87
88 void GraphicsLayerTexture::addChildBelow(GraphicsLayer *child, GraphicsLayer *sibling)
89 {
90     GraphicsLayer::addChildBelow(child, sibling);
91     m_platformLayer->notifyChange();
92 }
93
94 bool GraphicsLayerTexture::replaceChild(GraphicsLayer *oldChild, GraphicsLayer *newChild)
95 {
96     bool b = GraphicsLayer::replaceChild(oldChild, newChild);
97     m_platformLayer->notifyChange();
98     return b;
99 }
100
101 void GraphicsLayerTexture::removeFromParent()
102 {
103     GraphicsLayer::removeFromParent();
104 }
105
106 void GraphicsLayerTexture::setMaskLayer(GraphicsLayer* layer)
107 {
108     if (layer == m_maskLayer)
109         return;
110
111     GraphicsLayer::setMaskLayer(layer);
112 }
113
114 void GraphicsLayerTexture::setReplicatedByLayer(GraphicsLayer* layer)
115 {
116     if (layer == m_replicaLayer)
117         return;
118
119     GraphicsLayer::setReplicatedByLayer(layer);
120 }
121
122 void GraphicsLayerTexture::setMasksToBounds(bool b)
123 {
124     if (b == m_masksToBounds)
125         return;
126
127     LOG(AcceleratedCompositing, "Layer[%p/%p] GraphicsLayerTexture::%s()\n", this, m_platformLayer.get(), __func__);
128     LOG(AcceleratedCompositing, "---> Mask: %s\n", (b?"true":"false"));
129     GraphicsLayer::setMasksToBounds(b);
130     updateDebugIndicators();
131 }
132
133 void GraphicsLayerTexture::setPosition(const FloatPoint& position)
134 {
135     if (position == m_position)
136         return;
137
138     GraphicsLayer::setPosition(position);
139     m_platformLayer->setPosition(position);
140 }
141
142 void GraphicsLayerTexture::setAnchorPoint(const FloatPoint3D& anchorPoint)
143 {
144     if (anchorPoint == m_anchorPoint)
145         return;
146
147     GraphicsLayer::setAnchorPoint(anchorPoint);
148     m_platformLayer->setAnchorPoint(anchorPoint);
149 }
150
151 void GraphicsLayerTexture::setSize(const FloatSize& size)
152 {
153     if (size == m_size)
154         return;
155
156     GraphicsLayer::setSize(size);
157     m_platformLayer->setSize(size);
158 }
159
160 void GraphicsLayerTexture::setTransform(const TransformationMatrix& transform)
161 {
162     if (transform == m_transform)
163         return;
164
165     GraphicsLayer::setTransform(transform);
166     m_platformLayer->setTransform(transform);
167 }
168
169 void GraphicsLayerTexture::setChildrenTransform(const TransformationMatrix& transform)
170 {
171     if (transform == m_childrenTransform)
172         return;
173
174     GraphicsLayer::setChildrenTransform(transform);
175     m_platformLayer->setChildrenTransform(transform);
176 }
177
178 void GraphicsLayerTexture::setPreserves3D(bool b)
179 {
180     if (b == m_preserves3D)
181         return;
182
183     GraphicsLayer::setPreserves3D(b);
184 }
185
186 void GraphicsLayerTexture::setContentsRect(const IntRect& rect)
187 {
188     if (rect == m_contentsRect)
189         return;
190
191     GraphicsLayer::setContentsRect(rect);
192     m_platformLayer->setContentsRect(rect);
193 }
194
195 void GraphicsLayerTexture::setDrawsContent(bool b)
196 {
197     if (m_platformLayer->contentsType() == EflLayer::WebGLContentsType)
198         b = true;
199     if (b == m_drawsContent)
200         return;
201
202     GraphicsLayer::setDrawsContent(b);
203     m_platformLayer->setDrawsContent(b);
204     updateDebugIndicators();
205 }
206
207 void GraphicsLayerTexture::setContentsToImage(Image* image)
208 {
209     m_platformLayer->setContentsToImage(image);
210
211     updateDebugIndicators();
212 }
213
214 void GraphicsLayerTexture::setContentsToMedia(PlatformLayer* layer)
215 {
216     if (m_platformLayer == layer)
217         return;
218
219     LOG(AcceleratedCompositing, "Layer[%p/%p] GraphicsLayerTexture::%s()\n", this, m_platformLayer.get(), __func__);
220     LOG(AcceleratedCompositing, "---> EflLayer: %p\n", layer);
221
222     if (layer) {
223         m_platformLayer = layer;
224         m_platformLayer->setOwner(this);
225         m_platformLayer->setNeedsDisplay();
226     } else
227         m_platformLayer = EflLayer::create(this);
228
229     updateDebugIndicators();
230 }
231
232 void GraphicsLayerTexture::setContentsToCanvas(PlatformLayer* layer)
233 {
234     if (m_platformLayer == layer)
235         return;
236
237     LOG(AcceleratedCompositing, "Layer[%p/%p] GraphicsLayerTexture::%s()\n", this, m_platformLayer.get(), __func__);
238     LOG(AcceleratedCompositing, "---> EflLayer: %p\n", layer);
239
240     if (layer) {
241         m_platformLayer = layer;
242         m_platformLayer->setOwner(this);
243         m_platformLayer->setNeedsDisplay();
244     } else
245         m_platformLayer = EflLayer::create(this);
246
247     updateDebugIndicators();
248 }
249
250 void GraphicsLayerTexture::setContentsBackgroundColor(const Color& color)
251 {
252     m_platformLayer->setContentsToColor(color);
253 }
254
255 bool GraphicsLayerTexture::hasContentsLayer() const
256 {
257     return m_platformLayer->hasContentsLayer();
258 }
259
260 void GraphicsLayerTexture::setContentsOrientation(CompositingCoordinatesOrientation orientation)
261 {
262     if (orientation == m_contentsOrientation)
263         return;
264
265     GraphicsLayer::setContentsOrientation(orientation);
266 }
267
268 void GraphicsLayerTexture::setBackgroundColor(const Color& color)
269 {
270     if (color == m_backgroundColor)
271         return;
272
273     GraphicsLayer::setBackgroundColor(color);
274 }
275
276 void GraphicsLayerTexture::clearBackgroundColor()
277 {
278     GraphicsLayer::clearBackgroundColor();
279 }
280
281 void GraphicsLayerTexture::setDebugBackgroundColor(const Color& color)
282 {
283     if (color.isValid())
284         m_platformLayer->setBackgroundColor(color);
285     else
286         m_platformLayer->setBackgroundColor(static_cast<RGBA32>(0));
287 }
288
289 void GraphicsLayerTexture::setDebugBorder(const Color& color, float borderWidth)
290 {
291     if (color.isValid())
292         m_platformLayer->setBorderColor(color);
293     else
294         m_platformLayer->setBorderColor(static_cast<RGBA32>(0));
295
296     m_platformLayer->setBorderWidth(borderWidth);
297 }
298
299 void GraphicsLayerTexture::setContentsOpaque(bool b)
300 {
301     if (b == m_contentsOpaque)
302         return;
303
304     GraphicsLayer::setContentsOpaque(b);
305 }
306
307 void GraphicsLayerTexture::setBackfaceVisibility(bool b)
308 {
309     if (b == m_backfaceVisibility)
310         return;
311
312     LOG(AcceleratedCompositing, "Layer[%p/%p] GraphicsLayerTexture::%s()\n", this, m_platformLayer.get(), __func__);
313     LOG(AcceleratedCompositing, "---> Backface Visibility: %s\n", (b?"true":"false"));
314     GraphicsLayer::setBackfaceVisibility(b);
315 }
316
317 void GraphicsLayerTexture::setOpacity(float opacity)
318 {
319     if (opacity == m_opacity)
320         return;
321
322     GraphicsLayer::setOpacity(opacity);
323     m_platformLayer->setOpacity(opacity);
324 }
325
326 void GraphicsLayerTexture::setNeedsDisplay()
327 {
328     if (drawsContent())
329         m_platformLayer->setNeedsDisplay();
330 }
331
332 void GraphicsLayerTexture::setNeedsDisplayInRect(const FloatRect& r)
333 {
334     if (!drawsContent())
335         return;
336
337     FloatRect rect(r);
338     FloatRect layerBounds(FloatPoint(), m_size);
339     rect.intersect(layerBounds);
340     if (rect.isEmpty())
341         return;
342
343     m_platformLayer->setNeedsDisplayInRect(rect);
344 }
345
346 void GraphicsLayerTexture::setContentsNeedsDisplay()
347 {
348     if (m_platformLayer->hasContentsLayer())
349         m_platformLayer->setContentsNeedsDisplay();
350 }
351
352 void GraphicsLayerTexture::notifySyncRequired()
353 {
354     if (m_client)
355         m_client->notifySyncRequired(this);
356 }
357
358 }
359
360 #endif
361 #endif