2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
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.
21 #include "GraphicsLayerTransform.h"
25 GraphicsLayerTransform::GraphicsLayerTransform()
27 , m_dirty(false) // false by default since all default values would be combined as the identity matrix
28 , m_childrenDirty(false)
32 void GraphicsLayerTransform::setPosition(const FloatPoint& position)
34 m_position = position;
38 void GraphicsLayerTransform::setSize(const FloatSize& size)
44 void GraphicsLayerTransform::setAnchorPoint(const FloatPoint3D& anchorPoint)
46 m_anchorPoint = anchorPoint;
50 void GraphicsLayerTransform::setFlattening(bool flattening)
52 m_flattening = flattening;
56 void GraphicsLayerTransform::setLocalTransform(const TransformationMatrix& transform)
62 void GraphicsLayerTransform::setChildrenTransform(const TransformationMatrix& transform)
64 m_children = transform;
68 TransformationMatrix GraphicsLayerTransform::combined()
74 TransformationMatrix GraphicsLayerTransform::combinedForChildren()
78 combineTransformsForChildren();
79 return m_combinedForChildren;
82 void GraphicsLayerTransform::combineTransforms(const TransformationMatrix& parentTransform)
84 float originX = m_anchorPoint.x() * m_size.width();
85 float originY = m_anchorPoint.y() * m_size.height();
88 TransformationMatrix(parentTransform)
89 .translate3d(originX + m_position.x(), originY + m_position.y(), m_anchorPoint.z() )
92 // The children transform will take it from here, if it gets used.
93 m_combinedForChildren = m_combined;
94 m_combined.translate3d(-originX, -originY, -m_anchorPoint.z());
97 m_childrenDirty = true;
100 void GraphicsLayerTransform::combineTransformsForChildren()
103 ASSERT(m_childrenDirty);
105 float originX = m_anchorPoint.x() * m_size.width();
106 float originY = m_anchorPoint.y() * m_size.height();
108 // In case a parent had preserves3D and this layer has not, flatten our children.
110 m_combinedForChildren = m_combinedForChildren.to2dTransform();
111 m_combinedForChildren.multiply(m_children);
112 m_combinedForChildren.translate3d(-originX, -originY, -m_anchorPoint.z());
114 m_childrenDirty = false;