未验证 提交 2c2d4080 编写于 作者: C ColdPaleLight 提交者: GitHub

Support passing existing SurfaceTexture to TextureRegistry (#28358)

上级 f0a3c469
......@@ -90,12 +90,22 @@ public class FlutterRenderer implements TextureRegistry {
// ------ START TextureRegistry IMPLEMENTATION -----
/**
* Creates and returns a new {@link SurfaceTexture} that is also made available to Flutter code.
* Creates and returns a new {@link SurfaceTexture} managed by the Flutter engine that is also
* made available to Flutter code.
*/
@Override
public SurfaceTextureEntry createSurfaceTexture() {
Log.v(TAG, "Creating a SurfaceTexture.");
final SurfaceTexture surfaceTexture = new SurfaceTexture(0);
return registerSurfaceTexture(surfaceTexture);
}
/**
* Registers and returns a {@link SurfaceTexture} managed by the Flutter engine that is also made
* available to Flutter code.
*/
@Override
public SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture) {
surfaceTexture.detachFromGLContext();
final SurfaceTextureRegistryEntry entry =
new SurfaceTextureRegistryEntry(nextTextureId.getAndIncrement(), surfaceTexture);
......
......@@ -873,6 +873,12 @@ public class FlutterView extends SurfaceView
@Override
public TextureRegistry.SurfaceTextureEntry createSurfaceTexture() {
final SurfaceTexture surfaceTexture = new SurfaceTexture(0);
return registerSurfaceTexture(surfaceTexture);
}
@Override
public TextureRegistry.SurfaceTextureEntry registerSurfaceTexture(
@NonNull SurfaceTexture surfaceTexture) {
surfaceTexture.detachFromGLContext();
final SurfaceTextureRegistryEntry entry =
new SurfaceTextureRegistryEntry(nextTextureId.getAndIncrement(), surfaceTexture);
......
......@@ -5,6 +5,7 @@
package io.flutter.view;
import android.graphics.SurfaceTexture;
import androidx.annotation.NonNull;
// TODO(mattcarroll): re-evalute docs in this class and add nullability annotations.
/**
......@@ -20,6 +21,13 @@ public interface TextureRegistry {
*/
SurfaceTextureEntry createSurfaceTexture();
/**
* Registers a SurfaceTexture managed by the Flutter engine.
*
* @return A SurfaceTextureEntry.
*/
SurfaceTextureEntry registerSurfaceTexture(@NonNull SurfaceTexture surfaceTexture);
/** A registry entry for a managed SurfaceTexture. */
interface SurfaceTextureEntry {
/** @return The managed SurfaceTexture. */
......
package io.flutter.embedding.engine.renderer;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
......@@ -7,6 +8,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.robolectric.Shadows.shadowOf;
import android.graphics.SurfaceTexture;
import android.os.Looper;
import android.view.Surface;
import io.flutter.embedding.engine.FlutterJNI;
......@@ -122,6 +124,28 @@ public class FlutterRendererTest {
verify(fakeFlutterJNI, times(0)).markTextureFrameAvailable(eq(entry.id()));
}
@Test
public void itRegistersExistingSurfaceTexture() {
// Setup the test.
FlutterRenderer flutterRenderer = new FlutterRenderer(fakeFlutterJNI);
fakeFlutterJNI.detachFromNativeAndReleaseResources();
SurfaceTexture surfaceTexture = new SurfaceTexture(0);
// Execute the behavior under test.
FlutterRenderer.SurfaceTextureRegistryEntry entry =
(FlutterRenderer.SurfaceTextureRegistryEntry)
flutterRenderer.registerSurfaceTexture(surfaceTexture);
flutterRenderer.startRenderingToSurface(fakeSurface);
// Verify behavior under test.
assertEquals(surfaceTexture, entry.surfaceTexture());
verify(fakeFlutterJNI, times(1)).registerTexture(eq(entry.id()), eq(entry.textureWrapper()));
}
@Test
public void itUnregistersTextureWhenSurfaceTextureFinalized() {
// Setup the test.
......
......@@ -849,6 +849,11 @@ public class PlatformViewsControllerTest {
@Override
public SurfaceTextureEntry createSurfaceTexture() {
return registerSurfaceTexture(mock(SurfaceTexture.class));
}
@Override
public SurfaceTextureEntry registerSurfaceTexture(SurfaceTexture surfaceTexture) {
return new SurfaceTextureEntry() {
@Override
public SurfaceTexture surfaceTexture() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册