Re-Enable ExternalTexturesTest (flutter/engine#34118)
Use ImageFormat.PRIVATE since produced images are not read. Hint to downstream surface producers that the image will be sampled from on the GPU.
This commit is contained in:
@@ -14,14 +14,12 @@ import androidx.test.rule.ActivityTestRule;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
import dev.flutter.scenarios.ExternalTextureFlutterActivity;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@LargeTest
|
||||
@Ignore("Test fails with java.lang.UnsupportedOperationException")
|
||||
public class ExternalTextureTests {
|
||||
private static final int SURFACE_WIDTH = 192;
|
||||
private static final int SURFACE_HEIGHT = 256;
|
||||
@@ -42,7 +40,7 @@ public class ExternalTextureTests {
|
||||
|
||||
@Test
|
||||
public void testCanvasSurface() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "canvas");
|
||||
ScreenshotUtil.capture(
|
||||
activityRule.launchActivity(intent), "ExternalTextureTests_testCanvasSurface");
|
||||
@@ -51,7 +49,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
|
||||
public void testMediaSurface() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "media");
|
||||
ScreenshotUtil.capture(
|
||||
activityRule.launchActivity(intent), "ExternalTextureTests_testMediaSurface");
|
||||
@@ -60,7 +58,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
|
||||
public void testRotatedMediaSurface_90() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "media");
|
||||
intent.putExtra("rotation", 90);
|
||||
ScreenshotUtil.capture(
|
||||
@@ -70,7 +68,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
|
||||
public void testRotatedMediaSurface_180() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "media");
|
||||
intent.putExtra("rotation", 180);
|
||||
ScreenshotUtil.capture(
|
||||
@@ -80,7 +78,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.LOLLIPOP)
|
||||
public void testRotatedMediaSurface_270() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "media");
|
||||
intent.putExtra("rotation", 270);
|
||||
ScreenshotUtil.capture(
|
||||
@@ -90,7 +88,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
|
||||
public void testCroppedMediaSurface_bottomLeft() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "image");
|
||||
intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2));
|
||||
ScreenshotUtil.capture(
|
||||
@@ -101,7 +99,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
|
||||
public void testCroppedMediaSurface_topRight() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "image");
|
||||
intent.putExtra(
|
||||
"crop", new Rect(SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2, SURFACE_WIDTH, SURFACE_HEIGHT));
|
||||
@@ -113,7 +111,7 @@ public class ExternalTextureTests {
|
||||
@Test
|
||||
@SdkSuppress(minSdkVersion = VERSION_CODES.M)
|
||||
public void testCroppedRotatedMediaSurface_bottomLeft_90() throws Exception {
|
||||
intent.putExtra("scenario", "display_texture");
|
||||
intent.putExtra("scenario_name", "display_texture");
|
||||
intent.putExtra("surface_renderer", "image");
|
||||
intent.putExtra("crop", new Rect(0, 0, SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2));
|
||||
intent.putExtra("rotation", 90);
|
||||
|
||||
@@ -6,11 +6,13 @@ package dev.flutter.scenarios;
|
||||
|
||||
import android.content.res.AssetFileDescriptor;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.ImageFormat;
|
||||
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;
|
||||
import android.media.ImageWriter;
|
||||
@@ -91,7 +93,7 @@ public class ExternalTextureFlutterActivity extends TestActivity {
|
||||
super.waitUntilFlutterRendered();
|
||||
|
||||
try {
|
||||
firstFrameLatch.await();
|
||||
firstFrameLatch.await(10, java.util.concurrent.TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@@ -368,9 +370,23 @@ public class ExternalTextureFlutterActivity extends TestActivity {
|
||||
@Override
|
||||
public void attach(Surface surface, CountDownLatch onFirstFrame) {
|
||||
this.onFirstFrame = onFirstFrame;
|
||||
writer = ImageWriter.newInstance(surface, 3);
|
||||
reader = ImageReader.newInstance(SURFACE_WIDTH, SURFACE_HEIGHT, writer.getFormat(), 2);
|
||||
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.Q) {
|
||||
// On Android Q+, use PRIVATE image format.
|
||||
// Also let the frame producer know the images will
|
||||
// be sampled from by the GPU.
|
||||
writer = ImageWriter.newInstance(surface, 3, ImageFormat.PRIVATE);
|
||||
reader =
|
||||
ImageReader.newInstance(
|
||||
SURFACE_WIDTH,
|
||||
SURFACE_HEIGHT,
|
||||
ImageFormat.PRIVATE,
|
||||
2,
|
||||
HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE);
|
||||
} else {
|
||||
// Before Android Q, this will change the format of the surface to match the images.
|
||||
writer = ImageWriter.newInstance(surface, 3);
|
||||
reader = ImageReader.newInstance(SURFACE_WIDTH, SURFACE_HEIGHT, writer.getFormat(), 2);
|
||||
}
|
||||
inner.attach(reader.getSurface(), null);
|
||||
|
||||
handlerThread = new HandlerThread("image reader/writer thread");
|
||||
@@ -409,7 +425,8 @@ public class ExternalTextureFlutterActivity extends TestActivity {
|
||||
// If the output surface disconnects, this method will be interrupted with an
|
||||
// IllegalStateException.
|
||||
// Simply log and return.
|
||||
Log.i(TAG, "Surface disconnected from ImageWriter");
|
||||
Log.i(TAG, "Surface disconnected from ImageWriter", e);
|
||||
image.close();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user