Speedup TextView fades (no more layers required.)

Also fixes a crash in the drop shadows cache and improves
drop shadows caching.

Change-Id: I9c0208a49467f9201d786ae0c129194b8d423923
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java
index 0466c69..54ac906 100644
--- a/core/java/android/text/Layout.java
+++ b/core/java/android/text/Layout.java
@@ -1729,7 +1729,7 @@
     private Alignment mAlignment = Alignment.ALIGN_NORMAL;
     private float mSpacingMult;
     private float mSpacingAdd;
-    private static Rect sTempRect = new Rect();
+    private static final Rect sTempRect = new Rect();
     private boolean mSpannedText;
 
     public static final int DIR_LEFT_TO_RIGHT = 1;
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index c13ed15..0510701 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -197,6 +197,7 @@
     
     private static final int PRIORITY = 100;
 
+    private int mCurrentAlpha = 255;    
     private ColorStateList mTextColor;
     private int mCurTextColor;
     private ColorStateList mHintTextColor;
@@ -3857,6 +3858,22 @@
     }
 
     @Override
+    protected boolean onSetAlpha(int alpha) {
+        if (mMovement == null && getBackground() == null) {
+            mCurrentAlpha = alpha;
+            final Drawables dr = mDrawables;
+            if (dr != null) {
+                if (dr.mDrawableLeft != null) dr.mDrawableLeft.setAlpha(alpha);
+                if (dr.mDrawableTop != null) dr.mDrawableTop.setAlpha(alpha);
+                if (dr.mDrawableRight != null) dr.mDrawableRight.setAlpha(alpha);
+                if (dr.mDrawableBottom != null) dr.mDrawableBottom.setAlpha(alpha);
+            }
+            return true;
+        }
+        return false;
+    }
+
+    @Override
     protected void onDraw(Canvas canvas) {
         restartMarqueeIfNeeded();
 
@@ -3953,6 +3970,7 @@
         }
 
         mTextPaint.setColor(color);
+        mTextPaint.setAlpha(mCurrentAlpha);
         mTextPaint.drawableState = getDrawableState();
 
         canvas.save();
diff --git a/libs/hwui/TextDropShadowCache.h b/libs/hwui/TextDropShadowCache.h
index 5fbe9e5..c3be483 100644
--- a/libs/hwui/TextDropShadowCache.h
+++ b/libs/hwui/TextDropShadowCache.h
@@ -29,13 +29,18 @@
 namespace uirenderer {
 
 struct ShadowText {
-    ShadowText() { }
+    ShadowText() {
+        text = NULL;
+    }
 
     ShadowText(SkPaint* paint, uint32_t radius, uint32_t len, const char* srcText):
-            paint(paint), radius(radius), len(len) {
+            radius(radius), len(len) {
         text = new char[len];
         memcpy(text, srcText, len);
 
+        textSize = paint->getTextSize();
+        typeface = paint->getTypeface();
+
         hash = 0;
         uint32_t multiplier = 1;
         for (uint32_t i = 0; i < len; i++) {
@@ -46,7 +51,8 @@
     }
 
     ShadowText(const ShadowText& shadow):
-            paint(shadow.paint), radius(shadow.radius), len(shadow.len), hash(shadow.hash) {
+            radius(shadow.radius), len(shadow.len), hash(shadow.hash),
+            textSize(shadow.textSize), typeface(shadow.typeface) {
         text = new char[shadow.len];
         memcpy(text, shadow.text, shadow.len);
     }
@@ -55,10 +61,11 @@
         delete[] text;
     }
 
-    SkPaint* paint;
     uint32_t radius;
     uint32_t len;
     uint32_t hash;
+    float textSize;
+    SkTypeface* typeface;
     char *text;
 
     bool operator<(const ShadowText& rhs) const {
@@ -66,11 +73,14 @@
         else if (len == rhs.len) {
             if (radius < rhs.radius) return true;
             else if (radius == rhs.radius) {
-                if (paint < rhs.paint) return true;
-                else if (paint == rhs.paint) {
-                    if (hash < rhs.hash) return true;
-                    if (hash == rhs.hash) {
-                        return strncmp(text, rhs.text, len) < 0;
+                if (textSize < rhs.textSize) return true;
+                else if (textSize == rhs.textSize) {
+                    if (typeface < rhs.typeface) return true;
+                    else if (typeface == rhs.typeface) {
+                        if (hash < rhs.hash) return true;
+                        if (hash == rhs.hash) {
+                            return strncmp(text, rhs.text, len) < 0;
+                        }
                     }
                 }
             }