2 Copyright (C) 2011 Samsung Electronics
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.
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.
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.
22 #if ENABLE(TIZEN_ACCELERATED_COMPOSITING)
23 #if USE(ACCELERATED_COMPOSITING)
25 #include "LayerTransformation.h"
31 PassOwnPtr<LayerTransformation> LayerTransformation::create(EflLayer* owner)
33 return adoptPtr(new LayerTransformation(owner));
36 LayerTransformation::LayerTransformation(EflLayer* owner)
38 , m_anchorPoint(0.5f, 0.5f, 0.0f)
39 , m_contentsAnchorPoint(0.5f, 0.5f)
44 LayerTransformation::~LayerTransformation()
48 void LayerTransformation::setPosition(const FloatPoint& position)
50 m_position = position;
53 void LayerTransformation::setAnchorPoint(const FloatPoint3D& anchorPoint)
55 m_anchorPoint = anchorPoint;
58 void LayerTransformation::setSize(const FloatSize& size)
63 void LayerTransformation::setTransform(const TransformationMatrix& transform)
65 m_transform = transform;
68 void LayerTransformation::setChildrenTransform(const TransformationMatrix& transform)
70 m_childrenTransform = transform;
73 void LayerTransformation::setContentsPosition(const IntPoint& position)
75 m_contentsPosition = position;
78 void LayerTransformation::setContentsSize(const IntSize& size)
80 m_contentsSize = size;
83 void LayerTransformation::updateLayerMatrix()
85 EflLayer* parent = m_owner->parent();
87 float centerOffsetX = (0.5 - m_anchorPoint.x()) * m_size.width();
88 float centerOffsetY = (0.5 - m_anchorPoint.y()) * m_size.height();
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(),
95 m_layerMatrix.multiply(m_transform);
96 m_layerMatrix.translate3d(centerOffsetX, centerOffsetY, -m_anchorPoint.z());
98 m_contentsMatrix = m_layerMatrix;
99 m_contentsMatrix.scale3d(m_size.width(), m_size.height(), 1);
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);
111 m_layerMatrix.multiply(m_childrenTransform);
112 m_layerMatrix.translate3d(-m_size.width() * 0.5, -m_size.height() * 0.5, 0);
115 void LayerTransformation::updateContentsMatrix()
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),
122 m_contentsMatrix.scale3d(m_contentsSize.width(), m_contentsSize.height(), 1);
125 void LayerTransformation::updateContentsMatrix(const FloatRect& tempContentsRect)
127 m_contentsMatrix = m_layerMatrix;
128 m_contentsMatrix.translate3d(tempContentsRect.x() + (tempContentsRect.width() * 0.5),
129 tempContentsRect.y() + (tempContentsRect.height() * 0.5),
132 m_contentsMatrix.scale3d(tempContentsRect.width(), tempContentsRect.height(), 1);
135 void LayerTransformation::updateRenderMatrix(const TransformationMatrix& matrix)
137 m_renderMatrix = matrix;
138 m_renderMatrix.multiply(m_contentsMatrix);
141 m_renderMatrix.flipY();
146 void LayerTransformation::makeGLMatrix()
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();
166 } // namespace WebCore