From 66b2d8c7de323911406c829c5f208bb458891cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Fri, 3 Jun 2022 14:36:26 +0200 Subject: [PATCH] plugin: Also use min GL version when auto selecting context When we prefer GLES, make sure its no lower then 3.1 version, so it can color convert 10bit videos, otherwise core GL 3.2 that GTK4 normally defaults to takes precedence. With auto behavior we should select the best one, both performance and support wise. Otherwise user can request one or another with GST_GL_API env that works best with his specific HW. --- .../importers/gstclapperglbaseimporter.c | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/gst/plugin/importers/gstclapperglbaseimporter.c b/lib/gst/plugin/importers/gstclapperglbaseimporter.c index cb558030..c17c64e9 100644 --- a/lib/gst/plugin/importers/gstclapperglbaseimporter.c +++ b/lib/gst/plugin/importers/gstclapperglbaseimporter.c @@ -452,14 +452,19 @@ gst_clapper_gl_base_importer_add_allocation_metas (GstClapperImporter *importer, } static gboolean -_realize_gdk_context_with_api (GdkGLContext *gdk_context, GdkGLAPI api) +_realize_gdk_context_with_api (GdkGLContext *gdk_context, GdkGLAPI api, gint maj, gint min) { GError *error = NULL; gboolean success; gdk_gl_context_set_allowed_apis (gdk_context, api); + gdk_gl_context_set_required_version (gdk_context, maj, min); + + GST_DEBUG ("Trying to realize %s context, min ver: %i.%i", + (api & GDK_GL_API_GL) ? "GL" : "GLES", maj, min); + if (!(success = gdk_gl_context_realize (gdk_context, &error))) { - GST_WARNING ("Could not realize Gdk context with %s: %s", + GST_DEBUG ("Could not realize Gdk context with %s: %s", (api & GDK_GL_API_GL) ? "GL" : "GLES", error->message); g_clear_error (&error); } @@ -486,7 +491,7 @@ gst_clapper_gl_base_importer_gdk_context_realize (GstClapperGLBaseImporter *self : GDK_GL_API_GL | GDK_GL_API_GLES; /* With requested by user API, we either use it or give up */ - return _realize_gdk_context_with_api (gdk_context, preferred_api); + return _realize_gdk_context_with_api (gdk_context, preferred_api, 0, 0); } gdk_display = gdk_gl_context_get_display (gdk_context); @@ -519,13 +524,24 @@ gst_clapper_gl_base_importer_gdk_context_realize (GstClapperGLBaseImporter *self #endif #endif - if (!(success = _realize_gdk_context_with_api (gdk_context, preferred_api))) { + /* Continue with GLES only if it should have "GL_EXT_texture_norm16" + * extension, as we need it to handle P010_10LE, etc. */ + if ((preferred_api == GDK_GL_API_GLES) + && _realize_gdk_context_with_api (gdk_context, GDK_GL_API_GLES, 3, 1)) + return TRUE; + + /* If not using GLES 3.1, try with core GL 3.2 that GTK4 defaults to */ + if (_realize_gdk_context_with_api (gdk_context, GDK_GL_API_GL, 3, 2)) + return TRUE; + + /* Try with what we normally prefer first, otherwise use fallback */ + if (!(success = _realize_gdk_context_with_api (gdk_context, preferred_api, 0, 0))) { GdkGLAPI fallback_api; fallback_api = (GDK_GL_API_GL | GDK_GL_API_GLES); fallback_api &= ~preferred_api; - success = _realize_gdk_context_with_api (gdk_context, fallback_api); + success = _realize_gdk_context_with_api (gdk_context, fallback_api, 0, 0); } return success;