OSDN Git Service

[automerger skipped] Revert "Merge Android R" am: 56e3e9014e -s ours am: 850031de34...
[android-x86/external-minigbm.git] / gbm.c
diff --git a/gbm.c b/gbm.c
index d46d212..ab5b3f7 100644 (file)
--- a/gbm.c
+++ b/gbm.c
@@ -41,6 +41,12 @@ PUBLIC int gbm_device_is_format_supported(struct gbm_device *gbm, uint32_t forma
        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 @@ PUBLIC struct gbm_surface *gbm_surface_create(struct gbm_device *gbm, uint32_t w
        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 void gbm_surface_release_buffer(struct gbm_surface *surface, struct gbm_b
 {
 }
 
+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;
@@ -188,13 +210,17 @@ PUBLIC struct gbm_bo *gbm_bo_import(struct gbm_device *gbm, uint32_t type, void
                drv_data.format = fd_data->format;
                drv_data.fds[0] = fd_data->fd;
                drv_data.strides[0] = fd_data->stride;
+
+               for (i = 0; i < GBM_MAX_PLANES; ++i)
+                       drv_data.format_modifiers[i] = DRM_FORMAT_MOD_INVALID;
                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);
+               num_planes = drv_num_planes_from_modifier(gbm->drv, drv_data.format,
+                                                         fd_modifier_data->modifier);
                assert(num_planes);
 
                num_fds = fd_modifier_data->num_fds;
@@ -263,6 +289,11 @@ PUBLIC uint32_t gbm_bo_get_format(struct gbm_bo *bo)
        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 +346,38 @@ PUBLIC void *gbm_bo_get_user_data(struct gbm_bo *bo)
        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
@@ -333,6 +396,12 @@ PUBLIC int gbm_bo_get_plane_fd(struct gbm_bo *bo, size_t plane)
 PUBLIC void *gbm_bo_map(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, size_t plane)
 {
+       return gbm_bo_map2(bo, x, y, width, height, transfer_flags, stride, map_data, 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;
@@ -354,26 +423,3 @@ PUBLIC void *gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t widt
        offset += rect.x * drv_bytes_per_pixel_from_format(bo->gbm_format, plane);
        return (void *)((uint8_t *)addr + offset);
 }
-
-/*
- * The following functions are deprecated. They can be removed * once crbug.com/946907 is fixed.
- */
-PUBLIC size_t gbm_bo_get_num_planes(struct gbm_bo *bo)
-{
-       return gbm_bo_get_plane_count(bo);
-}
-
-PUBLIC union gbm_bo_handle gbm_bo_get_plane_handle(struct gbm_bo *bo, size_t plane)
-{
-       return gbm_bo_get_handle_for_plane(bo, plane);
-}
-
-PUBLIC uint32_t gbm_bo_get_plane_offset(struct gbm_bo *bo, size_t plane)
-{
-       return gbm_bo_get_offset(bo, plane);
-}
-
-PUBLIC uint32_t gbm_bo_get_plane_stride(struct gbm_bo *bo, size_t plane)
-{
-       return gbm_bo_get_stride_for_plane(bo, plane);
-}