13
13
import android .graphics .Canvas ;
14
14
import android .graphics .Rect ;
15
15
import android .graphics .SurfaceTexture ;
16
+ import android .opengl .EGL14 ;
17
+ import android .opengl .GLException ;
16
18
import android .view .Surface ;
17
19
import android .view .SurfaceHolder ;
18
20
import androidx .annotation .Nullable ;
@@ -66,7 +68,7 @@ public long getNativeEglContext() {
66
68
tempEglSurface =
67
69
egl .eglCreatePbufferSurface (currentDisplay , eglContextConfig , surfaceAttribs );
68
70
if (!egl .eglMakeCurrent (currentDisplay , tempEglSurface , tempEglSurface , eglContext )) {
69
- throw new RuntimeException (
71
+ throw new GLException ( egl . eglGetError (),
70
72
"Failed to make temporary EGL surface active: " + egl .eglGetError ());
71
73
}
72
74
}
@@ -187,7 +189,7 @@ private void createSurfaceInternal(Object nativeWindow) {
187
189
int [] surfaceAttribs = {EGL10 .EGL_NONE };
188
190
eglSurface = egl .eglCreateWindowSurface (eglDisplay , eglConfig , nativeWindow , surfaceAttribs );
189
191
if (eglSurface == EGL10 .EGL_NO_SURFACE ) {
190
- throw new RuntimeException (
192
+ throw new GLException ( egl . eglGetError (),
191
193
"Failed to create window surface: 0x" + Integer .toHexString (egl .eglGetError ()));
192
194
}
193
195
}
@@ -207,8 +209,9 @@ public void createPbufferSurface(int width, int height) {
207
209
int [] surfaceAttribs = {EGL10 .EGL_WIDTH , width , EGL10 .EGL_HEIGHT , height , EGL10 .EGL_NONE };
208
210
eglSurface = egl .eglCreatePbufferSurface (eglDisplay , eglConfig , surfaceAttribs );
209
211
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 ()));
212
215
}
213
216
}
214
217
@@ -271,7 +274,7 @@ public void makeCurrent() {
271
274
}
272
275
synchronized (EglBase .lock ) {
273
276
if (!egl .eglMakeCurrent (eglDisplay , eglSurface , eglSurface , eglContext )) {
274
- throw new RuntimeException (
277
+ throw new GLException ( egl . eglGetError (),
275
278
"eglMakeCurrent failed: 0x" + Integer .toHexString (egl .eglGetError ()));
276
279
}
277
280
}
@@ -283,7 +286,7 @@ public void detachCurrent() {
283
286
synchronized (EglBase .lock ) {
284
287
if (!egl .eglMakeCurrent (
285
288
eglDisplay , EGL10 .EGL_NO_SURFACE , EGL10 .EGL_NO_SURFACE , EGL10 .EGL_NO_CONTEXT )) {
286
- throw new RuntimeException (
289
+ throw new GLException ( egl . eglGetError (),
287
290
"eglDetachCurrent failed: 0x" + Integer .toHexString (egl .eglGetError ()));
288
291
}
289
292
}
@@ -310,12 +313,12 @@ public void swapBuffers(long timeStampNs) {
310
313
private EGLDisplay getEglDisplay () {
311
314
EGLDisplay eglDisplay = egl .eglGetDisplay (EGL10 .EGL_DEFAULT_DISPLAY );
312
315
if (eglDisplay == EGL10 .EGL_NO_DISPLAY ) {
313
- throw new RuntimeException (
316
+ throw new GLException ( egl . eglGetError (),
314
317
"Unable to get EGL10 display: 0x" + Integer .toHexString (egl .eglGetError ()));
315
318
}
316
319
int [] version = new int [2 ];
317
320
if (!egl .eglInitialize (eglDisplay , version )) {
318
- throw new RuntimeException (
321
+ throw new GLException ( egl . eglGetError (),
319
322
"Unable to initialize EGL10: 0x" + Integer .toHexString (egl .eglGetError ()));
320
323
}
321
324
return eglDisplay ;
@@ -326,8 +329,8 @@ private static EGLConfig getEglConfig(EGL10 egl, EGLDisplay eglDisplay, int[] co
326
329
EGLConfig [] configs = new EGLConfig [1 ];
327
330
int [] numConfigs = new int [1 ];
328
331
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 ()));
331
334
}
332
335
if (numConfigs [0 ] <= 0 ) {
333
336
throw new RuntimeException ("Unable to find any matching EGL config" );
@@ -352,7 +355,7 @@ private EGLContext createEglContext(@Nullable EGLContext sharedContext, EGLDispl
352
355
eglContext = egl .eglCreateContext (eglDisplay , eglConfig , rootContext , contextAttributes );
353
356
}
354
357
if (eglContext == EGL10 .EGL_NO_CONTEXT ) {
355
- throw new RuntimeException (
358
+ throw new GLException ( egl . eglGetError (),
356
359
"Failed to create EGL context: 0x" + Integer .toHexString (egl .eglGetError ()));
357
360
}
358
361
return eglContext ;
0 commit comments