Fix for using HARDWARE layers on unaccelerated views.

If a view is not accelerated but has its layer type set to
LAYER_TYPE_HARDWARE, then the framework will use the old drawing cache
approach, to cache it in a bitmap. This works fine, but when the layer
is set to NONE, that drawing cache is not destroyed, as it would be were
the layer set to LAYER_TYPE_SOFTWARE. This prevents future invalidations on
the view from working correctly because the bitmap cache has never been
destroyed and recreated.

The fix is to always destroy the drawing cache when the layer type is
changed from SOFTWARE or HARDWARE, to make sure that it gets set appropriately
regardless of the state of the view's acceleration.

Change-Id: I449649e6d370477825015505da76564455a156e6
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 791ffb9..a8770d2 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -8706,6 +8706,12 @@
 
         // Destroy any previous software drawing cache if needed
         switch (mLayerType) {
+            case LAYER_TYPE_HARDWARE:
+                if (mHardwareLayer != null) {
+                    mHardwareLayer.destroy();
+                    mHardwareLayer = null;
+                }
+                // fall through - unaccelerated views may use software layer mechanism instead
             case LAYER_TYPE_SOFTWARE:
                 if (mDrawingCache != null) {
                     mDrawingCache.recycle();
@@ -8717,12 +8723,6 @@
                     mUnscaledDrawingCache = null;
                 }
                 break;
-            case LAYER_TYPE_HARDWARE:
-                if (mHardwareLayer != null) {
-                    mHardwareLayer.destroy();
-                    mHardwareLayer = null;
-                }
-                break;
             default:
                 break;
         }