Deprecate SingleFrameShaderProgram

PiperOrigin-RevId: 555450958
This commit is contained in:
claincly 2023-08-10 12:14:59 +00:00 committed by Tianyi Feng
parent 4d0fb4326a
commit c1913e8d89
24 changed files with 37 additions and 34 deletions

View File

@ -23,14 +23,15 @@ import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.util.GlProgram; import androidx.media3.common.util.GlProgram;
import androidx.media3.common.util.GlUtil; import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Size; import androidx.media3.common.util.Size;
import androidx.media3.effect.SingleFrameGlShaderProgram; import androidx.media3.effect.BaseGlShaderProgram;
import androidx.media3.effect.GlShaderProgram;
import java.io.IOException; import java.io.IOException;
/** /**
* A {@link SingleFrameGlShaderProgram} that periodically dims the frames such that pixels are * A {@link GlShaderProgram} that periodically dims the frames such that pixels are darker the
* darker the further they are away from the frame center. * further they are away from the frame center.
*/ */
/* package */ final class PeriodicVignetteShaderProgram extends SingleFrameGlShaderProgram { /* package */ final class PeriodicVignetteShaderProgram extends BaseGlShaderProgram {
private static final String VERTEX_SHADER_PATH = "vertex_shader_copy_es2.glsl"; private static final String VERTEX_SHADER_PATH = "vertex_shader_copy_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "fragment_shader_vignette_es2.glsl"; private static final String FRAGMENT_SHADER_PATH = "fragment_shader_vignette_es2.glsl";
@ -70,7 +71,7 @@ import java.io.IOException;
float maxInnerRadius, float maxInnerRadius,
float outerRadius) float outerRadius)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
super(/* useHighPrecisionColorComponents= */ useHdr); super(/* useHighPrecisionColorComponents= */ useHdr, /* texturePoolCapacity= */ 1);
checkArgument(minInnerRadius <= maxInnerRadius); checkArgument(minInnerRadius <= maxInnerRadius);
checkArgument(maxInnerRadius <= outerRadius); checkArgument(maxInnerRadius <= outerRadius);
this.minInnerRadius = minInnerRadius; this.minInnerRadius = minInnerRadius;

View File

@ -78,7 +78,7 @@ public class ContrastPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private @MonotonicNonNull SingleFrameGlShaderProgram contrastShaderProgram; private @MonotonicNonNull BaseGlShaderProgram contrastShaderProgram;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;

View File

@ -70,7 +70,7 @@ public final class CropPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram cropShaderProgram; private @MonotonicNonNull BaseGlShaderProgram cropShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -71,7 +71,7 @@ public final class DefaultShaderProgramPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull BaseGlShaderProgram defaultShaderProgram;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;

View File

@ -75,7 +75,7 @@ public final class HslAdjustmentPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram hslProcessor; private @MonotonicNonNull BaseGlShaderProgram hslProcessor;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -96,7 +96,7 @@ public class OverlayShaderProgramPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram overlayShaderProgram; private @MonotonicNonNull BaseGlShaderProgram overlayShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -79,7 +79,7 @@ public final class PresentationPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram presentationShaderProgram; private @MonotonicNonNull BaseGlShaderProgram presentationShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -76,7 +76,7 @@ public final class RgbAdjustmentPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull BaseGlShaderProgram defaultShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -71,7 +71,7 @@ public final class RgbFilterPixelTest {
private @MonotonicNonNull String testId; private @MonotonicNonNull String testId;
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull SingleFrameGlShaderProgram defaultShaderProgram; private @MonotonicNonNull BaseGlShaderProgram defaultShaderProgram;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;

View File

@ -77,7 +77,7 @@ public class SingleColorLutPixelTest {
private @MonotonicNonNull EGLDisplay eglDisplay; private @MonotonicNonNull EGLDisplay eglDisplay;
private @MonotonicNonNull EGLContext eglContext; private @MonotonicNonNull EGLContext eglContext;
private @MonotonicNonNull EGLSurface placeholderEglSurface; private @MonotonicNonNull EGLSurface placeholderEglSurface;
private @MonotonicNonNull SingleFrameGlShaderProgram colorLutShaderProgram; private @MonotonicNonNull BaseGlShaderProgram colorLutShaderProgram;
private int inputTexId; private int inputTexId;
private int inputWidth; private int inputWidth;
private int inputHeight; private int inputHeight;

View File

@ -35,8 +35,7 @@ import java.util.concurrent.Executor;
* into an output frame, with changes to pixels specific to the implementation. * into an output frame, with changes to pixels specific to the implementation.
* *
* <p>{@code BaseShaderProgram} implementations can produce any number of output frames per input * <p>{@code BaseShaderProgram} implementations can produce any number of output frames per input
* frame with the same presentation timestamp. {@link SingleFrameGlShaderProgram} can be used to * frame with the same presentation timestamp.
* implement a {@link GlShaderProgram} that produces exactly one output frame per input frame.
* *
* <p>All methods in this class must be called on the thread that owns the OpenGL context. * <p>All methods in this class must be called on the thread that owns the OpenGL context.
*/ */

View File

@ -41,7 +41,7 @@ public interface ColorLut extends GlEffect {
void release() throws GlUtil.GlException; void release() throws GlUtil.GlException;
@Override @Override
default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) default GlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new ColorLutShaderProgram(context, /* colorLut= */ this, useHdr); return new ColorLutShaderProgram(context, /* colorLut= */ this, useHdr);
} }

View File

@ -27,7 +27,7 @@ import androidx.media3.common.util.Size;
import java.io.IOException; import java.io.IOException;
/** Applies a {@link ColorLut} to each frame in the fragment shader. */ /** Applies a {@link ColorLut} to each frame in the fragment shader. */
/* package */ final class ColorLutShaderProgram extends SingleFrameGlShaderProgram { /* package */ final class ColorLutShaderProgram extends BaseGlShaderProgram {
private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_transformation_es2.glsl"; private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_transformation_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_lut_es2.glsl"; private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_lut_es2.glsl";
@ -45,7 +45,7 @@ import java.io.IOException;
*/ */
public ColorLutShaderProgram(Context context, ColorLut colorLut, boolean useHdr) public ColorLutShaderProgram(Context context, ColorLut colorLut, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
super(/* useHighPrecisionColorComponents= */ useHdr); super(/* useHighPrecisionColorComponents= */ useHdr, /* texturePoolCapacity= */ 1);
// TODO(b/246315245): Add HDR support. // TODO(b/246315245): Add HDR support.
checkArgument(!useHdr, "ColorLutShaderProgram does not support HDR colors."); checkArgument(!useHdr, "ColorLutShaderProgram does not support HDR colors.");
this.colorLut = colorLut; this.colorLut = colorLut;

View File

@ -54,7 +54,7 @@ import java.util.List;
*/ */
@UnstableApi @UnstableApi
@SuppressWarnings("FunctionalInterfaceClash") // b/228192298 @SuppressWarnings("FunctionalInterfaceClash") // b/228192298
/* package */ final class DefaultShaderProgram extends SingleFrameGlShaderProgram /* package */ final class DefaultShaderProgram extends BaseGlShaderProgram
implements ExternalShaderProgram { implements ExternalShaderProgram {
private static final String VERTEX_SHADER_TRANSFORMATION_PATH = private static final String VERTEX_SHADER_TRANSFORMATION_PATH =
@ -387,7 +387,7 @@ import java.util.List;
checkArgument( checkArgument(
outputColorTransfer == C.COLOR_TRANSFER_SDR outputColorTransfer == C.COLOR_TRANSFER_SDR
|| outputColorTransfer == C.COLOR_TRANSFER_LINEAR); || outputColorTransfer == C.COLOR_TRANSFER_LINEAR);
// The SDR shader automatically applies an COLOR_TRANSFER_SDR EOTF. // The SDR shader automatically applies a COLOR_TRANSFER_SDR EOTF.
glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer); glProgram.setIntUniform("uOutputColorTransfer", outputColorTransfer);
} }
@ -417,7 +417,7 @@ import java.util.List;
ImmutableList<RgbMatrix> rgbMatrices, ImmutableList<RgbMatrix> rgbMatrices,
int outputColorTransfer, int outputColorTransfer,
boolean useHdr) { boolean useHdr) {
super(/* useHighPrecisionColorComponents= */ useHdr); super(/* useHighPrecisionColorComponents= */ useHdr, /* texturePoolCapacity= */ 1);
this.glProgram = glProgram; this.glProgram = glProgram;
this.outputColorTransfer = outputColorTransfer; this.outputColorTransfer = outputColorTransfer;
this.matrixTransformations = matrixTransformations; this.matrixTransformations = matrixTransformations;

View File

@ -53,7 +53,7 @@ public interface GlMatrixTransformation extends GlEffect {
float[] getGlMatrixArray(long presentationTimeUs); float[] getGlMatrixArray(long presentationTimeUs);
@Override @Override
default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) default BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return DefaultShaderProgram.create( return DefaultShaderProgram.create(
context, context,

View File

@ -116,7 +116,7 @@ public final class HslAdjustment implements GlEffect {
} }
@Override @Override
public SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) public BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new HslShaderProgram(context, /* hslAdjustment= */ this, useHdr); return new HslShaderProgram(context, /* hslAdjustment= */ this, useHdr);
} }

View File

@ -27,7 +27,7 @@ import androidx.media3.common.util.Size;
import java.io.IOException; import java.io.IOException;
/** Applies the {@link HslAdjustment} to each frame in the fragment shader. */ /** Applies the {@link HslAdjustment} to each frame in the fragment shader. */
/* package */ final class HslShaderProgram extends SingleFrameGlShaderProgram { /* package */ final class HslShaderProgram extends BaseGlShaderProgram {
private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_transformation_es2.glsl"; private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_transformation_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_hsl_es2.glsl"; private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_hsl_es2.glsl";
@ -44,7 +44,7 @@ import java.io.IOException;
*/ */
public HslShaderProgram(Context context, HslAdjustment hslAdjustment, boolean useHdr) public HslShaderProgram(Context context, HslAdjustment hslAdjustment, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
super(/* useHighPrecisionColorComponents= */ useHdr); super(/* useHighPrecisionColorComponents= */ useHdr, /* texturePoolCapacity= */ 1);
// TODO(b/241241680): Check if HDR <-> HSL works the same or not. // TODO(b/241241680): Check if HDR <-> HSL works the same or not.
checkArgument(!useHdr, "HDR is not yet supported."); checkArgument(!useHdr, "HDR is not yet supported.");

View File

@ -39,7 +39,7 @@ public final class OverlayEffect implements GlEffect {
} }
@Override @Override
public SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) public BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return new OverlayShaderProgram(context, useHdr, overlays); return new OverlayShaderProgram(context, useHdr, overlays);
} }

View File

@ -29,7 +29,7 @@ import androidx.media3.common.util.Util;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
/** Applies zero or more {@link TextureOverlay}s onto each frame. */ /** Applies zero or more {@link TextureOverlay}s onto each frame. */
/* package */ final class OverlayShaderProgram extends SingleFrameGlShaderProgram { /* package */ final class OverlayShaderProgram extends BaseGlShaderProgram {
private static final int MATRIX_OFFSET = 0; private static final int MATRIX_OFFSET = 0;
@ -61,7 +61,7 @@ import com.google.common.collect.ImmutableList;
public OverlayShaderProgram( public OverlayShaderProgram(
Context context, boolean useHdr, ImmutableList<TextureOverlay> overlays) Context context, boolean useHdr, ImmutableList<TextureOverlay> overlays)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
super(/* useHighPrecisionColorComponents= */ useHdr); super(/* useHighPrecisionColorComponents= */ useHdr, /* texturePoolCapacity= */ 1);
checkArgument(!useHdr, "OverlayShaderProgram does not support HDR colors yet."); checkArgument(!useHdr, "OverlayShaderProgram does not support HDR colors yet.");
// The maximum number of samplers allowed in a single GL program is 16. // The maximum number of samplers allowed in a single GL program is 16.
// We use one for every overlay and one for the video. // We use one for every overlay and one for the video.

View File

@ -92,7 +92,7 @@ public final class RgbFilter implements RgbMatrix {
} }
@Override @Override
public SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) public BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
checkForConsistentHdrSetting(useHdr); checkForConsistentHdrSetting(useHdr);
return RgbMatrix.super.toGlShaderProgram(context, useHdr); return RgbMatrix.super.toGlShaderProgram(context, useHdr);

View File

@ -40,7 +40,7 @@ public interface RgbMatrix extends GlEffect {
float[] getMatrix(long presentationTimeUs, boolean useHdr); float[] getMatrix(long presentationTimeUs, boolean useHdr);
@Override @Override
default SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) default BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
return DefaultShaderProgram.create( return DefaultShaderProgram.create(
context, context,

View File

@ -149,7 +149,7 @@ public final class SingleColorLut implements ColorLut {
} }
@Override @Override
public SingleFrameGlShaderProgram toGlShaderProgram(Context context, boolean useHdr) public BaseGlShaderProgram toGlShaderProgram(Context context, boolean useHdr)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
checkState(!useHdr, "HDR is currently not supported."); checkState(!useHdr, "HDR is currently not supported.");

View File

@ -26,8 +26,11 @@ import androidx.media3.common.util.UnstableApi;
* GlShaderProgram} directly. * GlShaderProgram} directly.
* *
* <p>All methods in this class must be called on the thread that owns the OpenGL context. * <p>All methods in this class must be called on the thread that owns the OpenGL context.
*
* @deprecated Use {@link BaseGlShaderProgram} instead.
*/ */
@UnstableApi @UnstableApi
@Deprecated
public abstract class SingleFrameGlShaderProgram extends BaseGlShaderProgram { public abstract class SingleFrameGlShaderProgram extends BaseGlShaderProgram {
// TODO(b/275384398): Remove this class as it only wraps the BaseGlShaderProgram. // TODO(b/275384398): Remove this class as it only wraps the BaseGlShaderProgram.

View File

@ -28,7 +28,7 @@ import java.io.IOException;
* Draws the target input frame at a given horizontal position of the output texture to generate an * Draws the target input frame at a given horizontal position of the output texture to generate an
* horizontal tiling effect. * horizontal tiling effect.
*/ */
/* package */ final class ThumbnailStripShaderProgram extends SingleFrameGlShaderProgram { /* package */ final class ThumbnailStripShaderProgram extends BaseGlShaderProgram {
private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_thumbnail_strip_es2.glsl"; private static final String VERTEX_SHADER_PATH = "shaders/vertex_shader_thumbnail_strip_es2.glsl";
private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_copy_es2.glsl"; private static final String FRAGMENT_SHADER_PATH = "shaders/fragment_shader_copy_es2.glsl";
@ -38,7 +38,7 @@ import java.io.IOException;
public ThumbnailStripShaderProgram( public ThumbnailStripShaderProgram(
Context context, boolean useHdr, ThumbnailStripEffect thumbnailStripEffect) Context context, boolean useHdr, ThumbnailStripEffect thumbnailStripEffect)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
super(useHdr); super(useHdr, /* texturePoolCapacity= */ 1);
this.thumbnailStripEffect = thumbnailStripEffect; this.thumbnailStripEffect = thumbnailStripEffect;
try { try {