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:
Jason Simmons
2025-03-25 21:10:58 +00:00
committed by GitHub
parent 882c4214e3
commit b4a69f00f9
2 changed files with 19 additions and 0 deletions

View File

@@ -52,6 +52,8 @@ final class SurfaceTextureSurfaceProducer
@Override
public void release() {
texture.release();
surface.release();
surface = null;
released = true;
}

View File

@@ -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());
}
}