forked from firka/flutter
Release the SurfaceTextureSurfaceProducer's surface in the release method (#165835)
The TextureRegistry.SurfaceProducer interface specifies that callers of getSurface should not cache the returned surface. Therefore, it should be safe for SurfaceTextureSurfaceProducer to release this surface when releasing the texture. Fixes https://github.com/flutter/flutter/issues/163235
This commit is contained in:
@@ -52,6 +52,8 @@ final class SurfaceTextureSurfaceProducer
|
||||
@Override
|
||||
public void release() {
|
||||
texture.release();
|
||||
surface.release();
|
||||
surface = null;
|
||||
released = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ package io.flutter.embedding.engine.renderer;
|
||||
|
||||
import static io.flutter.Build.API_LEVELS;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@@ -67,4 +69,19 @@ public final class SurfaceTextureSurfaceProducerTest {
|
||||
fakeJNI.detachFromNativeAndReleaseResources();
|
||||
producer.release();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseWillReleaseSurface() {
|
||||
final FlutterRenderer flutterRenderer = new FlutterRenderer(fakeJNI);
|
||||
|
||||
// Create a surface and set the initial size.
|
||||
final Handler handler = new Handler(Looper.getMainLooper());
|
||||
final SurfaceTextureSurfaceProducer producer =
|
||||
new SurfaceTextureSurfaceProducer(
|
||||
0, handler, fakeJNI, flutterRenderer.registerSurfaceTexture(new SurfaceTexture(0)));
|
||||
final Surface surface = producer.getSurface();
|
||||
assertTrue(surface.isValid());
|
||||
producer.release();
|
||||
assertFalse(surface.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user