[vlc-devel] [PATCH 2/2] egl: tune eglTerminate behaviour with display_reference availability

Alexandre Janniaux ajanni at videolabs.io
Wed Sep 25 11:31:52 CEST 2019


EGL_KHR_display_reference specifies the behaviour of eglTerminate
with regards to reference counting. In addition, it specifies that
the default is that reference counting is disabled X11 or wayland,
but enabled on Android.

As we can prevent EGL GL provider from terminating its state, it
makes sure the state is correctly refcounted in any case.
---
 modules/video_output/opengl/egl.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/modules/video_output/opengl/egl.c b/modules/video_output/opengl/egl.c
index 6d6ab05738f..a3d1274029a 100644
--- a/modules/video_output/opengl/egl.c
+++ b/modules/video_output/opengl/egl.c
@@ -181,6 +181,21 @@ static void Close(vlc_gl_t *gl)
 {
     vlc_gl_sys_t *sys = gl->sys;
 
+    /* See https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_display_reference.txt */
+    /* If EGL_KHR_display_reference is not present, eglTerminate will
+     * terminate the EGLDisplay which is shared between all clients.
+     * This extension turns the behaviour of eglTerminate into reference
+     * counting mode and prevents this issues.
+     * TODO: Currently, we're using the default behaviour of this extension,
+     *       but this behaviour should be changed whenever possible. */
+#ifdef USE_PLATFORM_ANDROID
+    /* Enforced by Android. */
+    const bool has_display_reference = true;
+#else
+    /* The default is false for all other platforms. */
+    const bool has_display_reference = false;
+#endif
+
     if (sys->display != EGL_NO_DISPLAY)
     {
         if (sys->context != EGL_NO_CONTEXT)
@@ -188,8 +203,10 @@ static void Close(vlc_gl_t *gl)
         if (sys->surface != EGL_NO_SURFACE)
             eglDestroySurface(sys->display, sys->surface);
 
-        /* Kill the egl state only if we own it. */
-        if (!sys->prevent_terminate)
+        /* If has_display_reference == true, sys->display is refcounted by
+         * eglInitialize and eglTerminate, so call it anyway.
+         * Otherwise, kill the egl state only if we own it. */
+        if (has_display_reference || !sys->prevent_terminate)
             eglTerminate(sys->display);
         eglReleaseThread();
     }
-- 
2.23.0



More information about the vlc-devel mailing list