Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Unified Diff: ui/gfx/transform.cc

Issue 11418197: Move temporary MathUtil wrappers to permanent home in gfx::Transform (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/transform.cc
diff --git a/ui/gfx/transform.cc b/ui/gfx/transform.cc
index 19b59dac2039be7debb9485a34d817392e79b978..ef87c70d3f3db4b6fdeb3814e0807fe0c4b6b2ac 100644
--- a/ui/gfx/transform.cc
+++ b/ui/gfx/transform.cc
@@ -185,10 +185,75 @@ bool Transform::IsIdentity() const {
return matrix_.isIdentity();
}
+bool Transform::IsIdentityOrTranslation() const {
+ bool has_no_perspective = !matrix_.getDouble(3, 0) &&
+ !matrix_.getDouble(3, 1) &&
+ !matrix_.getDouble(3, 2) &&
+ (matrix_.getDouble(3, 3) == 1);
+
+ bool has_no_rotation_or_skew = !matrix_.getDouble(0, 1) &&
+ !matrix_.getDouble(0, 2) &&
+ !matrix_.getDouble(1, 0) &&
+ !matrix_.getDouble(1, 2) &&
+ !matrix_.getDouble(2, 0) &&
+ !matrix_.getDouble(2, 1);
+
+ bool has_no_scale = matrix_.getDouble(0, 0) == 1 &&
+ matrix_.getDouble(1, 1) == 1 &&
+ matrix_.getDouble(2, 2) == 1;
+
+ return has_no_perspective && has_no_rotation_or_skew && has_no_scale;
+}
+
+bool Transform::IsScaleOrTranslation() const {
+ bool has_no_perspective = !matrix_.getDouble(3, 0) &&
+ !matrix_.getDouble(3, 1) &&
+ !matrix_.getDouble(3, 2) &&
+ (matrix_.getDouble(3, 3) == 1);
+
+ bool has_no_rotation_or_skew = !matrix_.getDouble(0, 1) &&
+ !matrix_.getDouble(0, 2) &&
+ !matrix_.getDouble(1, 0) &&
+ !matrix_.getDouble(1, 2) &&
+ !matrix_.getDouble(2, 0) &&
+ !matrix_.getDouble(2, 1);
+
+ return has_no_perspective && has_no_rotation_or_skew;
+}
+
+bool Transform::HasPerspective() const {
+ return matrix_.getDouble(3, 0) ||
+ matrix_.getDouble(3, 1) ||
+ matrix_.getDouble(3, 2) ||
+ (matrix_.getDouble(3, 3) != 1);
+}
+
bool Transform::IsInvertible() const {
return std::abs(matrix_.determinant()) > kTooSmallForDeterminant;
}
+bool Transform::IsBackFaceVisible() const {
+ // Compute whether a layer with a forward-facing normal of (0, 0, 1) would
+ // have its back face visible after applying the transform.
+ //
+ // This is done by transforming the normal and seeing if the resulting z
+ // value is positive or negative. However, note that transforming a normal
+ // actually requires using the inverse-transpose of the original transform.
+
+ // 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?
+ // actually need to instantiate/invert/transpose any matrices, exploiting the
+ // fact that we only need to transform (0, 0, 1, 0).
+ SkMatrix44 inverse;
+ bool invertible = matrix_.invert(&inverse);
+
+ // Assume the transform does not apply if it's not invertible, so it's
+ // front face remains visible.
+ if (!invertible)
+ return false;
+
+ return inverse.getDouble(2, 2) < 0;
+}
+
bool Transform::GetInverse(Transform* transform) const {
return matrix_.invert(&transform->matrix_);
}
« cc/layer_sorter_unittest.cc ('K') | « ui/gfx/transform.h ('k') | ui/gfx/vector3d_f.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698