Release TextureView surface within FlutterTextureView when disconnected. (#48535) (flutter/engine#15899)

This commit is contained in:
Matt Carroll 2020-01-23 13:19:42 -08:00 committed by GitHub
parent 74cbca7c98
commit fbd6f7a1f9

View File

@ -38,6 +38,8 @@ public class FlutterTextureView extends TextureView implements RenderSurface {
private boolean isAttachedToFlutterRenderer = false;
@Nullable
private FlutterRenderer flutterRenderer;
@Nullable
private Surface renderSurface;
// Connects the {@code SurfaceTexture} beneath this {@code TextureView} with Flutter's native code.
// Callbacks are received by this Object and then those messages are forwarded to our
@ -172,7 +174,8 @@ public class FlutterTextureView extends TextureView implements RenderSurface {
throw new IllegalStateException("connectSurfaceToRenderer() should only be called when flutterRenderer and getSurfaceTexture() are non-null.");
}
flutterRenderer.startRenderingToSurface(new Surface(getSurfaceTexture()));
renderSurface = new Surface(getSurfaceTexture());
flutterRenderer.startRenderingToSurface(renderSurface);
}
// FlutterRenderer must be non-null.
@ -192,5 +195,7 @@ public class FlutterTextureView extends TextureView implements RenderSurface {
}
flutterRenderer.stopRenderingToSurface();
renderSurface.release();
renderSurface = null;
}
}