From bdf78cb5bb4a104abf0b3bbe679ab7427e427a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Kalliom=C3=A4ki?= Date: Tue, 16 Feb 2021 10:40:57 +0000 Subject: [PATCH] Bug fixes to EglBase10Impl.getNativeEglContext. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use matching config to avoid EGL_BAD_MATCH. - Use the same display in both eglMakeCurrent calls to avoid EGL_BAD_ACCESS on subsequent calls because the context was not successfully unbound. Bug: webrtc:12471 Change-Id: Ifdf4bd94cdfd14b683959b8703d75a2a46ec1226 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/207861 Reviewed-by: Paulina Hensman Commit-Queue: Sami Kalliomäki Cr-Commit-Position: refs/heads/master@{#33279} --- .../src/java/org/webrtc/EglBase10Impl.java | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/sdk/android/src/java/org/webrtc/EglBase10Impl.java b/sdk/android/src/java/org/webrtc/EglBase10Impl.java index f512490d30..1affbd9de6 100644 --- a/sdk/android/src/java/org/webrtc/EglBase10Impl.java +++ b/sdk/android/src/java/org/webrtc/EglBase10Impl.java @@ -41,6 +41,7 @@ class EglBase10Impl implements EglBase10 { private static class Context implements EglBase10.Context { private final EGL10 egl; private final EGLContext eglContext; + private final EGLConfig eglContextConfig; @Override public EGLContext getRawContext() { @@ -50,21 +51,23 @@ class EglBase10Impl implements EglBase10 { @Override public long getNativeEglContext() { EGLContext previousContext = egl.eglGetCurrentContext(); - EGLDisplay previousDisplay = egl.eglGetCurrentDisplay(); + EGLDisplay currentDisplay = egl.eglGetCurrentDisplay(); EGLSurface previousDrawSurface = egl.eglGetCurrentSurface(EGL10.EGL_DRAW); EGLSurface previousReadSurface = egl.eglGetCurrentSurface(EGL10.EGL_READ); EGLSurface tempEglSurface = null; - EGLDisplay defaultDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + if (currentDisplay == EGL10.EGL_NO_DISPLAY) { + currentDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); + } try { if (previousContext != eglContext) { int[] surfaceAttribs = {EGL10.EGL_WIDTH, 1, EGL10.EGL_HEIGHT, 1, EGL10.EGL_NONE}; - EGLConfig eglConfig = getEglConfig(egl, defaultDisplay, EglBase.CONFIG_PIXEL_BUFFER); - - tempEglSurface = egl.eglCreatePbufferSurface(defaultDisplay, eglConfig, surfaceAttribs); - if (!egl.eglMakeCurrent(defaultDisplay, tempEglSurface, tempEglSurface, eglContext)) { - throw new RuntimeException("Failed to make temporary EGL surface active."); + tempEglSurface = + egl.eglCreatePbufferSurface(currentDisplay, eglContextConfig, surfaceAttribs); + if (!egl.eglMakeCurrent(currentDisplay, tempEglSurface, tempEglSurface, eglContext)) { + throw new RuntimeException( + "Failed to make temporary EGL surface active: " + egl.eglGetError()); } } @@ -72,15 +75,16 @@ class EglBase10Impl implements EglBase10 { } finally { if (tempEglSurface != null) { egl.eglMakeCurrent( - previousDisplay, previousDrawSurface, previousReadSurface, previousContext); - egl.eglDestroySurface(defaultDisplay, tempEglSurface); + currentDisplay, previousDrawSurface, previousReadSurface, previousContext); + egl.eglDestroySurface(currentDisplay, tempEglSurface); } } } - public Context(EGL10 egl, EGLContext eglContext) { + public Context(EGL10 egl, EGLContext eglContext, EGLConfig eglContextConfig) { this.egl = egl; this.eglContext = eglContext; + this.eglContextConfig = eglContextConfig; } } @@ -210,7 +214,7 @@ class EglBase10Impl implements EglBase10 { @Override public org.webrtc.EglBase.Context getEglBaseContext() { - return new Context(egl, eglContext); + return new Context(egl, eglContext, eglConfig); } @Override