From 5b9bb4bacf3c21669f71f873fffc07fd24c789a1 Mon Sep 17 00:00:00 2001 From: Matan Lurey Date: Mon, 26 Feb 2024 17:39:23 -0800 Subject: [PATCH] Migrate Android `scenario_app` to the `SurfaceProducer` API (flutter/engine#50993) Part of testing https://github.com/flutter/flutter/issues/139702. Without this PR, the Impeller + Vulkan Scenario App will draw nothing/potentially crash, because there is no way to draw the (current) `SurfaceTexture`-based textures in Vulkan (and never will be). This change does the following: - Skia -> Nothing - Impeller + OpenGLES -> On newer Android devices, uses `ImageReader` instead - Impeller + Vulkan -> Always uses `ImageReader` See also: https://api.flutter.dev/javadoc/io/flutter/view/TextureRegistry.SurfaceProducer.html. --- .../ExternalTextureFlutterActivity.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java b/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java index f06f75fcd8..8479673a6c 100644 --- a/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java +++ b/engine/src/flutter/testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java @@ -11,7 +11,6 @@ import android.graphics.LinearGradient; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Shader.TileMode; -import android.graphics.SurfaceTexture; import android.hardware.HardwareBuffer; import android.media.Image; import android.media.ImageReader; @@ -36,7 +35,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import androidx.core.util.Supplier; -import io.flutter.view.TextureRegistry.SurfaceTextureEntry; +import io.flutter.view.TextureRegistry; import java.io.IOException; import java.nio.ByteBuffer; import java.util.Map; @@ -54,7 +53,7 @@ public class ExternalTextureFlutterActivity extends TestActivity { private final CountDownLatch firstFrameLatch = new CountDownLatch(2); private long textureId = 0; - private SurfaceTextureEntry surfaceTextureEntry; + private TextureRegistry.SurfaceProducer surfaceProducer; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { @@ -143,19 +142,18 @@ public class ExternalTextureFlutterActivity extends TestActivity { public void onPause() { surfaceViewRenderer.destroy(); flutterRenderer.destroy(); - surfaceTextureEntry.release(); + surfaceProducer.release(); super.onPause(); } @Override public void onFlutterUiDisplayed() { - surfaceTextureEntry = - Objects.requireNonNull(getFlutterEngine()).getRenderer().createSurfaceTexture(); - SurfaceTexture surfaceTexture = surfaceTextureEntry.surfaceTexture(); - surfaceTexture.setDefaultBufferSize(SURFACE_WIDTH, SURFACE_HEIGHT); - flutterRenderer.attach(new Surface(surfaceTexture), firstFrameLatch); + surfaceProducer = + Objects.requireNonNull(getFlutterEngine()).getRenderer().createSurfaceProducer(); + surfaceProducer.setSize(SURFACE_WIDTH, SURFACE_HEIGHT); + flutterRenderer.attach(surfaceProducer.getSurface(), firstFrameLatch); flutterRenderer.repaint(); - textureId = surfaceTextureEntry.id(); + textureId = surfaceProducer.id(); super.onFlutterUiDisplayed(); }