[gtk/matthiasc/color-profiles] wayland: Pick a better fbconfig




commit 1bb3884f33c512c2815ab319d3d9c4e18b43386f
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Oct 1 12:23:36 2021 -0400

    wayland: Pick a better fbconfig
    
    Try to find an EGLConfig fp16 and use it.

 gdk/wayland/gdkglcontext-wayland.c | 123 ++++++++++++++++++++++++++++++-------
 1 file changed, 100 insertions(+), 23 deletions(-)
---
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 8543de3b58..8ce93827f1 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -434,37 +434,111 @@ static EGLConfig
 get_eglconfig (EGLDisplay dpy)
 {
   EGLint attrs[MAX_EGL_ATTRS];
-  EGLint count;
-  EGLConfig config;
-  int i = 0;
+  EGLint n_configs;
+  EGLConfig *configs;
+  int pass, i;
+
+  n_configs = 0;
+
+  for (pass = 0; pass <= 1; pass++)
+    {
+      i = 0;
+
+      attrs[i++] = EGL_SURFACE_TYPE;
+      attrs[i++] = EGL_WINDOW_BIT;
+
+      attrs[i++] = EGL_COLOR_BUFFER_TYPE;
+      attrs[i++] = EGL_RGB_BUFFER;
+
+      attrs[i++] = EGL_RED_SIZE;
+      attrs[i++] = 8;
+      attrs[i++] = EGL_GREEN_SIZE;
+      attrs[i++] = 8;
+      attrs[i++] = EGL_BLUE_SIZE;
+      attrs[i++] = 8;
+      attrs[i++] = EGL_ALPHA_SIZE;
+      attrs[i++] = 8;
+
+      if (pass == 0 && epoxy_has_egl_extension (dpy, "EGL_EXT_pixel_format_float"))
+        {
+          attrs[i++] = EGL_COLOR_COMPONENT_TYPE_EXT;
+          attrs[i++] = EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT;
+        }
 
-  attrs[i++] = EGL_SURFACE_TYPE;
-  attrs[i++] = EGL_WINDOW_BIT;
+      attrs[i++] = EGL_NONE;
+      g_assert (i < MAX_EGL_ATTRS);
 
-  attrs[i++] = EGL_COLOR_BUFFER_TYPE;
-  attrs[i++] = EGL_RGB_BUFFER;
+      eglChooseConfig (dpy, attrs, NULL, -1, &n_configs);
 
-  attrs[i++] = EGL_RED_SIZE;
-  attrs[i++] = 8;
-  attrs[i++] = EGL_GREEN_SIZE;
-  attrs[i++] = 8;
-  attrs[i++] = EGL_BLUE_SIZE;
-  attrs[i++] = 8;
-  attrs[i++] = EGL_ALPHA_SIZE;
-  attrs[i++] = 8;
+      if (n_configs > 0)
+        break;
+    }
 
-  attrs[i++] = EGL_NONE;
-  g_assert (i < MAX_EGL_ATTRS);
+  configs = g_alloca (sizeof (EGLConfig) * n_configs);
 
-  /* Pick first valid configuration i guess? */
-  if (!eglChooseConfig (dpy, attrs, &config, 1, &count) || count < 1)
+  if (!eglChooseConfig (dpy, attrs, configs, n_configs, &n_configs) || n_configs < 1)
     return NULL;
 
-  return config;
+  for (i = 0; i < n_configs; i++)
+    {
+      EGLint red, green, blue, alpha, type;
+
+      if (!eglGetConfigAttrib (dpy, configs[i], EGL_RED_SIZE, &red) ||
+          !eglGetConfigAttrib (dpy, configs[i], EGL_GREEN_SIZE, &green) ||
+          !eglGetConfigAttrib (dpy, configs[i], EGL_BLUE_SIZE, &blue) ||
+          !eglGetConfigAttrib (dpy, configs[i], EGL_ALPHA_SIZE, &alpha))
+        continue;
+
+      if (epoxy_has_egl_extension (dpy, "EGL_EXT_pixel_format_float"))
+        {
+          if (!eglGetConfigAttrib (dpy, configs[i], EGL_COLOR_COMPONENT_TYPE_EXT, &type))
+            type = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
+        }
+      else
+        type = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
+
+      if (type == EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT)
+        {
+          /* return the first fp16 config */
+          if (red == 16 && green == 16 && blue == 16 && alpha == 16)
+            return configs[i];
+        }
+      else
+        {
+          /* return the first rgba8 config */
+          if (red == 8 && green == 8 && blue == 8 && alpha == 8)
+            return configs[i];
+        }
+    }
+
+  return NULL;
 }
 
 #undef MAX_EGL_ATTRS
 
+static char *
+describe_egl_config (EGLDisplay dpy,
+                     EGLConfig  config)
+{
+  EGLint red, green, blue, alpha, type;
+
+  if (!eglGetConfigAttrib (dpy, config, EGL_RED_SIZE, &red) ||
+      !eglGetConfigAttrib (dpy, config, EGL_GREEN_SIZE, &green) ||
+      !eglGetConfigAttrib (dpy, config, EGL_BLUE_SIZE, &blue) ||
+      !eglGetConfigAttrib (dpy, config, EGL_ALPHA_SIZE, &alpha))
+    return g_strdup ("Undisclosed");
+
+  if (epoxy_has_egl_extension (dpy, "EGL_EXT_pixel_format_float"))
+    {
+      if (!eglGetConfigAttrib (dpy, config, EGL_COLOR_COMPONENT_TYPE_EXT, &type))
+        type = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
+    }
+  else
+    type = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT;
+
+  return g_strdup_printf ("R%dG%dB%dA%d%s", red, green, blue, alpha, type == 
EGL_COLOR_COMPONENT_TYPE_FIXED_EXT ? "" : " float");
+}
+
 GdkGLContext *
 gdk_wayland_display_init_gl (GdkDisplay  *display,
                              GError     **error)
@@ -579,19 +653,22 @@ gdk_wayland_display_init_gl (GdkDisplay  *display,
   GDK_DISPLAY_NOTE (display, OPENGL, {
             const char *extensions = eglQueryString (dpy, EGL_EXTENSIONS);
             char **exts = g_strsplit (extensions, " ", -1);
-            char *ext = g_strjoinv ("\n\t", exts);
+            char *ext = g_strstrip (g_strjoinv ("\n\t", exts));
+            char *cfg = describe_egl_config (dpy, display_wayland->egl_config);
             g_message ("EGL API version %d.%d found\n"
                        " - Vendor: %s\n"
                        " - Version: %s\n"
                        " - Client APIs: %s\n"
                        " - Extensions:\n"
-                       "\t%s",
+                       "\t%s\n"
+                       " - Selected fbconfig: %s",
                        display_wayland->egl_major_version,
                        display_wayland->egl_minor_version,
                        eglQueryString (dpy, EGL_VENDOR),
                        eglQueryString (dpy, EGL_VERSION),
                        eglQueryString (dpy, EGL_CLIENT_APIS),
-                       ext);
+                       ext, cfg);
+            g_free (cfg);
             g_free (ext);
             g_strfreev (exts);
   });


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