From 26698535625ebf971fa73b9c35f6a9fd9a5b77e3 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Wed, 16 Feb 2022 00:23:53 +0100 Subject: [PATCH] clients/simple-dmabuf-feedback: Add fallback print method for unknown formats Using `pixel_format_get_info()` can result in formats being reported as `UNKNOWN` when used on compositors other than Weston. As `weston-simple-dmabuf-feedback` somewhat succeeds `wayland-info` as tool for `zwp_linux_dmabuf_v1` debugging from version 4 on, copy the approach from the later for these cases. Signed-off-by: Robert Mader --- clients/simple-dmabuf-feedback.c | 41 ++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/clients/simple-dmabuf-feedback.c b/clients/simple-dmabuf-feedback.c index 2a729a62..9a66a981 100644 --- a/clients/simple-dmabuf-feedback.c +++ b/clients/simple-dmabuf-feedback.c @@ -26,6 +26,7 @@ #include "config.h" #include +#include #include #include #include @@ -1050,18 +1051,54 @@ dmabuf_feedback_tranche_formats(void *data, } } +static char +bits2graph(uint32_t value, unsigned bitoffset) +{ + int c = (value >> bitoffset) & 0xff; + + if (isgraph(c) || isspace(c)) + return c; + + return '?'; +} + +static void +fourcc2str(uint32_t format, char *str, int len) +{ + int i; + + assert(len >= 5); + + for (i = 0; i < 4; i++) + str[i] = bits2graph(format, i * 8); + str[i] = '\0'; +} + static void print_tranche_format_modifier(uint32_t format, uint64_t modifier) { const struct pixel_format_info *fmt_info; + char *format_str; char *mod_name; + int len; - fmt_info = pixel_format_get_info(format); mod_name = pixel_format_get_modifier(modifier); + fmt_info = pixel_format_get_info(format); + + if (fmt_info) { + len = asprintf(&format_str, "%s", fmt_info->drm_format_name); + } else { + char fourcc_str[5]; + + fourcc2str(format, fourcc_str, sizeof(fourcc_str)); + len = asprintf(&format_str, "0x%08x (%s)", format, fourcc_str); + } + assert(len > 0); fprintf(stderr, "│ ├────────tranche format/modifier pair - format %s, modifier %s\n", - fmt_info ? fmt_info->drm_format_name : "UNKNOWN", mod_name); + format_str, mod_name); + free(format_str); free(mod_name); }