[gtk/wip/otte/gl-hdr: 13/14] display: Get carried away by extension checker




commit 8e3cf748f46626a29323fb88f33953b7d4647dab
Author: Benjamin Otte <otte redhat com>
Date:   Sun Oct 3 17:40:09 2021 +0200

    display: Get carried away by extension checker
    
    I wanted to make it easy to check for multiple extensions and then got
    carried away by trying to generate beautiful error messages.

 gdk/gdkdisplay.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 50 insertions(+), 4 deletions(-)
---
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index 6d47f7011a..61b8d2c821 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -1561,6 +1561,50 @@ gdk_display_create_egl_config (GdkDisplay               *self,
 
 #undef MAX_EGL_ATTRS
 
+static gboolean
+gdk_display_check_egl_extensions (EGLDisplay   egl_display,
+                                  const char **extensions,
+                                  GError     **error)
+{
+  GString *missing = NULL;
+  gsize i, n_missing;
+
+  n_missing = 0;
+
+  for (i = 0; extensions[i] != NULL; i++)
+    {
+      if (!epoxy_has_egl_extension (egl_display, extensions[i]))
+        {
+          if (missing == NULL)
+            {
+              missing = g_string_new (extensions[i]);
+            }
+          else
+            {
+              g_string_append (missing, ", ");
+              g_string_append (missing, extensions[i]);
+            }
+          n_missing++;
+        }
+    }
+
+  if (n_missing)
+    {
+      g_set_error (error, GDK_GL_ERROR, GDK_GL_ERROR_UNSUPPORTED_PROFILE,
+                   /* translators: Arguments are the number of missing extensions
+                    * followed by a comma-separated list of their names */
+                   g_dngettext (GETTEXT_PACKAGE,
+                                "EGL implementation is missing extension %2$s",
+                                "EGL implementation is missing %d extensions: %s",
+                                n_missing),
+                   (int) n_missing, missing->str);
+
+      g_string_free (missing, TRUE);
+      return FALSE;
+    }
+
+  return TRUE;
+}
 
 gboolean
 gdk_display_init_egl (GdkDisplay  *self,
@@ -1620,12 +1664,14 @@ gdk_display_init_egl (GdkDisplay  *self,
       return FALSE;
     }
 
-  if (!epoxy_has_egl_extension (priv->egl_display, "EGL_KHR_surfaceless_context"))
+  if (!gdk_display_check_egl_extensions (priv->egl_display,
+                                         (const char *[]) {
+                                           "EGL_KHR_surfaceless_context",
+                                           NULL
+                                         },
+                                         error))
     {
       g_clear_pointer (&priv->egl_display, eglTerminate);
-      g_set_error_literal (error, GDK_GL_ERROR,
-                           GDK_GL_ERROR_UNSUPPORTED_PROFILE,
-                           _("Surfaceless contexts are not supported on this EGL implementation"));
       return FALSE;
     }
 


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