OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 12 matching lines...) Expand all Loading... |
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 #include "config.h" | 30 #include "config.h" |
31 #include "TransformationMatrix.h" | 31 #include "TransformationMatrix.h" |
32 | 32 |
33 #include "FloatRect.h" | |
34 #include "IntRect.h" | |
35 | |
36 #include "SkiaUtils.h" | 33 #include "SkiaUtils.h" |
37 | 34 |
38 namespace WebCore { | 35 namespace WebCore { |
39 | 36 |
40 TransformationMatrix::TransformationMatrix() | |
41 { | |
42 m_transform.reset(); | |
43 } | |
44 | |
45 TransformationMatrix::TransformationMatrix(double a, double b, double c, double
d, double e, double f) | |
46 { | |
47 setMatrix(a, b, c, d, e, f); | |
48 } | |
49 | |
50 TransformationMatrix::TransformationMatrix(const SkMatrix& matrix) | |
51 : m_transform(matrix) | |
52 { | |
53 } | |
54 | |
55 void TransformationMatrix::setMatrix(double a, double b, double c, double d, dou
ble e, double f) | |
56 { | |
57 m_transform.reset(); | |
58 | |
59 m_transform.setScaleX(WebCoreDoubleToSkScalar(a)); | |
60 m_transform.setSkewX(WebCoreDoubleToSkScalar(c)); | |
61 m_transform.setTranslateX(WebCoreDoubleToSkScalar(e)); | |
62 | |
63 m_transform.setScaleY(WebCoreDoubleToSkScalar(d)); | |
64 m_transform.setSkewY(WebCoreDoubleToSkScalar(b)); | |
65 m_transform.setTranslateY(WebCoreDoubleToSkScalar(f)); | |
66 } | |
67 | |
68 void TransformationMatrix::map(double x, double y, double* x2, double* y2) const | |
69 { | |
70 SkPoint src, dst; | |
71 src.set(WebCoreDoubleToSkScalar(x), WebCoreDoubleToSkScalar(y)); | |
72 m_transform.mapPoints(&dst, &src, 1); | |
73 | |
74 *x2 = SkScalarToDouble(dst.fX); | |
75 *y2 = SkScalarToDouble(dst.fY); | |
76 } | |
77 | |
78 IntRect TransformationMatrix::mapRect(const IntRect& src) const | |
79 { | |
80 SkRect dst; | |
81 m_transform.mapRect(&dst, src); | |
82 return enclosingIntRect(dst); | |
83 } | |
84 | |
85 FloatRect TransformationMatrix::mapRect(const FloatRect& src) const | |
86 { | |
87 SkRect dst; | |
88 m_transform.mapRect(&dst, src); | |
89 return dst; | |
90 } | |
91 | |
92 bool TransformationMatrix::isIdentity() const | |
93 { | |
94 return m_transform.isIdentity(); | |
95 } | |
96 | |
97 void TransformationMatrix::reset() | |
98 { | |
99 m_transform.reset(); | |
100 } | |
101 | |
102 TransformationMatrix &TransformationMatrix::scale(double sx, double sy) | |
103 { | |
104 m_transform.preScale(WebCoreDoubleToSkScalar(sx), WebCoreDoubleToSkScalar(sy
), 0, 0); | |
105 return *this; | |
106 } | |
107 | |
108 TransformationMatrix &TransformationMatrix::rotate(double d) | |
109 { | |
110 m_transform.preRotate(WebCoreDoubleToSkScalar(d), 0, 0); | |
111 return *this; | |
112 } | |
113 | |
114 TransformationMatrix &TransformationMatrix::translate(double tx, double ty) | |
115 { | |
116 m_transform.preTranslate(WebCoreDoubleToSkScalar(tx), WebCoreDoubleToSkScala
r(ty)); | |
117 return *this; | |
118 } | |
119 | |
120 TransformationMatrix &TransformationMatrix::shear(double sx, double sy) | |
121 { | |
122 m_transform.preSkew(WebCoreDoubleToSkScalar(sx), WebCoreDoubleToSkScalar(sy)
, 0, 0); | |
123 return *this; | |
124 } | |
125 | |
126 double TransformationMatrix::det() const | |
127 { | |
128 return SkScalarToDouble(m_transform.getScaleX()) * SkScalarToDouble(m_transf
orm.getScaleY()) - | |
129 SkScalarToDouble(m_transform.getSkewY()) * SkScalarToDouble(m_transfo
rm.getSkewX()); | |
130 } | |
131 | |
132 TransformationMatrix TransformationMatrix::inverse() const | |
133 { | |
134 TransformationMatrix inverse; | |
135 m_transform.invert(&inverse.m_transform); | |
136 return inverse; | |
137 } | |
138 | |
139 TransformationMatrix::operator SkMatrix() const | 37 TransformationMatrix::operator SkMatrix() const |
140 { | 38 { |
141 return m_transform; | 39 SkMatrix result; |
142 } | |
143 | 40 |
144 bool TransformationMatrix::operator==(const TransformationMatrix& m2) const | 41 result.setScaleX(WebCoreDoubleToSkScalar(a())); |
145 { | 42 result.setSkewX(WebCoreDoubleToSkScalar(c())); |
146 return m_transform == m2.m_transform; | 43 result.setTranslateX(WebCoreDoubleToSkScalar(e())); |
147 } | |
148 | 44 |
149 TransformationMatrix &TransformationMatrix::operator*=(const TransformationMatri
x& m2) | 45 result.setScaleY(WebCoreDoubleToSkScalar(d())); |
150 { | 46 result.setSkewY(WebCoreDoubleToSkScalar(b())); |
151 m_transform.setConcat(m2.m_transform, m_transform); | 47 result.setTranslateY(WebCoreDoubleToSkScalar(f())); |
152 return *this; | |
153 } | |
154 | 48 |
155 TransformationMatrix TransformationMatrix::operator*(const TransformationMatrix&
m2) | 49 result.setPerspX(0); |
156 { | 50 result.setPerspY(0); |
157 TransformationMatrix cat; | |
158 cat.m_transform.setConcat(m2.m_transform, m_transform); | |
159 return cat; | |
160 } | |
161 | 51 |
162 double TransformationMatrix::a() const | 52 return result; |
163 { | |
164 return SkScalarToDouble(m_transform.getScaleX()); | |
165 } | |
166 | |
167 void TransformationMatrix::setA(double a) | |
168 { | |
169 m_transform.setScaleX(WebCoreDoubleToSkScalar(a)); | |
170 } | |
171 | |
172 double TransformationMatrix::b() const | |
173 { | |
174 return SkScalarToDouble(m_transform.getSkewY()); | |
175 } | |
176 | |
177 void TransformationMatrix::setB(double b) | |
178 { | |
179 m_transform.setSkewY(WebCoreDoubleToSkScalar(b)); | |
180 } | |
181 | |
182 double TransformationMatrix::c() const | |
183 { | |
184 return SkScalarToDouble(m_transform.getSkewX()); | |
185 } | |
186 | |
187 void TransformationMatrix::setC(double c) | |
188 { | |
189 m_transform.setSkewX(WebCoreDoubleToSkScalar(c)); | |
190 } | |
191 | |
192 double TransformationMatrix::d() const | |
193 { | |
194 return SkScalarToDouble(m_transform.getScaleY()); | |
195 } | |
196 | |
197 void TransformationMatrix::setD(double d) | |
198 { | |
199 m_transform.setScaleY(WebCoreDoubleToSkScalar(d)); | |
200 } | |
201 | |
202 double TransformationMatrix::e() const | |
203 { | |
204 return SkScalarToDouble(m_transform.getTranslateX()); | |
205 } | |
206 | |
207 void TransformationMatrix::setE(double e) | |
208 { | |
209 m_transform.setTranslateX(WebCoreDoubleToSkScalar(e)); | |
210 } | |
211 | |
212 double TransformationMatrix::f() const | |
213 { | |
214 return SkScalarToDouble(m_transform.getTranslateY()); | |
215 } | |
216 | |
217 void TransformationMatrix::setF(double f) | |
218 { | |
219 m_transform.setTranslateY(WebCoreDoubleToSkScalar(f)); | |
220 } | 53 } |
221 | 54 |
222 } // namespace WebCore | 55 } // namespace WebCore |
OLD | NEW |