Merge "TextureView: destroy layer on destroyHardwareResources event" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ba3d4f6ea1
@@ -218,35 +218,47 @@ public class TextureView extends View {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindowInternal() {
|
protected void onDetachedFromWindowInternal() {
|
||||||
destroySurface();
|
destroyHardwareLayer();
|
||||||
|
releaseSurfaceTexture();
|
||||||
super.onDetachedFromWindowInternal();
|
super.onDetachedFromWindowInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void destroySurface() {
|
/**
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void destroyHardwareResources() {
|
||||||
|
destroyHardwareLayer();
|
||||||
|
mUpdateSurface = mSurface != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void destroyHardwareLayer() {
|
||||||
if (mLayer != null) {
|
if (mLayer != null) {
|
||||||
mLayer.detachSurfaceTexture();
|
mLayer.detachSurfaceTexture();
|
||||||
|
|
||||||
boolean shouldRelease = true;
|
|
||||||
if (mListener != null) {
|
|
||||||
shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (mNativeWindowLock) {
|
|
||||||
nDestroyNativeWindow();
|
|
||||||
}
|
|
||||||
|
|
||||||
mLayer.destroy();
|
mLayer.destroy();
|
||||||
if (shouldRelease) mSurface.release();
|
|
||||||
mSurface = null;
|
|
||||||
mLayer = null;
|
mLayer = null;
|
||||||
|
|
||||||
// Make sure if/when new layer gets re-created, transform matrix will
|
|
||||||
// be re-applied.
|
|
||||||
mMatrixChanged = true;
|
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
|
* 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
|
* 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.
|
// Create a new SurfaceTexture for the layer.
|
||||||
mSurface = new SurfaceTexture(false);
|
mSurface = new SurfaceTexture(false);
|
||||||
mLayer.setSurfaceTexture(mSurface);
|
mLayer.setSurfaceTexture(mSurface);
|
||||||
|
nCreateNativeWindow(mSurface);
|
||||||
}
|
}
|
||||||
mSurface.setDefaultBufferSize(getWidth(), getHeight());
|
mSurface.setDefaultBufferSize(getWidth(), getHeight());
|
||||||
nCreateNativeWindow(mSurface);
|
|
||||||
|
|
||||||
mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
|
mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user