[vlc-devel] [PATCH v3 5/7] egl_pbuffer: add support for surfaceless context

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


From: Alexandre Janniaux <ajanni at videolabs.io>

If the EGL extension EGL_KHR_surfaceless_context is available, create a
surfaceless context.

Co-authored-by: Romain Vimont <rom1v at videolabs.io>
---
 modules/video_filter/egl_pbuffer.c | 37 ++++++++++++++++++++++++------
 1 file changed, 30 insertions(+), 7 deletions(-)

diff --git a/modules/video_filter/egl_pbuffer.c b/modules/video_filter/egl_pbuffer.c
index 64bee6b403..7ac4ebf0b7 100644
--- a/modules/video_filter/egl_pbuffer.c
+++ b/modules/video_filter/egl_pbuffer.c
@@ -158,7 +158,11 @@ static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
 #endif
             );
 
-    const EGLint conf_attr[] = {
+    const char *extensions = eglQueryString(sys->display, EGL_EXTENSIONS);
+    bool need_surface =
+        !vlc_gl_StrHasToken(extensions, "EGL_KHR_surfaceless_context");
+
+    static const EGLint conf_attr_surface[] = {
         EGL_RED_SIZE, 8,
         EGL_GREEN_SIZE, 8,
         EGL_BLUE_SIZE, 8,
@@ -170,6 +174,19 @@ static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
         EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
         EGL_NONE,
     };
+
+    static const EGLint conf_attr_surfaceless[] = {
+#ifdef USE_OPENGL_ES2
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+#else
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+#endif
+        EGL_NONE,
+    };
+
+    const EGLint *conf_attr = need_surface ? conf_attr_surface
+                                           : conf_attr_surfaceless;
+
     EGLConfig cfgv[1];
     EGLint cfgc;
 
@@ -187,14 +204,20 @@ static int InitEGL(vlc_gl_t *gl, unsigned width, unsigned height)
         goto error;
     }
 
-    /* Create a drawing surface */
-    sys->surface = eglCreatePbufferSurface(sys->display, cfgv[0], surface_attr);
-    if (sys->surface == EGL_NO_SURFACE)
+    if (need_surface)
     {
-        msg_Err (gl, "cannot create EGL window surface");
-        assert(false);
-        goto error;
+        /* Create a drawing surface */
+        sys->surface = eglCreatePbufferSurface(sys->display, cfgv[0],
+                                               surface_attr);
+        if (sys->surface == EGL_NO_SURFACE)
+        {
+            msg_Err (gl, "cannot create EGL window surface");
+            assert(false);
+            goto error;
+        }
     }
+    else
+        sys->surface = EGL_NO_SURFACE;
 
 #ifdef USE_OPENGL_ES2
     if (eglBindAPI (EGL_OPENGL_ES_API) != EGL_TRUE)
-- 
2.31.0



More information about the vlc-devel mailing list