gl-renderer: prefer the base EGLConfig
authorPekka Paalanen <pekka.paalanen@collabora.com>
Wed, 18 Sep 2019 13:41:51 +0000 (16:41 +0300)
committerPekka Paalanen <pekka.paalanen@collabora.com>
Fri, 4 Oct 2019 09:17:18 +0000 (12:17 +0300)
If configless_context is not supported, we pick one EGLConfig as the "base
config" because we have just one GL context and different configs between the
context and EGLSurfaces might not work. Until now, we did not actually make
sure to pick the base config.

If the base config matches the requirements, prefer it. Only if it doesn't
match, go looking for another config.

This should give better chances of success on systems where configless_context
is not supported by relying less on eglChooseConfig().

Cc: Madhurkiran Harikrishnan <madhurkiran.harikrishnan@xilinx.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
libweston/renderer-gl/egl-glue.c

index dad8e57d1734f9173df90ab2d6499bfb1a2bb3ac..2c44c86bcf39712befa3503e17ba41b293478364 100644 (file)
@@ -185,6 +185,32 @@ out:
        return 0;
 }
 
+static bool
+egl_config_is_compatible(struct gl_renderer *gr,
+                        EGLConfig config,
+                        EGLint egl_surface_type,
+                        const struct pixel_format_info *const *pinfo,
+                        unsigned pinfo_count)
+{
+       EGLint value;
+       unsigned i;
+
+       if (config == EGL_NO_CONFIG_KHR)
+               return false;
+
+       if (!eglGetConfigAttrib(gr->egl_display, config,
+                               EGL_SURFACE_TYPE, &value))
+               return false;
+       if ((value & egl_surface_type) != egl_surface_type)
+               return false;
+
+       for (i = 0; i < pinfo_count; i++) {
+               if (egl_config_pixel_format_matches(gr, config, pinfo[i]))
+                       return true;
+       }
+       return false;
+}
+
 EGLConfig
 gl_renderer_get_egl_config(struct gl_renderer *gr,
                           EGLint egl_surface_type,
@@ -217,6 +243,10 @@ gl_renderer_get_egl_config(struct gl_renderer *gr,
                pinfo_count++;
        }
 
+       if (egl_config_is_compatible(gr, gr->egl_config, egl_surface_type,
+                                    pinfo, pinfo_count))
+               return gr->egl_config;
+
        if (egl_choose_config(gr, config_attribs, pinfo, pinfo_count,
                              &egl_config) < 0) {
                weston_log("No EGLConfig matches.\n");