Skip to content

Commit

Permalink
Release the surface texture entry when the platform view is disposed. (
Browse files Browse the repository at this point in the history
…flutter#6829)

We were leaking the texture after the view was disposed.
  • Loading branch information
amirh authored Nov 12, 2018
1 parent b1b5891 commit 266b098
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@
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 {

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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -130,6 +131,7 @@ public void dispose() {
mPresentation.detachState();
view.dispose();
mVirtualDisplay.release();
mTextureEntry.release();
}

public View getView() {
Expand Down

0 comments on commit 266b098

Please sign in to comment.