Recreate TextureView's display list on attach
Bug #9425270

When a TextureView is detached from its window and immediately
re-attached, the display list is not destroyed but reused as is.
TextureView will however destroy the layer and surface texture
reference by the display list.

The solution is to force TextureView to invalidate its display
list on re-attach if it previously had a surface/layer pair.

Change-Id: I475096ffa7e5709155c4c943bf1bfaaaedbd4a1d
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 5c3934d..244dc33 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -108,6 +108,7 @@
     private HardwareLayer mLayer;
     private SurfaceTexture mSurface;
     private SurfaceTextureListener mListener;
+    private boolean mHadSurface;
 
     private boolean mOpaque = true;
 
@@ -202,6 +203,11 @@
             Log.w(LOG_TAG, "A TextureView or a subclass can only be "
                     + "used with hardware acceleration enabled.");
         }
+
+        if (mHadSurface) {
+            invalidate(true);
+            mHadSurface = false;
+        }
     }
 
     @Override
@@ -241,6 +247,8 @@
             if (shouldRelease) mSurface.release();
             mSurface = null;
             mLayer = null;
+
+            mHadSurface = true;
         }
     }