| 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. Elements |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would | 134 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would |
| 123 // have its back side facing frontwards after applying the transform. | 135 // have its back side facing frontwards after applying the transform. |
| 124 bool IsBackFaceVisible() const; | 136 bool IsBackFaceVisible() const; |
| 125 | 137 |
| 126 // Inverts the transform which is passed in. Returns true if successful. | 138 // Inverts the transform which is passed in. Returns true if successful. |
| 127 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; | 139 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; |
| 128 | 140 |
| 129 // Transposes this transform in place. | 141 // Transposes this transform in place. |
| 130 void Transpose(); | 142 void Transpose(); |
| 131 | 143 |
| 144 // Set 3rd row and 3rd colum to (0, 0, 1, 0). Note that this flattening |
| 145 // operation is not quite the same as an orthographic projection and is |
| 146 // technically not a linear operation. |
| 147 // |
| 148 // One useful interpretation of doing this operation: |
| 149 // - For x and y values, the new transform behaves effectively like an |
| 150 // orthographic projection was added to the matrix sequence. |
| 151 // - For z values, the new transform overrides any effect that the transform |
| 152 // had on z, and instead it preserves the z value for any points that are |
| 153 // transformed. |
| 154 // - Because of linearity of transforms, this flattened transform also |
| 155 // preserves the effect that any subsequent (multiplied from the right) |
| 156 // transforms would have on z values. |
| 157 // |
| 158 void FlattenTo2d(); |
| 159 |
| 132 // Applies the transformation on the point. Returns true if the point is | 160 // Applies the transformation on the point. Returns true if the point is |
| 133 // transformed successfully. | 161 // transformed successfully. |
| 134 void TransformPoint(Point3F& point) const; | 162 void TransformPoint(Point3F& point) const; |
| 135 | 163 |
| 136 // Applies the transformation on the point. Returns true if the point is | 164 // Applies the transformation on the point. Returns true if the point is |
| 137 // transformed successfully. Rounds the result to the nearest point. | 165 // transformed successfully. Rounds the result to the nearest point. |
| 138 void TransformPoint(Point& point) const; | 166 void TransformPoint(Point& point) const; |
| 139 | 167 |
| 140 // Applies the reverse transformation on the point. Returns true if the | 168 // Applies the reverse transformation on the point. Returns true if the |
| 141 // transformation can be inverted. | 169 // transformation can be inverted. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 Point3F& point) const; | 220 Point3F& point) const; |
| 193 | 221 |
| 194 SkMatrix44 matrix_; | 222 SkMatrix44 matrix_; |
| 195 | 223 |
| 196 // copy/assign are allowed. | 224 // copy/assign are allowed. |
| 197 }; | 225 }; |
| 198 | 226 |
| 199 } // namespace gfx | 227 } // namespace gfx |
| 200 | 228 |
| 201 #endif // UI_GFX_TRANSFORM_H_ | 229 #endif // UI_GFX_TRANSFORM_H_ |
| OLD | NEW |