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

Side by Side Diff: ui/gfx/transform.h

Issue 23043011: cc: Use SkMScalar instead of doubles everywhere in cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Finalize test changes Created 7 years, 3 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 #ifndef UI_GFX_TRANSFORM_H_ 5 #ifndef UI_GFX_TRANSFORM_H_
6 #define UI_GFX_TRANSFORM_H_ 6 #define UI_GFX_TRANSFORM_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 22 matching lines...) Expand all
33 // Skips initializing this matrix to avoid overhead, when we know it will be 33 // Skips initializing this matrix to avoid overhead, when we know it will be
34 // initialized before use. 34 // initialized before use.
35 Transform(SkipInitialization) 35 Transform(SkipInitialization)
36 : matrix_(SkMatrix44::kUninitialized_Constructor) {} 36 : matrix_(SkMatrix44::kUninitialized_Constructor) {}
37 Transform(const Transform& rhs) : matrix_(rhs.matrix_) {} 37 Transform(const Transform& rhs) : matrix_(rhs.matrix_) {}
38 // Initialize with the concatenation of lhs * rhs. 38 // Initialize with the concatenation of lhs * rhs.
39 Transform(const Transform& lhs, const Transform& rhs) 39 Transform(const Transform& lhs, const Transform& rhs)
40 : matrix_(lhs.matrix_, rhs.matrix_) {} 40 : matrix_(lhs.matrix_, rhs.matrix_) {}
41 // Constructs a transform from explicit 16 matrix elements. Elements 41 // Constructs a transform from explicit 16 matrix elements. Elements
42 // should be given in row-major order. 42 // should be given in row-major order.
43 Transform(double col1row1, double col2row1, double col3row1, double col4row1, 43 Transform(SkMScalar col1row1,
44 double col1row2, double col2row2, double col3row2, double col4row2, 44 SkMScalar col2row1,
45 double col1row3, double col2row3, double col3row3, double col4row3, 45 SkMScalar col3row1,
46 double col1row4, double col2row4, double col3row4, double col4row4); 46 SkMScalar col4row1,
47 SkMScalar col1row2,
48 SkMScalar col2row2,
49 SkMScalar col3row2,
50 SkMScalar col4row2,
51 SkMScalar col1row3,
52 SkMScalar col2row3,
53 SkMScalar col3row3,
54 SkMScalar col4row3,
55 SkMScalar col1row4,
56 SkMScalar col2row4,
57 SkMScalar col3row4,
58 SkMScalar col4row4);
47 // Constructs a transform from explicit 2d elements. All other matrix 59 // Constructs a transform from explicit 2d elements. All other matrix
48 // elements remain the same as the corresponding elements of an identity 60 // elements remain the same as the corresponding elements of an identity
49 // matrix. 61 // matrix.
50 Transform(double col1row1, double col2row1, 62 Transform(SkMScalar col1row1,
51 double col1row2, double col2row2, 63 SkMScalar col2row1,
52 double x_translation, double y_translation); 64 SkMScalar col1row2,
65 SkMScalar col2row2,
66 SkMScalar x_translation,
67 SkMScalar y_translation);
53 ~Transform() {} 68 ~Transform() {}
54 69
55 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } 70 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; }
56 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } 71 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; }
57 72
58 // Resets this transform to the identity transform. 73 // Resets this transform to the identity transform.
59 void MakeIdentity() { matrix_.setIdentity(); } 74 void MakeIdentity() { matrix_.setIdentity(); }
60 75
61 // Applies the current transformation on a 2d rotation and assigns the result 76 // Applies the current transformation on a 2d rotation and assigns the result
62 // to |this|. 77 // to |this|.
63 void Rotate(double degrees) { RotateAboutZAxis(degrees); } 78 void Rotate(double degrees) { RotateAboutZAxis(degrees); }
64 79
65 // Applies the current transformation on an axis-angle rotation and assigns 80 // Applies the current transformation on an axis-angle rotation and assigns
66 // the result to |this|. 81 // the result to |this|.
67 void RotateAboutXAxis(double degrees); 82 void RotateAboutXAxis(double degrees);
68 void RotateAboutYAxis(double degrees); 83 void RotateAboutYAxis(double degrees);
69 void RotateAboutZAxis(double degrees); 84 void RotateAboutZAxis(double degrees);
70 void RotateAbout(const Vector3dF& axis, double degrees); 85 void RotateAbout(const Vector3dF& axis, double degrees);
71 86
72 // Applies the current transformation on a scaling and assigns the result 87 // Applies the current transformation on a scaling and assigns the result
73 // to |this|. 88 // to |this|.
74 void Scale(double x, double y); 89 void Scale(SkMScalar x, SkMScalar y);
75 void Scale3d(double x, double y, double z); 90 void Scale3d(SkMScalar x, SkMScalar y, SkMScalar z);
76 91
77 // Applies the current transformation on a translation and assigns the result 92 // Applies the current transformation on a translation and assigns the result
78 // to |this|. 93 // to |this|.
79 void Translate(double x, double y); 94 void Translate(SkMScalar x, SkMScalar y);
80 void Translate3d(double x, double y, double z); 95 void Translate3d(SkMScalar x, SkMScalar y, SkMScalar z);
81 96
82 // Applies the current transformation on a skew and assigns the result 97 // Applies the current transformation on a skew and assigns the result
83 // to |this|. 98 // to |this|.
84 void SkewX(double angle_x); 99 void SkewX(SkMScalar angle_x);
85 void SkewY(double angle_y); 100 void SkewY(SkMScalar angle_y);
86 101
87 // Applies the current transformation on a perspective transform and assigns 102 // Applies the current transformation on a perspective transform and assigns
88 // the result to |this|. 103 // the result to |this|.
89 void ApplyPerspectiveDepth(double depth); 104 void ApplyPerspectiveDepth(SkMScalar depth);
90 105
91 // Applies a transformation on the current transformation 106 // Applies a transformation on the current transformation
92 // (i.e. 'this = this * transform;'). 107 // (i.e. 'this = this * transform;').
93 void PreconcatTransform(const Transform& transform); 108 void PreconcatTransform(const Transform& transform);
94 109
95 // Applies a transformation on the current transformation 110 // Applies a transformation on the current transformation
96 // (i.e. 'this = transform * this;'). 111 // (i.e. 'this = transform * this;').
97 void ConcatTransform(const Transform& transform); 112 void ConcatTransform(const Transform& transform);
98 113
99 // Returns true if this is the identity matrix. 114 // Returns true if this is the identity matrix.
100 bool IsIdentity() const { return matrix_.isIdentity(); } 115 bool IsIdentity() const { return matrix_.isIdentity(); }
101 116
102 // Returns true if the matrix is either identity or pure translation. 117 // Returns true if the matrix is either identity or pure translation.
103 bool IsIdentityOrTranslation() const { 118 bool IsIdentityOrTranslation() const {
104 return !(matrix_.getType() & ~SkMatrix44::kTranslate_Mask); 119 return !(matrix_.getType() & ~SkMatrix44::kTranslate_Mask);
105 } 120 }
106 121
107 // Returns true if the matrix is either a positive scale and/or a translation. 122 // Returns true if the matrix is either a positive scale and/or a translation.
108 bool IsPositiveScaleOrTranslation() const { 123 bool IsPositiveScaleOrTranslation() const {
109 if (!IsScaleOrTranslation()) 124 if (!IsScaleOrTranslation())
110 return false; 125 return false;
111 return matrix_.getDouble(0, 0) > 0.0 && 126 return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 &&
112 matrix_.getDouble(1, 1) > 0.0 && 127 matrix_.get(2, 2) > 0.0;
113 matrix_.getDouble(2, 2) > 0.0;
114 } 128 }
115 129
116 // Returns true if the matrix is either identity or pure, non-fractional 130 // Returns true if the matrix is either identity or pure, non-fractional
117 // translation. 131 // translation.
118 bool IsIdentityOrIntegerTranslation() const; 132 bool IsIdentityOrIntegerTranslation() const;
119 133
120 // Returns true if the matrix is has only scaling and translation components. 134 // Returns true if the matrix is has only scaling and translation components.
121 bool IsScaleOrTranslation() const { 135 bool IsScaleOrTranslation() const {
122 int mask = SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask; 136 int mask = SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask;
123 return (matrix_.getType() & ~mask) == 0; 137 return (matrix_.getType() & ~mask) == 0;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 209
196 // Decomposes |this| and |from|, interpolates the decomposed values, and 210 // Decomposes |this| and |from|, interpolates the decomposed values, and
197 // sets |this| to the reconstituted result. Returns false if either matrix 211 // sets |this| to the reconstituted result. Returns false if either matrix
198 // can't be decomposed. Uses routines described in this spec: 212 // can't be decomposed. Uses routines described in this spec:
199 // http://www.w3.org/TR/css3-3d-transforms/. 213 // http://www.w3.org/TR/css3-3d-transforms/.
200 // 214 //
201 // Note: this call is expensive since we need to decompose the transform. If 215 // Note: this call is expensive since we need to decompose the transform. If
202 // you're going to be calling this rapidly (e.g., in an animation) you should 216 // you're going to be calling this rapidly (e.g., in an animation) you should
203 // decompose once using gfx::DecomposeTransforms and reuse your 217 // decompose once using gfx::DecomposeTransforms and reuse your
204 // DecomposedTransform. 218 // DecomposedTransform.
205 bool Blend(const Transform& from, double progress); 219 bool Blend(const Transform& from, SkMScalar progress);
danakj 2013/09/09 17:57:45 progress isn't a transform element, should stay as
206 220
207 // Returns |this| * |other|. 221 // Returns |this| * |other|.
208 Transform operator*(const Transform& other) const { 222 Transform operator*(const Transform& other) const {
209 return Transform(*this, other); 223 return Transform(*this, other);
210 } 224 }
211 225
212 // Sets |this| = |this| * |other| 226 // Sets |this| = |this| * |other|
213 Transform& operator*=(const Transform& other) { 227 Transform& operator*=(const Transform& other) {
214 PreconcatTransform(other); 228 PreconcatTransform(other);
215 return *this; 229 return *this;
(...skipping 13 matching lines...) Expand all
229 Point3F& point) const; 243 Point3F& point) const;
230 244
231 SkMatrix44 matrix_; 245 SkMatrix44 matrix_;
232 246
233 // copy/assign are allowed. 247 // copy/assign are allowed.
234 }; 248 };
235 249
236 } // namespace gfx 250 } // namespace gfx
237 251
238 #endif // UI_GFX_TRANSFORM_H_ 252 #endif // UI_GFX_TRANSFORM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698