From c276aee4eda7b1a466b139838f20e790bd746309 Mon Sep 17 00:00:00 2001 From: Fabian Bergmark Date: Wed, 3 Nov 2021 13:39:37 +0100 Subject: [PATCH] Throw EGL errors to GLExceptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:13359 Change-Id: I1528fcd4cd0a5fc243baccd61fc4032cd0db4004 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237141 Reviewed-by: Mirko Bonadei Reviewed-by: Xavier Lepaul‎ Commit-Queue: Xavier Lepaul‎ Cr-Commit-Position: refs/heads/main@{#35313} --- .../src/java/org/webrtc/EglBase10Impl.java | 25 +++++++++++-------- .../src/java/org/webrtc/EglBase14Impl.java | 20 ++++++++------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/EglBase10Impl.java b/sdk/android/src/java/org/webrtc/EglBase10Impl.java index 14b9141381..254a17c750 100644 --- a/sdk/android/src/java/org/webrtc/EglBase10Impl.java +++ b/sdk/android/src/java/org/webrtc/EglBase10Impl.java @@ -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; diff --git a/sdk/android/src/java/org/webrtc/EglBase14Impl.java b/sdk/android/src/java/org/webrtc/EglBase14Impl.java index 3e319bac85..aa27cf81e2 100644 --- a/sdk/android/src/java/org/webrtc/EglBase14Impl.java +++ b/sdk/android/src/java/org/webrtc/EglBase14Impl.java @@ -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;