Commit 6c061894 by hschlueter Committed by Ian Baker

Make GlProgram an outer class.

This change makes GlUtil.Program an outer class named GlProgram,
and also moves private static helpers as well as the inner classes
Attribute and Uniform which were only used by GlUtil.Program to
GlProgram. Other static utility methods remain in GlUtil.

No functional changes intended.

PiperOrigin-RevId: 426119299
parent 9927883b
...@@ -27,6 +27,7 @@ import android.graphics.drawable.BitmapDrawable; ...@@ -27,6 +27,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.opengl.GLES20; import android.opengl.GLES20;
import android.opengl.GLUtils; import android.opengl.GLUtils;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
import java.util.Locale; import java.util.Locale;
...@@ -50,7 +51,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -50,7 +51,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private final Bitmap logoBitmap; private final Bitmap logoBitmap;
private final Canvas overlayCanvas; private final Canvas overlayCanvas;
private GlUtil.@MonotonicNonNull Program program; private @MonotonicNonNull GlProgram program;
private float bitmapScaleX; private float bitmapScaleX;
private float bitmapScaleY; private float bitmapScaleY;
...@@ -78,7 +79,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -78,7 +79,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
public void initialize() { public void initialize() {
try { try {
program = program =
new GlUtil.Program( new GlProgram(
context, context,
/* vertexShaderFilePath= */ "bitmap_overlay_video_processor_vertex.glsl", /* vertexShaderFilePath= */ "bitmap_overlay_video_processor_vertex.glsl",
/* fragmentShaderFilePath= */ "bitmap_overlay_video_processor_fragment.glsl"); /* fragmentShaderFilePath= */ "bitmap_overlay_video_processor_fragment.glsl");
...@@ -117,7 +118,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -117,7 +118,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
GlUtil.checkGlError(); GlUtil.checkGlError();
// Run the shader program. // Run the shader program.
GlUtil.Program program = checkNotNull(this.program); GlProgram program = checkNotNull(this.program);
program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* unit= */ 0); program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* unit= */ 0);
program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* unit= */ 1); program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* unit= */ 1);
program.setFloatUniform("uScaleX", bitmapScaleX); program.setFloatUniform("uScaleX", bitmapScaleX);
......
...@@ -24,6 +24,7 @@ import android.util.AttributeSet; ...@@ -24,6 +24,7 @@ import android.util.AttributeSet;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer; import com.google.android.exoplayer2.decoder.VideoDecoderOutputBuffer;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
...@@ -144,7 +145,7 @@ public final class VideoDecoderGLSurfaceView extends GLSurfaceView ...@@ -144,7 +145,7 @@ public final class VideoDecoderGLSurfaceView extends GLSurfaceView
// glDrawArrays uses it. // glDrawArrays uses it.
private final FloatBuffer[] textureCoords; private final FloatBuffer[] textureCoords;
private GlUtil.@MonotonicNonNull Program program; private @MonotonicNonNull GlProgram program;
private int colorMatrixLocation; private int colorMatrixLocation;
// Accessed only from the GL thread. // Accessed only from the GL thread.
...@@ -165,7 +166,7 @@ public final class VideoDecoderGLSurfaceView extends GLSurfaceView ...@@ -165,7 +166,7 @@ public final class VideoDecoderGLSurfaceView extends GLSurfaceView
@Override @Override
public void onSurfaceCreated(GL10 unused, EGLConfig config) { public void onSurfaceCreated(GL10 unused, EGLConfig config) {
program = new GlUtil.Program(VERTEX_SHADER, FRAGMENT_SHADER); program = new GlProgram(VERTEX_SHADER, FRAGMENT_SHADER);
int posLocation = program.getAttributeArrayLocationAndEnable("in_pos"); int posLocation = program.getAttributeArrayLocationAndEnable("in_pos");
GLES20.glVertexAttribPointer( GLES20.glVertexAttribPointer(
posLocation, posLocation,
......
...@@ -21,6 +21,7 @@ import android.opengl.GLES11Ext; ...@@ -21,6 +21,7 @@ import android.opengl.GLES11Ext;
import android.opengl.GLES20; import android.opengl.GLES20;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.nio.FloatBuffer; import java.nio.FloatBuffer;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...@@ -87,7 +88,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -87,7 +88,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private int stereoMode; private int stereoMode;
@Nullable private MeshData leftMeshData; @Nullable private MeshData leftMeshData;
@Nullable private MeshData rightMeshData; @Nullable private MeshData rightMeshData;
private GlUtil.@MonotonicNonNull Program program; private @MonotonicNonNull GlProgram program;
// Program related GL items. These are only valid if Program is valid. // Program related GL items. These are only valid if Program is valid.
private int mvpMatrixHandle; private int mvpMatrixHandle;
...@@ -114,7 +115,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -114,7 +115,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** Initializes of the GL components. */ /** Initializes of the GL components. */
public void init() { public void init() {
program = new GlUtil.Program(VERTEX_SHADER, FRAGMENT_SHADER); program = new GlProgram(VERTEX_SHADER, FRAGMENT_SHADER);
mvpMatrixHandle = program.getUniformLocation("uMvpMatrix"); mvpMatrixHandle = program.getUniformLocation("uMvpMatrix");
uTexMatrixHandle = program.getUniformLocation("uTexMatrix"); uTexMatrixHandle = program.getUniformLocation("uTexMatrix");
positionHandle = program.getAttributeArrayLocationAndEnable("aPosition"); positionHandle = program.getAttributeArrayLocationAndEnable("aPosition");
...@@ -148,7 +149,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -148,7 +149,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
GLES20.glUniformMatrix3fv(uTexMatrixHandle, 1, false, texMatrix, 0); GLES20.glUniformMatrix3fv(uTexMatrixHandle, 1, false, texMatrix, 0);
// TODO(b/205002913): Update to use GlUtil.Uniform.bind(). // TODO(b/205002913): Update to use GlProgram.Uniform.bind().
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, mvpMatrix, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId); GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, textureId);
......
...@@ -31,6 +31,7 @@ import android.view.Surface; ...@@ -31,6 +31,7 @@ import android.view.Surface;
import android.view.SurfaceView; import android.view.SurfaceView;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlProgram;
import com.google.android.exoplayer2.util.GlUtil; import com.google.android.exoplayer2.util.GlUtil;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
...@@ -86,7 +87,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -86,7 +87,7 @@ import java.util.concurrent.atomic.AtomicInteger;
EGLContext eglContext; EGLContext eglContext;
EGLSurface eglSurface; EGLSurface eglSurface;
int textureId; int textureId;
GlUtil.Program glProgram; GlProgram glProgram;
@Nullable EGLSurface debugPreviewEglSurface = null; @Nullable EGLSurface debugPreviewEglSurface = null;
try { try {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.createEglDisplay();
...@@ -141,7 +142,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -141,7 +142,7 @@ import java.util.concurrent.atomic.AtomicInteger;
debugPreviewHeight); debugPreviewHeight);
} }
private static GlUtil.Program configureGlProgram( private static GlProgram configureGlProgram(
Context context, Context context,
Matrix transformationMatrix, Matrix transformationMatrix,
int textureId, int textureId,
...@@ -157,8 +158,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -157,8 +158,7 @@ import java.util.concurrent.atomic.AtomicInteger;
enableExperimentalHdrEditing enableExperimentalHdrEditing
? FRAGMENT_SHADER_COPY_EXTERNAL_YUV_ES3_PATH ? FRAGMENT_SHADER_COPY_EXTERNAL_YUV_ES3_PATH
: FRAGMENT_SHADER_COPY_EXTERNAL_PATH; : FRAGMENT_SHADER_COPY_EXTERNAL_PATH;
GlUtil.Program glProgram = GlProgram glProgram = new GlProgram(context, vertexShaderFilePath, fragmentShaderFilePath);
new GlUtil.Program(context, vertexShaderFilePath, fragmentShaderFilePath);
// Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y. // Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y.
glProgram.setBufferAttribute( glProgram.setBufferAttribute(
...@@ -242,7 +242,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -242,7 +242,7 @@ import java.util.concurrent.atomic.AtomicInteger;
private final AtomicInteger availableInputFrameCount; private final AtomicInteger availableInputFrameCount;
private final SurfaceTexture inputSurfaceTexture; private final SurfaceTexture inputSurfaceTexture;
private final Surface inputSurface; private final Surface inputSurface;
private final GlUtil.Program glProgram; private final GlProgram glProgram;
private final int outputWidth; private final int outputWidth;
private final int outputHeight; private final int outputHeight;
@Nullable private final EGLSurface debugPreviewEglSurface; @Nullable private final EGLSurface debugPreviewEglSurface;
...@@ -256,7 +256,7 @@ import java.util.concurrent.atomic.AtomicInteger; ...@@ -256,7 +256,7 @@ import java.util.concurrent.atomic.AtomicInteger;
EGLContext eglContext, EGLContext eglContext,
EGLSurface eglSurface, EGLSurface eglSurface,
int textureId, int textureId,
GlUtil.Program glProgram, GlProgram glProgram,
int outputWidth, int outputWidth,
int outputHeight, int outputHeight,
@Nullable EGLSurface debugPreviewEglSurface, @Nullable EGLSurface debugPreviewEglSurface,
......
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