1313import android .graphics .Canvas ;
1414import android .graphics .Rect ;
1515import android .graphics .SurfaceTexture ;
16+ import android .opengl .EGL14 ;
17+ import android .opengl .GLException ;
1618import android .view .Surface ;
1719import android .view .SurfaceHolder ;
1820import 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 ;
0 commit comments