Optimized implementation of SkMatrix44::preScale
preScale() does not need to do a general matrix multiply. It can do 4x less
arithmetic by directly scaling the columns of the input matrix.
Review URL: https://codereview.appspot.com/6923048
git-svn-id: http://skia.googlecode.com/svn/trunk@6807 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkMatrix44.cpp b/src/utils/SkMatrix44.cpp
index acd4ae6..e899cf8 100644
--- a/src/utils/SkMatrix44.cpp
+++ b/src/utils/SkMatrix44.cpp
@@ -277,9 +277,15 @@
return;
}
- SkMatrix44 tmp(kUninitialized_Constructor);
- tmp.setScale(sx, sy, sz);
- this->preConcat(tmp);
+ // The implementation matrix * pureScale can be shortcut
+ // by knowing that pureScale components effectively scale
+ // the columns of the original matrix.
+ for (int i = 0; i < 4; i++) {
+ fMat[0][i] *= sx;
+ fMat[1][i] *= sy;
+ fMat[2][i] *= sz;
+ }
+ this->dirtyTypeMask();
}
void SkMatrix44::postScale(SkMScalar sx, SkMScalar sy, SkMScalar sz) {