Throw EGL errors to GLExceptions.

Bug: webrtc:13359
Change-Id: I1528fcd4cd0a5fc243baccd61fc4032cd0db4004
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237141
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Xavier Lepaul‎ <xalep@webrtc.org>
Commit-Queue: Xavier Lepaul‎ <xalep@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35313}
This commit is contained in:
Fabian Bergmark
2021-11-03 13:39:37 +01:00
committed by WebRTC LUCI CQ
parent 0d018415d5
commit c276aee4ed
2 changed files with 25 additions and 20 deletions

View File

@ -13,6 +13,8 @@ package org.webrtc;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.opengl.EGL14;
import android.opengl.GLException;
import android.view.Surface;
import android.view.SurfaceHolder;
import androidx.annotation.Nullable;
@ -66,7 +68,7 @@ class EglBase10Impl implements EglBase10 {
tempEglSurface =
egl.eglCreatePbufferSurface(currentDisplay, eglContextConfig, surfaceAttribs);
if (!egl.eglMakeCurrent(currentDisplay, tempEglSurface, tempEglSurface, eglContext)) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"Failed to make temporary EGL surface active: " + egl.eglGetError());
}
}
@ -187,7 +189,7 @@ class EglBase10Impl implements EglBase10 {
int[] surfaceAttribs = {EGL10.EGL_NONE};
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs);
if (eglSurface == EGL10.EGL_NO_SURFACE) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"Failed to create window surface: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
@ -207,8 +209,9 @@ class EglBase10Impl implements EglBase10 {
int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE};
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 + ": 0x" + Integer.toHexString(egl.eglGetError()));
throw new GLException(egl.eglGetError(),
"Failed to create pixel buffer surface with size " + width + "x" + height + ": 0x"
+ Integer.toHexString(egl.eglGetError()));
}
}
@ -271,7 +274,7 @@ class EglBase10Impl implements EglBase10 {
}
synchronized (EglBase.lock) {
if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
@ -283,7 +286,7 @@ class EglBase10Impl implements EglBase10 {
synchronized (EglBase.lock) {
if (!egl.eglMakeCurrent(
eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"eglDetachCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
}
@ -310,12 +313,12 @@ class EglBase10Impl implements EglBase10 {
private EGLDisplay getEglDisplay() {
EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"Unable to get EGL10 display: 0x" + Integer.toHexString(egl.eglGetError()));
}
int[] version = new int[2];
if (!egl.eglInitialize(eglDisplay, version)) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"Unable to initialize EGL10: 0x" + Integer.toHexString(egl.eglGetError()));
}
return eglDisplay;
@ -326,8 +329,8 @@ class EglBase10Impl implements EglBase10 {
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
if (!egl.eglChooseConfig(eglDisplay, configAttributes, configs, configs.length, numConfigs)) {
throw new RuntimeException(
"eglChooseConfig failed: 0x" + Integer.toHexString(egl.eglGetError()));
throw new GLException(
egl.eglGetError(), "eglChooseConfig failed: 0x" + Integer.toHexString(egl.eglGetError()));
}
if (numConfigs[0] <= 0) {
throw new RuntimeException("Unable to find any matching EGL config");
@ -352,7 +355,7 @@ class EglBase10Impl implements EglBase10 {
eglContext = egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes);
}
if (eglContext == EGL10.EGL_NO_CONTEXT) {
throw new RuntimeException(
throw new GLException(egl.eglGetError(),
"Failed to create EGL context: 0x" + Integer.toHexString(egl.eglGetError()));
}
return eglContext;

View File

@ -18,6 +18,7 @@ import android.opengl.EGLContext;
import android.opengl.EGLDisplay;
import android.opengl.EGLExt;
import android.opengl.EGLSurface;
import android.opengl.GLException;
import android.os.Build;
import android.view.Surface;
import androidx.annotation.Nullable;
@ -102,7 +103,7 @@ class EglBase14Impl implements EglBase14 {
int[] surfaceAttribs = {EGL14.EGL_NONE};
eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0);
if (eglSurface == EGL14.EGL_NO_SURFACE) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
@ -121,8 +122,9 @@ class EglBase14Impl implements EglBase14 {
int[] surfaceAttribs = {EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE};
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 + ": 0x" + Integer.toHexString(EGL14.eglGetError()));
throw new GLException(EGL14.eglGetError(),
"Failed to create pixel buffer surface with size " + width + "x" + height + ": 0x"
+ Integer.toHexString(EGL14.eglGetError()));
}
}
@ -188,7 +190,7 @@ class EglBase14Impl implements EglBase14 {
}
synchronized (EglBase.lock) {
if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"eglMakeCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
@ -200,7 +202,7 @@ class EglBase14Impl implements EglBase14 {
synchronized (EglBase.lock) {
if (!EGL14.eglMakeCurrent(
eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"eglDetachCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
}
@ -235,12 +237,12 @@ class EglBase14Impl implements EglBase14 {
private static EGLDisplay getEglDisplay() {
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"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(
throw new GLException(EGL14.eglGetError(),
"Unable to initialize EGL14: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
return eglDisplay;
@ -252,7 +254,7 @@ class EglBase14Impl implements EglBase14 {
int[] numConfigs = new int[1];
if (!EGL14.eglChooseConfig(
eglDisplay, configAttributes, 0, configs, 0, configs.length, numConfigs, 0)) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"eglChooseConfig failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
if (numConfigs[0] <= 0) {
@ -278,7 +280,7 @@ class EglBase14Impl implements EglBase14 {
eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
}
if (eglContext == EGL14.EGL_NO_CONTEXT) {
throw new RuntimeException(
throw new GLException(EGL14.eglGetError(),
"Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
}
return eglContext;