Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 21 matching lines...) Expand all Loading... | |
| 32 // Skips initializing this matrix to avoid overhead, when we know it will be | 32 // Skips initializing this matrix to avoid overhead, when we know it will be |
| 33 // initialized before use. | 33 // initialized before use. |
| 34 Transform(SkipInitialization) | 34 Transform(SkipInitialization) |
| 35 : matrix_(SkMatrix44::kUninitialized_Constructor) {} | 35 : matrix_(SkMatrix44::kUninitialized_Constructor) {} |
| 36 Transform(const Transform& rhs) : matrix_(rhs.matrix_) {} | 36 Transform(const Transform& rhs) : matrix_(rhs.matrix_) {} |
| 37 // Initialize with the concatenation of lhs * rhs. | 37 // Initialize with the concatenation of lhs * rhs. |
| 38 Transform(const Transform& lhs, const Transform& rhs) | 38 Transform(const Transform& lhs, const Transform& rhs) |
| 39 : matrix_(lhs.matrix_, rhs.matrix_) {} | 39 : matrix_(lhs.matrix_, rhs.matrix_) {} |
| 40 ~Transform() {} | 40 ~Transform() {} |
| 41 | 41 |
| 42 // Constructs a transform from explicit 16 matrix elements. Elements should be | |
| 43 // given in column-major order. | |
| 44 Transform(double col1row1, double col1row2, double col1row3, double col1row4, | |
| 45 double col2row1, double col2row2, double col2row3, double col2row4, | |
| 46 double col3row1, double col3row2, double col3row3, double col3row4, | |
| 47 double col4row1, double col4row2, double col4row3, double col4row4); | |
|
Ian Vollick
2013/01/08 23:52:54
I'm sorry to start on this again, but can we pleas
danakj
2013/01/09 14:33:46
+1
OOO for a bit today, will review this later.
| |
| 48 | |
| 49 // Constructs a transform from explicit 2d elements. All other matrix | |
| 50 // elements remain the same as the corresponding elements of an identity | |
| 51 // matrix. | |
| 52 Transform(double col1row1, double col1row2, double col2row1, | |
| 53 double col2row2, double x_translation, double y_translation); | |
| 54 | |
| 42 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } | 55 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } |
| 43 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } | 56 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } |
| 44 | 57 |
| 45 // Resets this transform to the identity transform. | 58 // Resets this transform to the identity transform. |
| 46 void MakeIdentity() { matrix_.setIdentity(); } | 59 void MakeIdentity() { matrix_.setIdentity(); } |
| 47 | 60 |
| 48 // Applies the current transformation on a 2d rotation and assigns the result | 61 // Applies the current transformation on a 2d rotation and assigns the result |
| 49 // to |this|. | 62 // to |this|. |
| 50 void Rotate(double degrees) { RotateAboutZAxis(degrees); } | 63 void Rotate(double degrees) { RotateAboutZAxis(degrees); } |
| 51 | 64 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would | 126 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would |
| 114 // have its back side facing frontwards after applying the transform. | 127 // have its back side facing frontwards after applying the transform. |
| 115 bool IsBackFaceVisible() const; | 128 bool IsBackFaceVisible() const; |
| 116 | 129 |
| 117 // Inverts the transform which is passed in. Returns true if successful. | 130 // Inverts the transform which is passed in. Returns true if successful. |
| 118 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; | 131 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; |
| 119 | 132 |
| 120 // Transposes this transform in place. | 133 // Transposes this transform in place. |
| 121 void Transpose(); | 134 void Transpose(); |
| 122 | 135 |
| 136 // Set 3rd row and 3rd colum to (0, 0, 1, 0). Note that this flattening | |
| 137 // operation is not quite the same as an orthographic projection and is | |
| 138 // technically not a linear operation. | |
| 139 // | |
| 140 // One useful interpretation of doing this operation: | |
| 141 // - For x and y values, the new transform behaves effectively like an | |
| 142 // orthographic projection was added to the matrix sequence. | |
| 143 // - For z values, the new transform overrides any effect that the transform | |
| 144 // had on z, and instead it preserves the z value for any points that are | |
| 145 // transformed. | |
| 146 // - Because of linearity of transforms, this flattened transform also | |
| 147 // preserves the effect that any subsequent (multiplied from the right) | |
| 148 // transforms would have on z values. | |
| 149 // | |
| 150 void FlattenTo2d(); | |
| 151 | |
| 123 // Applies the transformation on the point. Returns true if the point is | 152 // Applies the transformation on the point. Returns true if the point is |
| 124 // transformed successfully. | 153 // transformed successfully. |
| 125 void TransformPoint(Point3F& point) const; | 154 void TransformPoint(Point3F& point) const; |
| 126 | 155 |
| 127 // Applies the transformation on the point. Returns true if the point is | 156 // Applies the transformation on the point. Returns true if the point is |
| 128 // transformed successfully. Rounds the result to the nearest point. | 157 // transformed successfully. Rounds the result to the nearest point. |
| 129 void TransformPoint(Point& point) const; | 158 void TransformPoint(Point& point) const; |
| 130 | 159 |
| 131 // Applies the reverse transformation on the point. Returns true if the | 160 // Applies the reverse transformation on the point. Returns true if the |
| 132 // transformation can be inverted. | 161 // transformation can be inverted. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 Point3F& point) const; | 212 Point3F& point) const; |
| 184 | 213 |
| 185 SkMatrix44 matrix_; | 214 SkMatrix44 matrix_; |
| 186 | 215 |
| 187 // copy/assign are allowed. | 216 // copy/assign are allowed. |
| 188 }; | 217 }; |
| 189 | 218 |
| 190 } // namespace gfx | 219 } // namespace gfx |
| 191 | 220 |
| 192 #endif // UI_GFX_TRANSFORM_H_ | 221 #endif // UI_GFX_TRANSFORM_H_ |
| OLD | NEW |