From 7d93f2d40c675e81dfb84eeb59607800e247cc9c Mon Sep 17 00:00:00 2001 From: huangdarwin Date: Fri, 10 Dec 2021 12:49:39 +0000 Subject: [PATCH] Transformer GL: Remove UnsupportedEglVersionException(). UnsupportedEglVersionException() is only used once, and seems a bit too specific for Transformer. Also, it's possible for eglCreateContext to fail for other reasons besides lack of support, so it wasn't always accurate when thrown. It is possible for devices not to support EGL version 2.0 though, per https://source.android.com/devices/graphics/implement-opengl-es, which doesn't specify the EGL version that must be supported. PiperOrigin-RevId: 415489396 --- .../android/exoplayer2/util/GlUtil.java | 20 ++++++------------- .../exoplayer2/transformer/FrameEditor.java | 7 +------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java b/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java index 9d8dd942de..427e6bf6f7 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/util/GlUtil.java @@ -53,9 +53,6 @@ public final class GlUtil { } } - /** Thrown when the required EGL version is not supported by the device. */ - public static final class UnsupportedEglVersionException extends Exception {} - /** * Represents a GLSL shader program. * @@ -259,15 +256,9 @@ public final class GlUtil { return Api17.createEglDisplay(); } - /** - * Returns a new {@link EGLContext} for the specified {@link EGLDisplay}. - * - * @throws UnsupportedEglVersionException If the device does not support EGL version 2. {@code - * eglDisplay} is terminated before the exception is thrown in this case. - */ + /** Returns a new {@link EGLContext} for the specified {@link EGLDisplay}. */ @RequiresApi(17) - public static EGLContext createEglContext(EGLDisplay eglDisplay) - throws UnsupportedEglVersionException { + public static EGLContext createEglContext(EGLDisplay eglDisplay) { return Api17.createEglContext(eglDisplay); } @@ -637,8 +628,7 @@ public final class GlUtil { } @DoNotInline - public static EGLContext createEglContext(EGLDisplay eglDisplay) - throws UnsupportedEglVersionException { + public static EGLContext createEglContext(EGLDisplay eglDisplay) { int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; EGLContext eglContext = EGL14.eglCreateContext( @@ -649,7 +639,9 @@ public final class GlUtil { /* offset= */ 0); if (eglContext == null) { EGL14.eglTerminate(eglDisplay); - throw new UnsupportedEglVersionException(); + throwGlException( + "eglCreateContext() failed to create a valid context. The device may not support EGL" + + " version 2"); } checkGlError(); return eglContext; diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameEditor.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameEditor.java index 3488517535..bce0d98026 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameEditor.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/FrameEditor.java @@ -60,12 +60,7 @@ import java.util.concurrent.atomic.AtomicInteger; Surface outputSurface, Transformer.DebugViewProvider debugViewProvider) { EGLDisplay eglDisplay = GlUtil.createEglDisplay(); - EGLContext eglContext; - try { - eglContext = GlUtil.createEglContext(eglDisplay); - } catch (GlUtil.UnsupportedEglVersionException e) { - throw new IllegalStateException("EGL version is unsupported", e); - } + EGLContext eglContext = GlUtil.createEglContext(eglDisplay); EGLSurface eglSurface = GlUtil.getEglSurface(eglDisplay, outputSurface); GlUtil.focusSurface(eglDisplay, eglContext, eglSurface, outputWidth, outputHeight); int textureId = GlUtil.createExternalTexture();