+
+/* 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
+ * disjoint YUV images, while Mesa GBM does not.
+ */
+PUBLIC uint32_t gbm_bo_get_plane_size(struct gbm_bo *bo, size_t plane)
+{
+ return drv_bo_get_plane_size(bo->bo, plane);
+}
+
+PUBLIC int gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
+{
+ return drv_bo_get_plane_fd(bo->bo, plane);
+}
+
+PUBLIC void *gbm_bo_map2(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t transfer_flags, uint32_t *stride, void **map_data, int plane)
+{
+ void *addr;
+ off_t offset;
+ uint32_t map_flags;
+ plane = (size_t)plane;
+ struct rectangle rect = { .x = x, .y = y, .width = width, .height = height };
+ if (!bo || width == 0 || height == 0 || !stride || !map_data)
+ return NULL;
+
+ map_flags = (transfer_flags & GBM_BO_TRANSFER_READ) ? BO_MAP_READ : BO_MAP_NONE;
+ map_flags |= (transfer_flags & GBM_BO_TRANSFER_WRITE) ? BO_MAP_WRITE : BO_MAP_NONE;
+
+ addr = drv_bo_map(bo->bo, &rect, map_flags, (struct mapping **)map_data, plane);
+ if (addr == MAP_FAILED)
+ return MAP_FAILED;
+
+ *stride = ((struct mapping *)*map_data)->vma->map_strides[plane];
+
+ offset = *stride * rect.y;
+ offset += rect.x * drv_bytes_per_pixel_from_format(bo->gbm_format, plane);
+ return (void *)((uint8_t *)addr + offset);
+}