plugin: Prefer GL over GLES on macOS

Apple decoder uses rectangle texture-target, which GLES does not support
This commit is contained in:
Rafał Dzięgiel
2022-05-16 19:16:36 +02:00
parent 8e89b0d8ca
commit 85bdbb1132

View File

@@ -446,36 +446,59 @@ gst_clapper_gl_base_importer_add_allocation_metas (GstClapperImporter *importer,
GST_CLAPPER_GL_BASE_IMPORTER_UNLOCK (self); GST_CLAPPER_GL_BASE_IMPORTER_UNLOCK (self);
} }
static gboolean
_realize_gdk_context_with_api (GdkGLContext *gdk_context, GdkGLAPI api)
{
GError *error = NULL;
gboolean success;
gdk_gl_context_set_allowed_apis (gdk_context, api);
if (!(success = gdk_gl_context_realize (gdk_context, &error))) {
GST_WARNING ("Could not realize Gdk context with %s: %s",
(api & GDK_GL_API_GL) ? "GL" : "GLES", error->message);
g_clear_error (&error);
}
return success;
}
static gboolean static gboolean
gst_clapper_gl_base_importer_gdk_context_realize (GstClapperGLBaseImporter *self, GdkGLContext *gdk_context) gst_clapper_gl_base_importer_gdk_context_realize (GstClapperGLBaseImporter *self, GdkGLContext *gdk_context)
{ {
GdkGLAPI allowed_apis; GdkGLAPI preferred_api;
GError *error = NULL;
const gchar *gl_env; const gchar *gl_env;
gboolean success; gboolean success;
GST_DEBUG_OBJECT (self, "Realizing GdkGLContext with default implementation"); GST_DEBUG_OBJECT (self, "Realizing GdkGLContext with default implementation");
/* Use single "GST_GL_API" env to also influence Gdk GL selection */ /* Use single "GST_GL_API" env to also influence Gdk GL selection */
gl_env = g_getenv ("GST_GL_API"); if ((gl_env = g_getenv ("GST_GL_API"))) {
allowed_apis = (!gl_env || g_str_has_prefix (gl_env, "gles")) preferred_api = (g_str_has_prefix (gl_env, "gles"))
? GDK_GL_API_GLES ? GDK_GL_API_GLES
: (g_str_has_prefix (gl_env, "opengl")) : g_str_has_prefix (gl_env, "opengl")
? GDK_GL_API_GL ? GDK_GL_API_GL
: GDK_GL_API_GL | GDK_GL_API_GLES; : GDK_GL_API_GL | GDK_GL_API_GLES;
gdk_gl_context_set_allowed_apis (gdk_context, allowed_apis); /* With requested by user API, we either use it or give up */
if (!(success = gdk_gl_context_realize (gdk_context, &error))) { return _realize_gdk_context_with_api (gdk_context, preferred_api);
GST_WARNING_OBJECT (self, "Could not realize Gdk context with %s: %s",
(allowed_apis & GDK_GL_API_GL) ? "GL" : "GLES", error->message);
g_clear_error (&error);
} }
if (!success && !gl_env) {
gdk_gl_context_set_allowed_apis (gdk_context, GDK_GL_API_GL); /* Apple decoder uses rectangle texture-target, which GLES does not support.
if (!(success = gdk_gl_context_realize (gdk_context, &error))) { * For Linux we prefer GLES in order to get HW colorspace conversion.
GST_WARNING_OBJECT (self, "Could not realize Gdk context with GL: %s", error->message); * Windows will try EGL + GLES setup first and auto fallback to WGL. */
g_clear_error (&error); #if GST_CLAPPER_GL_BASE_IMPORTER_HAVE_MACOS
} preferred_api = GDK_GL_API_GL;
#else
preferred_api = GDK_GL_API_GLES;
#endif
if (!(success = _realize_gdk_context_with_api (gdk_context, preferred_api))) {
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);
} }
return success; return success;