[vlc-devel] [PATCH v3 3/7] egl_pbuffer: use a default EGL display module

Romain Vimont rom1v at videolabs.io
Mon Mar 22 15:06:21 UTC 2021


Add a default EGL display module which just calls
eglGetDisplay(EGL_DEFAULT_DISPLAY).
---
 modules/video_filter/egl_pbuffer.c            | 16 +++++-
 modules/video_output/opengl/Makefile.am       | 10 +++-
 .../video_output/opengl/egl_display_generic.c | 50 +++++++++++++++++++
 3 files changed, 73 insertions(+), 3 deletions(-)
 create mode 100644 modules/video_output/opengl/egl_display_generic.c

diff --git a/modules/video_filter/egl_pbuffer.c b/modules/video_filter/egl_pbuffer.c
index 3774cf3a0b..64bee6b403 100644
--- a/modules/video_filter/egl_pbuffer.c
+++ b/modules/video_filter/egl_pbuffer.c
@@ -34,6 +34,7 @@
 #include "../video_output/opengl/gl_api.h"
 #include "../video_output/opengl/gl_common.h"
 #include "../video_output/opengl/interop.h"
+#include "../video_output/opengl/egl_display.h"
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 
@@ -64,6 +65,8 @@ struct vlc_gl_pbuffer
     GLuint                  textures[BUFFER_COUNT];
     struct pbo_picture_context     picture_contexts[BUFFER_COUNT];
 
+    struct vlc_egl_display *vlc_display;
+
     EGLDisplay display;
     EGLSurface surface;
     EGLContext context;
@@ -131,14 +134,20 @@ static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
 {
     struct vlc_gl_pbuffer *sys = gl->sys;
 
-    sys->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-    if (sys->display == EGL_NO_DISPLAY)
+    sys->vlc_display = vlc_egl_display_New(VLC_OBJECT(gl), NULL);
+    if (!sys->vlc_display)
         return VLC_EGENERIC;
 
+    sys->display = sys->vlc_display->display;
+    assert(sys->display != EGL_NO_DISPLAY);
+
     /* Initialize EGL display */
     EGLint major, minor;
     if (eglInitialize(sys->display, &major, &minor) != EGL_TRUE)
+    {
+        vlc_egl_display_Delete(sys->display);
         return VLC_EGENERIC;
+    }
     msg_Dbg(gl, "EGL version %s by %s, API %s",
             eglQueryString(sys->display, EGL_VERSION),
             eglQueryString(sys->display, EGL_VENDOR),
@@ -224,6 +233,7 @@ static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
     return VLC_SUCCESS;
 error:
     eglTerminate(sys->display);
+    vlc_egl_display_Delete(sys->display);
     return VLC_EGENERIC;
 }
 
@@ -355,6 +365,7 @@ static void Close( vlc_gl_t *gl )
     vlc_gl_ReleaseCurrent(sys->gl);
 
     eglTerminate(sys->display);
+    vlc_egl_display_Delete(sys->vlc_display);
 }
 
 static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
@@ -450,6 +461,7 @@ static int Open(vlc_gl_t *gl, unsigned width, unsigned height)
 
 error2:
     eglTerminate(sys->display);
+    vlc_egl_display_Delete(sys->vlc_display);
 error1:
     vlc_obj_free(&gl->obj, sys);
 
diff --git a/modules/video_output/opengl/Makefile.am b/modules/video_output/opengl/Makefile.am
index 4235607abc..364acbe87c 100644
--- a/modules/video_output/opengl/Makefile.am
+++ b/modules/video_output/opengl/Makefile.am
@@ -89,7 +89,15 @@ if HAVE_GL
 vout_LTLIBRARIES += libgl_plugin.la
 endif # HAVE_GL
 
-libegl_pbuffer_filter_plugin_la_SOURCES = video_filter/egl_pbuffer.c
+libegl_display_generic_plugin_la_SOURCES = video_output/opengl/egl_display_generic.c
+libegl_display_generic_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(EGL_FLAGS)
+libegl_display_generic_plugin_la_LIBADD = $(EGL_LIBS)
+if HAVE_ANDROID
+vout_LTLIBRARIES += libegl_display_generic_plugin.la
+endif
+
+libegl_pbuffer_filter_plugin_la_SOURCES = video_filter/egl_pbuffer.c \
+    video_output/opengl/egl_display.c
 libegl_pbuffer_filter_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(EGL_FLAGS)
 libegl_pbuffer_filter_plugin_la_LIBADD = $(EGL_LIBS)
 
diff --git a/modules/video_output/opengl/egl_display_generic.c b/modules/video_output/opengl/egl_display_generic.c
new file mode 100644
index 0000000000..dfa68125c4
--- /dev/null
+++ b/modules/video_output/opengl/egl_display_generic.c
@@ -0,0 +1,50 @@
+/*****************************************************************************
+ * egl_display_generic.c
+ *****************************************************************************
+ * Copyright (C) 2021 Videolabs
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_opengl.h>
+
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include "egl_display.h"
+
+static vlc_egl_display_open_fn Open;
+static int
+Open(struct vlc_egl_display *display)
+{
+    display->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+    if (display->display == EGL_NO_DISPLAY)
+        return VLC_EGENERIC;
+
+    return VLC_SUCCESS;
+}
+
+vlc_module_begin()
+    set_description("EGL generic display")
+    set_capability("egl display", 1)
+    set_callback(Open)
+    add_shortcut("egl_display_generic")
+vlc_module_end()
-- 
2.31.0



More information about the vlc-devel mailing list