From ee1183cae77dae59153bf4e78835a9dc102bff7b Mon Sep 17 00:00:00 2001 From: Amir Hardon Date: Mon, 12 Nov 2018 14:04:34 -0800 Subject: [PATCH] Release the surface texture entry when the platform view is disposed. We were leaking the texture after the view was disposed. --- .../platform/PlatformViewsController.java | 2 +- .../platform/VirtualDisplayController.java | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java index 8e3afa6ca93c6..e7297567e198c 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java @@ -179,7 +179,7 @@ private void createPlatformView(MethodCall call, MethodChannel.Result result) { VirtualDisplayController vdController = VirtualDisplayController.create( mContext, viewFactory, - textureEntry.surfaceTexture(), + textureEntry, toPhysicalPixels(logicalWidth), toPhysicalPixels(logicalHeight), id, diff --git a/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java b/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java index 77cf6a9dd06bc..59f49d3b96152 100644 --- a/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java +++ b/shell/platform/android/io/flutter/plugin/platform/VirtualDisplayController.java @@ -13,6 +13,7 @@ import android.view.Surface; import android.view.View; import android.view.ViewTreeObserver; +import io.flutter.view.TextureRegistry; @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) class VirtualDisplayController { @@ -20,14 +21,14 @@ class VirtualDisplayController { public static VirtualDisplayController create( Context context, PlatformViewFactory viewFactory, - SurfaceTexture surfaceTexture, + TextureRegistry.SurfaceTextureEntry textureEntry, int width, int height, int viewId, Object createParams ) { - surfaceTexture.setDefaultBufferSize(width, height); - Surface surface = new Surface(surfaceTexture); + textureEntry.surfaceTexture().setDefaultBufferSize(width, height); + Surface surface = new Surface(textureEntry.surfaceTexture()); DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); int densityDpi = context.getResources().getDisplayMetrics().densityDpi; @@ -45,12 +46,12 @@ public static VirtualDisplayController create( } return new VirtualDisplayController( - context, virtualDisplay, viewFactory, surface, surfaceTexture, viewId, createParams); + context, virtualDisplay, viewFactory, surface, textureEntry, viewId, createParams); } private final Context mContext; private final int mDensityDpi; - private final SurfaceTexture mSurfaceTexture; + private final TextureRegistry.SurfaceTextureEntry mTextureEntry; private VirtualDisplay mVirtualDisplay; private SingleViewPresentation mPresentation; private Surface mSurface; @@ -61,11 +62,11 @@ private VirtualDisplayController( VirtualDisplay virtualDisplay, PlatformViewFactory viewFactory, Surface surface, - SurfaceTexture surfaceTexture, + TextureRegistry.SurfaceTextureEntry textureEntry, int viewId, Object createParams ) { - mSurfaceTexture = surfaceTexture; + mTextureEntry = textureEntry; mSurface = surface; mContext = context; mVirtualDisplay = virtualDisplay; @@ -85,7 +86,7 @@ public void resize(final int width, final int height, final Runnable onNewSizeFr mVirtualDisplay.setSurface(null); mVirtualDisplay.release(); - mSurfaceTexture.setDefaultBufferSize(width, height); + mTextureEntry.surfaceTexture().setDefaultBufferSize(width, height); DisplayManager displayManager = (DisplayManager) mContext.getSystemService(Context.DISPLAY_SERVICE); mVirtualDisplay = displayManager.createVirtualDisplay( "flutter-vd", @@ -130,6 +131,7 @@ public void dispose() { mPresentation.detachState(); view.dispose(); mVirtualDisplay.release(); + mTextureEntry.release(); } public View getView() {