xf86drm: handle DRM_FORMAT_BIG_ENDIAN in drmGetFormatName()

This bit can be added to a DRM format to indicate that it's
big endian instead of little endian.

Signed-off-by: Simon Ser <contact@emersion.fr>
main
Simon Ser 2022-10-12 09:40:06 +02:00
parent e08a22dc43
commit ffb9375a50
1 changed files with 17 additions and 12 deletions

View File

@ -5117,27 +5117,32 @@ drmGetFormatModifierName(uint64_t modifier)
drm_public char * drm_public char *
drmGetFormatName(uint32_t format) drmGetFormatName(uint32_t format)
{ {
char *str; char *str, code[5];
const char *be;
size_t str_size, i; size_t str_size, i;
char a, b, c, d;
be = (format & DRM_FORMAT_BIG_ENDIAN) ? "_BE" : "";
format &= ~DRM_FORMAT_BIG_ENDIAN;
if (format == DRM_FORMAT_INVALID) if (format == DRM_FORMAT_INVALID)
return strdup("INVALID"); return strdup("INVALID");
str_size = 5; code[0] = (char) ((format >> 0) & 0xFF);
code[1] = (char) ((format >> 8) & 0xFF);
code[2] = (char) ((format >> 16) & 0xFF);
code[3] = (char) ((format >> 24) & 0xFF);
code[4] = '\0';
/* Trim spaces at the end */
for (i = 3; i > 0 && code[i] == ' '; i--)
code[i] = '\0';
str_size = strlen(code) + strlen(be) + 1;
str = malloc(str_size); str = malloc(str_size);
if (!str) if (!str)
return NULL; return NULL;
a = (char) ((format >> 0) & 0xFF); snprintf(str, str_size, "%s%s", code, be);
b = (char) ((format >> 8) & 0xFF);
c = (char) ((format >> 16) & 0xFF);
d = (char) ((format >> 24) & 0xFF);
snprintf(str, str_size, "%c%c%c%c", a, b, c, d);
/* Trim spaces at the end */
for (i = 3; i > 0 && str[i] == ' '; i--)
str[i] = '\0';
return str; return str;
} }