Commit 4c8d22fe by huangdarwin Committed by microkatz

HDR: Use factory for MatrixTransformationProcessor.

Separate MatrixTransformationProcessor constructors by color input and output.

PiperOrigin-RevId: 471034768
(cherry picked from commit a8e814ab)
parent fc8edfcd
...@@ -28,6 +28,7 @@ import android.opengl.EGLSurface; ...@@ -28,6 +28,7 @@ import android.opengl.EGLSurface;
import androidx.media3.common.FrameProcessingException; import androidx.media3.common.FrameProcessingException;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import com.google.common.collect.ImmutableList;
import java.io.IOException; import java.io.IOException;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.junit.After; import org.junit.After;
...@@ -94,11 +95,10 @@ public final class MatrixTransformationProcessorPixelTest { ...@@ -94,11 +95,10 @@ public final class MatrixTransformationProcessorPixelTest {
public void drawFrame_noEdits_producesExpectedOutput() throws Exception { public void drawFrame_noEdits_producesExpectedOutput() throws Exception {
String testId = "drawFrame_noEdits"; String testId = "drawFrame_noEdits";
Matrix identityMatrix = new Matrix(); Matrix identityMatrix = new Matrix();
MatrixTransformation noEditsTransformation = (long presentationTimeUs) -> identityMatrix;
matrixTransformationFrameProcessor = matrixTransformationFrameProcessor =
new MatrixTransformationProcessor( MatrixTransformationProcessor.create(
context, context, ImmutableList.of(noEditsTransformation), /* useHdr= */ false);
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> identityMatrix);
matrixTransformationFrameProcessor.configure(width, height); matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ORIGINAL_PNG_ASSET_PATH);
...@@ -120,11 +120,11 @@ public final class MatrixTransformationProcessorPixelTest { ...@@ -120,11 +120,11 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_translateRight"; String testId = "drawFrame_translateRight";
Matrix translateRightMatrix = new Matrix(); Matrix translateRightMatrix = new Matrix();
translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0); translateRightMatrix.postTranslate(/* dx= */ 1, /* dy= */ 0);
MatrixTransformation translateRightTransformation =
(long presentationTimeUs) -> translateRightMatrix;
matrixTransformationFrameProcessor = matrixTransformationFrameProcessor =
new MatrixTransformationProcessor( MatrixTransformationProcessor.create(
context, context, ImmutableList.of(translateRightTransformation), /* useHdr= */ false);
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> translateRightMatrix);
matrixTransformationFrameProcessor.configure(width, height); matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(TRANSLATE_RIGHT_PNG_ASSET_PATH);
...@@ -146,11 +146,10 @@ public final class MatrixTransformationProcessorPixelTest { ...@@ -146,11 +146,10 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_scaleNarrow"; String testId = "drawFrame_scaleNarrow";
Matrix scaleNarrowMatrix = new Matrix(); Matrix scaleNarrowMatrix = new Matrix();
scaleNarrowMatrix.postScale(.5f, 1.2f); scaleNarrowMatrix.postScale(.5f, 1.2f);
MatrixTransformation scaleNarrowTransformation = (long presentationTimeUs) -> scaleNarrowMatrix;
matrixTransformationFrameProcessor = matrixTransformationFrameProcessor =
new MatrixTransformationProcessor( MatrixTransformationProcessor.create(
context, context, ImmutableList.of(scaleNarrowTransformation), /* useHdr= */ false);
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> scaleNarrowMatrix);
matrixTransformationFrameProcessor.configure(width, height); matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(SCALE_NARROW_PNG_ASSET_PATH);
...@@ -172,11 +171,10 @@ public final class MatrixTransformationProcessorPixelTest { ...@@ -172,11 +171,10 @@ public final class MatrixTransformationProcessorPixelTest {
String testId = "drawFrame_rotate90"; String testId = "drawFrame_rotate90";
Matrix rotate90Matrix = new Matrix(); Matrix rotate90Matrix = new Matrix();
rotate90Matrix.postRotate(/* degrees= */ 90); rotate90Matrix.postRotate(/* degrees= */ 90);
MatrixTransformation rotate90Transformation = (long presentationTimeUs) -> rotate90Matrix;
matrixTransformationFrameProcessor = matrixTransformationFrameProcessor =
new MatrixTransformationProcessor( MatrixTransformationProcessor.create(
context, context, ImmutableList.of(rotate90Transformation), /* useHdr= */ false);
/* useHdr= */ false,
/* matrixTransformation= */ (long presentationTimeUs) -> rotate90Matrix);
matrixTransformationFrameProcessor.configure(width, height); matrixTransformationFrameProcessor.configure(width, height);
Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH); Bitmap expectedBitmap = BitmapTestUtil.readBitmap(ROTATE_90_PNG_ASSET_PATH);
......
...@@ -368,13 +368,19 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -368,13 +368,19 @@ 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));
MatrixTransformationProcessor matrixTransformationProcessor = MatrixTransformationProcessor matrixTransformationProcessor;
new MatrixTransformationProcessor( ImmutableList<GlMatrixTransformation> expandedMatrixTransformations =
context, matrixTransformationListBuilder.build();
matrixTransformationListBuilder.build(), if (sampleFromExternalTexture) {
sampleFromExternalTexture, matrixTransformationProcessor =
colorInfo, MatrixTransformationProcessor.createWithExternalSamplerApplyingEotfThenOetf(
/* outputElectricalColors= */ true); context, expandedMatrixTransformations, colorInfo);
} else {
matrixTransformationProcessor =
MatrixTransformationProcessor.createApplyingOetf(
context, expandedMatrixTransformations, colorInfo);
}
matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix); matrixTransformationProcessor.setTextureTransformMatrix(textureTransformMatrix);
Pair<Integer, Integer> outputSize = Pair<Integer, Integer> outputSize =
matrixTransformationProcessor.configure(inputWidth, inputHeight); matrixTransformationProcessor.configure(inputWidth, inputHeight);
......
...@@ -204,13 +204,17 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -204,13 +204,17 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
ImmutableList<GlMatrixTransformation> matrixTransformations = ImmutableList<GlMatrixTransformation> matrixTransformations =
matrixTransformationListBuilder.build(); matrixTransformationListBuilder.build();
if (!matrixTransformations.isEmpty() || sampleFromExternalTexture) { if (!matrixTransformations.isEmpty() || sampleFromExternalTexture) {
textureProcessorListBuilder.add( MatrixTransformationProcessor matrixTransformationProcessor;
new MatrixTransformationProcessor( if (sampleFromExternalTexture) {
context, matrixTransformationProcessor =
matrixTransformations, MatrixTransformationProcessor.createWithExternalSamplerApplyingEotf(
sampleFromExternalTexture, context, matrixTransformations, colorInfo);
colorInfo, } else {
/* outputElectricalColors= */ false)); matrixTransformationProcessor =
MatrixTransformationProcessor.create(
context, matrixTransformations, ColorInfo.isTransferHdr(colorInfo));
}
textureProcessorListBuilder.add(matrixTransformationProcessor);
matrixTransformationListBuilder = new ImmutableList.Builder<>(); matrixTransformationListBuilder = new ImmutableList.Builder<>();
sampleFromExternalTexture = false; sampleFromExternalTexture = false;
} }
...@@ -235,12 +239,8 @@ public final class GlEffectsFrameProcessor implements FrameProcessor { ...@@ -235,12 +239,8 @@ public final class GlEffectsFrameProcessor implements FrameProcessor {
// TODO(b/239757183): Remove the unnecessary MatrixTransformationProcessor after it got // TODO(b/239757183): Remove the unnecessary MatrixTransformationProcessor after it got
// merged with RgbMatrixProcessor. // merged with RgbMatrixProcessor.
textureProcessorListBuilder.add( textureProcessorListBuilder.add(
new MatrixTransformationProcessor( MatrixTransformationProcessor.createWithExternalSamplerApplyingEotf(
context, context, /* matrixTransformations= */ ImmutableList.of(), colorInfo));
ImmutableList.of(),
sampleFromExternalTexture,
colorInfo,
/* outputElectricalColors= */ false));
sampleFromExternalTexture = false; sampleFromExternalTexture = false;
} }
textureProcessorListBuilder.add( textureProcessorListBuilder.add(
......
...@@ -19,6 +19,7 @@ import android.content.Context; ...@@ -19,6 +19,7 @@ import android.content.Context;
import android.opengl.Matrix; import android.opengl.Matrix;
import android.util.Pair; import android.util.Pair;
import androidx.media3.common.FrameProcessingException; import androidx.media3.common.FrameProcessingException;
import com.google.common.collect.ImmutableList;
/** /**
* Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each frame. * Specifies a 4x4 transformation {@link Matrix} to apply in the vertex shader for each frame.
...@@ -52,6 +53,7 @@ public interface GlMatrixTransformation extends GlEffect { ...@@ -52,6 +53,7 @@ public interface GlMatrixTransformation extends GlEffect {
@Override @Override
default SingleFrameGlTextureProcessor toGlTextureProcessor(Context context, boolean useHdr) default SingleFrameGlTextureProcessor toGlTextureProcessor(Context context, boolean useHdr)
throws FrameProcessingException { throws FrameProcessingException {
return new MatrixTransformationProcessor(context, useHdr, /* matrixTransformation= */ this); return MatrixTransformationProcessor.create(
context, /* matrixTransformations= */ ImmutableList.of(this), useHdr);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment