From 1c16c37d8646ed25e844af8472eede988ad0c2f0 Mon Sep 17 00:00:00 2001 From: sergeyv Date: Tue, 2 Aug 2016 14:46:12 -0700 Subject: [PATCH] TextureView: destroy layer on destroyHardwareResources event bug:30468770 Change-Id: I5174808e3fa6e4a87e3522246522c4e6d7ee2c3c --- core/java/android/view/TextureView.java | 50 +++++++++++++++---------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index b2e2505f5c5b4..ce2fa81976a33 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -218,35 +218,47 @@ public class TextureView extends View { /** @hide */ @Override protected void onDetachedFromWindowInternal() { - destroySurface(); + destroyHardwareLayer(); + releaseSurfaceTexture(); super.onDetachedFromWindowInternal(); } - private void destroySurface() { + /** + * @hide + */ + @Override + protected void destroyHardwareResources() { + destroyHardwareLayer(); + mUpdateSurface = mSurface != null; + } + + private void destroyHardwareLayer() { if (mLayer != null) { mLayer.detachSurfaceTexture(); - - boolean shouldRelease = true; - if (mListener != null) { - shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface); - } - - synchronized (mNativeWindowLock) { - nDestroyNativeWindow(); - } - mLayer.destroy(); - if (shouldRelease) mSurface.release(); - mSurface = null; mLayer = null; - - // Make sure if/when new layer gets re-created, transform matrix will - // be re-applied. mMatrixChanged = true; - mHadSurface = true; } } + private void releaseSurfaceTexture() { + boolean shouldRelease = true; + + if (mListener != null) { + shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface); + } + + synchronized (mNativeWindowLock) { + nDestroyNativeWindow(); + } + + if (shouldRelease) { + mSurface.release(); + } + mSurface = null; + mHadSurface = true; + } + /** * The layer type of a TextureView is ignored since a TextureView is always * considered to act as a hardware layer. The optional paint supplied to this @@ -366,9 +378,9 @@ public class TextureView extends View { // Create a new SurfaceTexture for the layer. mSurface = new SurfaceTexture(false); mLayer.setSurfaceTexture(mSurface); + nCreateNativeWindow(mSurface); } mSurface.setDefaultBufferSize(getWidth(), getHeight()); - nCreateNativeWindow(mSurface); mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);