From c01ba92eb2756241f971bc0c408fe2e0cd76f2bd Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 30 Sep 2019 14:48:30 +0300 Subject: [PATCH] gl-renderer: use pixel_format_info internally for EGL Using arrays of pixel_format_info instead of just DRM format codes is useful for fuzzy matching of formats with EGLConfigs in the future. The immediate benefit is that we can easily print format names in log messages. We should never deal with formats we don't have in our database, so discarding unknown formats should be ok. Using unknown formats would become hard later, too. Signed-off-by: Pekka Paalanen --- libweston/renderer-gl/egl-glue.c | 48 ++++++++++++-------- libweston/renderer-gl/gl-renderer-internal.h | 8 +++- 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/libweston/renderer-gl/egl-glue.c b/libweston/renderer-gl/egl-glue.c index daee7cc1..87a84863 100644 --- a/libweston/renderer-gl/egl-glue.c +++ b/libweston/renderer-gl/egl-glue.c @@ -34,6 +34,7 @@ #include "gl-renderer.h" #include "gl-renderer-internal.h" +#include "pixel-formats.h" #include "weston-egl-ext.h" #include @@ -122,14 +123,17 @@ match_config_to_visual(EGLDisplay egl_display, } int -egl_choose_config(struct gl_renderer *gr, const EGLint *attribs, - const EGLint *visual_id, const int n_ids, +egl_choose_config(struct gl_renderer *gr, + const EGLint *attribs, + const struct pixel_format_info *const *pinfo, + unsigned pinfo_count, EGLConfig *config_out) { EGLint count = 0; EGLint matched = 0; EGLConfig *configs; - int i, config_index = -1; + unsigned i; + int config_index = -1; if (!eglGetConfigs(gr->egl_display, NULL, 0, &count) || count < 1) { weston_log("No EGL configs to choose from.\n"); @@ -145,12 +149,12 @@ egl_choose_config(struct gl_renderer *gr, const EGLint *attribs, goto out; } - if (!visual_id || n_ids == 0) + if (pinfo_count == 0) config_index = 0; - for (i = 0; config_index == -1 && i < n_ids; i++) + for (i = 0; config_index == -1 && i < pinfo_count; i++) config_index = match_config_to_visual(gr->egl_display, - visual_id[i], + pinfo[i]->format, configs, matched); @@ -163,9 +167,10 @@ out: return -1; if (i > 1) - weston_log("Unable to use first choice EGL config with id" - " 0x%x, succeeded with alternate id 0x%x.\n", - visual_id[0], visual_id[i - 1]); + weston_log("Unable to use first choice EGL config with" + " %s, succeeded with alternate %s.\n", + pinfo[0]->drm_format_name, + pinfo[i - 1]->drm_format_name); return 0; } @@ -176,18 +181,25 @@ gl_renderer_get_egl_config(struct gl_renderer *gr, unsigned drm_formats_count) { EGLConfig egl_config; - EGLint visual_id[16]; - int id_count; - int i; + const struct pixel_format_info *pinfo[16]; + unsigned pinfo_count; + unsigned i; - assert(drm_formats_count < ARRAY_LENGTH(visual_id)); - id_count = MIN(drm_formats_count, ARRAY_LENGTH(visual_id)); + assert(drm_formats_count < ARRAY_LENGTH(pinfo)); + drm_formats_count = MIN(drm_formats_count, ARRAY_LENGTH(pinfo)); - for (i = 0; i < id_count; i++) - visual_id[i] = drm_formats[i]; + for (pinfo_count = 0, i = 0; i < drm_formats_count; i++) { + pinfo[pinfo_count] = pixel_format_get_info(drm_formats[i]); + if (!pinfo[pinfo_count]) { + weston_log("Bad/unknown DRM format code 0x%08x.\n", + drm_formats[i]); + continue; + } + pinfo_count++; + } - if (egl_choose_config(gr, config_attribs, visual_id, - id_count, &egl_config) < 0) { + if (egl_choose_config(gr, config_attribs, pinfo, pinfo_count, + &egl_config) < 0) { weston_log("No EGLConfig matches.\n"); return EGL_NO_CONFIG_KHR; } diff --git a/libweston/renderer-gl/gl-renderer-internal.h b/libweston/renderer-gl/gl-renderer-internal.h index 0248424f..0c453616 100644 --- a/libweston/renderer-gl/gl-renderer-internal.h +++ b/libweston/renderer-gl/gl-renderer-internal.h @@ -126,9 +126,13 @@ gl_renderer_print_egl_error_state(void); void log_egl_config_info(EGLDisplay egldpy, EGLConfig eglconfig); +struct pixel_format_info; + int -egl_choose_config(struct gl_renderer *gr, const EGLint *attribs, - const EGLint *visual_id, const int n_ids, +egl_choose_config(struct gl_renderer *gr, + const EGLint *attribs, + const struct pixel_format_info *const *pinfo, + unsigned pinfo_count, EGLConfig *config_out); EGLConfig