Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Android scenario_app to the SurfaceProducer API #50993

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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;
Expand All @@ -36,7 +35,7 @@
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;
Expand All @@ -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) {
Expand Down Expand Up @@ -143,19 +142,18 @@ private MediaExtractor createMediaExtractor() {
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();
}
Expand Down