pixel-formats: Add human readable format modifier

Conditionally build support when libdrm is at least 2.4.107 to make use
of it.  Plug it in when printing out the buffer information.

With this in, we add a hard dependecy for libweston to link against
libdrm.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
dev
Marius Vlad 3 years ago committed by Daniel Stone
parent bc3c37840c
commit 6f6fd2686d
  1. 8
      libweston/compositor.c
  2. 2
      libweston/meson.build
  3. 55
      libweston/pixel-formats.c
  4. 12
      libweston/pixel-formats.h
  5. 6
      meson.build

@ -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;
}

@ -3,7 +3,7 @@ deps_libweston = [
dep_pixman,
dep_libm,
dep_libdl,
dep_libdrm_headers,
dep_libdrm,
dep_xkbcommon,
dep_matrix_c
]

@ -30,10 +30,15 @@
#include <inttypes.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <wayland-client-protocol.h>
#include <xf86drm.h>
#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

@ -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);

@ -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@' ]

Loading…
Cancel
Save