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 <iosfwd> | 8 #include <iosfwd> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 void PreconcatTransform(const Transform& transform); | 113 void PreconcatTransform(const Transform& transform); |
114 | 114 |
115 // Applies a transformation on the current transformation | 115 // Applies a transformation on the current transformation |
116 // (i.e. 'this = transform * this;'). | 116 // (i.e. 'this = transform * this;'). |
117 void ConcatTransform(const Transform& transform); | 117 void ConcatTransform(const Transform& transform); |
118 | 118 |
119 // Returns true if this is the identity matrix. | 119 // Returns true if this is the identity matrix. |
120 bool IsIdentity() const { return matrix_.isIdentity(); } | 120 bool IsIdentity() const { return matrix_.isIdentity(); } |
121 | 121 |
122 // Returns true if the matrix is either identity or pure translation. | 122 // Returns true if the matrix is either identity or pure translation. |
123 bool IsIdentityOrTranslation() const { | 123 bool IsIdentityOrTranslation() const { return matrix_.isTranslate(); } |
124 return !(matrix_.getType() & ~SkMatrix44::kTranslate_Mask); | |
125 } | |
126 | 124 |
127 // Returns true if the matrix is either identity or pure translation, | 125 // Returns true if the matrix is either identity or pure translation, |
128 // allowing for an amount of inaccuracy as specified by the parameter. | 126 // allowing for an amount of inaccuracy as specified by the parameter. |
129 bool IsApproximatelyIdentityOrTranslation(SkMScalar tolerance) const; | 127 bool IsApproximatelyIdentityOrTranslation(SkMScalar tolerance) const; |
130 | 128 |
131 // Returns true if the matrix is either a positive scale and/or a translation. | 129 // Returns true if the matrix is either a positive scale and/or a translation. |
132 bool IsPositiveScaleOrTranslation() const { | 130 bool IsPositiveScaleOrTranslation() const { |
133 if (!IsScaleOrTranslation()) | 131 if (!IsScaleOrTranslation()) |
134 return false; | 132 return false; |
135 return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 && | 133 return matrix_.get(0, 0) > 0.0 && matrix_.get(1, 1) > 0.0 && |
136 matrix_.get(2, 2) > 0.0; | 134 matrix_.get(2, 2) > 0.0; |
137 } | 135 } |
138 | 136 |
139 // Returns true if the matrix is either identity or pure, non-fractional | 137 // Returns true if the matrix is either identity or pure, non-fractional |
140 // translation. | 138 // translation. |
141 bool IsIdentityOrIntegerTranslation() const; | 139 bool IsIdentityOrIntegerTranslation() const; |
142 | 140 |
143 // Returns true if the matrix had only scaling components. | 141 // Returns true if the matrix had only scaling components. |
144 bool IsScale2d() const { | 142 bool IsScale2d() const { |
145 return !(matrix_.getType() & ~SkMatrix44::kScale_Mask); | 143 return !(matrix_.getType() & ~SkMatrix44::kScale_Mask); |
146 } | 144 } |
147 | 145 |
148 // Returns true if the matrix is has only scaling and translation components. | 146 // Returns true if the matrix is has only scaling and translation components. |
149 bool IsScaleOrTranslation() const { | 147 bool IsScaleOrTranslation() const { return matrix_.isScaleTranslate(); } |
150 int mask = SkMatrix44::kScale_Mask | SkMatrix44::kTranslate_Mask; | |
151 return (matrix_.getType() & ~mask) == 0; | |
152 } | |
153 | 148 |
154 // Returns true if axis-aligned 2d rects will remain axis-aligned after being | 149 // Returns true if axis-aligned 2d rects will remain axis-aligned after being |
155 // transformed by this matrix. | 150 // transformed by this matrix. |
156 bool Preserves2dAxisAlignment() const; | 151 bool Preserves2dAxisAlignment() const; |
157 | 152 |
158 // Returns true if the matrix has any perspective component that would | 153 // Returns true if the matrix has any perspective component that would |
159 // change the w-component of a homogeneous point. | 154 // change the w-component of a homogeneous point. |
160 bool HasPerspective() const { | 155 bool HasPerspective() const { return matrix_.hasPerspective(); } |
161 return (matrix_.getType() & SkMatrix44::kPerspective_Mask) != 0; | |
162 } | |
163 | 156 |
164 // Returns true if this transform is non-singular. | 157 // Returns true if this transform is non-singular. |
165 bool IsInvertible() const { return matrix_.invert(NULL); } | 158 bool IsInvertible() const { return matrix_.invert(NULL); } |
166 | 159 |
167 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would | 160 // Returns true if a layer with a forward-facing normal of (0, 0, 1) would |
168 // have its back side facing frontwards after applying the transform. | 161 // have its back side facing frontwards after applying the transform. |
169 bool IsBackFaceVisible() const; | 162 bool IsBackFaceVisible() const; |
170 | 163 |
171 // Inverts the transform which is passed in. Returns true if successful. | 164 // Inverts the transform which is passed in. Returns true if successful. |
172 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; | 165 bool GetInverse(Transform* transform) const WARN_UNUSED_RESULT; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 }; | 263 }; |
271 | 264 |
272 // This is declared here for use in gtest-based unit tests but is defined in | 265 // This is declared here for use in gtest-based unit tests but is defined in |
273 // the gfx_test_support target. Depend on that to use this in your unit test. | 266 // the gfx_test_support target. Depend on that to use this in your unit test. |
274 // This should not be used in production code - call ToString() instead. | 267 // This should not be used in production code - call ToString() instead. |
275 void PrintTo(const Transform& transform, ::std::ostream* os); | 268 void PrintTo(const Transform& transform, ::std::ostream* os); |
276 | 269 |
277 } // namespace gfx | 270 } // namespace gfx |
278 | 271 |
279 #endif // UI_GFX_TRANSFORM_H_ | 272 #endif // UI_GFX_TRANSFORM_H_ |
OLD | NEW |