summaryrefslogtreecommitdiffstats
path: root/libs/hwui/Matrix.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@curious-creature.com>2015-01-15 11:53:44 -0800
committerRomain Guy <romainguy@curious-creature.com>2015-01-15 16:49:18 -0800
commite4998e1ea93253c177f2358dc37c39d117b2f6c4 (patch)
tree7358fe43e5acd3eddc6875ec0cfdea2604ca3c60 /libs/hwui/Matrix.cpp
parenta747d5e47bef27acd18afda3ed43309ad5fab87b (diff)
downloadframeworks_base-e4998e1ea93253c177f2358dc37c39d117b2f6c4.zip
frameworks_base-e4998e1ea93253c177f2358dc37c39d117b2f6c4.tar.gz
frameworks_base-e4998e1ea93253c177f2358dc37c39d117b2f6c4.tar.bz2
Fast loadInverse() implementation for the common case
Most matrices used by the UI toolkit are translation matrices, whose inverses can be quickly computed by using the negated translation vector. Change-Id: I54a28a634a586085779bfc26f3a4160cd5ab2b22
Diffstat (limited to 'libs/hwui/Matrix.cpp')
-rw-r--r--libs/hwui/Matrix.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/libs/hwui/Matrix.cpp b/libs/hwui/Matrix.cpp
index 9f2014f..061d26a 100644
--- a/libs/hwui/Matrix.cpp
+++ b/libs/hwui/Matrix.cpp
@@ -203,6 +203,34 @@ void Matrix4::copyTo(SkMatrix& v) const {
}
void Matrix4::loadInverse(const Matrix4& v) {
+ // Fast case for common translation matrices
+ if (v.isPureTranslate()) {
+ // Reset the matrix
+ // Unnamed fields are never written to except by
+ // loadIdentity(), they don't need to be reset
+ data[kScaleX] = 1.0f;
+ data[kSkewX] = 0.0f;
+
+ data[kScaleY] = 1.0f;
+ data[kSkewY] = 0.0f;
+
+ data[kScaleZ] = 1.0f;
+
+ data[kPerspective0] = 0.0f;
+ data[kPerspective1] = 0.0f;
+ data[kPerspective2] = 1.0f;
+
+ // No need to deal with kTranslateZ because isPureTranslate()
+ // only returns true when the kTranslateZ component is 0
+ data[kTranslateX] = -v.data[kTranslateX];
+ data[kTranslateY] = -v.data[kTranslateY];
+ data[kTranslateZ] = 0.0f;
+
+ // A "pure translate" matrix can be identity or translation
+ mType = v.getType();
+ return;
+ }
+
double scale = 1.0 /
(v.data[kScaleX] * ((double) v.data[kScaleY] * v.data[kPerspective2] -
(double) v.data[kTranslateY] * v.data[kPerspective1]) +
@@ -212,18 +240,18 @@ void Matrix4::loadInverse(const Matrix4& v) {
(double) v.data[kScaleY] * v.data[kPerspective0]));
data[kScaleX] = (v.data[kScaleY] * v.data[kPerspective2] -
- v.data[kTranslateY] * v.data[kPerspective1]) * scale;
+ v.data[kTranslateY] * v.data[kPerspective1]) * scale;
data[kSkewX] = (v.data[kTranslateX] * v.data[kPerspective1] -
v.data[kSkewX] * v.data[kPerspective2]) * scale;
data[kTranslateX] = (v.data[kSkewX] * v.data[kTranslateY] -
- v.data[kTranslateX] * v.data[kScaleY]) * scale;
+ v.data[kTranslateX] * v.data[kScaleY]) * scale;
data[kSkewY] = (v.data[kTranslateY] * v.data[kPerspective0] -
v.data[kSkewY] * v.data[kPerspective2]) * scale;
data[kScaleY] = (v.data[kScaleX] * v.data[kPerspective2] -
- v.data[kTranslateX] * v.data[kPerspective0]) * scale;
+ v.data[kTranslateX] * v.data[kPerspective0]) * scale;
data[kTranslateY] = (v.data[kTranslateX] * v.data[kSkewY] -
- v.data[kScaleX] * v.data[kTranslateY]) * scale;
+ v.data[kScaleX] * v.data[kTranslateY]) * scale;
data[kPerspective0] = (v.data[kSkewY] * v.data[kPerspective1] -
v.data[kScaleY] * v.data[kPerspective0]) * scale;