Android EglBase: Include EGL error code in exceptions

This CL appends the EGL error code in exceptions after an EGL function
fails. This information is helpful when debugging.

BUG=webrtc:6350

Review-Url: https://codereview.webrtc.org/2338033002
Cr-Commit-Position: refs/heads/master@{#14208}
This commit is contained in:
magjed
2016-09-14 02:40:50 -07:00
committed by Commit bot
parent 194f40a2e7
commit b471d1cffb
2 changed files with 32 additions and 16 deletions

View File

@ -139,7 +139,8 @@ public final class EglBase10 extends EglBase {
int[] surfaceAttribs = {EGL10.EGL_NONE};
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs);
if (eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException("Failed to create window surface");
throw new RuntimeException(
"Failed to create window surface: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
@ -159,7 +160,8 @@ public final class EglBase10 extends EglBase {
eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs);
if (eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException(
"Failed to create pixel buffer surface with size: " + width + "x" + height);
"Failed to create pixel buffer surface with size " + width + "x" + height
+ ": 0x" + Integer.toHexString(egl.eglGetError()));
}
}
@ -222,7 +224,8 @@ public final class EglBase10 extends EglBase {
}
synchronized (EglBase.lock) {
if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException("eglMakeCurrent failed");
throw new RuntimeException(
"eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
}
@ -233,7 +236,8 @@ public final class EglBase10 extends EglBase {
synchronized (EglBase.lock) {
if (!egl.eglMakeCurrent(
eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
throw new RuntimeException("eglDetachCurrent failed");
throw new RuntimeException(
"eglDetachCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
}
@ -253,11 +257,13 @@ public final class EglBase10 extends EglBase {
private EGLDisplay getEglDisplay() {
EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("Unable to get EGL10 display");
throw new RuntimeException(
"Unable to get EGL10 display: 0x" + Integer.toHexString(egl.eglGetError()));
}
int[] version = new int[2];
if (!egl.eglInitialize(eglDisplay, version)) {
throw new RuntimeException("Unable to initialize EGL10");
throw new RuntimeException(
"Unable to initialize EGL10: 0x" + Integer.toHexString(egl.eglGetError()));
}
return eglDisplay;
}
@ -268,7 +274,8 @@ public final class EglBase10 extends EglBase {
int[] numConfigs = new int[1];
if (!egl.eglChooseConfig(
eglDisplay, configAttributes, configs, configs.length, numConfigs)) {
throw new RuntimeException("eglChooseConfig failed");
throw new RuntimeException(
"eglChooseConfig failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
if (numConfigs[0] <= 0) {
throw new RuntimeException("Unable to find any matching EGL config");
@ -294,7 +301,8 @@ public final class EglBase10 extends EglBase {
eglContext = egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes);
}
if (eglContext == EGL10.EGL_NO_CONTEXT) {
throw new RuntimeException("Failed to create EGL context");
throw new RuntimeException(
"Failed to create EGL context: 0x" + Integer.toHexString(egl.eglGetError()));
}
return eglContext;
}

View File

@ -82,7 +82,8 @@ public final class EglBase14 extends EglBase {
int[] surfaceAttribs = {EGL14.EGL_NONE};
eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0);
if (eglSurface == EGL14.EGL_NO_SURFACE) {
throw new RuntimeException("Failed to create window surface");
throw new RuntimeException(
"Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
@ -101,7 +102,8 @@ public final class EglBase14 extends EglBase {
eglSurface = EGL14.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs, 0);
if (eglSurface == EGL14.EGL_NO_SURFACE) {
throw new RuntimeException(
"Failed to create pixel buffer surface with size: " + width + "x" + height);
"Failed to create pixel buffer surface with size " + width + "x" + height
+ ": 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
@ -165,7 +167,8 @@ public final class EglBase14 extends EglBase {
}
synchronized (EglBase.lock) {
if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException("eglMakeCurrent failed");
throw new RuntimeException(
"eglMakeCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
}
@ -176,7 +179,8 @@ public final class EglBase14 extends EglBase {
synchronized (EglBase.lock) {
if (!EGL14.eglMakeCurrent(
eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)) {
throw new RuntimeException("eglDetachCurrent failed");
throw new RuntimeException(
"eglDetachCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
}
@ -208,11 +212,13 @@ public final class EglBase14 extends EglBase {
private static EGLDisplay getEglDisplay() {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
throw new RuntimeException("Unable to get EGL14 display");
throw new RuntimeException(
"Unable to get EGL14 display: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
int[] version = new int[2];
if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) {
throw new RuntimeException("Unable to initialize EGL14");
throw new RuntimeException(
"Unable to initialize EGL14: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
return eglDisplay;
}
@ -223,7 +229,8 @@ public final class EglBase14 extends EglBase {
int[] numConfigs = new int[1];
if (!EGL14.eglChooseConfig(
eglDisplay, configAttributes, 0, configs, 0, configs.length, numConfigs, 0)) {
throw new RuntimeException("eglChooseConfig failed");
throw new RuntimeException(
"eglChooseConfig failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
if (numConfigs[0] <= 0) {
throw new RuntimeException("Unable to find any matching EGL config");
@ -249,7 +256,8 @@ public final class EglBase14 extends EglBase {
eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
}
if (eglContext == EGL14.EGL_NO_CONTEXT) {
throw new RuntimeException("Failed to create EGL context");
throw new RuntimeException(
"Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
return eglContext;
}