Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7e1c44b

Browse files
authored
Migrate Android scenario_app to the SurfaceProducer API (#50993)
Part of testing flutter/flutter#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.
1 parent 924d5db commit 7e1c44b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

testing/scenario_app/android/app/src/main/java/dev/flutter/scenarios/ExternalTextureFlutterActivity.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.graphics.Paint;
1212
import android.graphics.Rect;
1313
import android.graphics.Shader.TileMode;
14-
import android.graphics.SurfaceTexture;
1514
import android.hardware.HardwareBuffer;
1615
import android.media.Image;
1716
import android.media.ImageReader;
@@ -36,7 +35,7 @@
3635
import androidx.annotation.Nullable;
3736
import androidx.annotation.RequiresApi;
3837
import androidx.core.util.Supplier;
39-
import io.flutter.view.TextureRegistry.SurfaceTextureEntry;
38+
import io.flutter.view.TextureRegistry;
4039
import java.io.IOException;
4140
import java.nio.ByteBuffer;
4241
import java.util.Map;
@@ -54,7 +53,7 @@ public class ExternalTextureFlutterActivity extends TestActivity {
5453
private final CountDownLatch firstFrameLatch = new CountDownLatch(2);
5554

5655
private long textureId = 0;
57-
private SurfaceTextureEntry surfaceTextureEntry;
56+
private TextureRegistry.SurfaceProducer surfaceProducer;
5857

5958
@Override
6059
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -143,19 +142,18 @@ private MediaExtractor createMediaExtractor() {
143142
public void onPause() {
144143
surfaceViewRenderer.destroy();
145144
flutterRenderer.destroy();
146-
surfaceTextureEntry.release();
145+
surfaceProducer.release();
147146
super.onPause();
148147
}
149148

150149
@Override
151150
public void onFlutterUiDisplayed() {
152-
surfaceTextureEntry =
153-
Objects.requireNonNull(getFlutterEngine()).getRenderer().createSurfaceTexture();
154-
SurfaceTexture surfaceTexture = surfaceTextureEntry.surfaceTexture();
155-
surfaceTexture.setDefaultBufferSize(SURFACE_WIDTH, SURFACE_HEIGHT);
156-
flutterRenderer.attach(new Surface(surfaceTexture), firstFrameLatch);
151+
surfaceProducer =
152+
Objects.requireNonNull(getFlutterEngine()).getRenderer().createSurfaceProducer();
153+
surfaceProducer.setSize(SURFACE_WIDTH, SURFACE_HEIGHT);
154+
flutterRenderer.attach(surfaceProducer.getSurface(), firstFrameLatch);
157155
flutterRenderer.repaint();
158-
textureId = surfaceTextureEntry.id();
156+
textureId = surfaceProducer.id();
159157

160158
super.onFlutterUiDisplayed();
161159
}

0 commit comments

Comments
 (0)