tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / GraphicsLayerTransform.cpp
1 /*
2  Copyright (C) 2011 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 #include "config.h"
21 #include "GraphicsLayerTransform.h"
22
23 namespace WebCore {
24
25 GraphicsLayerTransform::GraphicsLayerTransform()
26     : m_flattening(false)
27     , m_dirty(false) // false by default since all default values would be combined as the identity matrix
28     , m_childrenDirty(false)
29 {
30 }
31
32 void GraphicsLayerTransform::setPosition(const FloatPoint& position)
33 {
34     m_position = position;
35     m_dirty = true;
36 }
37
38 void GraphicsLayerTransform::setSize(const FloatSize& size)
39 {
40     m_size = size;
41     m_dirty = true;
42 }
43
44 void GraphicsLayerTransform::setAnchorPoint(const FloatPoint3D& anchorPoint)
45 {
46     m_anchorPoint = anchorPoint;
47     m_dirty = true;
48 }
49
50 void GraphicsLayerTransform::setFlattening(bool flattening)
51 {
52     m_flattening = flattening;
53     m_dirty = true;
54 }
55
56 void GraphicsLayerTransform::setLocalTransform(const TransformationMatrix& transform)
57 {
58     m_local = transform;
59     m_dirty = true;
60 }
61
62 void GraphicsLayerTransform::setChildrenTransform(const TransformationMatrix& transform)
63 {
64     m_children = transform;
65     m_dirty = true;
66 }
67
68 TransformationMatrix GraphicsLayerTransform::combined()
69 {
70     ASSERT(!m_dirty);
71     return m_combined;
72 }
73
74 TransformationMatrix GraphicsLayerTransform::combinedForChildren()
75 {
76     ASSERT(!m_dirty);
77     if (m_childrenDirty)
78         combineTransformsForChildren();
79     return m_combinedForChildren;
80 }
81
82 void GraphicsLayerTransform::combineTransforms(const TransformationMatrix& parentTransform)
83 {
84     float originX = m_anchorPoint.x() * m_size.width();
85     float originY = m_anchorPoint.y() * m_size.height();
86
87     m_combined =
88         TransformationMatrix(parentTransform)
89             .translate3d(originX + m_position.x(), originY + m_position.y(), m_anchorPoint.z() )
90             .multiply(m_local);
91
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());
95
96     m_dirty = false;
97     m_childrenDirty = true;
98 }
99
100 void GraphicsLayerTransform::combineTransformsForChildren()
101 {
102     ASSERT(!m_dirty);
103     ASSERT(m_childrenDirty);
104
105     float originX = m_anchorPoint.x() * m_size.width();
106     float originY = m_anchorPoint.y() * m_size.height();
107
108     // In case a parent had preserves3D and this layer has not, flatten our children.
109     if (m_flattening)
110         m_combinedForChildren = m_combinedForChildren.to2dTransform();
111     m_combinedForChildren.multiply(m_children);
112     m_combinedForChildren.translate3d(-originX, -originY, -m_anchorPoint.z());
113
114     m_childrenDirty = false;
115 }
116
117 }