GL: Rename GL methods.

To more accurately describe what they do, especially as Compositor will
starts to use more contexts or threads, and it's important to know what
needs to be reset/recreated/focused before what methods.

PiperOrigin-RevId: 541010135
This commit is contained in:
huangdarwin 2023-06-16 22:52:05 +01:00 committed by Marc Baechinger
parent c0e8513b7a
commit 949e9cbd96
15 changed files with 28 additions and 22 deletions

View File

@ -211,7 +211,7 @@ public final class GlUtil {
if (Util.areEqual(EGL14.eglGetCurrentContext(), EGL14.EGL_NO_CONTEXT)) { if (Util.areEqual(EGL14.eglGetCurrentContext(), EGL14.EGL_NO_CONTEXT)) {
// Create a placeholder context and make it current to allow calling GLES20.glGetString(). // Create a placeholder context and make it current to allow calling GLES20.glGetString().
try { try {
EGLDisplay eglDisplay = createEglDisplay(); EGLDisplay eglDisplay = getDefaultEglDisplay();
EGLContext eglContext = createEglContext(eglDisplay); EGLContext eglContext = createEglContext(eglDisplay);
createFocusedPlaceholderEglSurface(eglContext, eglDisplay); createFocusedPlaceholderEglSurface(eglContext, eglDisplay);
glExtensions = GLES20.glGetString(GLES20.GL_EXTENSIONS); glExtensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
@ -235,8 +235,8 @@ public final class GlUtil {
/** Returns an initialized default {@link EGLDisplay}. */ /** Returns an initialized default {@link EGLDisplay}. */
@RequiresApi(17) @RequiresApi(17)
public static EGLDisplay createEglDisplay() throws GlException { public static EGLDisplay getDefaultEglDisplay() throws GlException {
return Api17.createEglDisplay(); return Api17.getDefaultEglDisplay();
} }
/** /**
@ -424,8 +424,14 @@ public final class GlUtil {
} }
} }
/** Fills the pixels in the current output render target with (r=0, g=0, b=0, a=0). */ /**
public static void clearOutputFrame() throws GlException { * Fills the pixels in the current output render target buffers with (r=0, g=0, b=0, a=0).
*
* <p>Buffers can be focused using {@link #focusEglSurface} and {@link
* #focusFramebufferUsingCurrentContext}, {@link #focusFramebuffer}, and {@link
* #createFocusedPlaceholderEglSurface}.
*/
public static void clearFocusedBuffers() throws GlException {
GLES20.glClearColor(/* red= */ 0, /* green= */ 0, /* blue= */ 0, /* alpha= */ 0); GLES20.glClearColor(/* red= */ 0, /* green= */ 0, /* blue= */ 0, /* alpha= */ 0);
GLES20.glClearDepthf(1.0f); GLES20.glClearDepthf(1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
@ -672,7 +678,7 @@ public final class GlUtil {
private Api17() {} private Api17() {}
@DoNotInline @DoNotInline
public static EGLDisplay createEglDisplay() throws GlException { public static EGLDisplay getDefaultEglDisplay() throws GlException {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
checkGlException(!eglDisplay.equals(EGL14.EGL_NO_DISPLAY), "No EGL display."); checkGlException(!eglDisplay.equals(EGL14.EGL_NO_DISPLAY), "No EGL display.");
checkGlException( checkGlException(

View File

@ -78,7 +78,7 @@ public class ContrastPixelTest {
@Before @Before
public void createGlObjects() throws Exception { public void createGlObjects() throws Exception {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -71,7 +71,7 @@ public final class CropPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -71,7 +71,7 @@ public final class DefaultShaderProgramPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
EGLSurface placeholderEglSurface = EGLSurface placeholderEglSurface =
GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -387,7 +387,7 @@ public final class DefaultVideoFrameProcessorVideoFrameRenderingTest {
int fboId = GlUtil.createFboForTexture(texId); int fboId = GlUtil.createFboForTexture(texId);
blankTexture = new GlTextureInfo(texId, fboId, /* rboId= */ C.INDEX_UNSET, WIDTH, HEIGHT); blankTexture = new GlTextureInfo(texId, fboId, /* rboId= */ C.INDEX_UNSET, WIDTH, HEIGHT);
GlUtil.focusFramebufferUsingCurrentContext(fboId, WIDTH, HEIGHT); GlUtil.focusFramebufferUsingCurrentContext(fboId, WIDTH, HEIGHT);
GlUtil.clearOutputFrame(); GlUtil.clearFocusedBuffers();
} catch (GlUtil.GlException e) { } catch (GlUtil.GlException e) {
throw new VideoFrameProcessingException(e); throw new VideoFrameProcessingException(e);
} }

View File

@ -83,7 +83,7 @@ public final class HslAdjustmentPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -90,7 +90,7 @@ public class OverlayShaderProgramPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -80,7 +80,7 @@ public final class PresentationPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -77,7 +77,7 @@ public final class RgbAdjustmentPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -72,7 +72,7 @@ public final class RgbFilterPixelTest {
@Before @Before
public void createGlObjects() throws IOException, GlUtil.GlException { public void createGlObjects() throws IOException, GlUtil.GlException {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -77,7 +77,7 @@ public class SingleColorLutPixelTest {
@Before @Before
public void createGlObjects() throws Exception { public void createGlObjects() throws Exception {
eglDisplay = GlUtil.createEglDisplay(); eglDisplay = GlUtil.getDefaultEglDisplay();
eglContext = GlUtil.createEglContext(eglDisplay); eglContext = GlUtil.createEglContext(eglDisplay);
placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay); placeholderEglSurface = GlUtil.createFocusedPlaceholderEglSurface(eglContext, eglDisplay);

View File

@ -140,7 +140,7 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
// Copy frame to fbo. // Copy frame to fbo.
GlUtil.focusFramebufferUsingCurrentContext( GlUtil.focusFramebufferUsingCurrentContext(
outputTexture.getFboId(), outputTexture.getWidth(), outputTexture.getHeight()); outputTexture.getFboId(), outputTexture.getWidth(), outputTexture.getHeight());
GlUtil.clearOutputFrame(); GlUtil.clearFocusedBuffers();
drawFrame(inputTexture.getTexId(), presentationTimeUs); drawFrame(inputTexture.getTexId(), presentationTimeUs);
inputListener.onInputFrameProcessed(inputTexture); inputListener.onInputFrameProcessed(inputTexture);
outputListener.onOutputFrameAvailable(outputTexture, presentationTimeUs); outputListener.onOutputFrameAvailable(outputTexture, presentationTimeUs);

View File

@ -607,7 +607,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
throws GlUtil.GlException, VideoFrameProcessingException { throws GlUtil.GlException, VideoFrameProcessingException {
checkState(Thread.currentThread().getName().equals(THREAD_NAME)); checkState(Thread.currentThread().getName().equals(THREAD_NAME));
EGLDisplay eglDisplay = GlUtil.createEglDisplay(); EGLDisplay eglDisplay = GlUtil.getDefaultEglDisplay();
int[] configAttributes = int[] configAttributes =
ColorInfo.isTransferHdr(outputColorInfo) ColorInfo.isTransferHdr(outputColorInfo)
? GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102 ? GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_1010102

View File

@ -364,7 +364,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputEglSurface, outputEglSurface,
outputSurfaceInfo.width, outputSurfaceInfo.width,
outputSurfaceInfo.height); outputSurfaceInfo.height);
GlUtil.clearOutputFrame(); GlUtil.clearFocusedBuffers();
defaultShaderProgram.drawFrame(inputTexture.getTexId(), presentationTimeUs); defaultShaderProgram.drawFrame(inputTexture.getTexId(), presentationTimeUs);
EGLExt.eglPresentationTimeANDROID( EGLExt.eglPresentationTimeANDROID(
@ -383,7 +383,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputTextureTimestamps.add(presentationTimeUs); outputTextureTimestamps.add(presentationTimeUs);
GlUtil.focusFramebufferUsingCurrentContext( GlUtil.focusFramebufferUsingCurrentContext(
outputTexture.getFboId(), outputTexture.getWidth(), outputTexture.getHeight()); outputTexture.getFboId(), outputTexture.getWidth(), outputTexture.getHeight());
GlUtil.clearOutputFrame(); GlUtil.clearFocusedBuffers();
checkNotNull(defaultShaderProgram).drawFrame(inputTexture.getTexId(), presentationTimeUs); checkNotNull(defaultShaderProgram).drawFrame(inputTexture.getTexId(), presentationTimeUs);
// TODO(b/262694346): If Compositor's VFPs all use the same context, media3 should be able to // TODO(b/262694346): If Compositor's VFPs all use the same context, media3 should be able to
// avoid calling glFinish, and require the onTextureRendered listener to decide whether to // avoid calling glFinish, and require the onTextureRendered listener to decide whether to
@ -529,7 +529,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
checkNotNull(debugSurfaceViewWrapper) checkNotNull(debugSurfaceViewWrapper)
.maybeRenderToSurfaceView( .maybeRenderToSurfaceView(
() -> { () -> {
GlUtil.clearOutputFrame(); GlUtil.clearFocusedBuffers();
if (enableColorTransfers) { if (enableColorTransfers) {
@C.ColorTransfer @C.ColorTransfer
int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer(); int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer();

View File

@ -559,7 +559,7 @@ public final class AndroidTestUtil {
* {@link EGLContext}. * {@link EGLContext}.
*/ */
public static EGLContext createOpenGlObjects() throws GlUtil.GlException { public static EGLContext createOpenGlObjects() throws GlUtil.GlException {
EGLDisplay eglDisplay = GlUtil.createEglDisplay(); EGLDisplay eglDisplay = GlUtil.getDefaultEglDisplay();
int[] configAttributes = GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888; int[] configAttributes = GlUtil.EGL_CONFIG_ATTRIBUTES_RGBA_8888;
GlObjectsProvider glObjectsProvider = GlObjectsProvider glObjectsProvider =
new DefaultGlObjectsProvider(/* sharedEglContext= */ null); new DefaultGlObjectsProvider(/* sharedEglContext= */ null);