Alpha: Don't use deprecated SingleFrameGlShaderProgram interface.

PiperOrigin-RevId: 555990321
This commit is contained in:
huangdarwin 2023-08-11 16:58:39 +00:00 committed by Tianyi Feng
parent 1e2a5cd06a
commit 4ce83d88e5
2 changed files with 17 additions and 17 deletions

View File

@ -74,7 +74,7 @@ public final class AlphaScaleShaderProgramPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull AlphaScaleShaderProgram alphaScaleShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
@ -112,8 +112,8 @@ public final class AlphaScaleShaderProgramPixelTest {
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (defaultShaderProgram != null) { if (alphaScaleShaderProgram != null) {
defaultShaderProgram.release(); alphaScaleShaderProgram.release();
} }
GlUtil.destroyEglContext(eglDisplay, eglContext); GlUtil.destroyEglContext(eglDisplay, eglContext);
} }
@ -121,12 +121,12 @@ public final class AlphaScaleShaderProgramPixelTest {
@Test @Test
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void noOpAlpha_matchesGoldenFile() throws Exception { public void noOpAlpha_matchesGoldenFile() throws Exception {
defaultShaderProgram = new AlphaScale(1.0f).toGlShaderProgram(context, /* useHdr= */ false); alphaScaleShaderProgram = new AlphaScale(1.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = alphaScaleShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
maybeSaveTestBitmap(testId, /* bitmapLabel= */ "input", expectedBitmap, /* path= */ null); maybeSaveTestBitmap(testId, /* bitmapLabel= */ "input", expectedBitmap, /* path= */ null);
defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); alphaScaleShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -140,11 +140,11 @@ public final class AlphaScaleShaderProgramPixelTest {
@Test @Test
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void zeroAlpha_matchesGoldenFile() throws Exception { public void zeroAlpha_matchesGoldenFile() throws Exception {
defaultShaderProgram = new AlphaScale(0.0f).toGlShaderProgram(context, /* useHdr= */ false); alphaScaleShaderProgram = new AlphaScale(0.0f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = alphaScaleShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ZERO_ALPHA_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ZERO_ALPHA_PNG_ASSET_PATH);
defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); alphaScaleShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -158,11 +158,11 @@ public final class AlphaScaleShaderProgramPixelTest {
@Test @Test
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void decreaseAlpha_matchesGoldenFile() throws Exception { public void decreaseAlpha_matchesGoldenFile() throws Exception {
defaultShaderProgram = new AlphaScale(0.5f).toGlShaderProgram(context, /* useHdr= */ false); alphaScaleShaderProgram = new AlphaScale(0.5f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = alphaScaleShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(DECREASE_ALPHA_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(DECREASE_ALPHA_PNG_ASSET_PATH);
defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); alphaScaleShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -176,11 +176,11 @@ public final class AlphaScaleShaderProgramPixelTest {
@Test @Test
@RequiresNonNull("testId") @RequiresNonNull("testId")
public void increaseAlpha_matchesGoldenFile() throws Exception { public void increaseAlpha_matchesGoldenFile() throws Exception {
defaultShaderProgram = new AlphaScale(1.5f).toGlShaderProgram(context, /* useHdr= */ false); alphaScaleShaderProgram = new AlphaScale(1.5f).toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Size outputSize = alphaScaleShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(INCREASE_ALPHA_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INCREASE_ALPHA_PNG_ASSET_PATH);
defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); alphaScaleShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromFocusedGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -188,6 +188,6 @@ public final class AlphaScaleShaderProgramPixelTest {
maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual", actualBitmap, /* path= */ null); maybeSaveTestBitmap(testId, /* bitmapLabel= */ "actual", actualBitmap, /* path= */ null);
float averagePixelAbsoluteDifference = float averagePixelAbsoluteDifference =
getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId); getBitmapAveragePixelAbsoluteDifferenceArgb8888(expectedBitmap, actualBitmap, testId);
assertThat(averagePixelAbsoluteDifference).isAtMost(MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE); assertThat(averagePixelAbsoluteDifference).isAtMost(0);
} }
} }

View File

@ -40,7 +40,7 @@ public final class AlphaScale implements GlEffect {
} }
@Override @Override
public SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) public AlphaScaleShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new AlphaScaleShaderProgram(context, useHdr, alphaScale); return new AlphaScaleShaderProgram(context, useHdr, alphaScale);
} }