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)) {
// Create a placeholder context and make it current to allow calling GLES20.glGetString().
try {
EGLDisplay eglDisplay = createEglDisplay();
EGLDisplay eglDisplay = getDefaultEglDisplay();
EGLContext eglContext = createEglContext(eglDisplay);
createFocusedPlaceholderEglSurface(eglContext, eglDisplay);
glExtensions = GLES20.glGetString(GLES20.GL_EXTENSIONS);
@ -235,8 +235,8 @@ public final class GlUtil {
/** Returns an initialized default {@link EGLDisplay}. */
@RequiresApi(17)
public static EGLDisplay createEglDisplay() throws GlException {
return Api17.createEglDisplay();
public static EGLDisplay getDefaultEglDisplay() throws GlException {
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.glClearDepthf(1.0f);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
@ -672,7 +678,7 @@ public final class GlUtil {
private Api17() {}
@DoNotInline
public static EGLDisplay createEglDisplay() throws GlException {
public static EGLDisplay getDefaultEglDisplay() throws GlException {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
checkGlException(!eglDisplay.equals(EGL14.EGL_NO_DISPLAY), "No EGL display.");
checkGlException(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -364,7 +364,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputEglSurface,
outputSurfaceInfo.width,
outputSurfaceInfo.height);
GlUtil.clearOutputFrame();
GlUtil.clearFocusedBuffers();
defaultShaderProgram.drawFrame(inputTexture.getTexId(), presentationTimeUs);
EGLExt.eglPresentationTimeANDROID(
@ -383,7 +383,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
outputTextureTimestamps.add(presentationTimeUs);
GlUtil.focusFramebufferUsingCurrentContext(
outputTexture.getFboId(), outputTexture.getWidth(), outputTexture.getHeight());
GlUtil.clearOutputFrame();
GlUtil.clearFocusedBuffers();
checkNotNull(defaultShaderProgram).drawFrame(inputTexture.getTexId(), presentationTimeUs);
// 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
@ -529,7 +529,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
checkNotNull(debugSurfaceViewWrapper)
.maybeRenderToSurfaceView(
() -> {
GlUtil.clearOutputFrame();
GlUtil.clearFocusedBuffers();
if (enableColorTransfers) {
@C.ColorTransfer
int configuredColorTransfer = defaultShaderProgram.getOutputColorTransfer();

View File

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