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

Unified Diff: src/utils/SkMatrix44.cpp

Issue 23477020: Revert determinant-based ScaleTranslate inverse. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 4 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkMatrix44.cpp
diff --git a/src/utils/SkMatrix44.cpp b/src/utils/SkMatrix44.cpp
index 25052fd0f3c1d585fedbece4d54c92715381ec0f..82b171ba2d75814c098e804bb41b0debf9b687c6 100644
--- a/src/utils/SkMatrix44.cpp
+++ b/src/utils/SkMatrix44.cpp
@@ -491,55 +491,34 @@ bool SkMatrix44::invert(SkMatrix44* inverse) const {
return false;
}
- double a00 = fMat[0][0];
- double a11 = fMat[1][1];
- double a22 = fMat[2][2];
- double a30 = fMat[3][0];
- double a31 = fMat[3][1];
- double a32 = fMat[3][2];
-
- double b00 = a00 * a11;
- double b07 = -a22 * a30;
- double b09 = -a22 * a31;
- double b11 = a22;
-
- // Calculate the determinant
- double det = b00 * b11;
-
- double invdet = 1.0 / det;
- // If det is zero, we want to return false. However, we also want to return false
- // if 1/det overflows to infinity (i.e. det is denormalized). Both of these are
- // handled by checking that 1/det is finite.
- if (!sk_float_isfinite(invdet)) {
- return false;
- }
- if (NULL == inverse) {
- return true;
+ if (inverse) {
+ double invXScale = 1 / fMat[0][0];
+ double invYScale = 1 / fMat[1][1];
+ double invZScale = 1 / fMat[2][2];
+
+ inverse->fMat[0][0] = invXScale;
+ inverse->fMat[0][1] = 0;
+ inverse->fMat[0][2] = 0;
+ inverse->fMat[0][3] = 0;
+
+ inverse->fMat[1][0] = 0;
+ inverse->fMat[1][1] = invYScale;
+ inverse->fMat[1][2] = 0;
+ inverse->fMat[1][3] = 0;
+
+ inverse->fMat[2][0] = 0;
+ inverse->fMat[2][1] = 0;
+ inverse->fMat[2][2] = invZScale;
+ inverse->fMat[2][3] = 0;
+
+ inverse->fMat[3][0] = -fMat[3][0] * invXScale;
+ inverse->fMat[3][1] = -fMat[3][1] * invYScale;
+ inverse->fMat[3][2] = -fMat[3][2] * invZScale;
+ inverse->fMat[3][3] = 1;
+
+ inverse->setTypeMask(this->getType());
}
- b00 *= invdet;
- b07 *= invdet;
- b09 *= invdet;
- b11 *= invdet;
-
- inverse->fMat[0][0] = SkDoubleToMScalar(a11 * b11);
- inverse->fMat[0][1] = 0;
- inverse->fMat[0][2] = 0;
- inverse->fMat[0][3] = 0;
- inverse->fMat[1][0] = 0;
- inverse->fMat[1][1] = SkDoubleToMScalar(a00 * b11);
- inverse->fMat[1][2] = 0;
- inverse->fMat[1][3] = 0;
- inverse->fMat[2][0] = 0;
- inverse->fMat[2][1] = 0;
- inverse->fMat[2][2] = SkDoubleToMScalar(b00);
- inverse->fMat[2][3] = 0;
- inverse->fMat[3][0] = SkDoubleToMScalar(a11 * b07);
- inverse->fMat[3][1] = SkDoubleToMScalar(a00 * b09);
- inverse->fMat[3][2] = SkDoubleToMScalar(-a32 * b00);
- inverse->fMat[3][3] = 1;
-
- inverse->setTypeMask(this->getType());
return true;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698