File mutter-force-rgb8.patch of Package mutter.9850

Index: mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl-private.h
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/cogl/cogl/winsys/cogl-winsys-egl-private.h	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl-private.h	2018-02-28 10:27:18.840086775 +0100
@@ -90,6 +90,11 @@
   (* add_config_attributes) (CoglDisplay *display,
                              CoglFramebufferConfig *config,
                              EGLint *attributes);
+  CoglBool
+  (* choose_config) (CoglDisplay *display,
+                     EGLint *attributes,
+                     EGLConfig *out_config,
+                     CoglError **error);
 } CoglWinsysEGLVtable;
 
 typedef enum _CoglEGLWinsysFeature
Index: mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl-x11.c
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/cogl/cogl/winsys/cogl-winsys-egl-x11.c	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl-x11.c	2018-02-28 10:27:18.840086775 +0100
@@ -337,6 +337,32 @@
 }
 
 static CoglBool
+_cogl_winsys_egl_choose_config (CoglDisplay *display,
+                                EGLint *attributes,
+                                EGLConfig *out_config,
+                                CoglError **error)
+{
+  CoglRenderer *renderer = display->renderer;
+  CoglRendererEGL *egl_renderer = renderer->winsys;
+  EGLint config_count = 0;
+  EGLBoolean status;
+
+  status = eglChooseConfig (egl_renderer->edpy,
+                            attributes,
+                            out_config, 1,
+                            &config_count);
+  if (status != EGL_TRUE || config_count == 0)
+    {
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
+                       COGL_WINSYS_ERROR_CREATE_CONTEXT,
+                       "No compatible EGL configs found");
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+static CoglBool
 _cogl_winsys_egl_display_setup (CoglDisplay *display,
                                 CoglError **error)
 {
@@ -841,6 +867,7 @@
 _cogl_winsys_egl_vtable =
   {
     .add_config_attributes = _cogl_winsys_egl_add_config_attributes,
+    .choose_config = _cogl_winsys_egl_choose_config,
     .display_setup = _cogl_winsys_egl_display_setup,
     .display_destroy = _cogl_winsys_egl_display_destroy,
     .context_created = _cogl_winsys_egl_context_created,
Index: mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl.c
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/cogl/cogl/winsys/cogl-winsys-egl.c	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/cogl/cogl/winsys/cogl-winsys-egl.c	2018-02-28 10:27:18.840086775 +0100
@@ -338,10 +338,9 @@
   CoglRendererEGL *egl_renderer = renderer->winsys;
   EGLDisplay edpy;
   EGLConfig config;
-  EGLint config_count = 0;
-  EGLBoolean status;
   EGLint attribs[9];
   EGLint cfg_attribs[MAX_EGL_CONFIG_ATTRIBS];
+  GError *config_error = NULL;
   const char *error_message;
 
   _COGL_RETURN_VAL_IF_FAIL (egl_display->egl_context == NULL, TRUE);
@@ -356,14 +355,16 @@
 
   edpy = egl_renderer->edpy;
 
-  status = eglChooseConfig (edpy,
+  if (!egl_renderer->platform_vtable->choose_config (display,
                             cfg_attribs,
-                            &config, 1,
-                            &config_count);
-  if (status != EGL_TRUE || config_count == 0)
+                                                     &config,
+                                                     &config_error))
     {
-      error_message = "Unable to find a usable EGL configuration";
-      goto fail;
+      _cogl_set_error (error, COGL_WINSYS_ERROR,
+                       COGL_WINSYS_ERROR_CREATE_CONTEXT,
+                       "Couldn't choose config: %s", config_error->message);
+      g_error_free (config_error);
+      goto err;
     }
 
   egl_display->egl_config = config;
@@ -419,6 +420,7 @@
                COGL_WINSYS_ERROR_CREATE_CONTEXT,
                "%s", error_message);
 
+err:
   cleanup_context (display);
 
   return FALSE;
Index: mutter-3.26.2+20180207.4b2d21ff0/src/backends/meta-egl.c
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/src/backends/meta-egl.c	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/src/backends/meta-egl.c	2018-02-28 10:27:18.840086775 +0100
@@ -246,7 +246,73 @@
 }
 
 gboolean
-meta_egl_choose_config (MetaEgl      *egl,
+meta_egl_get_config_attrib (MetaEgl     *egl,
+                            EGLDisplay   display,
+                            EGLConfig    config,
+                            EGLint       attribute,
+                            EGLint      *value,
+                            GError     **error)
+{
+  if (!eglGetConfigAttrib (display,
+                           config,
+                           attribute,
+                           value))
+    {
+      set_egl_error (error);
+      return FALSE;
+    }
+
+  return TRUE;
+}
+
+EGLConfig *
+meta_egl_choose_all_configs (MetaEgl       *egl,
+                             EGLDisplay     display,
+                             const EGLint  *attrib_list,
+                             EGLint        *out_num_configs,
+                             GError       **error)
+{
+  EGLint num_configs;
+  EGLConfig *configs;
+  EGLint num_matches;
+
+  if (!eglGetConfigs (display, NULL, 0, &num_configs))
+    {
+      set_egl_error (error);
+      return FALSE;
+    }
+
+  if (num_configs < 1)
+    {
+      g_set_error (error, G_IO_ERROR,
+                   G_IO_ERROR_FAILED,
+                   "No EGL configurations available");
+      return FALSE;
+    }
+
+  configs = g_new0 (EGLConfig, num_configs);
+
+  if (!eglChooseConfig (display, attrib_list, configs, num_configs, &num_matches))
+    {
+      g_free (configs);
+      set_egl_error (error);
+      return FALSE;
+    }
+
+  if (num_matches == 0)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No matching EGL configs");
+      g_free (configs);
+      return NULL;
+    }
+
+  *out_num_configs = num_configs;
+  return configs;
+}
+
+gboolean
+meta_egl_choose_first_config (MetaEgl       *egl,
                         EGLDisplay    display,
                         const EGLint *attrib_list,
                         EGLConfig    *chosen_config,
@@ -279,6 +345,14 @@
       return FALSE;
     }
 
+  if (num_matches == 0)
+    {
+      g_free (configs);
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "No matching EGLConfig found");
+      return FALSE;
+    }
+
   /*
    * We don't have any preference specified yet, so lets choose the first one.
    */
Index: mutter-3.26.2+20180207.4b2d21ff0/src/backends/meta-egl.h
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/src/backends/meta-egl.h	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/src/backends/meta-egl.h	2018-02-28 10:27:18.840086775 +0100
@@ -46,12 +46,25 @@
                               EGLDisplay display,
                               GError   **error);
 
-gboolean meta_egl_choose_config (MetaEgl      *egl,
+gboolean meta_egl_choose_first_config (MetaEgl       *egl,
                                  EGLDisplay    display,
                                  const EGLint *attrib_list,
                                  EGLConfig    *chosen_config,
                                  GError      **error);
 
+gboolean meta_egl_get_config_attrib (MetaEgl     *egl,
+                                     EGLDisplay   display,
+                                     EGLConfig    config,
+                                     EGLint       attribute,
+                                     EGLint      *value,
+                                     GError     **error);
+
+EGLConfig * meta_egl_choose_all_configs (MetaEgl       *egl,
+                                         EGLDisplay     display,
+                                         const EGLint  *attrib_list,
+                                         EGLint        *out_num_configs,
+                                         GError       **error);
+
 EGLImageKHR meta_egl_create_image (MetaEgl        *egl,
                                    EGLDisplay      display,
                                    EGLContext      context,
Index: mutter-3.26.2+20180207.4b2d21ff0/src/backends/native/meta-renderer-native.c
===================================================================
--- mutter-3.26.2+20180207.4b2d21ff0.orig/src/backends/native/meta-renderer-native.c	2018-02-07 04:07:59.000000000 +0100
+++ mutter-3.26.2+20180207.4b2d21ff0/src/backends/native/meta-renderer-native.c	2018-02-28 10:27:18.840086775 +0100
@@ -332,6 +332,73 @@
 }
 
 static gboolean
+choose_egl_config_from_gbm_format (MetaEgl       *egl,
+                                   EGLDisplay     egl_display,
+                                   const EGLint  *attributes,
+                                   uint32_t       gbm_format,
+                                   EGLConfig     *out_config,
+                                   GError       **error)
+{
+  EGLConfig *egl_configs;
+  EGLint n_configs;
+  EGLint i;
+
+  egl_configs = meta_egl_choose_all_configs (egl, egl_display,
+                                             attributes,
+                                             &n_configs,
+                                             error);
+  if (!egl_configs)
+    return FALSE;
+
+  for (i = 0; i < n_configs; i++)
+    {
+      EGLint visual_id;
+
+      if (!meta_egl_get_config_attrib (egl, egl_display,
+                                       egl_configs[i],
+                                       EGL_NATIVE_VISUAL_ID,
+                                       &visual_id,
+                                       error))
+        {
+          g_free (egl_configs);
+          return FALSE;
+        }
+
+      if ((uint32_t) visual_id == gbm_format)
+        {
+          *out_config = egl_configs[i];
+          g_free (egl_configs);
+          return TRUE;
+        }
+    }
+
+  g_free (egl_configs);
+  g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+               "No EGL config matching supported GBM format found");
+  return FALSE;
+}
+
+static gboolean
+meta_renderer_native_choose_egl_config (CoglDisplay  *cogl_display,
+                                        EGLint       *attributes,
+                                        EGLConfig    *out_config,
+                                        GError      **error)
+{
+  CoglRenderer *cogl_renderer = cogl_display->renderer;
+  CoglRendererEGL *cogl_renderer_egl = cogl_renderer->winsys;
+  MetaBackend *backend = meta_get_backend ();
+  MetaEgl *egl = meta_backend_get_egl (backend);
+  EGLDisplay egl_display = cogl_renderer_egl->edpy;
+
+  return choose_egl_config_from_gbm_format (egl,
+                                            egl_display,
+                                            attributes,
+                                            GBM_FORMAT_XRGB8888,
+                                            out_config,
+                                            error);
+}
+
+static gboolean
 meta_renderer_native_setup_egl_display (CoglDisplay *cogl_display,
                                         GError     **error)
 {
@@ -376,7 +443,7 @@
     EGL_NONE
   };
 
-  if (!meta_egl_choose_config (egl, egl_display, pbuffer_config_attribs,
+  if (!meta_egl_choose_first_config (egl, egl_display, pbuffer_config_attribs,
                                &pbuffer_config, error))
     return EGL_NO_SURFACE;
 
@@ -1355,6 +1422,7 @@
 static const CoglWinsysEGLVtable
 _cogl_winsys_egl_vtable = {
   .add_config_attributes = meta_renderer_native_add_egl_config_attributes,
+  .choose_config = meta_renderer_native_choose_egl_config,
   .display_setup = meta_renderer_native_setup_egl_display,
   .display_destroy = meta_renderer_native_destroy_egl_display,
   .context_created = meta_renderer_native_egl_context_created,