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




commit dc7ed892df5bfea0df4f746c166cdf7a3861ec38
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 | 90 +++++++++++++++++++++++++++++---------
 1 file changed, 69 insertions(+), 21 deletions(-)
---
diff --git a/gdk/wayland/gdkglcontext-wayland.c b/gdk/wayland/gdkglcontext-wayland.c
index 93db8078f8..80767ae387 100644
--- a/gdk/wayland/gdkglcontext-wayland.c
+++ b/gdk/wayland/gdkglcontext-wayland.c
@@ -434,33 +434,81 @@ 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_NONE;
+      g_assert (i < MAX_EGL_ATTRS);
+
+      eglChooseConfig (dpy, attrs, NULL, -1, &n_configs);
 
-  attrs[i++] = EGL_SURFACE_TYPE;
-  attrs[i++] = EGL_WINDOW_BIT;
+      if (n_configs > 0)
+        break;
+    }
+
+  configs = g_alloca (sizeof (EGLConfig) * n_configs);
 
-  attrs[i++] = EGL_COLOR_BUFFER_TYPE;
-  attrs[i++] = EGL_RGB_BUFFER;
+  for (i = 0; i < n_configs; i++)
+    {
+      EGLint red, green, blue, alpha, type;
 
-  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 (!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;
 
-  attrs[i++] = EGL_NONE;
-  g_assert (i < MAX_EGL_ATTRS);
+      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;
 
-  /* Pick first valid configuration i guess? */
-  if (!eglChooseConfig (dpy, attrs, &config, 1, &count) || count < 1)
-     return NULL;
+      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 config;
+  return NULL;
 }
 
 #undef MAX_EGL_ATTRS


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