diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/GlObjectsProvider.java b/library/common/src/main/java/com/google/android/exoplayer2/util/GlObjectsProvider.java index b80dd97d9c..979384ab8f 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/GlObjectsProvider.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/GlObjectsProvider.java @@ -18,6 +18,7 @@ package com.google.android.exoplayer2.util; import android.opengl.EGLContext; import android.opengl.EGLDisplay; +import android.opengl.EGLSurface; import androidx.annotation.IntRange; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; @@ -39,6 +40,26 @@ public interface GlObjectsProvider { return GlUtil.createEglContext(eglDisplay, openGlVersion, configAttributes); } + @Override + @RequiresApi(17) + public EGLSurface createEglSurface( + EGLDisplay eglDisplay, + Object surface, + @C.ColorTransfer int colorTransfer, + boolean isEncoderInputSurface) + throws GlException { + return GlUtil.createEglSurface(eglDisplay, surface, colorTransfer, isEncoderInputSurface); + } + + @Override + @RequiresApi(17) + public EGLSurface createFocusedPlaceholderEglSurface( + EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes) + throws GlException { + return GlUtil.createFocusedPlaceholderEglSurface( + eglContext, eglDisplay, configAttributes); + } + @Override public GlTextureInfo createBuffersForTexture(int texId, int width, int height) throws GlException { @@ -66,6 +87,23 @@ 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. + @RequiresApi(17) + default EGLSurface createEglSurface( + EGLDisplay eglDisplay, + Object surface, + @C.ColorTransfer int colorTransfer, + boolean isEncoderInputSurface) + throws GlException { + return GlUtil.createEglSurface(eglDisplay, surface, colorTransfer, isEncoderInputSurface); + } + + @RequiresApi(17) + default EGLSurface createFocusedPlaceholderEglSurface( + EGLContext eglContext, EGLDisplay eglDisplay, int[] configAttributes) throws GlException { + return GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes); + } + /** * Returns a {@link GlTextureInfo} containing the identifiers of the newly created buffers. * diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/DefaultVideoFrameProcessor.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/DefaultVideoFrameProcessor.java index 4a0262f259..4f2b6583f9 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/DefaultVideoFrameProcessor.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/DefaultVideoFrameProcessor.java @@ -395,7 +395,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ColorInfo.isTransferHdr(inputColorInfo) || ColorInfo.isTransferHdr(outputColorInfo) ? 3 : 2; EGLContext eglContext = glObjectsProvider.createEglContext(eglDisplay, openGlVersion, configAttributes); - GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes); + glObjectsProvider.createFocusedPlaceholderEglSurface(eglContext, eglDisplay, configAttributes); // Not releaseFramesAutomatically means outputting to a display surface. HDR display surfaces // require the BT2020 PQ GL extension. @@ -422,7 +422,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { isInputTextureExternal, releaseFramesAutomatically, executor, - listener); + listener, + glObjectsProvider); setGlObjectProviderOnShaderPrograms(shaderPrograms, glObjectsProvider); VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor = new VideoFrameProcessingTaskExecutor(singleThreadExecutorService, listener); @@ -460,7 +461,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { boolean isInputTextureExternal, boolean releaseFramesAutomatically, Executor executor, - Listener listener) + Listener listener, + GlObjectsProvider glObjectsProvider) throws VideoFrameProcessingException { ImmutableList.Builder shaderProgramListBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder matrixTransformationListBuilder = @@ -533,7 +535,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { isInputTextureExternal, releaseFramesAutomatically, executor, - listener)); + listener, + glObjectsProvider)); return shaderProgramListBuilder.build(); } diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/FinalShaderProgramWrapper.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/FinalShaderProgramWrapper.java index 4409b306cb..4545113e33 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/FinalShaderProgramWrapper.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/FinalShaderProgramWrapper.java @@ -116,7 +116,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; boolean isInputTextureExternal, boolean releaseFramesAutomatically, Executor videoFrameProcessorListenerExecutor, - VideoFrameProcessor.Listener videoFrameProcessorListener) { + VideoFrameProcessor.Listener videoFrameProcessorListener, + GlObjectsProvider glObjectsProvider) { this.context = context; this.matrixTransformations = matrixTransformations; this.rgbMatrices = rgbMatrices; @@ -130,10 +131,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; this.releaseFramesAutomatically = releaseFramesAutomatically; this.videoFrameProcessorListenerExecutor = videoFrameProcessorListenerExecutor; this.videoFrameProcessorListener = videoFrameProcessorListener; + this.glObjectsProvider = glObjectsProvider; textureTransformMatrix = GlUtil.create4x4IdentityMatrix(); streamOffsetUsQueue = new ConcurrentLinkedQueue<>(); - glObjectsProvider = GlObjectsProvider.DEFAULT; inputListener = new InputListener() {}; availableFrames = new ConcurrentLinkedQueue<>(); } @@ -375,7 +376,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; @Nullable EGLSurface outputEglSurface = this.outputEglSurface; if (outputEglSurface == null) { outputEglSurface = - GlUtil.createEglSurface( + glObjectsProvider.createEglSurface( eglDisplay, outputSurfaceInfo.surface, outputColorInfo.colorTransfer, @@ -472,7 +473,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; checkNotNull(debugSurfaceViewWrapper).outputColorTransfer); defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer); - }); + }, + glObjectsProvider); } catch (VideoFrameProcessingException | GlUtil.GlException e) { Log.d(TAG, "Error rendering to debug preview", e); } @@ -546,7 +548,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; * *

Must be called on the GL thread. */ - public synchronized void maybeRenderToSurfaceView(VideoFrameProcessingTask renderingTask) + public synchronized void maybeRenderToSurfaceView( + VideoFrameProcessingTask renderingTask, GlObjectsProvider glObjectsProvider) throws GlUtil.GlException, VideoFrameProcessingException { if (surface == null) { return; @@ -554,7 +557,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; if (eglSurface == null) { eglSurface = - GlUtil.createEglSurface( + glObjectsProvider.createEglSurface( eglDisplay, surface, outputColorTransfer, /* isEncoderInputSurface= */ false); } EGLSurface eglSurface = this.eglSurface;