OSDN Git Service

minigbm: standardize naming of map flags
authorGurchetan Singh <gurchetansingh@chromium.org>
Fri, 29 Sep 2017 00:02:12 +0000 (17:02 -0700)
committerchrome-bot <chrome-bot@chromium.org>
Tue, 3 Oct 2017 03:25:45 +0000 (20:25 -0700)
It's helpful to differentiate map flags from normal buffer creation
flags. Note gralloc doesn't differentiate between map flags and buffer
creation flags. However, since flags are passed in with gralloc
(*lock)(), we can use a separate conversion function there.

BUG=chromium:764871
TEST=Boot Android and play games on Eve

Change-Id: Ic8aee84d9ac945abf93d9a9bda78fe3f77711cc3
Reviewed-on: https://chromium-review.googlesource.com/691424
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
cros_gralloc/cros_gralloc_buffer.cc
cros_gralloc/cros_gralloc_buffer.h
cros_gralloc/cros_gralloc_driver.cc
cros_gralloc/cros_gralloc_driver.h
cros_gralloc/gralloc0/gralloc0.cc
drv.c
drv.h
gbm.c

index 710b78f..a78390f 100644 (file)
@@ -44,7 +44,7 @@ int32_t cros_gralloc_buffer::decrease_refcount()
        return --refcount_;
 }
 
-int32_t cros_gralloc_buffer::lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES])
+int32_t cros_gralloc_buffer::lock(uint32_t map_flags, uint8_t *addr[DRV_MAX_PLANES])
 {
        void *vaddr = nullptr;
 
@@ -59,12 +59,12 @@ int32_t cros_gralloc_buffer::lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES])
                return -EINVAL;
        }
 
-       if (flags) {
+       if (map_flags & BO_MAP_READ_WRITE) {
                if (lock_data_[0]) {
                        vaddr = lock_data_[0]->addr;
                } else {
                        vaddr = drv_bo_map(bo_, 0, 0, drv_bo_get_width(bo_), drv_bo_get_height(bo_),
-                                          BO_TRANSFER_READ_WRITE, &lock_data_[0], 0);
+                                          map_flags, &lock_data_[0], 0);
                }
 
                if (vaddr == MAP_FAILED) {
index 2dc4d8b..f629199 100644 (file)
@@ -23,7 +23,7 @@ class cros_gralloc_buffer
        int32_t increase_refcount();
        int32_t decrease_refcount();
 
-       int32_t lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES]);
+       int32_t lock(uint32_t map_flags, uint8_t *addr[DRV_MAX_PLANES]);
        int32_t unlock();
 
       private:
index 7a4632e..3a0b013 100644 (file)
@@ -235,7 +235,7 @@ int32_t cros_gralloc_driver::release(buffer_handle_t handle)
        return 0;
 }
 
-int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence, uint64_t flags,
+int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence, uint32_t map_flags,
                                  uint8_t *addr[DRV_MAX_PLANES])
 {
        int32_t ret = cros_gralloc_sync_wait(acquire_fence);
@@ -255,7 +255,7 @@ int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence,
                return -EINVAL;
        }
 
-       return buffer->lock(flags, addr);
+       return buffer->lock(map_flags, addr);
 }
 
 int32_t cros_gralloc_driver::unlock(buffer_handle_t handle, int32_t *release_fence)
index b875497..dea2ac0 100644 (file)
@@ -26,7 +26,7 @@ class cros_gralloc_driver
        int32_t retain(buffer_handle_t handle);
        int32_t release(buffer_handle_t handle);
 
-       int32_t lock(buffer_handle_t handle, int32_t acquire_fence, uint64_t flags,
+       int32_t lock(buffer_handle_t handle, int32_t acquire_fence, uint32_t map_flags,
                     uint8_t *addr[DRV_MAX_PLANES]);
        int32_t unlock(buffer_handle_t handle, int32_t *release_fence);
 
index 22932f5..ab05376 100644 (file)
@@ -78,6 +78,18 @@ static uint64_t gralloc0_convert_usage(int usage)
        return use_flags;
 }
 
+static uint32_t gralloc0_convert_map_usage(int map_usage)
+{
+       uint32_t map_flags = BO_MAP_NONE;
+
+       if (map_usage & GRALLOC_USAGE_SW_READ_MASK)
+               map_flags |= BO_MAP_READ;
+       if (map_usage & GRALLOC_USAGE_SW_WRITE_MASK)
+               map_flags |= BO_MAP_WRITE;
+
+       return map_flags;
+}
+
 static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
                          buffer_handle_t *handle, int *stride)
 {
@@ -282,7 +294,7 @@ static int gralloc0_lock_async(struct gralloc_module_t const *module, buffer_han
                               int usage, int l, int t, int w, int h, void **vaddr, int fence_fd)
 {
        int32_t ret;
-       uint64_t flags;
+       uint32_t map_flags;
        uint8_t *addr[DRV_MAX_PLANES];
        auto mod = (struct gralloc0_module *)module;
 
@@ -297,8 +309,8 @@ static int gralloc0_lock_async(struct gralloc_module_t const *module, buffer_han
                return -EINVAL;
        }
 
-       flags = gralloc0_convert_usage(usage);
-       ret = mod->driver->lock(handle, fence_fd, flags, addr);
+       map_flags = gralloc0_convert_map_usage(usage);
+       ret = mod->driver->lock(handle, fence_fd, map_flags, addr);
        *vaddr = addr[0];
        return ret;
 }
@@ -314,8 +326,8 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff
                                     int usage, int l, int t, int w, int h,
                                     struct android_ycbcr *ycbcr, int fence_fd)
 {
-       uint64_t flags;
        int32_t ret;
+       uint32_t map_flags;
        uint8_t *addr[DRV_MAX_PLANES] = { nullptr, nullptr, nullptr, nullptr };
        auto mod = (struct gralloc0_module *)module;
 
@@ -332,8 +344,8 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff
                return -EINVAL;
        }
 
-       flags = gralloc0_convert_usage(usage);
-       ret = mod->driver->lock(handle, fence_fd, flags, addr);
+       map_flags = gralloc0_convert_map_usage(usage);
+       ret = mod->driver->lock(handle, fence_fd, map_flags, addr);
        if (ret)
                return ret;
 
diff --git a/drv.c b/drv.c
index 339aac1..fc8132a 100644 (file)
--- a/drv.c
+++ b/drv.c
@@ -361,7 +361,7 @@ struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data)
 }
 
 void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-                uint32_t flags, struct map_info **map_data, size_t plane)
+                uint32_t map_flags, struct map_info **map_data, size_t plane)
 {
        void *ptr;
        uint8_t *addr;
@@ -373,7 +373,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        assert(height > 0);
        assert(x + width <= drv_bo_get_width(bo));
        assert(y + height <= drv_bo_get_height(bo));
-       assert(BO_TRANSFER_READ_WRITE & flags);
+       assert(BO_MAP_READ_WRITE & map_flags);
 
        pthread_mutex_lock(&bo->drv->driver_lock);
 
@@ -384,7 +384,7 @@ void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t
        }
 
        data = calloc(1, sizeof(*data));
-       prot = BO_TRANSFER_WRITE & flags ? PROT_WRITE | PROT_READ : PROT_READ;
+       prot = BO_MAP_WRITE & map_flags ? PROT_WRITE | PROT_READ : PROT_READ;
        addr = bo->drv->backend->bo_map(bo, data, plane, prot);
        if (addr == MAP_FAILED) {
                *map_data = NULL;
diff --git a/drv.h b/drv.h
index fd544ca..ad2f82a 100644 (file)
--- a/drv.h
+++ b/drv.h
@@ -38,11 +38,11 @@ extern "C" {
 #define BO_USE_RENDERSCRIPT            (1ull << 16)
 #define BO_USE_TEXTURE                 (1ull << 17)
 
-/* Read-Write permissions for drv_bo_map() flags */
-#define BO_TRANSFER_NONE 0
-#define BO_TRANSFER_READ (1 << 0)
-#define BO_TRANSFER_WRITE (1 << 1)
-#define BO_TRANSFER_READ_WRITE (BO_TRANSFER_READ | BO_TRANSFER_WRITE)
+/* Map flags */
+#define BO_MAP_NONE 0
+#define BO_MAP_READ (1 << 0)
+#define BO_MAP_WRITE (1 << 1)
+#define BO_MAP_READ_WRITE (BO_MAP_READ | BO_MAP_WRITE)
 
 /* This is our extension to <drm_fourcc.h>.  We need to make sure we don't step
  * on the namespace of already defined formats, which can be done by using invalid
@@ -110,7 +110,7 @@ void drv_bo_destroy(struct bo *bo);
 struct bo *drv_bo_import(struct driver *drv, struct drv_import_fd_data *data);
 
 void *drv_bo_map(struct bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-                uint32_t flags, struct map_info **map_data, size_t plane);
+                uint32_t map_flags, struct map_info **map_data, size_t plane);
 
 int drv_bo_unmap(struct bo *bo, struct map_info *data);
 
diff --git a/gbm.c b/gbm.c
index f76e4ca..906560a 100644 (file)
--- a/gbm.c
+++ b/gbm.c
@@ -223,15 +223,16 @@ PUBLIC struct gbm_bo *gbm_bo_import(struct gbm_device *gbm, uint32_t type, void
 }
 
 PUBLIC void *gbm_bo_map(struct gbm_bo *bo, uint32_t x, uint32_t y, uint32_t width, uint32_t height,
-                       uint32_t flags, uint32_t *stride, void **map_data, size_t plane)
+                       uint32_t transfer_flags, uint32_t *stride, void **map_data, size_t plane)
 {
+       uint32_t map_flags;
        if (!bo || width == 0 || height == 0 || !stride || !map_data)
                return NULL;
 
        *stride = gbm_bo_get_plane_stride(bo, plane);
-       uint32_t drv_flags = flags & GBM_BO_TRANSFER_READ ? BO_TRANSFER_READ : BO_TRANSFER_NONE;
-       drv_flags |= flags & GBM_BO_TRANSFER_WRITE ? BO_TRANSFER_WRITE : BO_TRANSFER_NONE;
-       return drv_bo_map(bo->bo, x, y, width, height, drv_flags, (struct map_info **)map_data,
+       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;
+       return drv_bo_map(bo->bo, x, y, width, height, map_flags, (struct map_info **)map_data,
                          plane);
 }