[gtk/wip.win32.fixes: 6/6] gtkgstsink.c: Tell GstGL winsys type and API if needed




commit b70dfd4e0da2ce91837acfe81ad224abb7f514b1
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon May 17 17:56:56 2021 +0800

    gtkgstsink.c: Tell GstGL winsys type and API if needed
    
    GstGL may have been built with or without EGL/libANGLE support, so if it were,
    set in the environment that we want to use a Win32 winsys and a GL API that
    corresponds to the GL API that is used in our GdkGLContext.  If we are using
    EGL, set the API to glesv2 as it is needed for proper libANGLE support, so that
    we get the GstGLDisplay that we need configured properly via
    gst_gl_display_new().
    
    Unfortunately things must be set via envvars as GstGL do not have APIs for
    Windows to set these things up in other ways.

 modules/media/gtkgstsink.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
---
diff --git a/modules/media/gtkgstsink.c b/modules/media/gtkgstsink.c
index 91ce989188..3e6a534564 100644
--- a/modules/media/gtkgstsink.c
+++ b/modules/media/gtkgstsink.c
@@ -478,10 +478,31 @@ gtk_gst_sink_initialize_gl (GtkGstSink *self)
 
       gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
       gl_handle = gst_gl_context_get_current_gl_context (platform);
-         g_message ("GL Type: %s", gl_api == GST_GL_API_OPENGL3 ? "wgl" : "egl");
 
       if (gl_handle)
         {
+          gchar *gl_api_str = NULL;
+
+#ifdef GST_GL_HAVE_PLATFORM_EGL
+          /*
+           * We must force a win32 GstGL display type and if using desktop GL, the GL_Platform to be WGL
+           * and an appropriate GstGL API depending on the gl_api we receive.  We also ensure that we use
+           * an EGL GstGL API if we are using EGL in GDK.  Envvars are required, unfortunately, so that
+           * gst_gl_display_new() does things correctly if we have GstGL built with both EGL and WGL
+           * support, otherwise gst_gl_display_new() will assume an EGL display, which won't work for us
+           */
+          gl_api_str = gst_gl_api_to_string (gl_api);
+          g_setenv ("GST_GL_WINDOW", "win32", TRUE);
+
+          if (gl_api == GST_GL_API_OPENGL3 || gl_api == GST_GL_API_OPENGL)
+            g_setenv("GST_GL_PLATFORM", "wgl", TRUE);
+          else
+            g_setenv("GST_GL_PLATFORM", "egl", TRUE);
+
+          g_setenv ("GST_GL_API", gl_api_str, TRUE);
+          g_free (gl_api_str);
+#endif
+
           self->gst_display = gst_gl_display_new ();
           self->gst_app_context = gst_gl_context_new_wrapped (self->gst_display, gl_handle, platform, 
gl_api);
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]