Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/WebCore/platform/graphics/cg/TransformationMatrixCG.cpp

Issue 21184: WebKit merge 40722:40785 (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007 Apple Inc. 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 10 matching lines...) Expand all
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "TransformationMatrix.h" 27 #include "TransformationMatrix.h"
28 28
29 #if PLATFORM(CG) 29 #if PLATFORM(CG)
30 30
31 #include <CoreGraphics/CGAffineTransform.h>
31 #include "FloatConversion.h" 32 #include "FloatConversion.h"
32 #include "FloatRect.h"
33 #include "IntRect.h"
34
35 #include <wtf/MathExtras.h>
36 33
37 namespace WebCore { 34 namespace WebCore {
38 35
39 TransformationMatrix::TransformationMatrix() 36 TransformationMatrix::operator CGAffineTransform() const
40 : m_transform(CGAffineTransformIdentity)
41 { 37 {
42 } 38 return CGAffineTransformMake(narrowPrecisionToCGFloat(a()),
43 39 narrowPrecisionToCGFloat(b()),
44 TransformationMatrix::TransformationMatrix(double a, double b, double c, double d, double tx, double ty) 40 narrowPrecisionToCGFloat(c()),
45 { 41 narrowPrecisionToCGFloat(d()),
46 m_transform = CGAffineTransformMake(narrowPrecisionToCGFloat(a), 42 narrowPrecisionToCGFloat(e()),
47 narrowPrecisionToCGFloat(b), 43 narrowPrecisionToCGFloat(f()));
48 narrowPrecisionToCGFloat(c),
49 narrowPrecisionToCGFloat(d),
50 narrowPrecisionToCGFloat(tx),
51 narrowPrecisionToCGFloat(ty));
52 }
53
54 TransformationMatrix::TransformationMatrix(const PlatformTransformationMatrix& t )
55 : m_transform(t)
56 {
57 }
58
59 void TransformationMatrix::setMatrix(double a, double b, double c, double d, dou ble tx, double ty)
60 {
61 m_transform = CGAffineTransformMake(narrowPrecisionToCGFloat(a),
62 narrowPrecisionToCGFloat(b),
63 narrowPrecisionToCGFloat(c),
64 narrowPrecisionToCGFloat(d),
65 narrowPrecisionToCGFloat(tx),
66 narrowPrecisionToCGFloat(ty));
67 }
68
69 void TransformationMatrix::map(double x, double y, double *x2, double *y2) const
70 {
71 CGPoint result = CGPointApplyAffineTransform(CGPointMake(narrowPrecisionToCG Float(x), narrowPrecisionToCGFloat(y)), m_transform);
72 *x2 = result.x;
73 *y2 = result.y;
74 }
75
76 IntRect TransformationMatrix::mapRect(const IntRect &rect) const
77 {
78 return enclosingIntRect(CGRectApplyAffineTransform(CGRect(rect), m_transform ));
79 }
80
81 FloatRect TransformationMatrix::mapRect(const FloatRect &rect) const
82 {
83 return FloatRect(CGRectApplyAffineTransform(CGRect(rect), m_transform));
84 }
85
86 bool TransformationMatrix::isIdentity() const
87 {
88 return CGAffineTransformIsIdentity(m_transform);
89 }
90
91 double TransformationMatrix::a() const
92 {
93 return m_transform.a;
94 }
95
96 void TransformationMatrix::setA(double a)
97 {
98 m_transform.a = narrowPrecisionToCGFloat(a);
99 }
100
101 double TransformationMatrix::b() const
102 {
103 return m_transform.b;
104 }
105
106 void TransformationMatrix::setB(double b)
107 {
108 m_transform.b = narrowPrecisionToCGFloat(b);
109 }
110
111 double TransformationMatrix::c() const
112 {
113 return m_transform.c;
114 }
115
116 void TransformationMatrix::setC(double c)
117 {
118 m_transform.c = narrowPrecisionToCGFloat(c);
119 }
120
121 double TransformationMatrix::d() const
122 {
123 return m_transform.d;
124 }
125
126 void TransformationMatrix::setD(double d)
127 {
128 m_transform.d = narrowPrecisionToCGFloat(d);
129 }
130
131 double TransformationMatrix::e() const
132 {
133 return m_transform.tx;
134 }
135
136 void TransformationMatrix::setE(double e)
137 {
138 m_transform.tx = narrowPrecisionToCGFloat(e);
139 }
140
141 double TransformationMatrix::f() const
142 {
143 return m_transform.ty;
144 }
145
146 void TransformationMatrix::setF(double f)
147 {
148 m_transform.ty = narrowPrecisionToCGFloat(f);
149 }
150
151 void TransformationMatrix::reset()
152 {
153 m_transform = CGAffineTransformIdentity;
154 }
155
156 TransformationMatrix &TransformationMatrix::scale(double sx, double sy)
157 {
158 m_transform = CGAffineTransformScale(m_transform, narrowPrecisionToCGFloat(s x), narrowPrecisionToCGFloat(sy));
159 return *this;
160 }
161
162 TransformationMatrix &TransformationMatrix::rotate(double d)
163 {
164 m_transform = CGAffineTransformRotate(m_transform, narrowPrecisionToCGFloat( deg2rad(d)));
165 return *this;
166 }
167
168 TransformationMatrix &TransformationMatrix::translate(double tx, double ty)
169 {
170 m_transform = CGAffineTransformTranslate(m_transform, narrowPrecisionToCGFlo at(tx), narrowPrecisionToCGFloat(ty));
171 return *this;
172 }
173
174 TransformationMatrix &TransformationMatrix::shear(double sx, double sy)
175 {
176 CGAffineTransform shear = CGAffineTransformMake(1.0f, narrowPrecisionToCGFlo at(sy), narrowPrecisionToCGFloat(sx), 1.0f, 0.0f, 0.0f);
177 m_transform = CGAffineTransformConcat(shear, m_transform);
178 return *this;
179 }
180
181 double TransformationMatrix::det() const
182 {
183 return m_transform.a * m_transform.d - m_transform.b * m_transform.c;
184 }
185
186 TransformationMatrix TransformationMatrix::inverse() const
187 {
188 if (isInvertible())
189 return TransformationMatrix(CGAffineTransformInvert(m_transform));
190 return TransformationMatrix();
191 }
192
193 TransformationMatrix::operator PlatformTransformationMatrix() const
194 {
195 return m_transform;
196 }
197
198 bool TransformationMatrix::operator== (const TransformationMatrix &m2) const
199 {
200 return CGAffineTransformEqualToTransform(m_transform, CGAffineTransform(m2)) ;
201 }
202
203 TransformationMatrix &TransformationMatrix::operator*= (const TransformationMatr ix &m2)
204 {
205 m_transform = CGAffineTransformConcat(m_transform, CGAffineTransform(m2));
206 return *this;
207 }
208
209 TransformationMatrix TransformationMatrix::operator* (const TransformationMatrix &m2)
210 {
211 return CGAffineTransformConcat(m_transform, CGAffineTransform(m2));
212 } 44 }
213 45
214 } 46 }
215 47
216 #endif // PLATFORM(CG) 48 #endif // PLATFORM(CG)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698