Effect: Remove unused arguments in DefaultShaderProgram factories.

Partially addresses the following TODO, by simplifying the DefaultShaderProgram
API surface.
```
// TODO(b/274109008): Refactor DefaultShaderProgram to create a class just for sampling.
```

PiperOrigin-RevId: 597575575
This commit is contained in:
huangdarwin 2024-01-11 09:22:23 -08:00 committed by Copybara-Service
parent b4dfbed73d
commit c59711f592
2 changed files with 13 additions and 59 deletions

View File

@ -185,16 +185,11 @@ import java.util.List;
* <p>Input will be sampled from an internal (i.e. regular) texture. * <p>Input will be sampled from an internal (i.e. regular) texture.
* *
* <p>Applies the {@linkplain ColorInfo#colorTransfer inputColorInfo EOTF} to convert from * <p>Applies the {@linkplain ColorInfo#colorTransfer inputColorInfo EOTF} to convert from
* electrical color input, to intermediate optical {@link GlShaderProgram} color output, before * electrical color input, to intermediate optical {@link GlShaderProgram} color output. Also
* {@code matrixTransformations} and {@code rgbMatrices} are applied. Also applies the {@linkplain * applies the {@linkplain ColorInfo#colorTransfer outputColorInfo OETF}, if needed, to convert
* ColorInfo#colorTransfer outputColorInfo OETF}, if needed, to convert back to an electrical * back to an electrical color output.
* color output.
* *
* @param context The {@link Context}. * @param context The {@link Context}.
* @param matrixTransformations The {@link GlMatrixTransformation GlMatrixTransformations} to
* apply to each frame in order. Can be empty to apply no vertex transformations.
* @param rgbMatrices The {@link RgbMatrix RgbMatrices} to apply to each frame in order. Can be
* empty to apply no color transformations.
* @param inputColorInfo The input electrical (nonlinear) {@link ColorInfo}. * @param inputColorInfo The input electrical (nonlinear) {@link ColorInfo}.
* @param outputColorInfo The output electrical (nonlinear) or optical (linear) {@link ColorInfo}. * @param outputColorInfo The output electrical (nonlinear) or optical (linear) {@link ColorInfo}.
* If this is an optical color, it must be BT.2020 if {@code inputColorInfo} is {@linkplain * If this is an optical color, it must be BT.2020 if {@code inputColorInfo} is {@linkplain
@ -206,8 +201,6 @@ import java.util.List;
*/ */
public static DefaultShaderProgram createWithInternalSampler( public static DefaultShaderProgram createWithInternalSampler(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices,
ColorInfo inputColorInfo, ColorInfo inputColorInfo,
ColorInfo outputColorInfo, ColorInfo outputColorInfo,
boolean enableColorTransfers, boolean enableColorTransfers,
@ -226,13 +219,7 @@ import java.util.List;
: FRAGMENT_SHADER_TRANSFORMATION_SDR_INTERNAL_PATH; : FRAGMENT_SHADER_TRANSFORMATION_SDR_INTERNAL_PATH;
GlProgram glProgram = createGlProgram(context, vertexShaderFilePath, fragmentShaderFilePath); GlProgram glProgram = createGlProgram(context, vertexShaderFilePath, fragmentShaderFilePath);
glProgram.setIntUniform("uInputColorTransfer", inputColorInfo.colorTransfer); glProgram.setIntUniform("uInputColorTransfer", inputColorInfo.colorTransfer);
return createWithSampler( return createWithSampler(glProgram, inputColorInfo, outputColorInfo, enableColorTransfers);
glProgram,
matrixTransformations,
rgbMatrices,
inputColorInfo,
outputColorInfo,
enableColorTransfers);
} }
/** /**
@ -243,16 +230,11 @@ import java.util.List;
* external texture. * external texture.
* *
* <p>Applies the {@linkplain ColorInfo#colorTransfer inputColorInfo EOTF} to convert from * <p>Applies the {@linkplain ColorInfo#colorTransfer inputColorInfo EOTF} to convert from
* electrical color input, to intermediate optical {@link GlShaderProgram} color output, before * electrical color input, to intermediate optical {@link GlShaderProgram} color output. Also
* {@code matrixTransformations} and {@code rgbMatrices} are applied. Also applies the {@linkplain * applies the {@linkplain ColorInfo#colorTransfer outputColorInfo OETF}, if needed, to convert
* ColorInfo#colorTransfer outputColorInfo OETF}, if needed, to convert back to an electrical * back to an electrical color output.
* color output.
* *
* @param context The {@link Context}. * @param context The {@link Context}.
* @param matrixTransformations The {@link GlMatrixTransformation GlMatrixTransformations} to
* apply to each frame in order. Can be empty to apply no vertex transformations.
* @param rgbMatrices The {@link RgbMatrix RgbMatrices} to apply to each frame in order. Can be
* empty to apply no color transformations.
* @param inputColorInfo The input electrical (nonlinear) {@link ColorInfo}. * @param inputColorInfo The input electrical (nonlinear) {@link ColorInfo}.
* @param outputColorInfo The output electrical (nonlinear) or optical (linear) {@link ColorInfo}. * @param outputColorInfo The output electrical (nonlinear) or optical (linear) {@link ColorInfo}.
* If this is an optical color, it must be BT.2020 if {@code inputColorInfo} is {@linkplain * If this is an optical color, it must be BT.2020 if {@code inputColorInfo} is {@linkplain
@ -264,8 +246,6 @@ import java.util.List;
*/ */
public static DefaultShaderProgram createWithExternalSampler( public static DefaultShaderProgram createWithExternalSampler(
Context context, Context context,
List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices,
ColorInfo inputColorInfo, ColorInfo inputColorInfo,
ColorInfo outputColorInfo, ColorInfo outputColorInfo,
boolean enableColorTransfers) boolean enableColorTransfers)
@ -294,13 +274,7 @@ import java.util.List;
glProgram.setIntUniform("uInputColorTransfer", inputColorInfo.colorTransfer); glProgram.setIntUniform("uInputColorTransfer", inputColorInfo.colorTransfer);
} }
return createWithSampler( return createWithSampler(glProgram, inputColorInfo, outputColorInfo, enableColorTransfers);
glProgram,
matrixTransformations,
rgbMatrices,
inputColorInfo,
outputColorInfo,
enableColorTransfers);
} }
/** /**
@ -365,8 +339,6 @@ import java.util.List;
private static DefaultShaderProgram createWithSampler( private static DefaultShaderProgram createWithSampler(
GlProgram glProgram, GlProgram glProgram,
List<GlMatrixTransformation> matrixTransformations,
List<RgbMatrix> rgbMatrices,
ColorInfo inputColorInfo, ColorInfo inputColorInfo,
ColorInfo outputColorInfo, ColorInfo outputColorInfo,
boolean enableColorTransfers) { boolean enableColorTransfers) {
@ -397,8 +369,8 @@ import java.util.List;
return new DefaultShaderProgram( return new DefaultShaderProgram(
glProgram, glProgram,
ImmutableList.copyOf(matrixTransformations), /* matrixTransformations= */ ImmutableList.of(),
ImmutableList.copyOf(rgbMatrices), /* rgbMatrices= */ ImmutableList.of(),
outputColorInfo.colorTransfer, outputColorInfo.colorTransfer,
isInputTransferHdr); isInputTransferHdr);
} }

View File

@ -36,7 +36,6 @@ import androidx.media3.common.GlTextureInfo;
import androidx.media3.common.OnInputFrameProcessedListener; import androidx.media3.common.OnInputFrameProcessedListener;
import androidx.media3.common.VideoFrameProcessingException; import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.VideoFrameProcessor; import androidx.media3.common.VideoFrameProcessor;
import com.google.common.collect.ImmutableList;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -97,12 +96,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
case INPUT_TYPE_SURFACE: case INPUT_TYPE_SURFACE:
samplingShaderProgram = samplingShaderProgram =
DefaultShaderProgram.createWithExternalSampler( DefaultShaderProgram.createWithExternalSampler(
context, context, inputColorInfo, outputColorInfo, enableColorTransfers);
/* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(),
inputColorInfo,
outputColorInfo,
enableColorTransfers);
break; break;
case INPUT_TYPE_BITMAP: case INPUT_TYPE_BITMAP:
// HDR bitmap input is not supported. Bitmaps are always sRGB/Full range/BT.709. // HDR bitmap input is not supported. Bitmaps are always sRGB/Full range/BT.709.
@ -110,26 +104,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
ColorInfo bitmapColorInfo = ColorInfo.SRGB_BT709_FULL; ColorInfo bitmapColorInfo = ColorInfo.SRGB_BT709_FULL;
samplingShaderProgram = samplingShaderProgram =
DefaultShaderProgram.createWithInternalSampler( DefaultShaderProgram.createWithInternalSampler(
context, context, bitmapColorInfo, outputColorInfo, enableColorTransfers, inputType);
/* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(),
bitmapColorInfo,
outputColorInfo,
enableColorTransfers,
inputType);
break; break;
case INPUT_TYPE_TEXTURE_ID: case INPUT_TYPE_TEXTURE_ID:
// Image and textureId concatenation not supported. // Image and textureId concatenation not supported.
checkState(inputColorInfo.colorTransfer != C.COLOR_TRANSFER_SRGB); checkState(inputColorInfo.colorTransfer != C.COLOR_TRANSFER_SRGB);
samplingShaderProgram = samplingShaderProgram =
DefaultShaderProgram.createWithInternalSampler( DefaultShaderProgram.createWithInternalSampler(
context, context, inputColorInfo, outputColorInfo, enableColorTransfers, inputType);
/* matrixTransformations= */ ImmutableList.of(),
/* rgbMatrices= */ ImmutableList.of(),
inputColorInfo,
outputColorInfo,
enableColorTransfers,
inputType);
break; break;
default: default:
throw new VideoFrameProcessingException("Unsupported input type " + inputType); throw new VideoFrameProcessingException("Unsupported input type " + inputType);