1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "GraphicsLayerTransform.h"
namespace WebCore {
GraphicsLayerTransform::GraphicsLayerTransform()
: m_flattening(false)
, m_dirty(false) // false by default since all default values would be combined as the identity matrix
, m_childrenDirty(false)
{
}
void GraphicsLayerTransform::setPosition(const FloatPoint& position)
{
m_position = position;
m_dirty = true;
}
void GraphicsLayerTransform::setSize(const FloatSize& size)
{
m_size = size;
m_dirty = true;
}
void GraphicsLayerTransform::setAnchorPoint(const FloatPoint3D& anchorPoint)
{
m_anchorPoint = anchorPoint;
m_dirty = true;
}
void GraphicsLayerTransform::setFlattening(bool flattening)
{
m_flattening = flattening;
m_dirty = true;
}
void GraphicsLayerTransform::setLocalTransform(const TransformationMatrix& transform)
{
m_local = transform;
m_dirty = true;
}
void GraphicsLayerTransform::setChildrenTransform(const TransformationMatrix& transform)
{
m_children = transform;
m_dirty = true;
}
TransformationMatrix GraphicsLayerTransform::combined()
{
ASSERT(!m_dirty);
return m_combined;
}
TransformationMatrix GraphicsLayerTransform::combinedForChildren()
{
ASSERT(!m_dirty);
if (m_childrenDirty)
combineTransformsForChildren();
return m_combinedForChildren;
}
void GraphicsLayerTransform::combineTransforms(const TransformationMatrix& parentTransform)
{
float originX = m_anchorPoint.x() * m_size.width();
float originY = m_anchorPoint.y() * m_size.height();
m_combined =
TransformationMatrix(parentTransform)
.translate3d(originX + m_position.x(), originY + m_position.y(), m_anchorPoint.z() )
.multiply(m_local);
// The children transform will take it from here, if it gets used.
m_combinedForChildren = m_combined;
m_combined.translate3d(-originX, -originY, -m_anchorPoint.z());
m_dirty = false;
m_childrenDirty = true;
}
void GraphicsLayerTransform::combineTransformsForChildren()
{
ASSERT(!m_dirty);
ASSERT(m_childrenDirty);
float originX = m_anchorPoint.x() * m_size.width();
float originY = m_anchorPoint.y() * m_size.height();
// In case a parent had preserves3D and this layer has not, flatten our children.
if (m_flattening)
m_combinedForChildren = m_combinedForChildren.to2dTransform();
m_combinedForChildren.multiply(m_children);
m_combinedForChildren.translate3d(-originX, -originY, -m_anchorPoint.z());
m_childrenDirty = false;
}
}
|