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

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

Issue 11774005: Migrate more functions from MathUtil to gfx::Transform (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
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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 tempScale.setScale(SkDoubleToMScalar(decomp.scale[0]), 308 tempScale.setScale(SkDoubleToMScalar(decomp.scale[0]),
309 SkDoubleToMScalar(decomp.scale[1]), 309 SkDoubleToMScalar(decomp.scale[1]),
310 SkDoubleToMScalar(decomp.scale[2])); 310 SkDoubleToMScalar(decomp.scale[2]));
311 matrix.preConcat(tempScale); 311 matrix.preConcat(tempScale);
312 312
313 Transform to_return; 313 Transform to_return;
314 to_return.matrix() = matrix; 314 to_return.matrix() = matrix;
315 return to_return; 315 return to_return;
316 } 316 }
317 317
318 Transform CreateGfxTransform(
319 double col1row1, double col1row2, double col1row3, double col1row4,
320 double col2row1, double col2row2, double col2row3, double col2row4,
321 double col3row1, double col3row2, double col3row3, double col3row4,
322 double col4row1, double col4row2, double col4row3, double col4row4)
323 {
324 Transform result(Transform::kSkipInitialization);
325 SkMatrix44& matrix = result.matrix();
326
327 // Initialize column 1
328 matrix.setDouble(0, 0, col1row1);
329 matrix.setDouble(1, 0, col1row2);
330 matrix.setDouble(2, 0, col1row3);
331 matrix.setDouble(3, 0, col1row4);
332
333 // Initialize column 2
334 matrix.setDouble(0, 1, col2row1);
335 matrix.setDouble(1, 1, col2row2);
336 matrix.setDouble(2, 1, col2row3);
337 matrix.setDouble(3, 1, col2row4);
338
339 // Initialize column 3
340 matrix.setDouble(0, 2, col3row1);
341 matrix.setDouble(1, 2, col3row2);
342 matrix.setDouble(2, 2, col3row3);
343 matrix.setDouble(3, 2, col3row4);
344
345 // Initialize column 4
346 matrix.setDouble(0, 3, col4row1);
347 matrix.setDouble(1, 3, col4row2);
348 matrix.setDouble(2, 3, col4row3);
349 matrix.setDouble(3, 3, col4row4);
350
351 return result;
352 }
353
354 Transform CreateGfxTransform(
355 double col1row1, double col1row2, double col2row1,
356 double col2row2, double x_translation, double y_translation)
357 {
358 gfx::Transform result;
359 SkMatrix44& matrix = result.matrix();
360 matrix.setDouble(0, 0, col1row1);
361 matrix.setDouble(1, 0, col1row2);
362 matrix.setDouble(0, 1, col2row1);
363 matrix.setDouble(1, 1, col2row2);
364 matrix.setDouble(0, 3, x_translation);
365 matrix.setDouble(1, 3, y_translation);
366
367 return result;
368 }
369
370 void FlattenTransformTo2d(Transform& transform) {
371 // Set both the 3rd row and 3rd column to (0, 0, 1, 0).
372 transform.matrix().setDouble(2, 0, 0);
373 transform.matrix().setDouble(2, 1, 0);
374 transform.matrix().setDouble(0, 2, 0);
375 transform.matrix().setDouble(1, 2, 0);
376 transform.matrix().setDouble(2, 2, 1);
377 transform.matrix().setDouble(3, 2, 0);
378 transform.matrix().setDouble(2, 3, 0);
379 }
380
381 // Constructs a flattened version of the given transform.
382 Transform CreateFlattenedTransform(const Transform& transform) {
383 Transform result = transform;
384 FlattenTransformTo2d(result);
385 return result;
386 }
387
318 } // namespace ui 388 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698