summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2022-08-21 14:17:35 +0200
committerSimon Ser <contact@emersion.fr>2022-08-31 06:40:49 +0000
commitbaa4b8cafca0d52189bfd6e7cda9c558a261ae71 (patch)
tree51fe56cad1716242ac4f1a8b18af2a0d7238ee52
parent03e0ab4d888b23164f1e076f1d2fad9d2039b820 (diff)
downloaddrm-baa4b8cafca0d52189bfd6e7cda9c558a261ae71.tar.gz
xf86drm: add drmGetFormatName()
Same as drmGetFormatModifierName() but for formats. Signed-off-by: Simon Ser <contact@emersion.fr> Reviewed-by: Marius Vlad <marius.vlad@collabora.com> Reviewed-by: Eric Engestrom <eric@igalia.com>
-rw-r--r--core-symbols.txt1
-rw-r--r--xf86drm.c35
-rw-r--r--xf86drm.h3
3 files changed, 39 insertions, 0 deletions
diff --git a/core-symbols.txt b/core-symbols.txt
index da98a6a9..6c5a4af6 100644
--- a/core-symbols.txt
+++ b/core-symbols.txt
@@ -203,3 +203,4 @@ drmUpdateDrawableInfo
drmWaitVBlank
drmGetFormatModifierName
drmGetFormatModifierVendor
+drmGetFormatName
diff --git a/xf86drm.c b/xf86drm.c
index cca126b9..42c1a5d0 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -5106,3 +5106,38 @@ drmGetFormatModifierName(uint64_t modifier)
return modifier_found;
}
+
+/**
+ * Get a human-readable name for a DRM FourCC format.
+ *
+ * \param format The format.
+ * \return A malloc'ed string containing the format name. Caller is responsible
+ * for freeing it.
+ */
+drm_public char *
+drmGetFormatName(uint32_t format)
+{
+ char *str;
+ size_t str_size, i;
+ char a, b, c, d;
+
+ if (format == DRM_FORMAT_INVALID)
+ return strdup("INVALID");
+
+ str_size = 5;
+ str = malloc(str_size);
+ if (!str)
+ return NULL;
+
+ a = (char) ((format >> 0) & 0xFF);
+ 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;
+}
diff --git a/xf86drm.h b/xf86drm.h
index 1631396a..4badaae5 100644
--- a/xf86drm.h
+++ b/xf86drm.h
@@ -954,6 +954,9 @@ drmGetFormatModifierVendor(uint64_t modifier);
extern char *
drmGetFormatModifierName(uint64_t modifier);
+extern char *
+drmGetFormatName(uint32_t format);
+
#ifndef fourcc_mod_get_vendor
#define fourcc_mod_get_vendor(modifier) \
(((modifier) >> 56) & 0xff)