minigbm: implement new functions

These functions were newly added -- implement some, don't implement
surface functions.

This patch series is not bisectable.

BUG=b:145747113
TEST=emerge-nami minigbm

Cq-Depend: chromium:1963000
Change-Id: I36814955b754840daab31fa2762910aa44e80fd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/1963002
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Kristian H. Kristensen <hoegsberg@chromium.org>
Reviewed-by: Dominik Behr <dbehr@chromium.org>
diff --git a/gbm.c b/gbm.c
index d46d212..4f9c34b 100644
--- a/gbm.c
+++ b/gbm.c
@@ -41,6 +41,12 @@
 	return (drv_get_combination(gbm->drv, format, use_flags) != NULL);
 }
 
+PUBLIC int gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm, uint32_t format,
+						      uint64_t modifier)
+{
+	return 0;
+}
+
 PUBLIC struct gbm_device *gbm_create_device(int fd)
 {
 	struct gbm_device *gbm;
@@ -76,9 +82,15 @@
 	return surface;
 }
 
-PUBLIC void gbm_surface_destroy(struct gbm_surface *surface)
+PUBLIC struct gbm_surface *gbm_surface_create_with_modifiers(struct gbm_device *gbm, uint32_t width,
+							     uint32_t height, uint32_t format,
+							     const uint64_t *modifiers,
+							     const unsigned int count)
 {
-	free(surface);
+	if (count != 0 || modifiers != NULL)
+		return NULL;
+
+	return gbm_surface_create(gbm, width, height, format, 0);
 }
 
 PUBLIC struct gbm_bo *gbm_surface_lock_front_buffer(struct gbm_surface *surface)
@@ -90,6 +102,16 @@
 {
 }
 
+PUBLIC int gbm_surface_has_free_buffers(struct gbm_surface *surface)
+{
+	return 0;
+}
+
+PUBLIC void gbm_surface_destroy(struct gbm_surface *surface)
+{
+	free(surface);
+}
+
 static struct gbm_bo *gbm_bo_new(struct gbm_device *gbm, uint32_t format)
 {
 	struct gbm_bo *bo;
@@ -263,6 +285,11 @@
 	return bo->gbm_format;
 }
 
+PUBLIC uint32_t gbm_bo_get_bpp(struct gbm_bo *bo)
+{
+	return drv_bytes_per_pixel_from_format(drv_bo_get_format(bo->bo), 0);
+}
+
 PUBLIC uint64_t gbm_bo_get_modifier(struct gbm_bo *bo)
 {
 	return drv_bo_get_plane_format_modifier(bo->bo, 0);
@@ -315,6 +342,38 @@
 	return bo->user_data;
 }
 
+/* The two GBM_BO_FORMAT_[XA]RGB8888 formats alias the GBM_FORMAT_*
+ * formats of the same name. We want to accept them whenever someone
+ * has a GBM format, but never return them to the user.
+ */
+static uint32_t gbm_format_canonicalize(uint32_t gbm_format)
+{
+	switch (gbm_format) {
+	case GBM_BO_FORMAT_XRGB8888:
+		return GBM_FORMAT_XRGB8888;
+	case GBM_BO_FORMAT_ARGB8888:
+		return GBM_FORMAT_ARGB8888;
+	default:
+		return gbm_format;
+	}
+}
+
+/**
+ * Returns a string representing the fourcc format name.
+ */
+PUBLIC 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;
+}
+
 /*
  * The following functions are not deprecated, but not in the Mesa the gbm
  * header. The main difference is minigbm allows for the possibility of