Effect: Rename to DefaultShaderProgram.

Rename:
* MatrixShaderProgram to DefaultShaderProgram, and
* FinalMatrixShaderProgramWrapper to FinalShaderProgramWrapper.
PiperOrigin-RevId: 510498547
This commit is contained in:
huangdarwin 2023-02-17 20:42:53 +00:00 committed by tonihei
parent 84acfe7867
commit 92138fc83c
9 changed files with 128 additions and 127 deletions

View File

@ -42,7 +42,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
/** /**
* Pixel test for texture processing via {@link MatrixShaderProgram}. * Pixel test for texture processing via {@link DefaultShaderProgram}.
* *
* <p>Expected images are taken from an emulator, so tests on different emulators or physical * <p>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 * 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}. * bitmaps as recommended in {@link DefaultVideoFrameProcessorPixelTest}.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
public final class MatrixShaderProgramPixelTest { public final class DefaultShaderProgramPixelTest {
public static final String ORIGINAL_PNG_ASSET_PATH = public static final String ORIGINAL_PNG_ASSET_PATH =
"media/bitmap/sample_mp4_first_frame/electrical_colors/original.png"; "media/bitmap/sample_mp4_first_frame/electrical_colors/original.png";
public static final String TRANSLATE_RIGHT_PNG_ASSET_PATH = public static final String TRANSLATE_RIGHT_PNG_ASSET_PATH =
@ -64,7 +64,7 @@ public final class MatrixShaderProgramPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;
@ -88,8 +88,8 @@ public final class MatrixShaderProgramPixelTest {
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.release(); defaultShaderProgram.release();
} }
if (eglContext != null && eglDisplay != null) { if (eglContext != null && eglDisplay != null) {
GlUtil.destroyEglContext(eglDisplay, eglContext); GlUtil.destroyEglContext(eglDisplay, eglContext);
@ -101,11 +101,11 @@ public final class MatrixShaderProgramPixelTest {
String testId = "drawFrame_noEdits"; String testId = "drawFrame_noEdits";
Matrix identityMatrix = new Matrix(); Matrix identityMatrix = new Matrix();
MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix; MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix;
matrixShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = noEditsTransformation.toGlShaderProgram(context, /* useHdr= */ false);
matrixShaderProgram.configure(inputWidth, inputHeight); defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight);
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -122,12 +122,12 @@ public final class MatrixShaderProgramPixelTest {
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
MatrixTransformation translateRightTransformation = MatrixTransformation translateRightTransformation =
(long presentationTimeUs) -> translateRightMatrix; (long presentationTimeUs) -> translateRightMatrix;
matrixShaderProgram = defaultShaderProgram =
translateRightTransformation.toGlShaderProgram(context, /* useHdr= */ false); translateRightTransformation.toGlShaderProgram(context, /* useHdr= */ false);
matrixShaderProgram.configure(inputWidth, inputHeight); defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight);
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -143,11 +143,12 @@ public final class MatrixShaderProgramPixelTest {
Matrix scaleNarrowMatrix = new Matrix(); Matrix scaleNarrowMatrix = new Matrix();
scaleNarrowMatrix.postScale(.5f, 1.2f); scaleNarrowMatrix.postScale(.5f, 1.2f);
MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix; MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix;
matrixShaderProgram = scaleNarrowTransformation.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram =
matrixShaderProgram.configure(inputWidth, inputHeight); scaleNarrowTransformation.toGlShaderProgram(context, /* useHdr= */ false);
defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(SCALE_NARROW_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(SCALE_NARROW_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight);
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);
@ -163,11 +164,11 @@ public final class MatrixShaderProgramPixelTest {
Matrix rotate90Matrix = new Matrix(); Matrix rotate90Matrix = new Matrix();
rotate90Matrix.postRotate(/* degrees= */ 90); rotate90Matrix.postRotate(/* degrees= */ 90);
MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix; MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix;
matrixShaderProgram = rotate90Transformation.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = rotate90Transformation.toGlShaderProgram(context, /* useHdr= */ false);
matrixShaderProgram.configure(inputWidth, inputHeight); defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ROTATE_90_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ROTATE_90_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight); Bitmap actualBitmap = createArgb8888BitmapFromCurrentGlFramebuffer(inputWidth, inputHeight);
maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap); maybeSaveTestBitmapToCacheDirectory(testId, /* bitmapLabel= */ "actual", actualBitmap);

View File

@ -69,7 +69,7 @@ public final class RgbAdjustmentPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
@ -100,8 +100,8 @@ public final class RgbAdjustmentPixelTest {
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.release(); defaultShaderProgram.release();
} }
GlUtil.destroyEglContext(eglDisplay, eglContext); GlUtil.destroyEglContext(eglDisplay, eglContext);
} }
@ -110,11 +110,11 @@ public final class RgbAdjustmentPixelTest {
public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception { public void drawFrame_identityMatrix_leavesFrameUnchanged() throws Exception {
String testId = "drawFrame_identityMatrix"; String testId = "drawFrame_identityMatrix";
RgbMatrix identityMatrix = new RgbAdjustment.Builder().build(); RgbMatrix identityMatrix = new RgbAdjustment.Builder().build();
matrixShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = identityMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -129,13 +129,13 @@ public final class RgbAdjustmentPixelTest {
String testId = "drawFrame_removeColors"; String testId = "drawFrame_removeColors";
RgbMatrix removeColorMatrix = RgbMatrix removeColorMatrix =
new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build(); new RgbAdjustment.Builder().setRedScale(0).setGreenScale(0).setBlueScale(0).build();
matrixShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = removeColorMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = Bitmap expectedBitmap =
createArgb8888BitmapWithSolidColor( createArgb8888BitmapWithSolidColor(
outputSize.getWidth(), outputSize.getHeight(), Color.BLACK); outputSize.getWidth(), outputSize.getHeight(), Color.BLACK);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -149,11 +149,11 @@ public final class RgbAdjustmentPixelTest {
public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception { public void drawFrame_redOnlyFilter_removeBlueAndGreenValues() throws Exception {
String testId = "drawFrame_redOnlyFilter"; String testId = "drawFrame_redOnlyFilter";
RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build(); RgbMatrix redOnlyMatrix = new RgbAdjustment.Builder().setBlueScale(0).setGreenScale(0).build();
matrixShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = redOnlyMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -167,11 +167,11 @@ public final class RgbAdjustmentPixelTest {
public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception { public void drawFrame_increaseRedChannel_producesBrighterAndRedderFrame() throws Exception {
String testId = "drawFrame_increaseRedChannel"; String testId = "drawFrame_increaseRedChannel";
RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build(); RgbMatrix increaseRedMatrix = new RgbAdjustment.Builder().setRedScale(5).build();
matrixShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = increaseRedMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(INCREASE_RED_CHANNEL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INCREASE_RED_CHANNEL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -186,11 +186,11 @@ public final class RgbAdjustmentPixelTest {
String testId = "drawFrame_increaseBrightness"; String testId = "drawFrame_increaseBrightness";
RgbMatrix increaseBrightnessMatrix = RgbMatrix increaseBrightnessMatrix =
new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build(); new RgbAdjustment.Builder().setRedScale(5).setGreenScale(5).setBlueScale(5).build();
matrixShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = increaseBrightnessMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INCREASE_BRIGHTNESS_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -206,18 +206,18 @@ public final class RgbAdjustmentPixelTest {
RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build(); RgbMatrix noRed = new RgbAdjustment.Builder().setRedScale(0).build();
RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build();
RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build();
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.create( DefaultShaderProgram.create(
context, context,
/* matrixTransformations= */ ImmutableList.of(), /* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(noRed, noGreen, noBlue), /* rgbMatrices= */ ImmutableList.of(noRed, noGreen, noBlue),
/* useHdr= */ false); /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = Bitmap expectedBitmap =
createArgb8888BitmapWithSolidColor( createArgb8888BitmapWithSolidColor(
outputSize.getWidth(), outputSize.getHeight(), Color.BLACK); outputSize.getWidth(), outputSize.getHeight(), Color.BLACK);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -232,16 +232,16 @@ public final class RgbAdjustmentPixelTest {
String testId = "drawFrame_removeBlueAndGreenValuesInAChain"; String testId = "drawFrame_removeBlueAndGreenValuesInAChain";
RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build(); RgbMatrix noGreen = new RgbAdjustment.Builder().setGreenScale(0).build();
RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build(); RgbMatrix noBlue = new RgbAdjustment.Builder().setBlueScale(0).build();
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.create( DefaultShaderProgram.create(
context, context,
/* matrixTransformations= */ ImmutableList.of(), /* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(noGreen, noBlue), /* rgbMatrices= */ ImmutableList.of(noGreen, noBlue),
/* useHdr= */ false); /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ONLY_RED_CHANNEL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -258,16 +258,16 @@ public final class RgbAdjustmentPixelTest {
RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build(); RgbMatrix scaleRedMatrix = new RgbAdjustment.Builder().setRedScale(redScale).build();
RgbMatrix scaleRedByInverseMatrix = RgbMatrix scaleRedByInverseMatrix =
new RgbAdjustment.Builder().setRedScale(1 / redScale).build(); new RgbAdjustment.Builder().setRedScale(1 / redScale).build();
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.create( DefaultShaderProgram.create(
context, context,
/* matrixTransformations= */ ImmutableList.of(), /* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(scaleRedMatrix, scaleRedByInverseMatrix), /* rgbMatrices= */ ImmutableList.of(scaleRedMatrix, scaleRedByInverseMatrix),
/* useHdr= */ false); /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(ORIGINAL_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

View File

@ -64,7 +64,7 @@ public final class RgbFilterPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram matrixShaderProgram; private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
@ -95,8 +95,8 @@ public final class RgbFilterPixelTest {
@After @After
public void release() throws GlUtil.GlException, VideoFrameProcessingException { public void release() throws GlUtil.GlException, VideoFrameProcessingException {
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.release(); defaultShaderProgram.release();
} }
GlUtil.destroyEglContext(eglDisplay, eglContext); GlUtil.destroyEglContext(eglDisplay, eglContext);
} }
@ -105,11 +105,11 @@ public final class RgbFilterPixelTest {
public void drawFrame_grayscale_producesGrayscaleImage() throws Exception { public void drawFrame_grayscale_producesGrayscaleImage() throws Exception {
String testId = "drawFrame_grayscale"; String testId = "drawFrame_grayscale";
RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter(); RgbMatrix grayscaleMatrix = RgbFilter.createGrayscaleFilter();
matrixShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = grayscaleMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(GRAYSCALE_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());
@ -123,11 +123,11 @@ public final class RgbFilterPixelTest {
public void drawFrame_inverted_producesInvertedFrame() throws Exception { public void drawFrame_inverted_producesInvertedFrame() throws Exception {
String testId = "drawFrame_inverted"; String testId = "drawFrame_inverted";
RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter(); RgbMatrix invertedMatrix = RgbFilter.createInvertedFilter();
matrixShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false); defaultShaderProgram = invertedMatrix.toGlShaderProgram(context, /* useHdr= */ false);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH); Bitmap expectedBitmap = readBitmap(INVERT_PNG_ASSET_PATH);
matrixShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0); defaultShaderProgram.drawFrame(inputTexId, /* presentationTimeUs= */ 0);
Bitmap actualBitmap = Bitmap actualBitmap =
createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight()); createArgb8888BitmapFromCurrentGlFramebuffer(outputSize.getWidth(), outputSize.getHeight());

View File

@ -52,7 +52,7 @@ import java.util.List;
*/ */
@UnstableApi @UnstableApi
@SuppressWarnings("FunctionalInterfaceClash") // b/228192298 @SuppressWarnings("FunctionalInterfaceClash") // b/228192298
/* package */ final class MatrixShaderProgram extends SingleFrameGlShaderProgram /* package */ final class DefaultShaderProgram extends SingleFrameGlShaderProgram
implements ExternalShaderProgram { implements ExternalShaderProgram {
private static final String VERTEX_SHADER_TRANSFORMATION_PATH = 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 * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an
* OpenGL operation fails or is unsupported. * OpenGL operation fails or is unsupported.
*/ */
public static MatrixShaderProgram create( public static DefaultShaderProgram create(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations, List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices, List<RgbMatrix> rgbMatrices,
@ -157,7 +157,7 @@ import java.util.List;
context, VERTEX_SHADER_TRANSFORMATION_PATH, FRAGMENT_SHADER_TRANSFORMATION_PATH); context, VERTEX_SHADER_TRANSFORMATION_PATH, FRAGMENT_SHADER_TRANSFORMATION_PATH);
// No transfer functions needed, because input and output are both optical colors. // No transfer functions needed, because input and output are both optical colors.
return new MatrixShaderProgram( return new DefaultShaderProgram(
glProgram, glProgram,
ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(matrixTransformations),
ImmutableList.copyOf(rgbMatrices), ImmutableList.copyOf(rgbMatrices),
@ -188,7 +188,7 @@ import java.util.List;
* @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an
* OpenGL operation fails or is unsupported. * OpenGL operation fails or is unsupported.
*/ */
public static MatrixShaderProgram createWithInternalSampler( public static DefaultShaderProgram createWithInternalSampler(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations, List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices, List<RgbMatrix> rgbMatrices,
@ -197,7 +197,7 @@ import java.util.List;
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
checkState( checkState(
!ColorInfo.isTransferHdr(inputColorInfo), !ColorInfo.isTransferHdr(inputColorInfo),
"MatrixShaderProgram doesn't support HDR internal sampler input yet."); "DefaultShaderProgram doesn't support HDR internal sampler input yet.");
GlProgram glProgram = GlProgram glProgram =
createGlProgram( createGlProgram(
context, context,
@ -232,7 +232,7 @@ import java.util.List;
* @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an
* OpenGL operation fails or is unsupported. * OpenGL operation fails or is unsupported.
*/ */
public static MatrixShaderProgram createWithExternalSampler( public static DefaultShaderProgram createWithExternalSampler(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations, List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices, List<RgbMatrix> rgbMatrices,
@ -275,7 +275,7 @@ import java.util.List;
* @throws VideoFrameProcessingException If a problem occurs while reading shader files or an * @throws VideoFrameProcessingException If a problem occurs while reading shader files or an
* OpenGL operation fails or is unsupported. * OpenGL operation fails or is unsupported.
*/ */
public static MatrixShaderProgram createApplyingOetf( public static DefaultShaderProgram createApplyingOetf(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations, List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices, List<RgbMatrix> rgbMatrices,
@ -303,7 +303,7 @@ import java.util.List;
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer); glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
} }
return new MatrixShaderProgram( return new DefaultShaderProgram(
glProgram, glProgram,
ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(matrixTransformations),
ImmutableList.copyOf(rgbMatrices), ImmutableList.copyOf(rgbMatrices),
@ -311,7 +311,7 @@ import java.util.List;
outputIsHdr); outputIsHdr);
} }
private static MatrixShaderProgram createWithSampler( private static DefaultShaderProgram createWithSampler(
GlProgram glProgram, GlProgram glProgram,
List<GlMatrixTransformation> matrixTransformations, List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices, List<RgbMatrix> rgbMatrices,
@ -355,7 +355,7 @@ import java.util.List;
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer); glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
} }
return new MatrixShaderProgram( return new DefaultShaderProgram(
glProgram, glProgram,
ImmutableList.copyOf(matrixTransformations), ImmutableList.copyOf(matrixTransformations),
ImmutableList.copyOf(rgbMatrices), 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 * @param useHdr Whether to process the input as an HDR signal. Using HDR requires the {@code
* EXT_YUV_target} OpenGL extension. * EXT_YUV_target} OpenGL extension.
*/ */
private MatrixShaderProgram( private DefaultShaderProgram(
GlProgram glProgram, GlProgram glProgram,
ImmutableList<GlMatrixTransformation> matrixTransformations, ImmutableList<GlMatrixTransformation> matrixTransformations,
ImmutableList<RgbMatrix> rgbMatrices, ImmutableList<RgbMatrix> rgbMatrices,
@ -462,7 +462,7 @@ import java.util.List;
/** /**
* Sets the output {@link C.ColorTransfer}. * Sets the output {@link C.ColorTransfer}.
* *
* <p>This method must not be called on {@code MatrixShaderProgram} instances that output * <p>This method must not be called on {@code DefaultShaderProgram} instances that output
* {@linkplain C#COLOR_TRANSFER_LINEAR linear colors}. * {@linkplain C#COLOR_TRANSFER_LINEAR linear colors}.
*/ */
public void setOutputColorTransfer(@C.ColorTransfer int colorTransfer) { public void setOutputColorTransfer(@C.ColorTransfer int colorTransfer) {

View File

@ -231,14 +231,14 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
/** /**
* Combines consecutive {@link GlMatrixTransformation} and {@link RgbMatrix} instances into a * 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. * separate {@link GlShaderProgram} instances.
* *
* <p>All {@link Effect} instances must be {@link GlEffect} instances. * <p>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 * @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 * first is an {@link ExternalShaderProgram} and the last is a {@link
* FinalMatrixShaderProgramWrapper}. * FinalShaderProgramWrapper}.
*/ */
private static ImmutableList<GlShaderProgram> getGlShaderProgramsForGlEffects( private static ImmutableList<GlShaderProgram> getGlShaderProgramsForGlEffects(
Context context, Context context,
@ -286,23 +286,23 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
ImmutableList<RgbMatrix> rgbMatrices = rgbMatrixListBuilder.build(); ImmutableList<RgbMatrix> rgbMatrices = rgbMatrixListBuilder.build();
boolean isOutputTransferHdr = ColorInfo.isTransferHdr(outputColorInfo); boolean isOutputTransferHdr = ColorInfo.isTransferHdr(outputColorInfo);
if (!matrixTransformations.isEmpty() || !rgbMatrices.isEmpty() || sampleFromInputTexture) { if (!matrixTransformations.isEmpty() || !rgbMatrices.isEmpty() || sampleFromInputTexture) {
MatrixShaderProgram matrixShaderProgram; DefaultShaderProgram defaultShaderProgram;
if (sampleFromInputTexture) { if (sampleFromInputTexture) {
if (isInputTextureExternal) { if (isInputTextureExternal) {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.createWithExternalSampler( DefaultShaderProgram.createWithExternalSampler(
context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo); context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo);
} else { } else {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.createWithInternalSampler( DefaultShaderProgram.createWithInternalSampler(
context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo); context, matrixTransformations, rgbMatrices, inputColorInfo, linearColorInfo);
} }
} else { } else {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.create( DefaultShaderProgram.create(
context, matrixTransformations, rgbMatrices, isOutputTransferHdr); context, matrixTransformations, rgbMatrices, isOutputTransferHdr);
} }
shaderProgramListBuilder.add(matrixShaderProgram); shaderProgramListBuilder.add(defaultShaderProgram);
matrixTransformationListBuilder = new ImmutableList.Builder<>(); matrixTransformationListBuilder = new ImmutableList.Builder<>();
rgbMatrixListBuilder = new ImmutableList.Builder<>(); rgbMatrixListBuilder = new ImmutableList.Builder<>();
sampleFromInputTexture = false; sampleFromInputTexture = false;
@ -311,7 +311,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
} }
shaderProgramListBuilder.add( shaderProgramListBuilder.add(
new FinalMatrixShaderProgramWrapper( new FinalShaderProgramWrapper(
context, context,
eglDisplay, eglDisplay,
eglContext, eglContext,
@ -359,7 +359,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
private @MonotonicNonNull InternalTextureManager inputInternalTextureManager; private @MonotonicNonNull InternalTextureManager inputInternalTextureManager;
private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager; private @MonotonicNonNull ExternalTextureManager inputExternalTextureManager;
private final boolean releaseFramesAutomatically; private final boolean releaseFramesAutomatically;
private final FinalMatrixShaderProgramWrapper finalShaderProgramWrapper; private final FinalShaderProgramWrapper finalShaderProgramWrapper;
private final ImmutableList<GlShaderProgram> allShaderPrograms; private final ImmutableList<GlShaderProgram> allShaderPrograms;
/** /**
@ -386,7 +386,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
this.releaseFramesAutomatically = releaseFramesAutomatically; this.releaseFramesAutomatically = releaseFramesAutomatically;
checkState(!shaderPrograms.isEmpty()); checkState(!shaderPrograms.isEmpty());
checkState(getLast(shaderPrograms) instanceof FinalMatrixShaderProgramWrapper); checkState(getLast(shaderPrograms) instanceof FinalShaderProgramWrapper);
GlShaderProgram inputShaderProgram = shaderPrograms.get(0); GlShaderProgram inputShaderProgram = shaderPrograms.get(0);
@ -402,7 +402,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
inputShaderProgram.setInputListener(inputInternalTextureManager); inputShaderProgram.setInputListener(inputInternalTextureManager);
} }
finalShaderProgramWrapper = (FinalMatrixShaderProgramWrapper) getLast(shaderPrograms); finalShaderProgramWrapper = (FinalShaderProgramWrapper) getLast(shaderPrograms);
allShaderPrograms = shaderPrograms; allShaderPrograms = shaderPrograms;
previousStreamOffsetUs = C.TIME_UNSET; previousStreamOffsetUs = C.TIME_UNSET;
} }

View File

@ -51,17 +51,17 @@ import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* Wrapper around a {@link GlShaderProgram} that writes to the provided output surface and optional * Wrapper around a {@link DefaultShaderProgram} that writes to the provided output surface and
* debug surface view. * optional debug surface view.
* *
* <p>The wrapped {@link GlShaderProgram} applies the {@link GlMatrixTransformation} and {@link * <p>The wrapped {@link DefaultShaderProgram} applies the {@link GlMatrixTransformation} and {@link
* RgbMatrix} instances passed to the constructor, followed by any transformations needed to convert * RgbMatrix} instances passed to the constructor, followed by any transformations needed to convert
* the frames to the dimensions specified by the provided {@link SurfaceInfo}. * the frames to the dimensions specified by the provided {@link SurfaceInfo}.
* *
* <p>This wrapper is used for the final {@link GlShaderProgram} instance in the chain of {@link * <p>This wrapper is used for the final {@link DefaultShaderProgram} instance in the chain of
* GlShaderProgram} instances used by {@link VideoFrameProcessor}. * {@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"; private static final String TAG = "FinalShaderWrapper";
@ -84,7 +84,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;
@Nullable private MatrixShaderProgram matrixShaderProgram; @Nullable private DefaultShaderProgram defaultShaderProgram;
@Nullable private SurfaceViewWrapper debugSurfaceViewWrapper; @Nullable private SurfaceViewWrapper debugSurfaceViewWrapper;
private InputListener inputListener; private InputListener inputListener;
private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation; private @MonotonicNonNull Size outputSizeBeforeSurfaceTransformation;
@ -100,7 +100,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable @Nullable
private EGLSurface outputEglSurface; private EGLSurface outputEglSurface;
public FinalMatrixShaderProgramWrapper( public FinalShaderProgramWrapper(
Context context, Context context,
EGLDisplay eglDisplay, EGLDisplay eglDisplay,
EGLContext eglContext, EGLContext eglContext,
@ -197,8 +197,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public void flush() { public void flush() {
// Drops all frames that aren't released yet. // Drops all frames that aren't released yet.
availableFrames.clear(); availableFrames.clear();
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.flush(); defaultShaderProgram.flush();
} }
inputListener.onFlush(); inputListener.onFlush();
inputListener.onReadyToAcceptInputFrame(); inputListener.onReadyToAcceptInputFrame();
@ -207,8 +207,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
@WorkerThread @WorkerThread
public synchronized void release() throws VideoFrameProcessingException { public synchronized void release() throws VideoFrameProcessingException {
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.release(); defaultShaderProgram.release();
} }
try { try {
GlUtil.destroyEglSurface(eglDisplay, outputEglSurface); GlUtil.destroyEglSurface(eglDisplay, outputEglSurface);
@ -226,8 +226,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/* destPost= */ 0, /* destPost= */ 0,
/* length= */ textureTransformMatrix.length); /* length= */ textureTransformMatrix.length);
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.setTextureTransformMatrix(textureTransformMatrix); defaultShaderProgram.setTextureTransformMatrix(textureTransformMatrix);
} }
} }
@ -296,7 +296,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
EGLSurface outputEglSurface = this.outputEglSurface; EGLSurface outputEglSurface = this.outputEglSurface;
SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo; SurfaceInfo outputSurfaceInfo = this.outputSurfaceInfo;
MatrixShaderProgram matrixShaderProgram = this.matrixShaderProgram; DefaultShaderProgram defaultShaderProgram = this.defaultShaderProgram;
GlUtil.focusEglSurface( GlUtil.focusEglSurface(
eglDisplay, eglDisplay,
@ -305,7 +305,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputSurfaceInfo.width, outputSurfaceInfo.width,
outputSurfaceInfo.height); outputSurfaceInfo.height);
GlUtil.clearOutputFrame(); GlUtil.clearOutputFrame();
matrixShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs);
EGLExt.eglPresentationTimeANDROID( EGLExt.eglPresentationTimeANDROID(
eglDisplay, eglDisplay,
@ -317,7 +317,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
@EnsuresNonNullIf( @EnsuresNonNullIf(
expression = {"outputSurfaceInfo", "outputEglSurface", "matrixShaderProgram"}, expression = {"outputSurfaceInfo", "outputEglSurface", "defaultShaderProgram"},
result = true) result = true)
private synchronized boolean ensureConfigured(int inputWidth, int inputHeight) private synchronized boolean ensureConfigured(int inputWidth, int inputHeight)
throws VideoFrameProcessingException, GlUtil.GlException { throws VideoFrameProcessingException, GlUtil.GlException {
@ -341,9 +341,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
if (outputSurfaceInfo == null) { if (outputSurfaceInfo == null) {
if (matrixShaderProgram != null) { if (defaultShaderProgram != null) {
matrixShaderProgram.release(); defaultShaderProgram.release();
matrixShaderProgram = null; defaultShaderProgram = null;
} }
GlUtil.destroyEglSurface(eglDisplay, outputEglSurface); GlUtil.destroyEglSurface(eglDisplay, outputEglSurface);
outputEglSurface = null; outputEglSurface = null;
@ -373,13 +373,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
this.debugSurfaceView = debugSurfaceView; this.debugSurfaceView = debugSurfaceView;
} }
if (matrixShaderProgram != null && outputSizeOrRotationChanged) { if (defaultShaderProgram != null && outputSizeOrRotationChanged) {
matrixShaderProgram.release(); defaultShaderProgram.release();
matrixShaderProgram = null; defaultShaderProgram = null;
outputSizeOrRotationChanged = false; outputSizeOrRotationChanged = false;
} }
if (matrixShaderProgram == null) { if (defaultShaderProgram == null) {
matrixShaderProgram = createMatrixShaderProgramForOutputSurface(outputSurfaceInfo); defaultShaderProgram = createDefaultShaderProgramForOutputSurface(outputSurfaceInfo);
} }
this.outputSurfaceInfo = outputSurfaceInfo; this.outputSurfaceInfo = outputSurfaceInfo;
@ -387,7 +387,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
return true; return true;
} }
private MatrixShaderProgram createMatrixShaderProgramForOutputSurface( private DefaultShaderProgram createDefaultShaderProgramForOutputSurface(
SurfaceInfo outputSurfaceInfo) throws VideoFrameProcessingException { SurfaceInfo outputSurfaceInfo) throws VideoFrameProcessingException {
ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder = ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder =
new ImmutableList.Builder<GlMatrixTransformation>().addAll(matrixTransformations); new ImmutableList.Builder<GlMatrixTransformation>().addAll(matrixTransformations);
@ -401,21 +401,21 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
Presentation.createForWidthAndHeight( Presentation.createForWidthAndHeight(
outputSurfaceInfo.width, outputSurfaceInfo.height, Presentation.LAYOUT_SCALE_TO_FIT)); outputSurfaceInfo.width, outputSurfaceInfo.height, Presentation.LAYOUT_SCALE_TO_FIT));
MatrixShaderProgram matrixShaderProgram; DefaultShaderProgram defaultShaderProgram;
ImmutableList<GlMatrixTransformation> expandedMatrixTransformations = ImmutableList<GlMatrixTransformation> expandedMatrixTransformations =
matrixTransformationListBuilder.build(); matrixTransformationListBuilder.build();
if (sampleFromInputTexture) { if (sampleFromInputTexture) {
if (isInputTextureExternal) { if (isInputTextureExternal) {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.createWithExternalSampler( DefaultShaderProgram.createWithExternalSampler(
context, context,
expandedMatrixTransformations, expandedMatrixTransformations,
rgbMatrices, rgbMatrices,
inputColorInfo, inputColorInfo,
outputColorInfo); outputColorInfo);
} else { } else {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.createWithInternalSampler( DefaultShaderProgram.createWithInternalSampler(
context, context,
expandedMatrixTransformations, expandedMatrixTransformations,
rgbMatrices, rgbMatrices,
@ -423,34 +423,34 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputColorInfo); outputColorInfo);
} }
} else { } else {
matrixShaderProgram = defaultShaderProgram =
MatrixShaderProgram.createApplyingOetf( DefaultShaderProgram.createApplyingOetf(
context, expandedMatrixTransformations, rgbMatrices, outputColorInfo); context, expandedMatrixTransformations, rgbMatrices, outputColorInfo);
} }
matrixShaderProgram.setTextureTransformMatrix(textureTransformMatrix); defaultShaderProgram.setTextureTransformMatrix(textureTransformMatrix);
Size outputSize = matrixShaderProgram.configure(inputWidth, inputHeight); Size outputSize = defaultShaderProgram.configure(inputWidth, inputHeight);
checkState(outputSize.getWidth() == outputSurfaceInfo.width); checkState(outputSize.getWidth() == outputSurfaceInfo.width);
checkState(outputSize.getHeight() == outputSurfaceInfo.height); checkState(outputSize.getHeight() == outputSurfaceInfo.height);
return matrixShaderProgram; return defaultShaderProgram;
} }
private void maybeRenderFrameToDebugSurface(TextureInfo inputTexture, long presentationTimeUs) { private void maybeRenderFrameToDebugSurface(TextureInfo inputTexture, long presentationTimeUs) {
if (debugSurfaceViewWrapper == null || this.matrixShaderProgram == null) { if (debugSurfaceViewWrapper == null || this.defaultShaderProgram == null) {
return; return;
} }
MatrixShaderProgram matrixShaderProgram = this.matrixShaderProgram; DefaultShaderProgram defaultShaderProgram = this.defaultShaderProgram;
try { try {
debugSurfaceViewWrapper.maybeRenderToSurfaceView( debugSurfaceViewWrapper.maybeRenderToSurfaceView(
() -> { () -> {
GlUtil.clearOutputFrame(); GlUtil.clearOutputFrame();
@C.ColorTransfer @C.ColorTransfer
int configuredColorTransfer = matrixShaderProgram.getOutputColorTransfer(); int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer();
matrixShaderProgram.setOutputColorTransfer( defaultShaderProgram.setOutputColorTransfer(
checkNotNull(debugSurfaceViewWrapper).outputColorTransfer); checkNotNull(debugSurfaceViewWrapper).outputColorTransfer);
matrixShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs);
matrixShaderProgram.setOutputColorTransfer(configuredColorTransfer); defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer);
}); });
} catch (VideoFrameProcessingException | GlUtil.GlException e) { } catch (VideoFrameProcessingException | GlUtil.GlException e) {
Log.d(TAG, "Error rendering to debug preview", e); Log.d(TAG, "Error rendering to debug preview", e);

View File

@ -55,7 +55,7 @@ public interface GlMatrixTransformation extends GlEffect {
@Override @Override
default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return MatrixShaderProgram.create( return DefaultShaderProgram.create(
context, context,
/* matrixTransformations= */ ImmutableList.of(this), /* matrixTransformations= */ ImmutableList.of(this),
/* rgbMatrices= */ ImmutableList.of(), /* rgbMatrices= */ ImmutableList.of(),

View File

@ -42,7 +42,7 @@ public interface RgbMatrix extends GlEffect {
@Override @Override
default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return MatrixShaderProgram.create( return DefaultShaderProgram.create(
context, context,
/* matrixTransformations= */ ImmutableList.of(), /* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(this), /* rgbMatrices= */ ImmutableList.of(this),

View File

@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
/** /**
* Unit tests for {@link ScaleAndRotateTransformation}. * Unit tests for {@link ScaleAndRotateTransformation}.
* *
* <p>See {@code MatrixShaderProgramPixelTest} for pixel tests testing {@link MatrixShaderProgram} * <p>See {@code DefaultShaderProgramPixelTest} for pixel tests testing {@link DefaultShaderProgram}
* given a transformation matrix. * given a transformation matrix.
*/ */
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)