Effect: Rename to DefaultShaderProgram.
Rename: * MatrixShaderProgram to DefaultShaderProgram, and * FinalMatrixShaderProgramWrapper to FinalShaderProgramWrapper. PiperOrigin-RevId: 510498547
This commit is contained in:
parent
84acfe7867
commit
92138fc83c
@ -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}.
|
||||
*
|
||||
* <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
|
||||
@ -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);
|
@ -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());
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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<GlMatrixTransformation> matrixTransformations,
|
||||
List<RgbMatrix> 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<GlMatrixTransformation> matrixTransformations,
|
||||
List<RgbMatrix> 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<GlMatrixTransformation> matrixTransformations,
|
||||
List<RgbMatrix> 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<GlMatrixTransformation> matrixTransformations,
|
||||
List<RgbMatrix> 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<GlMatrixTransformation> matrixTransformations,
|
||||
List<RgbMatrix> 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<GlMatrixTransformation> matrixTransformations,
|
||||
ImmutableList<RgbMatrix> rgbMatrices,
|
||||
@ -462,7 +462,7 @@ import java.util.List;
|
||||
/**
|
||||
* 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}.
|
||||
*/
|
||||
public void setOutputColorTransfer(@C.ColorTransfer int colorTransfer) {
|
@ -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.
|
||||
*
|
||||
* <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
|
||||
* first is an {@link ExternalShaderProgram} and the last is a {@link
|
||||
* FinalMatrixShaderProgramWrapper}.
|
||||
* FinalShaderProgramWrapper}.
|
||||
*/
|
||||
private static ImmutableList<GlShaderProgram> getGlShaderProgramsForGlEffects(
|
||||
Context context,
|
||||
@ -286,23 +286,23 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
|
||||
ImmutableList<RgbMatrix> 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<GlShaderProgram> 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;
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
* <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
|
||||
* 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
|
||||
* GlShaderProgram} instances used by {@link VideoFrameProcessor}.
|
||||
* <p>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<GlMatrixTransformation> matrixTransformationListBuilder =
|
||||
new ImmutableList.Builder<GlMatrixTransformation>().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<GlMatrixTransformation> 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);
|
@ -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(),
|
||||
|
@ -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),
|
||||
|
@ -25,7 +25,7 @@ import org.junit.runner.RunWith;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
|
Loading…
x
Reference in New Issue
Block a user