Add missing exception checks after EGL14 calls in GlUtil.

PiperOrigin-RevId: 435308470
This commit is contained in:
hschlueter 2022-03-17 11:23:46 +00:00 committed by Ian Baker
parent b2b27dc571
commit c74b16e9f4

View File

@ -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) @RequiresApi(17)
private static final class Api17 { private static final class Api17 {
private Api17() {} private Api17() {}
@ -462,12 +467,15 @@ public final class GlUtil {
Object surface, Object surface,
int[] configAttributes, int[] configAttributes,
int[] windowSurfaceAttributes) { int[] windowSurfaceAttributes) {
return EGL14.eglCreateWindowSurface( EGLSurface eglSurface =
eglDisplay, EGL14.eglCreateWindowSurface(
getEglConfig(eglDisplay, configAttributes), eglDisplay,
surface, getEglConfig(eglDisplay, configAttributes),
windowSurfaceAttributes, surface,
/* offset= */ 0); windowSurfaceAttributes,
/* offset= */ 0);
checkEglException("Error creating surface");
return eglSurface;
} }
@DoNotInline @DoNotInline
@ -483,8 +491,11 @@ public final class GlUtil {
if (boundFramebuffer[0] != framebuffer) { if (boundFramebuffer[0] != framebuffer) {
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, framebuffer);
} }
checkGlError();
EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
checkEglException("Error making context current");
GLES20.glViewport(/* x= */ 0, /* y= */ 0, width, height); GLES20.glViewport(/* x= */ 0, /* y= */ 0, width, height);
checkGlError();
} }
@DoNotInline @DoNotInline
@ -495,19 +506,15 @@ public final class GlUtil {
} }
EGL14.eglMakeCurrent( EGL14.eglMakeCurrent(
eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
int error = EGL14.eglGetError(); checkEglException("Error releasing context");
checkEglException(error == EGL14.EGL_SUCCESS, "Error releasing context: " + error);
if (eglContext != null) { if (eglContext != null) {
EGL14.eglDestroyContext(eglDisplay, eglContext); EGL14.eglDestroyContext(eglDisplay, eglContext);
error = EGL14.eglGetError(); checkEglException("Error destroying context");
checkEglException(error == EGL14.EGL_SUCCESS, "Error destroying context: " + error);
} }
EGL14.eglReleaseThread(); EGL14.eglReleaseThread();
error = EGL14.eglGetError(); checkEglException("Error releasing thread");
checkEglException(error == EGL14.EGL_SUCCESS, "Error releasing thread: " + error);
EGL14.eglTerminate(eglDisplay); EGL14.eglTerminate(eglDisplay);
error = EGL14.eglGetError(); checkEglException("Error terminating display");
checkEglException(error == EGL14.EGL_SUCCESS, "Error terminating display: " + error);
} }
@DoNotInline @DoNotInline