Skip to content

Commit c276aee

Browse files
Fabian BergmarkWebRTC LUCI CQ
authored andcommitted
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 <[email protected]> Reviewed-by: Xavier Lepaul‎ <[email protected]> Commit-Queue: Xavier Lepaul‎ <[email protected]> Cr-Commit-Position: refs/heads/main@{#35313}
1 parent 0d01841 commit c276aee

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

sdk/android/src/java/org/webrtc/EglBase10Impl.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import android.graphics.Canvas;
1414
import android.graphics.Rect;
1515
import android.graphics.SurfaceTexture;
16+
import android.opengl.EGL14;
17+
import android.opengl.GLException;
1618
import android.view.Surface;
1719
import android.view.SurfaceHolder;
1820
import androidx.annotation.Nullable;
@@ -66,7 +68,7 @@ public long getNativeEglContext() {
6668
tempEglSurface =
6769
egl.eglCreatePbufferSurface(currentDisplay, eglContextConfig, surfaceAttribs);
6870
if (!egl.eglMakeCurrent(currentDisplay, tempEglSurface, tempEglSurface, eglContext)) {
69-
throw new RuntimeException(
71+
throw new GLException(egl.eglGetError(),
7072
"Failed to make temporary EGL surface active: " + egl.eglGetError());
7173
}
7274
}
@@ -187,7 +189,7 @@ private void createSurfaceInternal(Object nativeWindow) {
187189
int[] surfaceAttribs = {EGL10.EGL_NONE};
188190
eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, nativeWindow, surfaceAttribs);
189191
if (eglSurface == EGL10.EGL_NO_SURFACE) {
190-
throw new RuntimeException(
192+
throw new GLException(egl.eglGetError(),
191193
"Failed to create window surface: 0x" + Integer.toHexString(egl.eglGetError()));
192194
}
193195
}
@@ -207,8 +209,9 @@ public void createPbufferSurface(int width, int height) {
207209
int[] surfaceAttribs = {EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE};
208210
eglSurface = egl.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs);
209211
if (eglSurface == EGL10.EGL_NO_SURFACE) {
210-
throw new RuntimeException("Failed to create pixel buffer surface with size " + width + "x"
211-
+ height + ": 0x" + Integer.toHexString(egl.eglGetError()));
212+
throw new GLException(egl.eglGetError(),
213+
"Failed to create pixel buffer surface with size " + width + "x" + height + ": 0x"
214+
+ Integer.toHexString(egl.eglGetError()));
212215
}
213216
}
214217

@@ -271,7 +274,7 @@ public void makeCurrent() {
271274
}
272275
synchronized (EglBase.lock) {
273276
if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
274-
throw new RuntimeException(
277+
throw new GLException(egl.eglGetError(),
275278
"eglMakeCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
276279
}
277280
}
@@ -283,7 +286,7 @@ public void detachCurrent() {
283286
synchronized (EglBase.lock) {
284287
if (!egl.eglMakeCurrent(
285288
eglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT)) {
286-
throw new RuntimeException(
289+
throw new GLException(egl.eglGetError(),
287290
"eglDetachCurrent failed: 0x" + Integer.toHexString(egl.eglGetError()));
288291
}
289292
}
@@ -310,12 +313,12 @@ public void swapBuffers(long timeStampNs) {
310313
private EGLDisplay getEglDisplay() {
311314
EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
312315
if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
313-
throw new RuntimeException(
316+
throw new GLException(egl.eglGetError(),
314317
"Unable to get EGL10 display: 0x" + Integer.toHexString(egl.eglGetError()));
315318
}
316319
int[] version = new int[2];
317320
if (!egl.eglInitialize(eglDisplay, version)) {
318-
throw new RuntimeException(
321+
throw new GLException(egl.eglGetError(),
319322
"Unable to initialize EGL10: 0x" + Integer.toHexString(egl.eglGetError()));
320323
}
321324
return eglDisplay;
@@ -326,8 +329,8 @@ private static EGLConfig getEglConfig(EGL10 egl, EGLDisplay eglDisplay, int[] co
326329
EGLConfig[] configs = new EGLConfig[1];
327330
int[] numConfigs = new int[1];
328331
if (!egl.eglChooseConfig(eglDisplay, configAttributes, configs, configs.length, numConfigs)) {
329-
throw new RuntimeException(
330-
"eglChooseConfig failed: 0x" + Integer.toHexString(egl.eglGetError()));
332+
throw new GLException(
333+
egl.eglGetError(), "eglChooseConfig failed: 0x" + Integer.toHexString(egl.eglGetError()));
331334
}
332335
if (numConfigs[0] <= 0) {
333336
throw new RuntimeException("Unable to find any matching EGL config");
@@ -352,7 +355,7 @@ private EGLContext createEglContext(@Nullable EGLContext sharedContext, EGLDispl
352355
eglContext = egl.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes);
353356
}
354357
if (eglContext == EGL10.EGL_NO_CONTEXT) {
355-
throw new RuntimeException(
358+
throw new GLException(egl.eglGetError(),
356359
"Failed to create EGL context: 0x" + Integer.toHexString(egl.eglGetError()));
357360
}
358361
return eglContext;

sdk/android/src/java/org/webrtc/EglBase14Impl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.opengl.EGLDisplay;
1919
import android.opengl.EGLExt;
2020
import android.opengl.EGLSurface;
21+
import android.opengl.GLException;
2122
import android.os.Build;
2223
import android.view.Surface;
2324
import androidx.annotation.Nullable;
@@ -102,7 +103,7 @@ private void createSurfaceInternal(Object surface) {
102103
int[] surfaceAttribs = {EGL14.EGL_NONE};
103104
eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig, surface, surfaceAttribs, 0);
104105
if (eglSurface == EGL14.EGL_NO_SURFACE) {
105-
throw new RuntimeException(
106+
throw new GLException(EGL14.eglGetError(),
106107
"Failed to create window surface: 0x" + Integer.toHexString(EGL14.eglGetError()));
107108
}
108109
}
@@ -121,8 +122,9 @@ public void createPbufferSurface(int width, int height) {
121122
int[] surfaceAttribs = {EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE};
122123
eglSurface = EGL14.eglCreatePbufferSurface(eglDisplay, eglConfig, surfaceAttribs, 0);
123124
if (eglSurface == EGL14.EGL_NO_SURFACE) {
124-
throw new RuntimeException("Failed to create pixel buffer surface with size " + width + "x"
125-
+ height + ": 0x" + Integer.toHexString(EGL14.eglGetError()));
125+
throw new GLException(EGL14.eglGetError(),
126+
"Failed to create pixel buffer surface with size " + width + "x" + height + ": 0x"
127+
+ Integer.toHexString(EGL14.eglGetError()));
126128
}
127129
}
128130

@@ -188,7 +190,7 @@ public void makeCurrent() {
188190
}
189191
synchronized (EglBase.lock) {
190192
if (!EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
191-
throw new RuntimeException(
193+
throw new GLException(EGL14.eglGetError(),
192194
"eglMakeCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
193195
}
194196
}
@@ -200,7 +202,7 @@ public void detachCurrent() {
200202
synchronized (EglBase.lock) {
201203
if (!EGL14.eglMakeCurrent(
202204
eglDisplay, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT)) {
203-
throw new RuntimeException(
205+
throw new GLException(EGL14.eglGetError(),
204206
"eglDetachCurrent failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
205207
}
206208
}
@@ -235,12 +237,12 @@ public void swapBuffers(long timeStampNs) {
235237
private static EGLDisplay getEglDisplay() {
236238
EGLDisplay eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
237239
if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
238-
throw new RuntimeException(
240+
throw new GLException(EGL14.eglGetError(),
239241
"Unable to get EGL14 display: 0x" + Integer.toHexString(EGL14.eglGetError()));
240242
}
241243
int[] version = new int[2];
242244
if (!EGL14.eglInitialize(eglDisplay, version, 0, version, 1)) {
243-
throw new RuntimeException(
245+
throw new GLException(EGL14.eglGetError(),
244246
"Unable to initialize EGL14: 0x" + Integer.toHexString(EGL14.eglGetError()));
245247
}
246248
return eglDisplay;
@@ -252,7 +254,7 @@ private static EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] configAttribu
252254
int[] numConfigs = new int[1];
253255
if (!EGL14.eglChooseConfig(
254256
eglDisplay, configAttributes, 0, configs, 0, configs.length, numConfigs, 0)) {
255-
throw new RuntimeException(
257+
throw new GLException(EGL14.eglGetError(),
256258
"eglChooseConfig failed: 0x" + Integer.toHexString(EGL14.eglGetError()));
257259
}
258260
if (numConfigs[0] <= 0) {
@@ -278,7 +280,7 @@ private static EGLContext createEglContext(@Nullable EGLContext sharedContext,
278280
eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0);
279281
}
280282
if (eglContext == EGL14.EGL_NO_CONTEXT) {
281-
throw new RuntimeException(
283+
throw new GLException(EGL14.eglGetError(),
282284
"Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError()));
283285
}
284286
return eglContext;

0 commit comments

Comments
 (0)