summaryrefslogtreecommitdiff
path: root/libs/hwui/Matrix.h
diff options
context:
space:
mode:
authorRomain Guy <romainguy@google.com>2013-06-11 16:19:24 -0700
committerRomain Guy <romainguy@google.com>2013-06-11 17:14:59 -0700
commit4c2547fa9244e78115cde0a259291053108c3dc7 (patch)
tree4337937e216918e4febe861daa7ef093b99aff03 /libs/hwui/Matrix.h
parentfadd2081443dd2f59f8e8143256a34b7485fe72e (diff)
Avoid 9patch cache lookups when possible
This optimization saves up to 0.3ms per frame on the Play Store's front page, on a Nexus 4 device. Change-Id: Iaa4ef33c6e3b37e175efd5b9eea9ef59b43f14f3
Diffstat (limited to 'libs/hwui/Matrix.h')
-rw-r--r--libs/hwui/Matrix.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/libs/hwui/Matrix.h b/libs/hwui/Matrix.h
index 75e280cf502b..df744bef6aca 100644
--- a/libs/hwui/Matrix.h
+++ b/libs/hwui/Matrix.h
@@ -128,10 +128,27 @@ public:
void multiply(float v);
- void translate(float x, float y, float z) {
- Matrix4 u;
- u.loadTranslate(x, y, z);
- multiply(u);
+ void translate(float x, float y) {
+ if ((getType() & sGeometryMask) == kTypeTranslate) {
+ data[kTranslateX] += x;
+ data[kTranslateY] += y;
+ } else {
+ // Doing a translation will only affect the translate bit of the type
+ // Save the type
+ uint32_t type = mType;
+
+ Matrix4 u;
+ u.loadTranslate(x, y, 0.0f);
+ multiply(u);
+
+ // Restore the type and fix the translate bit
+ mType = type;
+ if (data[kTranslateX] != 0.0f || data[kTranslateY] != 0.0f) {
+ mType |= kTypeTranslate;
+ } else {
+ mType &= ~kTypeTranslate;
+ }
+ }
}
void scale(float sx, float sy, float sz) {