Commit e996d48b by hschlueter Committed by Ian Baker

Don't use API 26 SurfaceTexture constructor in frame processor tests.

After this change the test will use EGL_NO_SURFACE or a pixel buffer surface if using no surface is not supported.

PiperOrigin-RevId: 443113794
parent 34591976
...@@ -214,22 +214,47 @@ public final class GlUtil { ...@@ -214,22 +214,47 @@ public final class GlUtil {
} }
/** /**
* Creates and focuses a new {@link EGLSurface} wrapping a 1x1 pixel buffer. * Creates a new {@link EGLSurface} wrapping a pixel buffer.
* *
* @param eglContext The {@link EGLContext} to make current.
* @param eglDisplay The {@link EGLDisplay} to attach the surface to. * @param eglDisplay The {@link EGLDisplay} to attach the surface to.
* @param width The width of the pixel buffer.
* @param height The height of the pixel buffer.
*/ */
@RequiresApi(17) @RequiresApi(17)
public static void focusPlaceholderEglSurface(EGLContext eglContext, EGLDisplay eglDisplay) { private static EGLSurface createPbufferSurface(EGLDisplay eglDisplay, int width, int height) {
int[] pbufferAttributes = int[] pbufferAttributes =
new int[] { new int[] {
EGL14.EGL_WIDTH, /* width= */ 1, EGL14.EGL_WIDTH, width,
EGL14.EGL_HEIGHT, /* height= */ 1, EGL14.EGL_HEIGHT, height,
EGL14.EGL_NONE EGL14.EGL_NONE
}; };
EGLSurface eglSurface = return Api17.createEglPbufferSurface(
Api17.createEglPbufferSurface( eglDisplay, EGL_CONFIG_ATTRIBUTES_RGBA_8888, pbufferAttributes);
eglDisplay, EGL_CONFIG_ATTRIBUTES_RGBA_8888, pbufferAttributes); }
/**
* Returns a placeholder {@link EGLSurface} to use when reading and writing to the surface is not
* required.
*
* @param eglDisplay The {@link EGLDisplay} to attach the surface to.
* @return {@link EGL14#EGL_NO_SURFACE} if supported and a 1x1 pixel buffer surface otherwise.
*/
@RequiresApi(17)
public static EGLSurface createPlaceholderEglSurface(EGLDisplay eglDisplay) {
return isSurfacelessContextExtensionSupported()
? EGL14.EGL_NO_SURFACE
: createPbufferSurface(eglDisplay, /* width= */ 1, /* height= */ 1);
}
/**
* Creates and focuses a new {@link EGLSurface} wrapping a 1x1 pixel buffer.
*
* @param eglContext The {@link EGLContext} to make current.
* @param eglDisplay The {@link EGLDisplay} to attach the surface to.
*/
@RequiresApi(17)
public static void focusPlaceholderEglSurface(EGLContext eglContext, EGLDisplay eglDisplay) {
EGLSurface eglSurface = createPbufferSurface(eglDisplay, /* width= */ 1, /* height= */ 1);
focusEglSurface(eglDisplay, eglContext, eglSurface, /* width= */ 1, /* height= */ 1); focusEglSurface(eglDisplay, eglContext, eglSurface, /* width= */ 1, /* height= */ 1);
} }
......
...@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat; ...@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.SurfaceTexture;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
...@@ -70,15 +69,13 @@ public final class AdvancedFrameProcessorPixelTest { ...@@ -70,15 +69,13 @@ public final class AdvancedFrameProcessorPixelTest {
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
width = inputBitmap.getWidth(); width = inputBitmap.getWidth();
height = inputBitmap.getHeight(); height = inputBitmap.getHeight();
// This surface is needed for focussing a render target, but the tests don't write output to it. EGLSurface placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
// The frame processor's output is written to a framebuffer instead. GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, width, height);
EGLSurface eglSurface =
GlUtil.getEglSurface(eglDisplay, new SurfaceTexture(/* singleBufferMode= */ false));
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, width, height);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap);
outputTexId = GlUtil.createTexture(width, height); outputTexId = GlUtil.createTexture(width, height);
int frameBuffer = GlUtil.createFboForTexture(outputTexId); int frameBuffer = GlUtil.createFboForTexture(outputTexId);
GlUtil.focusFramebuffer(eglDisplay, eglContext, eglSurface, frameBuffer, width, height); GlUtil.focusFramebuffer(
eglDisplay, eglContext, placeholderEglSurface, frameBuffer, width, height);
} }
@After @After
......
...@@ -17,16 +17,15 @@ package com.google.android.exoplayer2.transformer; ...@@ -17,16 +17,15 @@ package com.google.android.exoplayer2.transformer;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.google.android.exoplayer2.transformer.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE; import static com.google.android.exoplayer2.transformer.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface; import android.opengl.EGLSurface;
import android.util.Size; import android.util.Size;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...@@ -71,7 +70,7 @@ public final class PresentationFrameProcessorPixelTest { ...@@ -71,7 +70,7 @@ public final class PresentationFrameProcessorPixelTest {
private final EGLDisplay eglDisplay = GlUtil.createEglDisplay(); private final EGLDisplay eglDisplay = GlUtil.createEglDisplay();
private final EGLContext eglContext = GlUtil.createEglContext(eglDisplay); private final EGLContext eglContext = GlUtil.createEglContext(eglDisplay);
private @MonotonicNonNull GlFrameProcessor presentationFrameProcessor; private @MonotonicNonNull GlFrameProcessor presentationFrameProcessor;
private @MonotonicNonNull EGLSurface eglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int outputTexId; private int outputTexId;
private int inputWidth; private int inputWidth;
...@@ -82,11 +81,8 @@ public final class PresentationFrameProcessorPixelTest { ...@@ -82,11 +81,8 @@ public final class PresentationFrameProcessorPixelTest {
Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap inputBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
inputWidth = inputBitmap.getWidth(); inputWidth = inputBitmap.getWidth();
inputHeight = inputBitmap.getHeight(); inputHeight = inputBitmap.getHeight();
// This surface is needed for focussing a render target, but the tests don't write output to it. placeholderEglSurface = GlUtil.createPlaceholderEglSurface(eglDisplay);
// The frame processor's output is written to a framebuffer instead. GlUtil.focusEglSurface(eglDisplay, eglContext, placeholderEglSurface, inputWidth, inputHeight);
eglSurface =
GlUtil.getEglSurface(eglDisplay, new SurfaceTexture(/* singleBufferMode= */ false));
GlUtil.focusEglSurface(eglDisplay, eglContext, eglSurface, inputWidth, inputHeight);
inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap); inputTexId = BitmapTestUtil.createGlTextureFromBitmap(inputBitmap);
} }
...@@ -356,7 +352,7 @@ public final class PresentationFrameProcessorPixelTest { ...@@ -356,7 +352,7 @@ public final class PresentationFrameProcessorPixelTest {
GlUtil.focusFramebuffer( GlUtil.focusFramebuffer(
eglDisplay, eglDisplay,
eglContext, eglContext,
Assertions.checkNotNull(eglSurface), checkNotNull(placeholderEglSurface),
frameBuffer, frameBuffer,
outputWidth, outputWidth,
outputHeight); outputHeight);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment