diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/MatrixShaderProgramPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java similarity index 87% rename from libraries/effect/src/androidTest/java/androidx/media3/effect/MatrixShaderProgramPixelTest.java rename to libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java index a5b5999eff..ab31246b4c 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/MatrixShaderProgramPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultShaderProgramPixelTest.java @@ -42,7 +42,7 @@ import org.junit.Test; import org.junit.runner.RunWith; /** - * Pixel test for texture processing via {@link MatrixShaderProgram}. + * Pixel test for texture processing via {@link DefaultShaderProgram}. * *

Expected images are taken from an emulator, so tests on different emulators or physical * devices may fail. To test on other devices, please increase the {@link @@ -50,7 +50,7 @@ import org.junit.runner.RunWith; * bitmaps as recommended in {@link DefaultVideoFrameProcessorPixelTest}. */ @RunWith(AndroidJUnit4.class) -public final class MatrixShaderProgramPixelTest { +public final class DefaultShaderProgramPixelTest { public static final String ORIGINAL_PNG_ASSET_PATH = "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; public static final String TRANSLATE_RIGHT_PNG_ASSET_PATH = @@ -64,7 +64,7 @@ public final class MatrixShaderProgramPixelTest { private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; - private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; + private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private int inputTexId; private int inputWidth; private int inputHeight; @@ -88,8 +88,8 @@ public final class MatrixShaderProgramPixelTest { @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { - if (matrixShaderProgram != null) { - matrixShaderProgram.release(); + if (defaultShaderProgram != null) { + defaultShaderProgram.release(); } if (eglContext != null && eglDisplay != null) { GlUtil.destroyEglContext(eglDisplay, eglContext); @@ -101,11 +101,11 @@ public final class MatrixShaderProgramPixelTest { String testId = "drawFrame_noEdits"; Matrix identityMatrix = new Matrix(); MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix; - matrixShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false); - matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false); + defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); @@ -122,12 +122,12 @@ public final class MatrixShaderProgramPixelTest { translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); MatrixTransformation translateRightTransformation = (long presentationTimeUs) -> translateRightMatrix; - matrixShaderProgram = + defaultShaderProgram = translateRightTransformation.toGlShaderProgram(context, /* useHdr= */ false); - matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); @@ -143,11 +143,12 @@ public final class MatrixShaderProgramPixelTest { Matrix scaleNarrowMatrix = new Matrix(); scaleNarrowMatrix.postScale(.5f, 1.2f); MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix; - matrixShaderProgram = scaleNarrowTransformation.toGlShaderProgram(context, /* useHdr= */ false); - matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = + scaleNarrowTransformation.toGlShaderProgram(context, /* useHdr= */ false); + defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(SCALE_NARROW_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); @@ -163,11 +164,11 @@ public final class MatrixShaderProgramPixelTest { Matrix rotate90Matrix = new Matrix(); rotate90Matrix.postRotate(/* degrees= */ 90); MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix; - matrixShaderProgram = rotate90Transformation.toGlShaderProgram(context, /* useHdr= */ false); - matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = rotate90Transformation.toGlShaderProgram(context, /* useHdr= */ false); + defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ROTATE_90_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java index 5fbb74b2cc..d75568649b 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbAdjustmentPixelTest.java @@ -69,7 +69,7 @@ public final class RgbAdjustmentPixelTest { private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; - private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; + private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull EGLSurface placeholderEglSurface; private int inputTexId; private int inputWidth; @@ -100,8 +100,8 @@ public final class RgbAdjustmentPixelTest { @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { - if (matrixShaderProgram != null) { - matrixShaderProgram.release(); + if (defaultShaderProgram != null) { + defaultShaderProgram.release(); } GlUtil.destroyEglContext(eglDisplay, eglContext); } @@ -110,11 +110,11 @@ public final class RgbAdjustmentPixelTest { public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception { String testId = "drawFrame_identityMatrix"; RgbMatrix identityMatrix = new RgbAdjustment.Builder().build(); - matrixShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -129,13 +129,13 @@ public final class RgbAdjustmentPixelTest { String testId = "drawFrame_removeColors"; RgbMatrix removeColorMatrix = new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build(); - matrixShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = createArgb8888BitmapWithSolidColor( outputSize.getWidth(), outputSize.getHeight(), Color.BLACK); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -149,11 +149,11 @@ public final class RgbAdjustmentPixelTest { public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception { String testId = "drawFrame_redOnlyFilter"; RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build(); - matrixShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -167,11 +167,11 @@ public final class RgbAdjustmentPixelTest { public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception { String testId = "drawFrame_increaseRedChannel"; RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build(); - matrixShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(INCREASE_RED_CHANNEL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -186,11 +186,11 @@ public final class RgbAdjustmentPixelTest { String testId = "drawFrame_increaseBrightness"; RgbMatrix increaseBrightnessMatrix = new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build(); - matrixShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -206,18 +206,18 @@ public final class RgbAdjustmentPixelTest { RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); - matrixShaderProgram = - MatrixShaderProgram.create( + defaultShaderProgram = + DefaultShaderProgram.create( context, /* matrixTransformations= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(noRed, noGreen, noBlue), /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = createArgb8888BitmapWithSolidColor( outputSize.getWidth(), outputSize.getHeight(), Color.BLACK); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -232,16 +232,16 @@ public final class RgbAdjustmentPixelTest { String testId = "drawFrame_removeBlueAndGreenValuesInAChain"; RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); - matrixShaderProgram = - MatrixShaderProgram.create( + defaultShaderProgram = + DefaultShaderProgram.create( context, /* matrixTransformations= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(noGreen, noBlue), /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -258,16 +258,16 @@ public final class RgbAdjustmentPixelTest { RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build(); RgbMatrix scaleRedByInverseMatrix = new RgbAdjustment.Builder().setRedScale(1 / redScale).build(); - matrixShaderProgram = - MatrixShaderProgram.create( + defaultShaderProgram = + DefaultShaderProgram.create( context, /* matrixTransformations= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(scaleRedMatrix, scaleRedByInverseMatrix), /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java index 551330c9c5..77d4706180 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/RgbFilterPixelTest.java @@ -64,7 +64,7 @@ public final class RgbFilterPixelTest { private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLContext eglContext; - private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; + private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull EGLSurface placeholderEglSurface; private int inputTexId; private int inputWidth; @@ -95,8 +95,8 @@ public final class RgbFilterPixelTest { @After public void release() throws GlUtil.GlException, VideoFrameProcessingException { - if (matrixShaderProgram != null) { - matrixShaderProgram.release(); + if (defaultShaderProgram != null) { + defaultShaderProgram.release(); } GlUtil.destroyEglContext(eglDisplay, eglContext); } @@ -105,11 +105,11 @@ public final class RgbFilterPixelTest { public void drawFrame_grayscale_producesGrayscaleImage() throws Exception { String testId = "drawFrame_grayscale"; RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter(); - matrixShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); @@ -123,11 +123,11 @@ public final class RgbFilterPixelTest { public void drawFrame_inverted_producesInvertedFrame() throws Exception { String testId = "drawFrame_inverted"; RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter(); - matrixShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH); - matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); + defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/MatrixShaderProgram.java b/libraries/effect/src/main/java/androidx/media3/effect/DefaultShaderProgram.java similarity index 97% rename from libraries/effect/src/main/java/androidx/media3/effect/MatrixShaderProgram.java rename to libraries/effect/src/main/java/androidx/media3/effect/DefaultShaderProgram.java index 65735121d6..53b0c4235a 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/MatrixShaderProgram.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/DefaultShaderProgram.java @@ -52,7 +52,7 @@ import java.util.List; */ @UnstableApi @SuppressWarnings("FunctionalInterfaceClash") // b/228192298 -/* package */ final class MatrixShaderProgram extends SingleFrameGlShaderProgram +/* package */ final class DefaultShaderProgram extends SingleFrameGlShaderProgram implements ExternalShaderProgram { private static final String VERTEX_SHADER_TRANSFORMATION_PATH = @@ -146,7 +146,7 @@ import java.util.List; * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * OpenGL operation fails or is unsupported. */ - public static MatrixShaderProgram create( + public static DefaultShaderProgram create( Context context, List matrixTransformations, List rgbMatrices, @@ -157,7 +157,7 @@ import java.util.List; context, VERTEX_SHADER_TRANSFORMATION_PATH, FRAGMENT_SHADER_TRANSFORMATION_PATH); // No transfer functions needed, because input and output are both optical colors. - return new MatrixShaderProgram( + return new DefaultShaderProgram( glProgram, ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(rgbMatrices), @@ -188,7 +188,7 @@ import java.util.List; * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * OpenGL operation fails or is unsupported. */ - public static MatrixShaderProgram createWithInternalSampler( + public static DefaultShaderProgram createWithInternalSampler( Context context, List matrixTransformations, List rgbMatrices, @@ -197,7 +197,7 @@ import java.util.List; throws VideoFrameProcessingException { checkState( !ColorInfo.isTransferHdr(inputColorInfo), - "MatrixShaderProgram doesn't support HDR internal sampler input yet."); + "DefaultShaderProgram doesn't support HDR internal sampler input yet."); GlProgram glProgram = createGlProgram( context, @@ -232,7 +232,7 @@ import java.util.List; * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * OpenGL operation fails or is unsupported. */ - public static MatrixShaderProgram createWithExternalSampler( + public static DefaultShaderProgram createWithExternalSampler( Context context, List matrixTransformations, List rgbMatrices, @@ -275,7 +275,7 @@ import java.util.List; * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * OpenGL operation fails or is unsupported. */ - public static MatrixShaderProgram createApplyingOetf( + public static DefaultShaderProgram createApplyingOetf( Context context, List matrixTransformations, List rgbMatrices, @@ -303,7 +303,7 @@ import java.util.List; glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer); } - return new MatrixShaderProgram( + return new DefaultShaderProgram( glProgram, ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(rgbMatrices), @@ -311,7 +311,7 @@ import java.util.List; outputIsHdr); } - private static MatrixShaderProgram createWithSampler( + private static DefaultShaderProgram createWithSampler( GlProgram glProgram, List matrixTransformations, List rgbMatrices, @@ -355,7 +355,7 @@ import java.util.List; glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer); } - return new MatrixShaderProgram( + return new DefaultShaderProgram( glProgram, ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(rgbMatrices), @@ -375,7 +375,7 @@ import java.util.List; * @param useHdr Whether to process the input as an HDR signal. Using HDR requires the {@code * EXT_YUV_target} OpenGL extension. */ - private MatrixShaderProgram( + private DefaultShaderProgram( GlProgram glProgram, ImmutableList matrixTransformations, ImmutableList rgbMatrices, @@ -462,7 +462,7 @@ import java.util.List; /** * Sets the output {@link C.ColorTransfer}. * - *

This method must not be called on {@code MatrixShaderProgram} instances that output + *

This method must not be called on {@code DefaultShaderProgram} instances that output * {@linkplain C#COLOR_TRANSFER_LINEAR linear colors}. */ public void setOutputColorTransfer(@C.ColorTransfer int colorTransfer) { diff --git a/libraries/effect/src/main/java/androidx/media3/effect/DefaultVideoFrameProcessor.java b/libraries/effect/src/main/java/androidx/media3/effect/DefaultVideoFrameProcessor.java index f76a239fad..114ab77b2b 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/DefaultVideoFrameProcessor.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/DefaultVideoFrameProcessor.java @@ -231,14 +231,14 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { /** * Combines consecutive {@link GlMatrixTransformation} and {@link RgbMatrix} instances into a - * single {@link MatrixShaderProgram} and converts all other {@link GlEffect} instances to + * single {@link DefaultShaderProgram} and converts all other {@link GlEffect} instances to * separate {@link GlShaderProgram} instances. * *

All {@link Effect} instances must be {@link GlEffect} instances. * * @return A non-empty list of {@link GlShaderProgram} instances to apply in the given order. The * first is an {@link ExternalShaderProgram} and the last is a {@link - * FinalMatrixShaderProgramWrapper}. + * FinalShaderProgramWrapper}. */ private static ImmutableList getGlShaderProgramsForGlEffects( Context context, @@ -286,23 +286,23 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ImmutableList rgbMatrices = rgbMatrixListBuilder.build(); boolean isOutputTransferHdr = ColorInfo.isTransferHdr(outputColorInfo); if (!matrixTransformations.isEmpty() || !rgbMatrices.isEmpty() || sampleFromInputTexture) { - MatrixShaderProgram matrixShaderProgram; + DefaultShaderProgram defaultShaderProgram; if (sampleFromInputTexture) { if (isInputTextureExternal) { - matrixShaderProgram = - MatrixShaderProgram.createWithExternalSampler( + defaultShaderProgram = + DefaultShaderProgram.createWithExternalSampler( context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo); } else { - matrixShaderProgram = - MatrixShaderProgram.createWithInternalSampler( + defaultShaderProgram = + DefaultShaderProgram.createWithInternalSampler( context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo); } } else { - matrixShaderProgram = - MatrixShaderProgram.create( + defaultShaderProgram = + DefaultShaderProgram.create( context, matrixTransformations, rgbMatrices, isOutputTransferHdr); } - shaderProgramListBuilder.add(matrixShaderProgram); + shaderProgramListBuilder.add(defaultShaderProgram); matrixTransformationListBuilder = new ImmutableList.Builder<>(); rgbMatrixListBuilder = new ImmutableList.Builder<>(); sampleFromInputTexture = false; @@ -311,7 +311,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { } shaderProgramListBuilder.add( - new FinalMatrixShaderProgramWrapper( + new FinalShaderProgramWrapper( context, eglDisplay, eglContext, @@ -359,7 +359,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { private @MonotonicNonNull InternalTextureManager inputInternalTextureManager; private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager; private final boolean releaseFramesAutomatically; - private final FinalMatrixShaderProgramWrapper finalShaderProgramWrapper; + private final FinalShaderProgramWrapper finalShaderProgramWrapper; private final ImmutableList allShaderPrograms; /** @@ -386,7 +386,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { this.releaseFramesAutomatically = releaseFramesAutomatically; checkState(!shaderPrograms.isEmpty()); - checkState(getLast(shaderPrograms) instanceof FinalMatrixShaderProgramWrapper); + checkState(getLast(shaderPrograms) instanceof FinalShaderProgramWrapper); GlShaderProgram inputShaderProgram = shaderPrograms.get(0); @@ -402,7 +402,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { inputShaderProgram.setInputListener(inputInternalTextureManager); } - finalShaderProgramWrapper = (FinalMatrixShaderProgramWrapper) getLast(shaderPrograms); + finalShaderProgramWrapper = (FinalShaderProgramWrapper) getLast(shaderPrograms); allShaderPrograms = shaderPrograms; previousStreamOffsetUs = C.TIME_UNSET; } diff --git a/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixShaderProgramWrapper.java b/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java similarity index 88% rename from libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixShaderProgramWrapper.java rename to libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java index 1383a54c2e..321382151d 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/FinalMatrixShaderProgramWrapper.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java @@ -51,17 +51,17 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf; import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /** - * Wrapper around a {@link GlShaderProgram} that writes to the provided output surface and optional - * debug surface view. + * Wrapper around a {@link DefaultShaderProgram} that writes to the provided output surface and + * optional debug surface view. * - *

The wrapped {@link GlShaderProgram} applies the {@link GlMatrixTransformation} and {@link + *

The wrapped {@link DefaultShaderProgram} applies the {@link GlMatrixTransformation} and {@link * RgbMatrix} instances passed to the constructor, followed by any transformations needed to convert * the frames to the dimensions specified by the provided {@link SurfaceInfo}. * - *

This wrapper is used for the final {@link GlShaderProgram} instance in the chain of {@link - * GlShaderProgram} instances used by {@link VideoFrameProcessor}. + *

This wrapper is used for the final {@link DefaultShaderProgram} instance in the chain of + * {@link DefaultShaderProgram} instances used by {@link VideoFrameProcessor}. */ -/* package */ final class FinalMatrixShaderProgramWrapper implements ExternalShaderProgram { +/* package */ final class FinalShaderProgramWrapper implements ExternalShaderProgram { private static final String TAG = "FinalShaderWrapper"; @@ -84,7 +84,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; private int inputWidth; private int inputHeight; - @Nullable private MatrixShaderProgram matrixShaderProgram; + @Nullable private DefaultShaderProgram defaultShaderProgram; @Nullable private SurfaceViewWrapper debugSurfaceViewWrapper; private InputListener inputListener; private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation; @@ -100,7 +100,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @Nullable private EGLSurface outputEglSurface; - public FinalMatrixShaderProgramWrapper( + public FinalShaderProgramWrapper( Context context, EGLDisplay eglDisplay, EGLContext eglContext, @@ -197,8 +197,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; public void flush() { // Drops all frames that aren't released yet. availableFrames.clear(); - if (matrixShaderProgram != null) { - matrixShaderProgram.flush(); + if (defaultShaderProgram != null) { + defaultShaderProgram.flush(); } inputListener.onFlush(); inputListener.onReadyToAcceptInputFrame(); @@ -207,8 +207,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @Override @WorkerThread public synchronized void release() throws VideoFrameProcessingException { - if (matrixShaderProgram != null) { - matrixShaderProgram.release(); + if (defaultShaderProgram != null) { + defaultShaderProgram.release(); } try { GlUtil.destroyEglSurface(eglDisplay, outputEglSurface); @@ -226,8 +226,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; /* destPost= */ 0, /* length= */ textureTransformMatrix.length); - if (matrixShaderProgram != null) { - matrixShaderProgram.setTextureTransformMatrix(textureTransformMatrix); + if (defaultShaderProgram != null) { + defaultShaderProgram.setTextureTransformMatrix(textureTransformMatrix); } } @@ -296,7 +296,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; EGLSurface outputEglSurface = this.outputEglSurface; SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo; - MatrixShaderProgram matrixShaderProgram = this.matrixShaderProgram; + DefaultShaderProgram defaultShaderProgram = this.defaultShaderProgram; GlUtil.focusEglSurface( eglDisplay, @@ -305,7 +305,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; outputSurfaceInfo.width, outputSurfaceInfo.height); GlUtil.clearOutputFrame(); - matrixShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); + defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); EGLExt.eglPresentationTimeANDROID( eglDisplay, @@ -317,7 +317,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } @EnsuresNonNullIf( - expression = {"outputSurfaceInfo", "outputEglSurface", "matrixShaderProgram"}, + expression = {"outputSurfaceInfo", "outputEglSurface", "defaultShaderProgram"}, result = true) private synchronized boolean ensureConfigured(int inputWidth, int inputHeight) throws VideoFrameProcessingException, GlUtil.GlException { @@ -341,9 +341,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; } if (outputSurfaceInfo == null) { - if (matrixShaderProgram != null) { - matrixShaderProgram.release(); - matrixShaderProgram = null; + if (defaultShaderProgram != null) { + defaultShaderProgram.release(); + defaultShaderProgram = null; } GlUtil.destroyEglSurface(eglDisplay, outputEglSurface); outputEglSurface = null; @@ -373,13 +373,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; this.debugSurfaceView = debugSurfaceView; } - if (matrixShaderProgram != null && outputSizeOrRotationChanged) { - matrixShaderProgram.release(); - matrixShaderProgram = null; + if (defaultShaderProgram != null && outputSizeOrRotationChanged) { + defaultShaderProgram.release(); + defaultShaderProgram = null; outputSizeOrRotationChanged = false; } - if (matrixShaderProgram == null) { - matrixShaderProgram = createMatrixShaderProgramForOutputSurface(outputSurfaceInfo); + if (defaultShaderProgram == null) { + defaultShaderProgram = createDefaultShaderProgramForOutputSurface(outputSurfaceInfo); } this.outputSurfaceInfo = outputSurfaceInfo; @@ -387,7 +387,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; return true; } - private MatrixShaderProgram createMatrixShaderProgramForOutputSurface( + private DefaultShaderProgram createDefaultShaderProgramForOutputSurface( SurfaceInfo outputSurfaceInfo) throws VideoFrameProcessingException { ImmutableList.Builder matrixTransformationListBuilder = new ImmutableList.Builder().addAll(matrixTransformations); @@ -401,21 +401,21 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; Presentation.createForWidthAndHeight( outputSurfaceInfo.width, outputSurfaceInfo.height, Presentation.LAYOUT_SCALE_TO_FIT)); - MatrixShaderProgram matrixShaderProgram; + DefaultShaderProgram defaultShaderProgram; ImmutableList expandedMatrixTransformations = matrixTransformationListBuilder.build(); if (sampleFromInputTexture) { if (isInputTextureExternal) { - matrixShaderProgram = - MatrixShaderProgram.createWithExternalSampler( + defaultShaderProgram = + DefaultShaderProgram.createWithExternalSampler( context, expandedMatrixTransformations, rgbMatrices, inputColorInfo, outputColorInfo); } else { - matrixShaderProgram = - MatrixShaderProgram.createWithInternalSampler( + defaultShaderProgram = + DefaultShaderProgram.createWithInternalSampler( context, expandedMatrixTransformations, rgbMatrices, @@ -423,34 +423,34 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; outputColorInfo); } } else { - matrixShaderProgram = - MatrixShaderProgram.createApplyingOetf( + defaultShaderProgram = + DefaultShaderProgram.createApplyingOetf( context, expandedMatrixTransformations, rgbMatrices, outputColorInfo); } - matrixShaderProgram.setTextureTransformMatrix(textureTransformMatrix); - Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); + defaultShaderProgram.setTextureTransformMatrix(textureTransformMatrix); + Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight); checkState(outputSize.getWidth() == outputSurfaceInfo.width); checkState(outputSize.getHeight() == outputSurfaceInfo.height); - return matrixShaderProgram; + return defaultShaderProgram; } private void maybeRenderFrameToDebugSurface(TextureInfo inputTexture, long presentationTimeUs) { - if (debugSurfaceViewWrapper == null || this.matrixShaderProgram == null) { + if (debugSurfaceViewWrapper == null || this.defaultShaderProgram == null) { return; } - MatrixShaderProgram matrixShaderProgram = this.matrixShaderProgram; + DefaultShaderProgram defaultShaderProgram = this.defaultShaderProgram; try { debugSurfaceViewWrapper.maybeRenderToSurfaceView( () -> { GlUtil.clearOutputFrame(); @C.ColorTransfer - int configuredColorTransfer = matrixShaderProgram.getOutputColorTransfer(); - matrixShaderProgram.setOutputColorTransfer( + int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer(); + defaultShaderProgram.setOutputColorTransfer( checkNotNull(debugSurfaceViewWrapper).outputColorTransfer); - matrixShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); - matrixShaderProgram.setOutputColorTransfer(configuredColorTransfer); + defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); + defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer); }); } catch (VideoFrameProcessingException | GlUtil.GlException e) { Log.d(TAG, "Error rendering to debug preview", e); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/GlMatrixTransformation.java b/libraries/effect/src/main/java/androidx/media3/effect/GlMatrixTransformation.java index 6136405d8a..4946a44e70 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/GlMatrixTransformation.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/GlMatrixTransformation.java @@ -55,7 +55,7 @@ public interface GlMatrixTransformation extends GlEffect { @Override default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) throws VideoFrameProcessingException { - return MatrixShaderProgram.create( + return DefaultShaderProgram.create( context, /* matrixTransformations= */ ImmutableList.of(this), /* rgbMatrices= */ ImmutableList.of(), diff --git a/libraries/effect/src/main/java/androidx/media3/effect/RgbMatrix.java b/libraries/effect/src/main/java/androidx/media3/effect/RgbMatrix.java index de00e76601..6b4debcf96 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/RgbMatrix.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/RgbMatrix.java @@ -42,7 +42,7 @@ public interface RgbMatrix extends GlEffect { @Override default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) throws VideoFrameProcessingException { - return MatrixShaderProgram.create( + return DefaultShaderProgram.create( context, /* matrixTransformations= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(this), diff --git a/libraries/effect/src/test/java/androidx/media3/effect/ScaleAndRotateTransformationTest.java b/libraries/effect/src/test/java/androidx/media3/effect/ScaleAndRotateTransformationTest.java index c7253b218b..7192c2ee9e 100644 --- a/libraries/effect/src/test/java/androidx/media3/effect/ScaleAndRotateTransformationTest.java +++ b/libraries/effect/src/test/java/androidx/media3/effect/ScaleAndRotateTransformationTest.java @@ -25,7 +25,7 @@ import org.junit.runner.RunWith; /** * Unit tests for {@link ScaleAndRotateTransformation}. * - *

See {@code MatrixShaderProgramPixelTest} for pixel tests testing {@link MatrixShaderProgram} + *

See {@code DefaultShaderProgramPixelTest} for pixel tests testing {@link DefaultShaderProgram} * given a transformation matrix. */ @RunWith(AndroidJUnit4.class)