From e40f11def5b0631469786cbadf4a858061c85cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Fri, 16 Jul 2021 23:50:26 +0200 Subject: [PATCH 1/3] sink: Small code cleanup --- lib/gst/clapper/gtk4/gstclapperglsink.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/gst/clapper/gtk4/gstclapperglsink.c b/lib/gst/clapper/gtk4/gstclapperglsink.c index cadcacc0..dbd34c04 100644 --- a/lib/gst/clapper/gtk4/gstclapperglsink.c +++ b/lib/gst/clapper/gtk4/gstclapperglsink.c @@ -434,12 +434,9 @@ gst_clapper_gl_sink_query (GstBaseSink * bsink, GstQuery * query) switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CONTEXT: - { - if (gst_gl_handle_context_query ((GstElement *) clapper_sink, query, - clapper_sink->display, clapper_sink->context, clapper_sink->gtk_context)) - return TRUE; + res = gst_gl_handle_context_query ((GstElement *) clapper_sink, query, + clapper_sink->display, clapper_sink->context, clapper_sink->gtk_context); break; - } default: res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query); break; From b308ae367fd1f6b4fc16fd75efe4d6c34af1c75d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Sat, 17 Jul 2021 09:14:24 +0200 Subject: [PATCH 2/3] sink: When GTK is using GLES on EGL, use it too If for some reason GTK ended up with using EGL with GLES instead of OpenGL and user did not specify anything other, use it by default in gstreamer part of the app too. --- lib/gst/clapper/gtk4/gtkclapperglwidget.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/gst/clapper/gtk4/gtkclapperglwidget.c b/lib/gst/clapper/gtk4/gtkclapperglwidget.c index f7e56f33..ab5bb602 100644 --- a/lib/gst/clapper/gtk4/gtkclapperglwidget.c +++ b/lib/gst/clapper/gtk4/gtkclapperglwidget.c @@ -901,7 +901,7 @@ gtk_clapper_gl_widget_set_buffer (GtkClapperGLWidget * clapper_widget, } static GstGLAPI -_get_current_gl_api (GstGLPlatform platform) +_get_current_gl_api (GstGLDisplay * display, GstGLPlatform platform) { GstGLAPI gl_api = GST_GL_API_NONE; guint gl_major = 0, gl_minor = 0; @@ -910,8 +910,15 @@ _get_current_gl_api (GstGLPlatform platform) if (gl_api) { const gboolean is_es = gl_api & (GST_GL_API_GLES1 | GST_GL_API_GLES2); + gchar *gl_api_str = gst_gl_api_to_string (gl_api); - GST_INFO ("Using OpenGL%s %d.%d", is_es ? " ES" : "", gl_major, gl_minor); + GST_INFO ("Using GL API: %s, ver: %d.%d", gl_api_str, gl_major, gl_minor); + g_free (gl_api_str); + + if (is_es && platform == GST_GL_PLATFORM_EGL && !g_getenv ("GST_GL_API")) { + GST_DEBUG ("No GST_GL_API env and GTK is using EGL GLES2, enforcing it"); + gst_gl_display_filter_gl_api (display, GST_GL_API_GLES2); + } } return gl_api; @@ -962,7 +969,7 @@ _get_gl_context (GtkClapperGLWidget * clapper_widget) } #endif if (gl_handle) { - gl_api = _get_current_gl_api (platform); + gl_api = _get_current_gl_api (priv->display, platform); priv->other_context = gst_gl_context_new_wrapped (priv->display, gl_handle, platform, gl_api); @@ -971,7 +978,7 @@ _get_gl_context (GtkClapperGLWidget * clapper_widget) #if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND) if (GST_IS_GL_DISPLAY_WAYLAND (priv->display)) { platform = GST_GL_PLATFORM_EGL; - gl_api = _get_current_gl_api (platform); + gl_api = _get_current_gl_api (priv->display, platform); gl_handle = gst_gl_context_get_current_gl_context (platform); if (gl_handle) priv->other_context = From 19e159d1bd47186060eae14f9e669b86d3a478db Mon Sep 17 00:00:00 2001 From: Rafostar <40623528+Rafostar@users.noreply.github.com> Date: Sun, 1 Aug 2021 12:44:35 +0200 Subject: [PATCH 3/3] sink: Cleanup GL context init code --- lib/gst/clapper/gtk4/gtkclapperglwidget.c | 61 +++++++++++------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/lib/gst/clapper/gtk4/gtkclapperglwidget.c b/lib/gst/clapper/gtk4/gtkclapperglwidget.c index ab5bb602..5c0a348e 100644 --- a/lib/gst/clapper/gtk4/gtkclapperglwidget.c +++ b/lib/gst/clapper/gtk4/gtkclapperglwidget.c @@ -900,8 +900,9 @@ gtk_clapper_gl_widget_set_buffer (GtkClapperGLWidget * clapper_widget, GTK_CLAPPER_GL_WIDGET_UNLOCK (clapper_widget); } -static GstGLAPI -_get_current_gl_api (GstGLDisplay * display, GstGLPlatform platform) +static gboolean +_wrap_current_gl (GstGLDisplay * display, GstGLPlatform platform, + GstGLContext ** other_context) { GstGLAPI gl_api = GST_GL_API_NONE; guint gl_major = 0, gl_minor = 0; @@ -911,6 +912,7 @@ _get_current_gl_api (GstGLDisplay * display, GstGLPlatform platform) if (gl_api) { const gboolean is_es = gl_api & (GST_GL_API_GLES1 | GST_GL_API_GLES2); gchar *gl_api_str = gst_gl_api_to_string (gl_api); + guintptr gl_handle = 0; GST_INFO ("Using GL API: %s, ver: %d.%d", gl_api_str, gl_major, gl_minor); g_free (gl_api_str); @@ -919,9 +921,16 @@ _get_current_gl_api (GstGLDisplay * display, GstGLPlatform platform) GST_DEBUG ("No GST_GL_API env and GTK is using EGL GLES2, enforcing it"); gst_gl_display_filter_gl_api (display, GST_GL_API_GLES2); } + + gl_handle = gst_gl_context_get_current_gl_context (platform); + if (gl_handle) { + if ((*other_context = gst_gl_context_new_wrapped (display, + gl_handle, platform, gl_api))) + return TRUE; + } } - return gl_api; + return FALSE; } static void @@ -929,8 +938,6 @@ _get_gl_context (GtkClapperGLWidget * clapper_widget) { GtkClapperGLWidgetPrivate *priv = clapper_widget->priv; GstGLPlatform platform = GST_GL_PLATFORM_NONE; - GstGLAPI gl_api = GST_GL_API_NONE; - guintptr gl_handle = 0; gtk_widget_realize (GTK_WIDGET (clapper_widget)); @@ -952,53 +959,45 @@ _get_gl_context (GtkClapperGLWidget * clapper_widget) } g_object_ref (priv->gdk_context); - gdk_gl_context_make_current (priv->gdk_context); +#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND) + if (GST_IS_GL_DISPLAY_WAYLAND (priv->display)) { + platform = GST_GL_PLATFORM_EGL; + GST_DEBUG ("Using EGL on Wayland"); + goto have_platform; + } +#endif #if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11) #if GST_GL_HAVE_PLATFORM_EGL if (GST_IS_GL_DISPLAY_EGL (priv->display)) { platform = GST_GL_PLATFORM_EGL; - gl_handle = gst_gl_context_get_current_gl_context (platform); + GST_DEBUG ("Using EGL on x11"); + goto have_platform; } #endif #if GST_GL_HAVE_PLATFORM_GLX - if (!gl_handle && GST_IS_GL_DISPLAY_X11 (priv->display)) { + if (GST_IS_GL_DISPLAY_X11 (priv->display)) { platform = GST_GL_PLATFORM_GLX; - gl_handle = gst_gl_context_get_current_gl_context (platform); + GST_DEBUG ("Using GLX on x11"); + goto have_platform; } #endif - if (gl_handle) { - gl_api = _get_current_gl_api (priv->display, platform); - priv->other_context = - gst_gl_context_new_wrapped (priv->display, gl_handle, - platform, gl_api); - } -#endif -#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND) - if (GST_IS_GL_DISPLAY_WAYLAND (priv->display)) { - platform = GST_GL_PLATFORM_EGL; - gl_api = _get_current_gl_api (priv->display, platform); - gl_handle = gst_gl_context_get_current_gl_context (platform); - if (gl_handle) - priv->other_context = - gst_gl_context_new_wrapped (priv->display, gl_handle, - platform, gl_api); - } #endif - (void) platform; - (void) gl_api; - (void) gl_handle; + GST_ERROR ("Unknown GL platform"); + return; - if (priv->other_context) { +have_platform: + + if (_wrap_current_gl (priv->display, platform, &priv->other_context)) { GError *error = NULL; GST_INFO ("Retrieved Gdk OpenGL context %" GST_PTR_FORMAT, priv->other_context); gst_gl_context_activate (priv->other_context, TRUE); if (!gst_gl_context_fill_info (priv->other_context, &error)) { - GST_ERROR ("failed to retrieve gdk context info: %s", error->message); + GST_ERROR ("Failed to retrieve gdk context info: %s", error->message); g_clear_error (&error); g_object_unref (priv->other_context); priv->other_context = NULL;