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 // MSVC++ requires this to be set before any other includes to get M_PI. | 5 // MSVC++ requires this to be set before any other includes to get M_PI. |
| 6 #define _USE_MATH_DEFINES | 6 #define _USE_MATH_DEFINES |
| 7 | 7 |
| 8 #include "ui/gfx/transform.h" | 8 #include "ui/gfx/transform.h" |
| 9 | 9 |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 void Transform::ConcatTransform(const Transform& transform) { | 178 void Transform::ConcatTransform(const Transform& transform) { |
| 179 if (!transform.matrix_.isIdentity()) { | 179 if (!transform.matrix_.isIdentity()) { |
| 180 matrix_.postConcat(transform.matrix_); | 180 matrix_.postConcat(transform.matrix_); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 bool Transform::IsIdentity() const { | 184 bool Transform::IsIdentity() const { |
| 185 return matrix_.isIdentity(); | 185 return matrix_.isIdentity(); |
| 186 } | 186 } |
| 187 | 187 |
| 188 bool Transform::IsIdentityOrTranslation() const { | |
| 189 bool has_no_perspective = !matrix_.getDouble(3, 0) && | |
| 190 !matrix_.getDouble(3, 1) && | |
| 191 !matrix_.getDouble(3, 2) && | |
| 192 (matrix_.getDouble(3, 3) == 1); | |
| 193 | |
| 194 bool has_no_rotation_or_skew = !matrix_.getDouble(0, 1) && | |
| 195 !matrix_.getDouble(0, 2) && | |
| 196 !matrix_.getDouble(1, 0) && | |
| 197 !matrix_.getDouble(1, 2) && | |
| 198 !matrix_.getDouble(2, 0) && | |
| 199 !matrix_.getDouble(2, 1); | |
| 200 | |
| 201 bool has_no_scale = matrix_.getDouble(0, 0) == 1 && | |
| 202 matrix_.getDouble(1, 1) == 1 && | |
| 203 matrix_.getDouble(2, 2) == 1; | |
| 204 | |
| 205 return has_no_perspective && has_no_rotation_or_skew && has_no_scale; | |
| 206 } | |
| 207 | |
| 208 bool Transform::IsScaleOrTranslation() const { | |
| 209 bool has_no_perspective = !matrix_.getDouble(3, 0) && | |
| 210 !matrix_.getDouble(3, 1) && | |
| 211 !matrix_.getDouble(3, 2) && | |
| 212 (matrix_.getDouble(3, 3) == 1); | |
| 213 | |
| 214 bool has_no_rotation_or_skew = !matrix_.getDouble(0, 1) && | |
| 215 !matrix_.getDouble(0, 2) && | |
| 216 !matrix_.getDouble(1, 0) && | |
| 217 !matrix_.getDouble(1, 2) && | |
| 218 !matrix_.getDouble(2, 0) && | |
| 219 !matrix_.getDouble(2, 1); | |
| 220 | |
| 221 return has_no_perspective && has_no_rotation_or_skew; | |
| 222 } | |
| 223 | |
| 224 bool Transform::HasPerspective() const { | |
| 225 return matrix_.getDouble(3, 0) || | |
| 226 matrix_.getDouble(3, 1) || | |
| 227 matrix_.getDouble(3, 2) || | |
| 228 (matrix_.getDouble(3, 3) != 1); | |
| 229 } | |
| 230 | |
| 188 bool Transform::IsInvertible() const { | 231 bool Transform::IsInvertible() const { |
| 189 return std::abs(matrix_.determinant()) > kTooSmallForDeterminant; | 232 return std::abs(matrix_.determinant()) > kTooSmallForDeterminant; |
| 190 } | 233 } |
| 191 | 234 |
| 235 bool Transform::IsBackFaceVisible() const { | |
| 236 // Compute whether a layer with a forward-facing normal of (0, 0, 1) would | |
| 237 // have its back face visible after applying the transform. | |
| 238 // | |
| 239 // This is done by transforming the normal and seeing if the resulting z | |
| 240 // value is positive or negative. However, note that transforming a normal | |
| 241 // actually requires using the inverse-transpose of the original transform. | |
| 242 | |
| 243 // TODO (shawnsingh) make this perform more efficiently - we do not | |
|
danakj
2012/11/28 00:42:12
is there a bug for this, for M25?
| |
| 244 // actually need to instantiate/invert/transpose any matrices, exploiting the | |
| 245 // fact that we only need to transform (0, 0, 1, 0). | |
| 246 SkMatrix44 inverse; | |
| 247 bool invertible = matrix_.invert(&inverse); | |
| 248 | |
| 249 // Assume the transform does not apply if it's not invertible, so it's | |
| 250 // front face remains visible. | |
| 251 if (!invertible) | |
| 252 return false; | |
| 253 | |
| 254 return inverse.getDouble(2, 2) < 0; | |
| 255 } | |
| 256 | |
| 192 bool Transform::GetInverse(Transform* transform) const { | 257 bool Transform::GetInverse(Transform* transform) const { |
| 193 return matrix_.invert(&transform->matrix_); | 258 return matrix_.invert(&transform->matrix_); |
| 194 } | 259 } |
| 195 | 260 |
| 196 void Transform::Transpose() { | 261 void Transform::Transpose() { |
| 197 matrix_.transpose(); | 262 matrix_.transpose(); |
| 198 } | 263 } |
| 199 | 264 |
| 200 void Transform::TransformPoint(Point& point) const { | 265 void Transform::TransformPoint(Point& point) const { |
| 201 TransformPointInternal(matrix_, point); | 266 TransformPointInternal(matrix_, point); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 SkDoubleToMScalar(0), | 367 SkDoubleToMScalar(0), |
| 303 SkDoubleToMScalar(1) | 368 SkDoubleToMScalar(1) |
| 304 }; | 369 }; |
| 305 | 370 |
| 306 xform.mapMScalars(p); | 371 xform.mapMScalars(p); |
| 307 | 372 |
| 308 point.SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1])); | 373 point.SetPoint(ToRoundedInt(p[0]), ToRoundedInt(p[1])); |
| 309 } | 374 } |
| 310 | 375 |
| 311 } // namespace gfx | 376 } // namespace gfx |
| OLD | NEW |