Cherry pick TextureView fixes
The following changes are in this commit: Avoid destroying TextureView surfaces for onStop bug:30238922 TextureViews will hold onto their backing surfaces, which will allow them to resume gracefully when the app's surfaces are saved. Now only resources that are destroyed for onStop are DisplayLists. (cherry picked from commit391d560402) TextureView: destroy layer on destroyHardwareResources event bug:30468770 (cherry picked from commit1c16c37d86) Fix NPE in TextureView Bug: 30651595 (cherry picked from commit3c2587f26e) Fix NPE in TextureView Bug: 30779663 (cherry picked from commit7e237189c2) Fix maps resume being blank Bug: 30889568 Fixes an issue where mLayer didn't have the mSurface set on it in certain resume scenarios. (cherry picked from commit03df0834e6)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user