tizen beta release
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / efl / LayerTransformation.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 "LayerTransformation.h"
26
27 #include "EflLayer.h"
28
29 namespace WebCore {
30
31 PassOwnPtr<LayerTransformation> LayerTransformation::create(EflLayer* owner)
32 {
33     return adoptPtr(new LayerTransformation(owner));
34 }
35
36 LayerTransformation::LayerTransformation(EflLayer* owner)
37     : m_owner(owner)
38     , m_anchorPoint(0.5f, 0.5f, 0.0f)
39     , m_contentsAnchorPoint(0.5f, 0.5f)
40     , m_flipY(false)
41 {
42 }
43
44 LayerTransformation::~LayerTransformation()
45 {
46 }
47
48 void LayerTransformation::setPosition(const FloatPoint& position)
49 {
50     m_position = position;
51 }
52
53 void LayerTransformation::setAnchorPoint(const FloatPoint3D& anchorPoint)
54 {
55     m_anchorPoint = anchorPoint;
56 }
57
58 void LayerTransformation::setSize(const FloatSize& size)
59 {
60     m_size = size;
61 }
62
63 void LayerTransformation::setTransform(const TransformationMatrix& transform)
64 {
65     m_transform = transform;
66 }
67
68 void LayerTransformation::setChildrenTransform(const TransformationMatrix& transform)
69 {
70     m_childrenTransform = transform;
71 }
72
73 void LayerTransformation::setContentsPosition(const IntPoint& position)
74 {
75     m_contentsPosition = position;
76 }
77
78 void LayerTransformation::setContentsSize(const IntSize& size)
79 {
80     m_contentsSize = size;
81 }
82
83 void LayerTransformation::updateLayerMatrix()
84 {
85     EflLayer* parent = m_owner->parent();
86
87     float centerOffsetX = (0.5 - m_anchorPoint.x()) * m_size.width();
88     float centerOffsetY = (0.5 - m_anchorPoint.y()) * m_size.height();
89
90     m_layerMatrix = parent->layerTransform();
91     m_layerMatrix.translate3d(m_position.x() + m_anchorPoint.x() * m_size.width(),
92                               m_position.y() + m_anchorPoint.y() * m_size.height(),
93                               m_anchorPoint.z());
94
95     m_layerMatrix.multiply(m_transform);
96     m_layerMatrix.translate3d(centerOffsetX, centerOffsetY, -m_anchorPoint.z());
97
98     m_contentsMatrix = m_layerMatrix;
99     m_contentsMatrix.scale3d(m_size.width(), m_size.height(), 1);
100
101     if (!m_owner->owner()->preserves3D()) {
102         m_layerMatrix.setM13(0);
103         m_layerMatrix.setM23(0);
104         m_layerMatrix.setM31(0);
105         m_layerMatrix.setM32(0);
106         m_layerMatrix.setM33(1);
107         m_layerMatrix.setM34(0);
108         m_layerMatrix.setM43(0);
109     }
110
111     m_layerMatrix.multiply(m_childrenTransform);
112     m_layerMatrix.translate3d(-m_size.width() * 0.5, -m_size.height() * 0.5, 0);
113 }
114
115 void LayerTransformation::updateContentsMatrix()
116 {
117     m_contentsMatrix = m_layerMatrix;
118     m_contentsMatrix.translate3d(m_contentsPosition.x() + (m_contentsSize.width() * 0.5),
119                                  m_contentsPosition.y() + (m_contentsSize.height() * 0.5),
120                                  0);
121
122     m_contentsMatrix.scale3d(m_contentsSize.width(), m_contentsSize.height(), 1);
123 }
124
125 void LayerTransformation::updateContentsMatrix(const FloatRect& tempContentsRect)
126 {
127     m_contentsMatrix = m_layerMatrix;
128     m_contentsMatrix.translate3d(tempContentsRect.x() + (tempContentsRect.width() * 0.5),
129                                  tempContentsRect.y() + (tempContentsRect.height() * 0.5),
130                                  0);
131
132     m_contentsMatrix.scale3d(tempContentsRect.width(), tempContentsRect.height(), 1);
133 }
134
135 void LayerTransformation::updateRenderMatrix(const TransformationMatrix& matrix)
136 {
137     m_renderMatrix = matrix;
138     m_renderMatrix.multiply(m_contentsMatrix);
139
140     if (m_flipY)
141         m_renderMatrix.flipY();
142
143     makeGLMatrix();
144 }
145
146 void LayerTransformation::makeGLMatrix()
147 {
148     m_glMatrix[0] = m_renderMatrix.m11();
149     m_glMatrix[1] = m_renderMatrix.m12();
150     m_glMatrix[2] = m_renderMatrix.m13();
151     m_glMatrix[3] = m_renderMatrix.m14();
152     m_glMatrix[4] = m_renderMatrix.m21();
153     m_glMatrix[5] = m_renderMatrix.m22();
154     m_glMatrix[6] = m_renderMatrix.m23();
155     m_glMatrix[7] = m_renderMatrix.m24();
156     m_glMatrix[8] = m_renderMatrix.m31();
157     m_glMatrix[9] = m_renderMatrix.m32();
158     m_glMatrix[10] = m_renderMatrix.m33();
159     m_glMatrix[11] = m_renderMatrix.m34();
160     m_glMatrix[12] = m_renderMatrix.m41();
161     m_glMatrix[13] = m_renderMatrix.m42();
162     m_glMatrix[14] = m_renderMatrix.m43();
163     m_glMatrix[15] = m_renderMatrix.m44();
164 }
165
166 } // namespace WebCore
167
168 #endif
169 #endif