TextureView: destroy layer on destroyHardwareResources event

am: 1c16c37d86

Change-Id: I75a9c06c81f696b8a65d128f4ec20ca9d3083a07
This commit is contained in:
sergeyv
2016-08-03 22:08:13 +00:00
committed by android-build-merger

View File

@@ -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);