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 19 matching lines...) Expand all Loading... | |
| 30 Transform() : matrix_(SkMatrix44::kIdentity_Constructor) {} | 30 Transform() : matrix_(SkMatrix44::kIdentity_Constructor) {} |
| 31 | 31 |
| 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 // Constructs a transform from explicit 16 matrix elements. NOTE: Elements | |
|
danakj
2013/01/11 04:14:12
nit: drop the NOTE? the variable names kinda say t
| |
| 41 // should be given in row-major order. | |
| 42 Transform(double col1row1, double col2row1, double col3row1, double col4row1, | |
| 43 double col1row2, double col2row2, double col3row2, double col4row2, | |
| 44 double col1row3, double col2row3, double col3row3, double col4row3, | |
| 45 double col1row4, double col2row4, double col3row4, double col4row4); | |
| 46 // Constructs a transform from explicit 2d elements. All other matrix | |
| 47 // elements remain the same as the corresponding elements of an identity | |
| 48 // matrix. | |
| 49 Transform(double col1row1, double col2row1, | |
| 50 double col1row2, double col2row2, | |
| 51 double x_translation, double y_translation); | |
| 40 ~Transform() {} | 52 ~Transform() {} |
| 41 | 53 |
| 42 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } | 54 bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } |
| 43 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } | 55 bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } |
| 44 | 56 |
| 45 // Resets this transform to the identity transform. | 57 // Resets this transform to the identity transform. |
| 46 void MakeIdentity() { matrix_.setIdentity(); } | 58 void MakeIdentity() { matrix_.setIdentity(); } |
| 47 | 59 |
| 48 // Applies the current transformation on a 2d rotation and assigns the result | 60 // Applies the current transformation on a 2d rotation and assigns the result |
| 49 // to |this|. | 61 // to |this|. |
| (...skipping 63 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 | 125 // 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. | 126 // have its back side facing frontwards after applying the transform. |
| 115 bool IsBackFaceVisible() const; | 127 bool IsBackFaceVisible() const; |
| 116 | 128 |
| 117 // Inverts the transform which is passed in. Returns true if successful. | 129 // Inverts the transform which is passed in. Returns true if successful. |
| 118 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; | 130 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; |
| 119 | 131 |
| 120 // Transposes this transform in place. | 132 // Transposes this transform in place. |
| 121 void Transpose(); | 133 void Transpose(); |
| 122 | 134 |
| 135 // Set 3rd row and 3rd colum to (0, 0, 1, 0). Note that this flattening | |
| 136 // operation is not quite the same as an orthographic projection and is | |
| 137 // technically not a linear operation. | |
| 138 // | |
| 139 // One useful interpretation of doing this operation: | |
| 140 // - For x and y values, the new transform behaves effectively like an | |
| 141 // orthographic projection was added to the matrix sequence. | |
| 142 // - For z values, the new transform overrides any effect that the transform | |
| 143 // had on z, and instead it preserves the z value for any points that are | |
| 144 // transformed. | |
| 145 // - Because of linearity of transforms, this flattened transform also | |
| 146 // preserves the effect that any subsequent (multiplied from the right) | |
| 147 // transforms would have on z values. | |
| 148 // | |
| 149 void FlattenTo2d(); | |
| 150 | |
| 123 // Applies the transformation on the point. Returns true if the point is | 151 // Applies the transformation on the point. Returns true if the point is |
| 124 // transformed successfully. | 152 // transformed successfully. |
| 125 void TransformPoint(Point3F& point) const; | 153 void TransformPoint(Point3F& point) const; |
| 126 | 154 |
| 127 // Applies the transformation on the point. Returns true if the point is | 155 // Applies the transformation on the point. Returns true if the point is |
| 128 // transformed successfully. Rounds the result to the nearest point. | 156 // transformed successfully. Rounds the result to the nearest point. |
| 129 void TransformPoint(Point& point) const; | 157 void TransformPoint(Point& point) const; |
| 130 | 158 |
| 131 // Applies the reverse transformation on the point. Returns true if the | 159 // Applies the reverse transformation on the point. Returns true if the |
| 132 // transformation can be inverted. | 160 // transformation can be inverted. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 Point3F& point) const; | 211 Point3F& point) const; |
| 184 | 212 |
| 185 SkMatrix44 matrix_; | 213 SkMatrix44 matrix_; |
| 186 | 214 |
| 187 // copy/assign are allowed. | 215 // copy/assign are allowed. |
| 188 }; | 216 }; |
| 189 | 217 |
| 190 } // namespace gfx | 218 } // namespace gfx |
| 191 | 219 |
| 192 #endif // UI_GFX_TRANSFORM_H_ | 220 #endif // UI_GFX_TRANSFORM_H_ |
| OLD | NEW |