diff options
| author | 2016-08-29 23:33:55 +0000 | |
|---|---|---|
| committer | 2016-08-29 23:33:57 +0000 | |
| commit | 8eaa65b86745e6a6f7e66d4a3344d76d7a19bcf8 (patch) | |
| tree | 78bd765a2c04b2282fe2012caa51c63ca7fee081 | |
| parent | b7efddfc41003fa85e17b9eeb635ee7cc8f9ad03 (diff) | |
| parent | 2e8a8a24320fac0eedfdfb4151068499bb6b00cd (diff) | |
Merge "Cherry pick TextureView fixes" into nyc-dev
| -rw-r--r-- | core/java/android/view/TextureView.java | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 1a712c3916db..c7eca44c8749 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -218,15 +218,32 @@ public class TextureView extends View { /** @hide */ @Override protected void onDetachedFromWindowInternal() { - destroySurface(); + destroyHardwareLayer(); + releaseSurfaceTexture(); super.onDetachedFromWindowInternal(); } - private void destroySurface() { + /** + * @hide + */ + @Override + protected void destroyHardwareResources() { + destroyHardwareLayer(); + } + + private void destroyHardwareLayer() { if (mLayer != null) { mLayer.detachSurfaceTexture(); + mLayer.destroy(); + mLayer = null; + mMatrixChanged = true; + } + } + private void releaseSurfaceTexture() { + if (mSurface != null) { boolean shouldRelease = true; + if (mListener != null) { shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface); } @@ -235,14 +252,10 @@ public class TextureView extends View { nDestroyNativeWindow(); } - mLayer.destroy(); - if (shouldRelease) mSurface.release(); + 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; } } @@ -355,17 +368,6 @@ public class TextureView extends View { } } - /** - * @hide - */ - @Override - protected void destroyHardwareResources() { - super.destroyHardwareResources(); - destroySurface(); - invalidateParentCaches(); - invalidate(true); - } - HardwareLayer getHardwareLayer() { if (mLayer == null) { if (mAttachInfo == null || mAttachInfo.mHardwareRenderer == null) { @@ -373,17 +375,17 @@ public class TextureView extends View { } mLayer = mAttachInfo.mHardwareRenderer.createTextureLayer(); - if (!mUpdateSurface) { + boolean createNewSurface = (mSurface == null); + if (createNewSurface) { // Create a new SurfaceTexture for the layer. mSurface = new SurfaceTexture(false); - mLayer.setSurfaceTexture(mSurface); + nCreateNativeWindow(mSurface); } + mLayer.setSurfaceTexture(mSurface); mSurface.setDefaultBufferSize(getWidth(), getHeight()); - nCreateNativeWindow(mSurface); - mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); - if (mListener != null && !mUpdateSurface) { + if (mListener != null && createNewSurface) { mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight()); } mLayer.setLayerPaint(mLayerPaint); @@ -742,9 +744,11 @@ public class TextureView extends View { "released SurfaceTexture"); } if (mSurface != null) { + nDestroyNativeWindow(); mSurface.release(); } mSurface = surfaceTexture; + nCreateNativeWindow(mSurface); /* * If the view is visible and we already made a layer, update the |