diff --git a/libweston/compositor.c b/libweston/compositor.c index 8f9de03e..e6331902 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -7379,13 +7379,17 @@ debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) dmabuf = linux_dmabuf_buffer_get(buffer->resource); if (dmabuf) { + uint64_t modifier = dmabuf->attributes.modifier[0]; + char *modifier_name = pixel_format_get_modifier(modifier); pixel_info = pixel_format_get_info(dmabuf->attributes.format); fprintf(fp, "\t\tdmabuf buffer\n"); fprintf(fp, "\t\t\tformat: 0x%lx %s\n", (unsigned long) dmabuf->attributes.format, pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); - fprintf(fp, "\t\t\tmodifier: 0x%llx\n", - (unsigned long long) dmabuf->attributes.modifier[0]); + + fprintf(fp, "\t\t\tmodifier: %s\n", modifier_name ? modifier_name : + "Failed to convert to a modifier name"); + free(modifier_name); return; } diff --git a/libweston/meson.build b/libweston/meson.build index cbf36a80..2d716cc1 100644 --- a/libweston/meson.build +++ b/libweston/meson.build @@ -3,7 +3,7 @@ deps_libweston = [ dep_pixman, dep_libm, dep_libdl, - dep_libdrm_headers, + dep_libdrm, dep_xkbcommon, dep_matrix_c ] diff --git a/libweston/pixel-formats.c b/libweston/pixel-formats.c index 22726c49..9c19a550 100644 --- a/libweston/pixel-formats.c +++ b/libweston/pixel-formats.c @@ -30,10 +30,15 @@ #include #include #include +#include #include +#include #include +#include + #include "shared/helpers.h" +#include "shared/string-helpers.h" #include "shared/weston-drm-fourcc.h" #include "wayland-util.h" #include "pixel-formats.h" @@ -514,3 +519,53 @@ pixel_format_height_for_plane(const struct pixel_format_info *info, return height / info->vsub; } + +#ifdef HAVE_HUMAN_FORMAT_MODIFIER +WL_EXPORT char * +pixel_format_get_modifier(uint64_t modifier) +{ + char *modifier_name; + char *vendor_name; + char *mod_str; + + modifier_name = drmGetFormatModifierName(modifier); + vendor_name = drmGetFormatModifierVendor(modifier); + + if (!modifier_name) { + if (vendor_name) + str_printf(&mod_str, "%s_%s (0x%llx)", + vendor_name, "UNKNOWN_MODIFIER", + (unsigned long long) modifier); + else + str_printf(&mod_str, "0x%llx", + (unsigned long long) modifier); + + free(vendor_name); + return mod_str; + } + + if (modifier == DRM_FORMAT_MOD_LINEAR) { + str_printf(&mod_str, "%s (0x%llx)", modifier_name, + (unsigned long long) modifier); + free(modifier_name); + free(vendor_name); + return mod_str; + } + + str_printf(&mod_str, "%s_%s (0x%llx)", vendor_name, modifier_name, + (unsigned long long) modifier); + + free(modifier_name); + free(vendor_name); + + return mod_str; +} +#else +WL_EXPORT char * +pixel_format_get_modifier(uint64_t modifier) +{ + char *mod_str; + str_printf(&mod_str, "0x%llx", (unsigned long long) modifier); + return mod_str; +} +#endif diff --git a/libweston/pixel-formats.h b/libweston/pixel-formats.h index 3e125260..d96bcfbe 100644 --- a/libweston/pixel-formats.h +++ b/libweston/pixel-formats.h @@ -260,3 +260,15 @@ unsigned int pixel_format_height_for_plane(const struct pixel_format_info *format, unsigned int plane, unsigned int height); +/** + * Return a human-readable format modifier. Comprised from the modifier name, + * the vendor name, and the original encoded value in hexadecimal, using + * 'VENDOR_NAME_MODIFIER_NAME (modifier_encoded_value)' pattern. In case the + * modifier name (and the vendor name) isn't found, this returns the original + * encoded value, as a string value. + * + * @param modifier the modifier in question + * @returns a malloc'ed string, caller responsible for freeing after use. + */ +char * +pixel_format_get_modifier(uint64_t modifier); diff --git a/meson.build b/meson.build index 44efeaee..f818ab19 100644 --- a/meson.build +++ b/meson.build @@ -150,6 +150,12 @@ dep_libdrm = dependency('libdrm', version: '>= 2.4.95') dep_libdrm_headers = dep_libdrm.partial_dependency(compile_args: true) dep_threads = dependency('threads') +dep_libdrm_version = dep_libdrm.version() +if dep_libdrm_version.version_compare('>=2.4.107') + message('Found libdrm with human format modifier support.') + config_h.set('HAVE_HUMAN_FORMAT_MODIFIER', '1') +endif + prog_python = import('python').find_installation('python3') files_xxd_py = files('tools/xxd.py') cmd_xxd = [ prog_python, files_xxd_py, '@INPUT@', '@OUTPUT@' ]