mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
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
This commit is contained in:
parent
f903e4a9f8
commit
6939464f91
3 changed files with 43 additions and 25 deletions
|
|
@ -214,6 +214,39 @@ public final class GlUtil {
|
||||||
EGL_WINDOW_SURFACE_ATTRIBUTES_BT2020_PQ);
|
EGL_WINDOW_SURFACE_ATTRIBUTES_BT2020_PQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link EGLSurface} wrapping a pixel buffer.
|
||||||
|
*
|
||||||
|
* @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)
|
||||||
|
private static EGLSurface createPbufferSurface(EGLDisplay eglDisplay, int width, int height) {
|
||||||
|
int[] pbufferAttributes =
|
||||||
|
new int[] {
|
||||||
|
EGL14.EGL_WIDTH, width,
|
||||||
|
EGL14.EGL_HEIGHT, height,
|
||||||
|
EGL14.EGL_NONE
|
||||||
|
};
|
||||||
|
return Api17.createEglPbufferSurface(
|
||||||
|
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.
|
* Creates and focuses a new {@link EGLSurface} wrapping a 1x1 pixel buffer.
|
||||||
*
|
*
|
||||||
|
|
@ -222,15 +255,7 @@ public final class GlUtil {
|
||||||
*/
|
*/
|
||||||
@RequiresApi(17)
|
@RequiresApi(17)
|
||||||
public static void focusPlaceholderEglSurface(EGLContext eglContext, EGLDisplay eglDisplay) {
|
public static void focusPlaceholderEglSurface(EGLContext eglContext, EGLDisplay eglDisplay) {
|
||||||
int[] pbufferAttributes =
|
EGLSurface eglSurface = createPbufferSurface(eglDisplay, /* width= */ 1, /* height= */ 1);
|
||||||
new int[] {
|
|
||||||
EGL14.EGL_WIDTH, /* width= */ 1,
|
|
||||||
EGL14.EGL_HEIGHT, /* height= */ 1,
|
|
||||||
EGL14.EGL_NONE
|
|
||||||
};
|
|
||||||
EGLSurface eglSurface =
|
|
||||||
Api17.createEglPbufferSurface(
|
|
||||||
eglDisplay, EGL_CONFIG_ATTRIBUTES_RGBA_8888, pbufferAttributes);
|
|
||||||
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;
|
||||||
|
|
||||||
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 {
|
||||||
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
|
||||||
|
|
|
||||||
|
|
@ -15,17 +15,16 @@
|
||||||
*/
|
*/
|
||||||
package androidx.media3.transformer;
|
package androidx.media3.transformer;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
import static androidx.media3.transformer.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
|
import static androidx.media3.transformer.BitmapTestUtil.MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE;
|
||||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||||
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.media3.common.util.Assertions;
|
|
||||||
import androidx.media3.common.util.GlUtil;
|
import androidx.media3.common.util.GlUtil;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -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 {
|
||||||
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 {
|
||||||
GlUtil.focusFramebuffer(
|
GlUtil.focusFramebuffer(
|
||||||
eglDisplay,
|
eglDisplay,
|
||||||
eglContext,
|
eglContext,
|
||||||
Assertions.checkNotNull(eglSurface),
|
checkNotNull(placeholderEglSurface),
|
||||||
frameBuffer,
|
frameBuffer,
|
||||||
outputWidth,
|
outputWidth,
|
||||||
outputHeight);
|
outputHeight);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue