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

Side by Side Diff: ui/gfx/transform_util.cc

Issue 11931017: Use explicit constructor-enums for SkMatrix44, either kUninitialized or kIdentity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/transform_util.h" 5 #include "ui/gfx/transform_util.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ui/gfx/point.h" 9 #include "ui/gfx/point.h"
10 10
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 // rhs is the right hand side of the equation. 159 // rhs is the right hand side of the equation.
160 SkMScalar rhs[4] = { 160 SkMScalar rhs[4] = {
161 matrix.get(3, 0), 161 matrix.get(3, 0),
162 matrix.get(3, 1), 162 matrix.get(3, 1),
163 matrix.get(3, 2), 163 matrix.get(3, 2),
164 matrix.get(3, 3) 164 matrix.get(3, 3)
165 }; 165 };
166 166
167 // Solve the equation by inverting perspectiveMatrix and multiplying 167 // Solve the equation by inverting perspectiveMatrix and multiplying
168 // rhs by the inverse. 168 // rhs by the inverse.
169 SkMatrix44 inversePerspectiveMatrix; 169 SkMatrix44 inversePerspectiveMatrix(SkMatrix44::kUninitialized_Constructor);
170 if (!perspectiveMatrix.invert(&inversePerspectiveMatrix)) 170 if (!perspectiveMatrix.invert(&inversePerspectiveMatrix))
171 return false; 171 return false;
172 172
173 SkMatrix44 transposedInversePerspectiveMatrix = 173 SkMatrix44 transposedInversePerspectiveMatrix =
174 inversePerspectiveMatrix; 174 inversePerspectiveMatrix;
175 175
176 transposedInversePerspectiveMatrix.transpose(); 176 transposedInversePerspectiveMatrix.transpose();
177 transposedInversePerspectiveMatrix.mapMScalars(rhs); 177 transposedInversePerspectiveMatrix.mapMScalars(rhs);
178 178
179 for (int i = 0; i < 4; ++i) 179 for (int i = 0; i < 4; ++i)
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (row[0][2] > row[2][0]) 251 if (row[0][2] > row[2][0])
252 decomp->quaternion[1] = -decomp->quaternion[1]; 252 decomp->quaternion[1] = -decomp->quaternion[1];
253 if (row[1][0] > row[0][1]) 253 if (row[1][0] > row[0][1])
254 decomp->quaternion[2] = -decomp->quaternion[2]; 254 decomp->quaternion[2] = -decomp->quaternion[2];
255 255
256 return true; 256 return true;
257 } 257 }
258 258
259 // Taken from http://www.w3.org/TR/css3-transforms/. 259 // Taken from http://www.w3.org/TR/css3-transforms/.
260 Transform ComposeTransform(const DecomposedTransform& decomp) { 260 Transform ComposeTransform(const DecomposedTransform& decomp) {
261 SkMatrix44 matrix; 261 SkMatrix44 matrix(SkMatrix44::kIdentity_Constructor);
262 for (int i = 0; i < 4; i++) 262 for (int i = 0; i < 4; i++)
263 matrix.setDouble(3, i, decomp.perspective[i]); 263 matrix.setDouble(3, i, decomp.perspective[i]);
264 264
265 SkMatrix44 tempTranslation; 265 matrix.preTranslate(SkDoubleToMScalar(decomp.translate[0]),
266 tempTranslation.setTranslate(SkDoubleToMScalar(decomp.translate[0]), 266 SkDoubleToMScalar(decomp.translate[1]),
267 SkDoubleToMScalar(decomp.translate[1]), 267 SkDoubleToMScalar(decomp.translate[2]));
268 SkDoubleToMScalar(decomp.translate[2]));
269 matrix.preConcat(tempTranslation);
270 268
271 double x = decomp.quaternion[0]; 269 double x = decomp.quaternion[0];
272 double y = decomp.quaternion[1]; 270 double y = decomp.quaternion[1];
273 double z = decomp.quaternion[2]; 271 double z = decomp.quaternion[2];
274 double w = decomp.quaternion[3]; 272 double w = decomp.quaternion[3];
275 273
276 SkMatrix44 rotation_matrix; 274 SkMatrix44 rotation_matrix(SkMatrix44::kUninitialized_Constructor);
277 rotation_matrix.setDouble(0, 0, 1.0 - 2.0 * (y * y + z * z)); 275 rotation_matrix.set3x3(1.0 - 2.0 * (y * y + z * z),
278 rotation_matrix.setDouble(0, 1, 2.0 * (x * y - z * w)); 276 2.0 * (x * y + z * w),
279 rotation_matrix.setDouble(0, 2, 2.0 * (x * z + y * w)); 277 2.0 * (x * z - y * w),
280 rotation_matrix.setDouble(1, 0, 2.0 * (x * y + z * w)); 278 2.0 * (x * y - z * w),
281 rotation_matrix.setDouble(1, 1, 1.0 - 2.0 * (x * x + z * z)); 279 1.0 - 2.0 * (x * x + z * z),
282 rotation_matrix.setDouble(1, 2, 2.0 * (y * z - x * w)); 280 2.0 * (y * z + x * w),
283 rotation_matrix.setDouble(2, 0, 2.0 * (x * z - y * w)); 281 2.0 * (x * z + y * w),
284 rotation_matrix.setDouble(2, 1, 2.0 * (y * z + x * w)); 282 2.0 * (y * z - x * w),
285 rotation_matrix.setDouble(2, 2, 1.0 - 2.0 * (x * x + y * y)); 283 1.0 - 2.0 * (x * x + y * y));
286 284
287 matrix.preConcat(rotation_matrix); 285 matrix.preConcat(rotation_matrix);
288 286
289 SkMatrix44 temp; 287 SkMatrix44 temp(SkMatrix44::kIdentity_Constructor);
290 if (decomp.skew[2]) { 288 if (decomp.skew[2]) {
291 temp.setDouble(1, 2, decomp.skew[2]); 289 temp.setDouble(1, 2, decomp.skew[2]);
292 matrix.preConcat(temp); 290 matrix.preConcat(temp);
293 } 291 }
294 292
295 if (decomp.skew[1]) { 293 if (decomp.skew[1]) {
296 temp.setDouble(1, 2, 0); 294 temp.setDouble(1, 2, 0);
297 temp.setDouble(0, 2, decomp.skew[1]); 295 temp.setDouble(0, 2, decomp.skew[1]);
298 matrix.preConcat(temp); 296 matrix.preConcat(temp);
299 } 297 }
300 298
301 if (decomp.skew[0]) { 299 if (decomp.skew[0]) {
302 temp.setDouble(0, 2, 0); 300 temp.setDouble(0, 2, 0);
303 temp.setDouble(0, 1, decomp.skew[0]); 301 temp.setDouble(0, 1, decomp.skew[0]);
304 matrix.preConcat(temp); 302 matrix.preConcat(temp);
305 } 303 }
306 304
307 SkMatrix44 tempScale; 305 matrix.preScale(SkDoubleToMScalar(decomp.scale[0]),
308 tempScale.setScale(SkDoubleToMScalar(decomp.scale[0]), 306 SkDoubleToMScalar(decomp.scale[1]),
309 SkDoubleToMScalar(decomp.scale[1]), 307 SkDoubleToMScalar(decomp.scale[2]));
310 SkDoubleToMScalar(decomp.scale[2]));
311 matrix.preConcat(tempScale);
312 308
313 Transform to_return; 309 Transform to_return;
314 to_return.matrix() = matrix; 310 to_return.matrix() = matrix;
315 return to_return; 311 return to_return;
316 } 312 }
317 313
318 } // namespace ui 314 } // namespace ui
OLDNEW
« no previous file with comments | « ui/gfx/transform.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698