gbm: Introduce a helper function for printing GBM format names.
authorEric Anholt <eric@anholt.net>
Fri, 2 Nov 2018 21:35:06 +0000 (14:35 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 12 Nov 2018 23:20:23 +0000 (15:20 -0800)
This requires that the caller make a little (stack) allocation to store
the string.

v2: Use gbm_format_canonicalize (suggested by Daniel)

Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
src/gbm/main/gbm.c
src/gbm/main/gbm.h

index d301661b48ee4330cb965aff3fa105b709df44c3..2e2014205cb82e6cb44a23626defc1f9e4add9fc 100644 (file)
@@ -711,3 +711,23 @@ gbm_format_canonicalize(uint32_t gbm_format)
       return gbm_format;
    }
 }
+
+/**
+ * Returns a string representing the fourcc format name.
+ *
+ * \param desc Caller-provided storage for the format name string.
+ * \return String containing the fourcc of the format.
+ */
+GBM_EXPORT char *
+gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
+{
+   gbm_format = gbm_format_canonicalize(gbm_format);
+
+   desc->name[0] = gbm_format;
+   desc->name[1] = gbm_format >> 8;
+   desc->name[2] = gbm_format >> 16;
+   desc->name[3] = gbm_format >> 24;
+   desc->name[4] = 0;
+
+   return desc->name;
+}
index e95f9e34960bd23083a03e2e3fdeca2b3d24a35e..9b5288710a5b4cf5536352eacfa0313c1b12be70 100644 (file)
@@ -190,6 +190,9 @@ enum gbm_bo_format {
 #define GBM_FORMAT_YUV444      __gbm_fourcc_code('Y', 'U', '2', '4') /* non-subsampled Cb (1) and Cr (2) planes */
 #define GBM_FORMAT_YVU444      __gbm_fourcc_code('Y', 'V', '2', '4') /* non-subsampled Cr (1) and Cb (2) planes */
 
+struct gbm_format_name_desc {
+   char name[5];
+};
 
 /**
  * Flags to indicate the intended use for the buffer - these are passed into
@@ -399,6 +402,9 @@ gbm_surface_has_free_buffers(struct gbm_surface *surface);
 void
 gbm_surface_destroy(struct gbm_surface *surface);
 
+char *
+gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
+
 #ifdef __cplusplus
 }
 #endif