Commit 44cf5735 by tofunmi Committed by tonihei

Update GlObjectsProvider to cover creating surface.

PiperOrigin-RevId: 516300480
parent 8a9c51a8
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.util; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.util;
import android.opengl.EGLContext; import android.opengl.EGLContext;
import android.opengl.EGLDisplay; import android.opengl.EGLDisplay;
import android.opengl.EGLSurface;
import androidx.annotation.IntRange; import androidx.annotation.IntRange;
import androidx.annotation.RequiresApi; import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -40,6 +41,26 @@ public interface GlObjectsProvider { ...@@ -40,6 +41,26 @@ public interface GlObjectsProvider {
} }
@Override @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) public GlTextureInfo createBuffersForTexture(int texId, int width, int height)
throws GlException { throws GlException {
int fboId = GlUtil.createFboForTexture(texId); int fboId = GlUtil.createFboForTexture(texId);
...@@ -66,6 +87,23 @@ public interface GlObjectsProvider { ...@@ -66,6 +87,23 @@ public interface GlObjectsProvider {
EGLDisplay eglDisplay, @IntRange(from = 2, to = 3) int openGlVersion, int[] configAttributes) EGLDisplay eglDisplay, @IntRange(from = 2, to = 3) int openGlVersion, int[] configAttributes)
throws GlException; 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. * Returns a {@link GlTextureInfo} containing the identifiers of the newly created buffers.
* *
......
...@@ -395,7 +395,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -395,7 +395,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
ColorInfo.isTransferHdr(inputColorInfo) || ColorInfo.isTransferHdr(outputColorInfo) ? 3 : 2; ColorInfo.isTransferHdr(inputColorInfo) || ColorInfo.isTransferHdr(outputColorInfo) ? 3 : 2;
EGLContext eglContext = EGLContext eglContext =
glObjectsProvider.createEglContext(eglDisplay, openGlVersion, configAttributes); 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 // Not releaseFramesAutomatically means outputting to a display surface. HDR display surfaces
// require the BT2020 PQ GL extension. // require the BT2020 PQ GL extension.
...@@ -422,7 +422,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -422,7 +422,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
isInputTextureExternal, isInputTextureExternal,
releaseFramesAutomatically, releaseFramesAutomatically,
executor, executor,
listener); listener,
glObjectsProvider);
setGlObjectProviderOnShaderPrograms(shaderPrograms, glObjectsProvider); setGlObjectProviderOnShaderPrograms(shaderPrograms, glObjectsProvider);
VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor = VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor =
new VideoFrameProcessingTaskExecutor(singleThreadExecutorService, listener); new VideoFrameProcessingTaskExecutor(singleThreadExecutorService, listener);
...@@ -460,7 +461,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -460,7 +461,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
boolean isInputTextureExternal, boolean isInputTextureExternal,
boolean releaseFramesAutomatically, boolean releaseFramesAutomatically,
Executor executor, Executor executor,
Listener listener) Listener listener,
GlObjectsProvider glObjectsProvider)
throws VideoFrameProcessingException { throws VideoFrameProcessingException {
ImmutableList.Builder<GlShaderProgram> shaderProgramListBuilder = new ImmutableList.Builder<>(); ImmutableList.Builder<GlShaderProgram> shaderProgramListBuilder = new ImmutableList.Builder<>();
ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder = ImmutableList.Builder<GlMatrixTransformation> matrixTransformationListBuilder =
...@@ -533,7 +535,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor { ...@@ -533,7 +535,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
isInputTextureExternal, isInputTextureExternal,
releaseFramesAutomatically, releaseFramesAutomatically,
executor, executor,
listener)); listener,
glObjectsProvider));
return shaderProgramListBuilder.build(); return shaderProgramListBuilder.build();
} }
......
...@@ -116,7 +116,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -116,7 +116,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
boolean isInputTextureExternal, boolean isInputTextureExternal,
boolean releaseFramesAutomatically, boolean releaseFramesAutomatically,
Executor videoFrameProcessorListenerExecutor, Executor videoFrameProcessorListenerExecutor,
VideoFrameProcessor.Listener videoFrameProcessorListener) { VideoFrameProcessor.Listener videoFrameProcessorListener,
GlObjectsProvider glObjectsProvider) {
this.context = context; this.context = context;
this.matrixTransformations = matrixTransformations; this.matrixTransformations = matrixTransformations;
this.rgbMatrices = rgbMatrices; this.rgbMatrices = rgbMatrices;
...@@ -130,10 +131,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -130,10 +131,10 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
this.releaseFramesAutomatically = releaseFramesAutomatically; this.releaseFramesAutomatically = releaseFramesAutomatically;
this.videoFrameProcessorListenerExecutor = videoFrameProcessorListenerExecutor; this.videoFrameProcessorListenerExecutor = videoFrameProcessorListenerExecutor;
this.videoFrameProcessorListener = videoFrameProcessorListener; this.videoFrameProcessorListener = videoFrameProcessorListener;
this.glObjectsProvider = glObjectsProvider;
textureTransformMatrix = GlUtil.create4x4IdentityMatrix(); textureTransformMatrix = GlUtil.create4x4IdentityMatrix();
streamOffsetUsQueue = new ConcurrentLinkedQueue<>(); streamOffsetUsQueue = new ConcurrentLinkedQueue<>();
glObjectsProvider = GlObjectsProvider.DEFAULT;
inputListener = new InputListener() {}; inputListener = new InputListener() {};
availableFrames = new ConcurrentLinkedQueue<>(); availableFrames = new ConcurrentLinkedQueue<>();
} }
...@@ -375,7 +376,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -375,7 +376,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Nullable EGLSurface outputEglSurface = this.outputEglSurface; @Nullable EGLSurface outputEglSurface = this.outputEglSurface;
if (outputEglSurface == null) { if (outputEglSurface == null) {
outputEglSurface = outputEglSurface =
GlUtil.createEglSurface( glObjectsProvider.createEglSurface(
eglDisplay, eglDisplay,
outputSurfaceInfo.surface, outputSurfaceInfo.surface,
outputColorInfo.colorTransfer, outputColorInfo.colorTransfer,
...@@ -472,7 +473,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -472,7 +473,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
checkNotNull(debugSurfaceViewWrapper).outputColorTransfer); checkNotNull(debugSurfaceViewWrapper).outputColorTransfer);
defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs); defaultShaderProgram.drawFrame(inputTexture.texId, presentationTimeUs);
defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer); defaultShaderProgram.setOutputColorTransfer(configuredColorTransfer);
}); },
glObjectsProvider);
} catch (VideoFrameProcessingException | GlUtil.GlException e) { } catch (VideoFrameProcessingException | GlUtil.GlException e) {
Log.d(TAG, "Error rendering to debug preview", e); Log.d(TAG, "Error rendering to debug preview", e);
} }
...@@ -546,7 +548,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -546,7 +548,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* *
* <p>Must be called on the GL thread. * <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 { throws GlUtil.GlException, VideoFrameProcessingException {
if (surface == null) { if (surface == null) {
return; return;
...@@ -554,7 +557,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -554,7 +557,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
if (eglSurface == null) { if (eglSurface == null) {
eglSurface = eglSurface =
GlUtil.createEglSurface( glObjectsProvider.createEglSurface(
eglDisplay, surface, outputColorTransfer, /* isEncoderInputSurface= */ false); eglDisplay, surface, outputColorTransfer, /* isEncoderInputSurface= */ false);
} }
EGLSurface eglSurface = this.eglSurface; EGLSurface eglSurface = this.eglSurface;
......
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