Update GlObjectsProvider to cover creating surface.

PiperOrigin-RevId: 516300480
This commit is contained in:
tofunmi 2023-03-13 20:10:27 +00:00 committed by tonihei
parent 8a9c51a8a2
commit 44cf57350a
3 changed files with 54 additions and 10 deletions

View File

@ -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.
*

View File

@ -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<GlShaderProgram> shaderProgramListBuilder = new ImmutableList.Builder<>();
ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder =
@ -533,7 +535,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
isInputTextureExternal,
releaseFramesAutomatically,
executor,
listener));
listener,
glObjectsProvider));
return shaderProgramListBuilder.build();
}

View File

@ -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;
*
* <p>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;