diff --git a/libraries/common/src/main/java/androidx/media3/common/GlObjectsProvider.java b/libraries/common/src/main/java/androidx/media3/common/GlObjectsProvider.java index 79f9757dc9..8a4bd7fc6c 100644 --- a/libraries/common/src/main/java/androidx/media3/common/GlObjectsProvider.java +++ b/libraries/common/src/main/java/androidx/media3/common/GlObjectsProvider.java @@ -16,6 +16,7 @@ package androidx.media3.common; +import android.opengl.EGL14; import android.opengl.EGLContext; import android.opengl.EGLDisplay; import android.opengl.EGLSurface; @@ -68,11 +69,6 @@ public interface GlObjectsProvider { int fboId = GlUtil.createFboForTexture(texId); return new GlTextureInfo(texId, fboId, /* rboId= */ C.INDEX_UNSET, width, height); } - - @Override - public void clearOutputFrame() throws GlException { - GlUtil.clearOutputFrame(); - } }; /** @@ -89,22 +85,38 @@ public interface GlObjectsProvider { EGLDisplay eglDisplay, @IntRange(from = 2, to = 3) int openGlVersion, int[] configAttributes) throws GlException; - // TODO(b/271433904): Remove default implementations once photos have implemented these methods. + /** + * Creates a new {@link EGLSurface} wrapping the specified {@code surface}. + * + * @param eglDisplay The {@link EGLDisplay} to attach the surface to. + * @param surface The surface to wrap; must be a surface, surface texture or surface holder. + * @param colorTransfer The {@linkplain C.ColorTransfer color transfer characteristics} to which + * the {@code surface} is configured. + * @param isEncoderInputSurface Whether the {@code surface} is the input surface of an encoder. + * @throws GlException If an error occurs during creation. + */ @RequiresApi(17) - default EGLSurface createEglSurface( + EGLSurface createEglSurface( EGLDisplay eglDisplay, Object surface, @C.ColorTransfer int colorTransfer, boolean isEncoderInputSurface) - throws GlException { - return GlUtil.createEglSurface(eglDisplay, surface, colorTransfer, isEncoderInputSurface); - } + throws GlException; + /** + * Creates and focuses a placeholder {@link EGLSurface}. + * + * @param eglContext The {@link EGLContext} to make current. + * @param eglDisplay The {@link EGLDisplay} to attach the surface to. + * @param configAttributes The attributes to configure EGL with. + * @return A placeholder {@link EGLSurface} that has been focused to allow rendering to take + * place, or {@link EGL14#EGL_NO_SURFACE} if the current context supports rendering without a + * surface. + * @throws GlException If an error occurs during creation. + */ @RequiresApi(17) - default EGLSurface createFocusedPlaceholderEglSurface( - EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes) throws GlException { - return GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes); - } + EGLSurface createFocusedPlaceholderEglSurface( + EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes) throws GlException; /** * Returns a {@link GlTextureInfo} containing the identifiers of the newly created buffers. @@ -115,11 +127,4 @@ public interface GlObjectsProvider { * @throws GlException If an error occurs during creation. */ GlTextureInfo createBuffersForTexture(int texId, int width, int height) throws GlException; - - /** - * Clears the current render target. - * - * @throws GlException If an error occurs during clearing. - */ - void clearOutputFrame() throws GlException; } diff --git a/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java b/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java index b1887f7157..e300d0081c 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/FinalShaderProgramWrapper.java @@ -324,7 +324,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; outputEglSurface, outputSurfaceInfo.width, outputSurfaceInfo.height); - glObjectsProvider.clearOutputFrame(); + GlUtil.clearOutputFrame(); defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); EGLExt.eglPresentationTimeANDROID( @@ -466,7 +466,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; try { debugSurfaceViewWrapper.maybeRenderToSurfaceView( () -> { - glObjectsProvider.clearOutputFrame(); + GlUtil.clearOutputFrame(); @C.ColorTransfer int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer(); defaultShaderProgram.setOutputColorTransfer( diff --git a/libraries/effect/src/main/java/androidx/media3/effect/FrameCacheGlShaderProgram.java b/libraries/effect/src/main/java/androidx/media3/effect/FrameCacheGlShaderProgram.java index fa4571c422..a7a4963642 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/FrameCacheGlShaderProgram.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/FrameCacheGlShaderProgram.java @@ -137,7 +137,7 @@ import java.util.concurrent.Executor; // Copy frame to fbo. GlUtil.focusFramebufferUsingCurrentContext( outputTexture.fboId, outputTexture.width, outputTexture.height); - glObjectsProvider.clearOutputFrame(); + GlUtil.clearOutputFrame(); drawFrame(inputTexture.texId); inputListener.onInputFrameProcessed(inputTexture); outputListener.onOutputFrameAvailable(outputTexture, presentationTimeUs); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/SingleFrameGlShaderProgram.java b/libraries/effect/src/main/java/androidx/media3/effect/SingleFrameGlShaderProgram.java index e42f1e1268..3b91f8b7a9 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/SingleFrameGlShaderProgram.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/SingleFrameGlShaderProgram.java @@ -144,7 +144,7 @@ public abstract class SingleFrameGlShaderProgram implements GlShaderProgram { outputTextureInUse = true; GlUtil.focusFramebufferUsingCurrentContext( outputTexture.fboId, outputTexture.width, outputTexture.height); - glObjectsProvider.clearOutputFrame(); + GlUtil.clearOutputFrame(); drawFrame(inputTexture.texId, presentationTimeUs); inputListener.onInputFrameProcessed(inputTexture); outputListener.onOutputFrameAvailable(outputTexture, presentationTimeUs);