From c74b16e9f41cc9b4c35c42c976629769751e7eef Mon Sep 17 00:00:00 2001 From: hschlueter Date: Thu, 17 Mar 2022 11:23:46 +0000 Subject: [PATCH] Add missing exception checks after EGL14 calls in GlUtil. PiperOrigin-RevId: 435308470 --- .../androidx/media3/common/util/GlUtil.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java index 9d4f5ce45c..a293a30932 100644 --- a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java +++ b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java @@ -414,6 +414,11 @@ public final class GlUtil { } } + private static void checkEglException(String errorMessage) { + int error = EGL14.eglGetError(); + checkEglException(error == EGL14.EGL_SUCCESS, errorMessage + ", error code: " + error); + } + @RequiresApi(17) private static final class Api17 { private Api17() {} @@ -462,12 +467,15 @@ public final class GlUtil { Object surface, int[] configAttributes, int[] windowSurfaceAttributes) { - return EGL14.eglCreateWindowSurface( - eglDisplay, - getEglConfig(eglDisplay, configAttributes), - surface, - windowSurfaceAttributes, - /* offset= */ 0); + EGLSurface eglSurface = + EGL14.eglCreateWindowSurface( + eglDisplay, + getEglConfig(eglDisplay, configAttributes), + surface, + windowSurfaceAttributes, + /* offset= */ 0); + checkEglException("Error creating surface"); + return eglSurface; } @DoNotInline @@ -483,8 +491,11 @@ public final class GlUtil { if (boundFramebuffer[0] != framebuffer) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer); } + checkGlError(); EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); + checkEglException("Error making context current"); GLES20.glViewport(/* x= */ 0, /* y= */ 0, width, height); + checkGlError(); } @DoNotInline @@ -495,19 +506,15 @@ public final class GlUtil { } EGL14.eglMakeCurrent( eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); - int error = EGL14.eglGetError(); - checkEglException(error == EGL14.EGL_SUCCESS, "Error releasing context: " + error); + checkEglException("Error releasing context"); if (eglContext != null) { EGL14.eglDestroyContext(eglDisplay, eglContext); - error = EGL14.eglGetError(); - checkEglException(error == EGL14.EGL_SUCCESS, "Error destroying context: " + error); + checkEglException("Error destroying context"); } EGL14.eglReleaseThread(); - error = EGL14.eglGetError(); - checkEglException(error == EGL14.EGL_SUCCESS, "Error releasing thread: " + error); + checkEglException("Error releasing thread"); EGL14.eglTerminate(eglDisplay); - error = EGL14.eglGetError(); - checkEglException(error == EGL14.EGL_SUCCESS, "Error terminating display: " + error); + checkEglException("Error terminating display"); } @DoNotInline