minigbm: define GBM_BO_IMPORT_FD_MODIFIER

This CL aligns the minigbm more with the upstream GBM
by defining GBM_BO_IMPORT_FD_MODIFIER and using
gbm_import_fd_modifier_data instead.

That is, the main difference between the old
gbm_import_fd_planar_data one and the new one is
the format_modifiers variable. In the upstream
GBM, it's a single variable. In the minigbm, it is
an array.

As we know there are no cases when modifiers would
be different for each plane. Thus, it's safe to eliminate
that and adapt more to the upstream.

Change-Id: Iaae062ef1fe9fc9ab0ead09c5f4bfa91d2db67c3
Reviewed-on: https://chromium-review.googlesource.com/1360771
Commit-Ready: Maksim Sisov <msisov@igalia.com>
Tested-by: Maksim Sisov <msisov@igalia.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
diff --git a/gbm.c b/gbm.c
index dd6013c..b57b345 100644
--- a/gbm.c
+++ b/gbm.c
@@ -167,6 +167,7 @@
 	struct drv_import_fd_data drv_data;
 	struct gbm_import_fd_data *fd_data = buffer;
 	struct gbm_import_fd_planar_data *fd_planar_data = buffer;
+	struct gbm_import_fd_modifier_data *fd_modifier_data = buffer;
 	uint32_t gbm_format;
 	size_t num_planes, i;
 
@@ -181,6 +182,26 @@
 		drv_data.fds[0] = fd_data->fd;
 		drv_data.strides[0] = fd_data->stride;
 		break;
+	case GBM_BO_IMPORT_FD_MODIFIER:
+		gbm_format = fd_modifier_data->format;
+		drv_data.width = fd_modifier_data->width;
+		drv_data.height = fd_modifier_data->height;
+		drv_data.format = fd_modifier_data->format;
+		num_planes = drv_num_planes_from_format(drv_data.format);
+
+		assert(num_planes);
+
+		for (i = 0; i < num_planes; i++) {
+			drv_data.fds[i] = fd_modifier_data->fds[i];
+			drv_data.offsets[i] = fd_modifier_data->offsets[i];
+			drv_data.strides[i] = fd_modifier_data->strides[i];
+			drv_data.format_modifiers[i] = fd_modifier_data->modifier;
+		}
+
+		for (i = num_planes; i < GBM_MAX_PLANES; i++)
+			drv_data.fds[i] = -1;
+
+		break;
 	case GBM_BO_IMPORT_FD_PLANAR:
 		gbm_format = fd_planar_data->format;
 		drv_data.width = fd_planar_data->width;
diff --git a/gbm.h b/gbm.h
index 68a34c5..2e9d218 100644
--- a/gbm.h
+++ b/gbm.h
@@ -305,7 +305,9 @@
 #define GBM_BO_IMPORT_WL_BUFFER         0x5501
 #define GBM_BO_IMPORT_EGL_IMAGE         0x5502
 #define GBM_BO_IMPORT_FD                0x5503
-#define GBM_BO_IMPORT_FD_PLANAR         0x5504
+#define GBM_BO_IMPORT_FD_MODIFIER       0x5504
+// Deprecated. Use GBM_BO_IMPORT_FD_MODIFIER instead.
+#define GBM_BO_IMPORT_FD_PLANAR         0x5505
 
 struct gbm_import_fd_data {
    int fd;
@@ -315,6 +317,18 @@
    uint32_t format;
 };
 
+struct gbm_import_fd_modifier_data {
+   uint32_t width;
+   uint32_t height;
+   uint32_t format;
+   uint32_t num_fds;
+   int fds[GBM_MAX_PLANES];
+   int strides[GBM_MAX_PLANES];
+   int offsets[GBM_MAX_PLANES];
+   uint64_t modifier;
+};
+
+// Deprecated. Use gbm_import_fd_modifier_data instead.
 struct gbm_import_fd_planar_data {
    int fds[GBM_MAX_PLANES];
    uint32_t width;