From 7ba4c515a35c26b2f7ece5c39e6536714f7e91e8 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 18 Sep 2019 16:41:51 +0300 Subject: [PATCH] gl-renderer: prefer the base EGLConfig 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 Signed-off-by: Pekka Paalanen --- libweston/renderer-gl/egl-glue.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/libweston/renderer-gl/egl-glue.c b/libweston/renderer-gl/egl-glue.c index dad8e57d..2c44c86b 100644 --- a/libweston/renderer-gl/egl-glue.c +++ b/libweston/renderer-gl/egl-glue.c @@ -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");