[vlc-devel] [PATCH 1/2] egl_pbuffer: improve support detection
Romain Vimont
rom1v at videolabs.io
Tue Mar 2 13:51:38 UTC 2021
The video filter egl_pbuffer may be used only if the display is
refcounted, because we don't know if other modules are using EGL.
This is always the case on Android, so egl_pbuffer was initially only
enabled on Android:
https://android.googlesource.com/platform/frameworks/native/+/master/opengl/libs/EGL/egl_display.cpp
But this may also be the case on other platforms which support
EGL_KHR_display_reference:
https://www.khronos.org/registry/EGL/extensions/KHR/EGL_KHR_display_reference.txt
Co-authored-by: Alexandre Janniaux <ajanni at videolabs.io>
---
modules/video_filter/egl_pbuffer.c | 53 ++++++++++++++++++++++++-
modules/video_output/opengl/Makefile.am | 7 ++++
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/modules/video_filter/egl_pbuffer.c b/modules/video_filter/egl_pbuffer.c
index 0ecc2562d0..78cd48b3fd 100644
--- a/modules/video_filter/egl_pbuffer.c
+++ b/modules/video_filter/egl_pbuffer.c
@@ -127,12 +127,61 @@ static bool DestroyImageKHR(vlc_gl_t *gl, void *image)
return sys->eglDestroyImageKHR(sys->display, image);
}
-static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
+static bool GetPlatform(const char *extensions, EGLenum *out)
+{
+#ifdef EGL_KHR_platform_x11
+ if (vlc_gl_StrHasToken(extensions, "EGL_EXT_platform_x11"))
+ {
+ *out = EGL_PLATFORM_X11_KHR;
+ return true;
+ }
+#endif
+
+#ifdef EGL_KHR_platform_wayland
+ if (vlc_gl_StrHasToken(extensions, "EGL_EXT_platform_wayland"))
+ {
+ *out = EGL_PLATFORM_WAYLAND_KHR;
+ return true;
+ }
+#endif
+
+ return false;
+}
+
+static bool InitDefaultEGLDisplay(vlc_gl_t *gl)
{
struct vlc_gl_pbuffer *sys = gl->sys;
+#ifdef __ANDROID__
+ /* The default display is refcounted on Android */
sys->display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
- if (sys->display == EGL_NO_DISPLAY)
+#elif defined(EGL_KHR_display_reference)
+ const char *extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+
+ if (!vlc_gl_StrHasToken(extensions, "EGL_KHR_display_reference"))
+ return false;
+
+ EGLenum platform;
+ if (!GetPlatform(extensions, &platform))
+ return false;
+
+ const EGLAttrib attribs[] = {
+ EGL_TRACK_REFERENCES_KHR, EGL_TRUE,
+ EGL_NONE,
+ };
+
+ sys->display =
+ eglGetPlatformDisplay(platform, EGL_DEFAULT_DISPLAY, attribs);
+#endif
+
+ return sys->display != EGL_NO_DISPLAY;
+}
+
+static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
+{
+ struct vlc_gl_pbuffer *sys = gl->sys;
+
+ if (!InitDefaultEGLDisplay(gl))
return VLC_EGENERIC;
/* Initialize EGL display */
diff --git a/modules/video_output/opengl/Makefile.am b/modules/video_output/opengl/Makefile.am
index dcb8ace5c6..d3170d9ac7 100644
--- a/modules/video_output/opengl/Makefile.am
+++ b/modules/video_output/opengl/Makefile.am
@@ -93,6 +93,13 @@ libegl_pbuffer_filter_plugin_la_SOURCES = video_filter/egl_pbuffer.c
libegl_pbuffer_filter_plugin_la_CPPFLAGS = $(AM_CPPFLAGS) $(EGL_FLAGS)
libegl_pbuffer_filter_plugin_la_LIBADD = $(LIBM) $(EGL_LIBS)
+if HAVE_LINUX
+if HAVE_GL
+libegl_pbuffer_filter_plugin_la_LIBADD += libvlc_opengl.la $(GL_LIBS)
+vout_LTLIBRARIES += libegl_pbuffer_filter_plugin.la
+endif
+endif
+
if HAVE_ANDROID
libegl_pbuffer_filter_plugin_la_LIBADD += libvlc_opengles.la $(GLES2_LIBS)
libegl_pbuffer_filter_plugin_la_CPPFLAGS += -DUSE_OPENGL_ES2=1
--
2.30.1
More information about the vlc-devel
mailing list