[email protected] | 3c2196b2 | 2012-03-17 03:42:25 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_GFX_TRANSFORM_H_ |
| 6 | #define UI_GFX_TRANSFORM_H_ |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 7 | |
[email protected] | a109fd0 | 2014-07-10 07:41:43 | [diff] [blame] | 8 | #include <iosfwd> |
[email protected] | 6ab42d9 | 2012-12-20 20:36:53 | [diff] [blame] | 9 | #include <string> |
| 10 | |
[email protected] | 4512792 | 2012-11-17 12:24:49 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
reed | e3d45123 | 2016-05-05 23:29:38 | [diff] [blame] | 12 | #include "third_party/skia/include/core/SkMatrix44.h" |
tfarina | 93bfa91 | 2014-12-05 14:23:15 | [diff] [blame] | 13 | #include "ui/gfx/geometry/vector2d_f.h" |
danakj | f3e1d7f | 2018-10-04 18:00:25 | [diff] [blame] | 14 | #include "ui/gfx/geometry_skia_export.h" |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 15 | |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 16 | namespace gfx { |
[email protected] | 0f0453e | 2012-10-14 18:15:35 | [diff] [blame] | 17 | |
[email protected] | f4d2b901 | 2013-10-11 19:10:50 | [diff] [blame] | 18 | class BoxF; |
[email protected] | 79fbdab0 | 2012-11-14 07:28:11 | [diff] [blame] | 19 | class RectF; |
Malay Keshav | f512431 | 2019-10-17 07:20:27 | [diff] [blame] | 20 | class RRectF; |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 21 | class Point; |
Ella Ge | 7540c84 | 2017-10-19 03:27:27 | [diff] [blame] | 22 | class PointF; |
[email protected] | 2771b1c | 2012-10-31 05:15:43 | [diff] [blame] | 23 | class Point3F; |
Ian Vollick | 4d40fcb | 2017-06-08 01:13:15 | [diff] [blame] | 24 | class Quaternion; |
[email protected] | f7c321eb | 2012-11-26 20:13:08 | [diff] [blame] | 25 | class Vector3dF; |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 26 | |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 27 | // 4x4 transformation matrix. Transform is cheap and explicitly allows |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 28 | // copy/assign. |
danakj | f3e1d7f | 2018-10-04 18:00:25 | [diff] [blame] | 29 | class GEOMETRY_SKIA_EXPORT Transform { |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 30 | public: |
[email protected] | bda4196 | 2013-01-07 18:46:17 | [diff] [blame] | 31 | |
| 32 | enum SkipInitialization { |
| 33 | kSkipInitialization |
| 34 | }; |
| 35 | |
Aldo Culquicondor | d01cf10d | 2018-07-28 02:59:30 | [diff] [blame] | 36 | constexpr Transform() : matrix_(SkMatrix44::kIdentity_Constructor) {} |
[email protected] | bda4196 | 2013-01-07 18:46:17 | [diff] [blame] | 37 | |
| 38 | // Skips initializing this matrix to avoid overhead, when we know it will be |
| 39 | // initialized before use. |
| 40 | Transform(SkipInitialization) |
| 41 | : matrix_(SkMatrix44::kUninitialized_Constructor) {} |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 42 | Transform(const Transform& rhs) : matrix_(rhs.matrix_) {} |
[email protected] | d9a6f330 | 2012-12-07 19:17:54 | [diff] [blame] | 43 | // Initialize with the concatenation of lhs * rhs. |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 44 | Transform(const Transform& lhs, const Transform& rhs) |
| 45 | : matrix_(lhs.matrix_, rhs.matrix_) {} |
vollick | 9c7f6d0 | 2016-01-08 04:36:38 | [diff] [blame] | 46 | explicit Transform(const SkMatrix44& matrix) : matrix_(matrix) {} |
[email protected] | 78634b0c | 2013-01-15 07:49:40 | [diff] [blame] | 47 | // Constructs a transform from explicit 16 matrix elements. Elements |
| 48 | // should be given in row-major order. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 49 | Transform(SkScalar col1row1, |
| 50 | SkScalar col2row1, |
| 51 | SkScalar col3row1, |
| 52 | SkScalar col4row1, |
| 53 | SkScalar col1row2, |
| 54 | SkScalar col2row2, |
| 55 | SkScalar col3row2, |
| 56 | SkScalar col4row2, |
| 57 | SkScalar col1row3, |
| 58 | SkScalar col2row3, |
| 59 | SkScalar col3row3, |
| 60 | SkScalar col4row3, |
| 61 | SkScalar col1row4, |
| 62 | SkScalar col2row4, |
| 63 | SkScalar col3row4, |
| 64 | SkScalar col4row4); |
[email protected] | 78634b0c | 2013-01-15 07:49:40 | [diff] [blame] | 65 | // Constructs a transform from explicit 2d elements. All other matrix |
| 66 | // elements remain the same as the corresponding elements of an identity |
| 67 | // matrix. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 68 | Transform(SkScalar col1row1, |
| 69 | SkScalar col2row1, |
| 70 | SkScalar col1row2, |
| 71 | SkScalar col2row2, |
| 72 | SkScalar x_translation, |
| 73 | SkScalar y_translation); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 74 | |
Ian Vollick | 4d40fcb | 2017-06-08 01:13:15 | [diff] [blame] | 75 | // Constructs a transform corresponding to the given quaternion. |
| 76 | explicit Transform(const Quaternion& q); |
| 77 | |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 78 | bool operator==(const Transform& rhs) const { return matrix_ == rhs.matrix_; } |
| 79 | bool operator!=(const Transform& rhs) const { return matrix_ != rhs.matrix_; } |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 80 | |
[email protected] | f7c321eb | 2012-11-26 20:13:08 | [diff] [blame] | 81 | // Resets this transform to the identity transform. |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 82 | void MakeIdentity() { matrix_.setIdentity(); } |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 83 | |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 84 | // Applies the current transformation on a 2d rotation and assigns the result |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 85 | // to |this|. |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 86 | void Rotate(double degrees) { RotateAboutZAxis(degrees); } |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 87 | |
| 88 | // Applies the current transformation on an axis-angle rotation and assigns |
| 89 | // the result to |this|. |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 90 | void RotateAboutXAxis(double degrees); |
| 91 | void RotateAboutYAxis(double degrees); |
| 92 | void RotateAboutZAxis(double degrees); |
| 93 | void RotateAbout(const Vector3dF& axis, double degrees); |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 94 | |
| 95 | // Applies the current transformation on a scaling and assigns the result |
| 96 | // to |this|. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 97 | void Scale(SkScalar x, SkScalar y); |
| 98 | void Scale3d(SkScalar x, SkScalar y, SkScalar z); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 99 | gfx::Vector2dF Scale2d() const { |
| 100 | return gfx::Vector2dF(matrix_.get(0, 0), matrix_.get(1, 1)); |
| 101 | } |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 102 | |
Mason Freed | 8692368 | 2019-05-02 03:36:04 | [diff] [blame] | 103 | // Applies a scale to the current transformation and assigns the result to |
| 104 | // |this|. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 105 | void PostScale(SkScalar x, SkScalar y); |
Mason Freed | 8692368 | 2019-05-02 03:36:04 | [diff] [blame] | 106 | |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 107 | // Applies the current transformation on a translation and assigns the result |
| 108 | // to |this|. |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 109 | void Translate(const Vector2dF& offset); |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 110 | void Translate(SkScalar x, SkScalar y); |
flackr | 2215b4e | 2016-09-21 20:16:01 | [diff] [blame] | 111 | void Translate3d(const Vector3dF& offset); |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 112 | void Translate3d(SkScalar x, SkScalar y, SkScalar z); |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 113 | |
Mason Freed | 8692368 | 2019-05-02 03:36:04 | [diff] [blame] | 114 | // Applies a translation to the current transformation and assigns the result |
| 115 | // to |this|. |
| 116 | void PostTranslate(const Vector2dF& offset); |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 117 | void PostTranslate(SkScalar x, SkScalar y); |
Mason Freed | 8692368 | 2019-05-02 03:36:04 | [diff] [blame] | 118 | |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 119 | // Applies the current transformation on a skew and assigns the result |
| 120 | // to |this|. |
nainar | 8ca8ee6 | 2015-09-03 01:04:10 | [diff] [blame] | 121 | void Skew(double angle_x, double angle_y); |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 122 | |
| 123 | // Applies the current transformation on a perspective transform and assigns |
| 124 | // the result to |this|. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 125 | void ApplyPerspectiveDepth(SkScalar depth); |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 126 | |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 127 | // Applies a transformation on the current transformation |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 128 | // (i.e. 'this = this * transform;'). |
| 129 | void PreconcatTransform(const Transform& transform); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 130 | |
[email protected] | 59808008 | 2011-04-14 19:36:33 | [diff] [blame] | 131 | // Applies a transformation on the current transformation |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 132 | // (i.e. 'this = transform * this;'). |
| 133 | void ConcatTransform(const Transform& transform); |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 134 | |
[email protected] | 4512792 | 2012-11-17 12:24:49 | [diff] [blame] | 135 | // Returns true if this is the identity matrix. |
Ria Jiang | 5be06c08 | 2017-09-13 15:22:25 | [diff] [blame] | 136 | // This function modifies a mutable variable in |matrix_|. |
[email protected] | d9a6f330 | 2012-12-07 19:17:54 | [diff] [blame] | 137 | bool IsIdentity() const { return matrix_.isIdentity(); } |
[email protected] | 4512792 | 2012-11-17 12:24:49 | [diff] [blame] | 138 | |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 139 | // Returns true if the matrix is either identity or pure translation. |
danakj | 670a4ab | 2014-09-19 19:38:28 | [diff] [blame] | 140 | bool IsIdentityOrTranslation() const { return matrix_.isTranslate(); } |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 141 | |
vollick | 51ed1a2 | 2014-12-17 02:03:00 | [diff] [blame] | 142 | // Returns true if the matrix is either the identity or a 2d translation. |
| 143 | bool IsIdentityOr2DTranslation() const { |
| 144 | return matrix_.isTranslate() && matrix_.get(2, 3) == 0; |
| 145 | } |
| 146 | |
[email protected] | 19f9054 | 2013-10-19 18:26:07 | [diff] [blame] | 147 | // Returns true if the matrix is either identity or pure translation, |
| 148 | // allowing for an amount of inaccuracy as specified by the parameter. |
Mike Reed | 2f2c200 | 2020-01-23 22:09:40 | [diff] [blame] | 149 | bool IsApproximatelyIdentityOrTranslation(SkScalar tolerance) const; |
Xianzhu Wang | a036fbde | 2020-06-02 18:17:26 | [diff] [blame] | 150 | bool IsApproximatelyIdentityOrIntegerTranslation(SkScalar tolerance) const; |
[email protected] | 19f9054 | 2013-10-19 18:26:07 | [diff] [blame] | 151 | |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 152 | // Returns true if the matrix is either a positive scale and/or a translation. |
| 153 | bool IsPositiveScaleOrTranslation() const { |
| 154 | if (!IsScaleOrTranslation()) |
| 155 | return false; |
[email protected] | 803f6b5 | 2013-09-12 00:51:26 | [diff] [blame] | 156 | return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 && |
| 157 | matrix_.get(2, 2) > 0.0; |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 158 | } |
| 159 | |
danakj | 602038a | 2016-12-19 22:06:46 | [diff] [blame] | 160 | // Returns true if the matrix is identity or, if the matrix consists only |
| 161 | // of a translation whose components can be represented as integers. Returns |
| 162 | // false if the translation contains a fractional component or is too large to |
| 163 | // fit in an integer. |
[email protected] | d1a56f0 | 2012-12-04 12:18:30 | [diff] [blame] | 164 | bool IsIdentityOrIntegerTranslation() const; |
| 165 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 166 | // Returns true if the matrix had only scaling components. |
tfarina | 81090b4 | 2014-11-06 14:50:43 | [diff] [blame] | 167 | bool IsScale2d() const { return matrix_.isScale(); } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 168 | |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 169 | // Returns true if the matrix is has only scaling and translation components. |
danakj | 670a4ab | 2014-09-19 19:38:28 | [diff] [blame] | 170 | bool IsScaleOrTranslation() const { return matrix_.isScaleTranslate(); } |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 171 | |
[email protected] | 3a9a92d | 2013-07-11 04:37:00 | [diff] [blame] | 172 | // Returns true if axis-aligned 2d rects will remain axis-aligned after being |
| 173 | // transformed by this matrix. |
| 174 | bool Preserves2dAxisAlignment() const; |
| 175 | |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 176 | // Returns true if the matrix has any perspective component that would |
| 177 | // change the w-component of a homogeneous point. |
danakj | 670a4ab | 2014-09-19 19:38:28 | [diff] [blame] | 178 | bool HasPerspective() const { return matrix_.hasPerspective(); } |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 179 | |
[email protected] | 4512792 | 2012-11-17 12:24:49 | [diff] [blame] | 180 | // Returns true if this transform is non-singular. |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 181 | bool IsInvertible() const { return matrix_.invert(NULL); } |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 182 | |
[email protected] | 2c7cd6d | 2012-11-28 23:49:26 | [diff] [blame] | 183 | // Returns true if a layer with a forward-facing normal of (0, 0, 1) would |
| 184 | // have its back side facing frontwards after applying the transform. |
| 185 | bool IsBackFaceVisible() const; |
| 186 | |
danakj | 54af81a | 2018-05-24 23:59:02 | [diff] [blame] | 187 | // Inverts the transform which is passed in. Returns true if successful, or |
| 188 | // sets |transform| to the identify matrix on failure. |
[email protected] | 4512792 | 2012-11-17 12:24:49 | [diff] [blame] | 189 | bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; |
| 190 | |
| 191 | // Transposes this transform in place. |
| 192 | void Transpose(); |
[email protected] | 3891939 | 2011-10-24 22:26:23 | [diff] [blame] | 193 | |
[email protected] | 78634b0c | 2013-01-15 07:49:40 | [diff] [blame] | 194 | // Set 3rd row and 3rd colum to (0, 0, 1, 0). Note that this flattening |
| 195 | // operation is not quite the same as an orthographic projection and is |
| 196 | // technically not a linear operation. |
| 197 | // |
| 198 | // One useful interpretation of doing this operation: |
| 199 | // - For x and y values, the new transform behaves effectively like an |
| 200 | // orthographic projection was added to the matrix sequence. |
| 201 | // - For z values, the new transform overrides any effect that the transform |
| 202 | // had on z, and instead it preserves the z value for any points that are |
| 203 | // transformed. |
| 204 | // - Because of linearity of transforms, this flattened transform also |
| 205 | // preserves the effect that any subsequent (multiplied from the right) |
| 206 | // transforms would have on z values. |
| 207 | // |
| 208 | void FlattenTo2d(); |
| 209 | |
ajuma | d0d6442 | 2015-03-14 04:20:08 | [diff] [blame] | 210 | // Returns true if the 3rd row and 3rd column are both (0, 0, 1, 0). |
| 211 | bool IsFlat() const; |
| 212 | |
[email protected] | d81752b | 2013-10-25 08:32:23 | [diff] [blame] | 213 | // Returns the x and y translation components of the matrix. |
[email protected] | bea4c87 | 2013-08-14 18:10:00 | [diff] [blame] | 214 | Vector2dF To2dTranslation() const; |
| 215 | |
[email protected] | 908af42 | 2013-10-10 22:22:42 | [diff] [blame] | 216 | // Applies the transformation to the point. |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 217 | void TransformPoint(Point3F* point) const; |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 218 | |
[email protected] | 908af42 | 2013-10-10 22:22:42 | [diff] [blame] | 219 | // Applies the transformation to the point. |
Ella Ge | 7540c84 | 2017-10-19 03:27:27 | [diff] [blame] | 220 | void TransformPoint(PointF* point) const; |
| 221 | |
| 222 | // Applies the transformation to the point. |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 223 | void TransformPoint(Point* point) const; |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 224 | |
petermayo | 59d3768 | 2016-04-13 14:37:35 | [diff] [blame] | 225 | // Applies the transformation to the vector. |
| 226 | void TransformVector(Vector3dF* vector) const; |
| 227 | |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 228 | // Applies the reverse transformation on the point. Returns true if the |
| 229 | // transformation can be inverted. |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 230 | bool TransformPointReverse(Point3F* point) const; |
[email protected] | 463eb0e | 2011-05-10 03:11:04 | [diff] [blame] | 231 | |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 232 | // Applies the reverse transformation on the point. Returns true if the |
| 233 | // transformation can be inverted. Rounds the result to the nearest point. |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 234 | bool TransformPointReverse(Point* point) const; |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 235 | |
[email protected] | f4d2b901 | 2013-10-11 19:10:50 | [diff] [blame] | 236 | // Applies transformation on the given rect. After the function completes, |
| 237 | // |rect| will be the smallest axis aligned bounding rect containing the |
| 238 | // transformed rect. |
[email protected] | 79fbdab0 | 2012-11-14 07:28:11 | [diff] [blame] | 239 | void TransformRect(RectF* rect) const; |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 240 | |
[email protected] | f4d2b901 | 2013-10-11 19:10:50 | [diff] [blame] | 241 | // Applies the reverse transformation on the given rect. After the function |
| 242 | // completes, |rect| will be the smallest axis aligned bounding rect |
| 243 | // containing the transformed rect. Returns false if the matrix cannot be |
| 244 | // inverted. |
[email protected] | 79fbdab0 | 2012-11-14 07:28:11 | [diff] [blame] | 245 | bool TransformRectReverse(RectF* rect) const; |
[email protected] | 277c7b7 | 2011-06-06 15:23:09 | [diff] [blame] | 246 | |
Malay Keshav | f512431 | 2019-10-17 07:20:27 | [diff] [blame] | 247 | // Applies transformation on the given |rrect|. Returns false if the transform |
| 248 | // matrix cannot be applied to rrect. |
| 249 | bool TransformRRectF(RRectF* rrect) const; |
| 250 | |
[email protected] | f4d2b901 | 2013-10-11 19:10:50 | [diff] [blame] | 251 | // Applies transformation on the given box. After the function completes, |
| 252 | // |box| will be the smallest axis aligned bounding box containing the |
| 253 | // transformed box. |
| 254 | void TransformBox(BoxF* box) const; |
| 255 | |
| 256 | // Applies the reverse transformation on the given box. After the function |
| 257 | // completes, |box| will be the smallest axis aligned bounding box |
| 258 | // containing the transformed box. Returns false if the matrix cannot be |
| 259 | // inverted. |
| 260 | bool TransformBoxReverse(BoxF* box) const; |
| 261 | |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 262 | // Decomposes |this| and |from|, interpolates the decomposed values, and |
| 263 | // sets |this| to the reconstituted result. Returns false if either matrix |
| 264 | // can't be decomposed. Uses routines described in this spec: |
| 265 | // http://www.w3.org/TR/css3-3d-transforms/. |
| 266 | // |
| 267 | // Note: this call is expensive since we need to decompose the transform. If |
| 268 | // you're going to be calling this rapidly (e.g., in an animation) you should |
| 269 | // decompose once using gfx::DecomposeTransforms and reuse your |
| 270 | // DecomposedTransform. |
[email protected] | 6138db70 | 2013-09-25 03:25:05 | [diff] [blame] | 271 | bool Blend(const Transform& from, double progress); |
[email protected] | 2fcafa0 | 2012-11-15 01:12:55 | [diff] [blame] | 272 | |
vollick | b169ff62 | 2015-02-10 01:22:33 | [diff] [blame] | 273 | void RoundTranslationComponents(); |
| 274 | |
[email protected] | f7c321eb | 2012-11-26 20:13:08 | [diff] [blame] | 275 | // Returns |this| * |other|. |
[email protected] | d9a6f330 | 2012-12-07 19:17:54 | [diff] [blame] | 276 | Transform operator*(const Transform& other) const { |
| 277 | return Transform(*this, other); |
| 278 | } |
[email protected] | f7c321eb | 2012-11-26 20:13:08 | [diff] [blame] | 279 | |
| 280 | // Sets |this| = |this| * |other| |
[email protected] | 0db1322 | 2012-12-13 21:27:54 | [diff] [blame] | 281 | Transform& operator*=(const Transform& other) { |
| 282 | PreconcatTransform(other); |
| 283 | return *this; |
| 284 | } |
[email protected] | f7c321eb | 2012-11-26 20:13:08 | [diff] [blame] | 285 | |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 286 | // Returns the underlying matrix. |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 287 | const SkMatrix44& matrix() const { return matrix_; } |
| 288 | SkMatrix44& matrix() { return matrix_; } |
jaydasika | cb93d1c | 2015-12-09 23:52:46 | [diff] [blame] | 289 | bool ApproximatelyEqual(const gfx::Transform& transform) const; |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 290 | |
[email protected] | 6ab42d9 | 2012-12-20 20:36:53 | [diff] [blame] | 291 | std::string ToString() const; |
| 292 | |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 293 | private: |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 294 | void TransformPointInternal(const SkMatrix44& xform, |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 295 | Point* point) const; |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 296 | |
Ella Ge | 7540c84 | 2017-10-19 03:27:27 | [diff] [blame] | 297 | void TransformPointInternal(const SkMatrix44& xform, PointF* point) const; |
| 298 | |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 299 | void TransformPointInternal(const SkMatrix44& xform, |
[email protected] | 26d7ece | 2013-09-12 20:59:47 | [diff] [blame] | 300 | Point3F* point) const; |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 301 | |
petermayo | 59d3768 | 2016-04-13 14:37:35 | [diff] [blame] | 302 | void TransformVectorInternal(const SkMatrix44& xform, |
| 303 | Vector3dF* vector) const; |
| 304 | |
[email protected] | 80248e3 | 2011-07-08 15:31:11 | [diff] [blame] | 305 | SkMatrix44 matrix_; |
[email protected] | b9b1e7a4 | 2011-05-17 15:29:51 | [diff] [blame] | 306 | |
| 307 | // copy/assign are allowed. |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 308 | }; |
| 309 | |
[email protected] | a109fd0 | 2014-07-10 07:41:43 | [diff] [blame] | 310 | // This is declared here for use in gtest-based unit tests but is defined in |
mlliu | a8e9f71 | 2016-08-20 02:17:52 | [diff] [blame] | 311 | // the //ui/gfx:test_support target. Depend on that to use this in your unit |
| 312 | // test. This should not be used in production code - call ToString() instead. |
[email protected] | a109fd0 | 2014-07-10 07:41:43 | [diff] [blame] | 313 | void PrintTo(const Transform& transform, ::std::ostream* os); |
| 314 | |
[email protected] | 0f0453e | 2012-10-14 18:15:35 | [diff] [blame] | 315 | } // namespace gfx |
[email protected] | 36df22b | 2011-02-24 21:47:56 | [diff] [blame] | 316 | |
| 317 | #endif // UI_GFX_TRANSFORM_H_ |