OSDN Git Service

minigbm: cros_gralloc: Use standard error codes
authorTomasz Figa <tfiga@chromium.org>
Fri, 21 Jul 2017 08:54:05 +0000 (17:54 +0900)
committerchrome-bot <chrome-bot@chromium.org>
Tue, 25 Jul 2017 21:04:06 +0000 (14:04 -0700)
Since we decided not to support gralloc1 and gralloc0 requires standard
errno-based error codes to be returned to callers, remove the custom
error code enumeration and use standard codes everywhere in
cros_gralloc.

BUG=b:63915090
TEST=Play store starts on Eve

Change-Id: I4f466e8cac6323554f29a7da5c2c00ab47b0abf2
Reviewed-on: https://chromium-review.googlesource.com/580735
Commit-Ready: Tomasz Figa <tfiga@chromium.org>
Tested-by: Tomasz Figa <tfiga@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
cros_gralloc/cros_gralloc_buffer.cc
cros_gralloc/cros_gralloc_driver.cc
cros_gralloc/cros_gralloc_types.h
cros_gralloc/gralloc0/gralloc0.cc

index 3609f58..a3d65ab 100644 (file)
@@ -52,7 +52,7 @@ int32_t cros_gralloc_buffer::lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES])
         */
        if (drv_num_buffers_per_bo(bo_) != 1) {
                cros_gralloc_error("Can only support one buffer per bo.");
-               return CROS_GRALLOC_ERROR_NO_RESOURCES;
+               return -EINVAL;
        }
 
        if (flags) {
@@ -66,7 +66,7 @@ int32_t cros_gralloc_buffer::lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES])
 
                if (vaddr == MAP_FAILED) {
                        cros_gralloc_error("Mapping failed.");
-                       return CROS_GRALLOC_ERROR_UNSUPPORTED;
+                       return -EFAULT;
                }
 
                addr[0] = static_cast<uint8_t *>(vaddr);
@@ -76,14 +76,14 @@ int32_t cros_gralloc_buffer::lock(uint64_t flags, uint8_t *addr[DRV_MAX_PLANES])
                addr[plane] = addr[0] + drv_bo_get_plane_offset(bo_, plane);
 
        lockcount_++;
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 int32_t cros_gralloc_buffer::unlock()
 {
        if (lockcount_ <= 0) {
                cros_gralloc_error("Buffer was not locked.");
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
        if (!--lockcount_) {
@@ -93,5 +93,5 @@ int32_t cros_gralloc_buffer::unlock()
                }
        }
 
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
index d43719e..761895d 100644 (file)
@@ -67,11 +67,11 @@ int32_t cros_gralloc_driver::init()
                        drmFreeVersion(version);
                        drv_ = drv_create(fd);
                        if (drv_)
-                               return CROS_GRALLOC_ERROR_NONE;
+                               return 0;
                }
        }
 
-       return CROS_GRALLOC_ERROR_NO_RESOURCES;
+       return -ENODEV;
 }
 
 bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descriptor *descriptor)
@@ -99,7 +99,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
                           descriptor->drv_usage);
        if (!bo) {
                cros_gralloc_error("Failed to create bo.");
-               return CROS_GRALLOC_ERROR_NO_RESOURCES;
+               return -ENOMEM;
        }
 
        /*
@@ -110,7 +110,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        if (drv_num_buffers_per_bo(bo) != 1) {
                drv_bo_destroy(bo);
                cros_gralloc_error("Can only support one buffer per bo.");
-               return CROS_GRALLOC_ERROR_NO_RESOURCES;
+               return -EINVAL;
        }
 
        hnd = new cros_gralloc_handle();
@@ -146,7 +146,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        buffers_.emplace(id, buffer);
        handles_.emplace(hnd, std::make_pair(buffer, 1));
        *out_handle = &hnd->base;
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
@@ -157,19 +157,19 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (buffer) {
                handles_[hnd].second++;
                buffer->increase_refcount();
-               return CROS_GRALLOC_ERROR_NONE;
+               return 0;
        }
 
        if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) {
                cros_gralloc_error("drmPrimeFDToHandle failed.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -errno;
        }
 
        if (buffers_.count(id)) {
@@ -194,7 +194,7 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
 
                bo = drv_bo_import(drv_, &data);
                if (!bo)
-                       return CROS_GRALLOC_ERROR_NO_RESOURCES;
+                       return -EFAULT;
 
                id = drv_bo_get_plane_handle(bo, 0).u32;
 
@@ -203,7 +203,7 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
        }
 
        handles_.emplace(hnd, std::make_pair(buffer, 1));
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 int32_t cros_gralloc_driver::release(buffer_handle_t handle)
@@ -213,13 +213,13 @@ int32_t cros_gralloc_driver::release(buffer_handle_t handle)
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
                cros_gralloc_error("Invalid Reference.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        if (!--handles_[hnd].second)
@@ -230,7 +230,7 @@ int32_t cros_gralloc_driver::release(buffer_handle_t handle)
                delete buffer;
        }
 
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence, uint64_t flags,
@@ -241,18 +241,18 @@ int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence,
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
                cros_gralloc_error("Invalid Reference.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        if (acquire_fence >= 0) {
                cros_gralloc_error("Sync wait not yet supported.");
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
        return buffer->lock(flags, addr);
@@ -265,13 +265,13 @@ int32_t cros_gralloc_driver::unlock(buffer_handle_t handle)
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
                cros_gralloc_error("Invalid Reference.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        return buffer->unlock();
@@ -284,17 +284,17 @@ int32_t cros_gralloc_driver::get_backing_store(buffer_handle_t handle, uint64_t
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
                cros_gralloc_error("Invalid Reference.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        *out_store = static_cast<uint64_t>(buffer->get_id());
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 cros_gralloc_buffer *cros_gralloc_driver::get_buffer(cros_gralloc_handle_t hnd)
index b1938c8..2f6122e 100644 (file)
@@ -7,17 +7,6 @@
 #ifndef CROS_GRALLOC_TYPES_H
 #define CROS_GRALLOC_TYPES_H
 
-typedef enum {
-       CROS_GRALLOC_ERROR_NONE = 0,
-       CROS_GRALLOC_ERROR_BAD_DESCRIPTOR = 1,
-       CROS_GRALLOC_ERROR_BAD_HANDLE = 2,
-       CROS_GRALLOC_ERROR_BAD_VALUE = 3,
-       CROS_GRALLOC_ERROR_NOT_SHARED = 4,
-       CROS_GRALLOC_ERROR_NO_RESOURCES = 5,
-       CROS_GRALLOC_ERROR_UNDEFINED = 6,
-       CROS_GRALLOC_ERROR_UNSUPPORTED = 7,
-} cros_gralloc_error_t;
-
 struct cros_gralloc_buffer_descriptor {
        uint32_t width;
        uint32_t height;
index 0843215..484763e 100644 (file)
@@ -103,7 +103,7 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
                                   "drv_format: %4.4s, drv_flags: %llu",
                                   format, usage, reinterpret_cast<char *>(&descriptor.drm_format),
                                   static_cast<unsigned long long>(descriptor.drv_usage));
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
        ret = mod->driver->allocate(&descriptor, handle);
@@ -113,7 +113,7 @@ static int gralloc0_alloc(alloc_device_t *dev, int w, int h, int format, int usa
        auto hnd = cros_gralloc_convert_handle(*handle);
        *stride = hnd->pixel_stride;
 
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 static int gralloc0_free(alloc_device_t *dev, buffer_handle_t handle)
@@ -125,7 +125,7 @@ static int gralloc0_free(alloc_device_t *dev, buffer_handle_t handle)
 static int gralloc0_close(struct hw_device_t *dev)
 {
        /* Memory is freed by managed pointers on process close. */
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
@@ -134,18 +134,18 @@ static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct
 
        if (module->alloc) {
                *dev = &module->alloc->common;
-               return CROS_GRALLOC_ERROR_NONE;
+               return 0;
        }
 
        if (strcmp(name, GRALLOC_HARDWARE_GPU0)) {
                cros_gralloc_error("Incorrect device name - %s.", name);
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
        module->driver = std::make_unique<cros_gralloc_driver>();
        if (module->driver->init()) {
                cros_gralloc_error("Failed to initialize driver.");
-               return CROS_GRALLOC_ERROR_NO_RESOURCES;
+               return -ENOMEM;
        }
 
        module->alloc = std::make_unique<alloc_device_t>();
@@ -158,7 +158,7 @@ static int gralloc0_open(const struct hw_module_t *mod, const char *name, struct
        module->alloc->common.close = gralloc0_close;
 
        *dev = &module->alloc->common;
-       return CROS_GRALLOC_ERROR_NONE;
+       return 0;
 }
 
 static int gralloc0_register_buffer(struct gralloc_module_t const *module, buffer_handle_t handle)
@@ -169,7 +169,7 @@ static int gralloc0_register_buffer(struct gralloc_module_t const *module, buffe
                mod->driver = std::make_unique<cros_gralloc_driver>();
                if (mod->driver->init()) {
                        cros_gralloc_error("Failed to initialize driver.");
-                       return CROS_GRALLOC_ERROR_NO_RESOURCES;
+                       return -ENOMEM;
                }
        }
 
@@ -193,12 +193,12 @@ static int gralloc0_lock(struct gralloc_module_t const *module, buffer_handle_t
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        if ((hnd->droid_format == HAL_PIXEL_FORMAT_YCbCr_420_888)) {
                cros_gralloc_error("HAL_PIXEL_FORMAT_YCbCr_*_888 format not compatible.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        fence = -1;
@@ -230,17 +230,17 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...)
        case GRALLOC_DRM_GET_BACKING_STORE:
                break;
        default:
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
        va_start(args, op);
 
-       ret = CROS_GRALLOC_ERROR_NONE;
+       ret = 0;
        handle = va_arg(args, buffer_handle_t);
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        switch (op) {
@@ -263,7 +263,7 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...)
                ret = mod->driver->get_backing_store(handle, out_store);
                break;
        default:
-               ret = CROS_GRALLOC_ERROR_UNSUPPORTED;
+               ret = -EINVAL;
        }
 
        va_end(args);
@@ -282,14 +282,14 @@ static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_han
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        if ((hnd->droid_format != HAL_PIXEL_FORMAT_YCbCr_420_888) &&
            (hnd->droid_format != HAL_PIXEL_FORMAT_YV12) &&
            (hnd->droid_format != HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED)) {
                cros_gralloc_error("Non-YUV format not compatible.");
-               return CROS_GRALLOC_ERROR_BAD_HANDLE;
+               return -EINVAL;
        }
 
        fence = -1;
@@ -318,10 +318,10 @@ static int gralloc0_lock_ycbcr(struct gralloc_module_t const *module, buffer_han
                break;
        default:
                mod->driver->unlock(handle);
-               return CROS_GRALLOC_ERROR_UNSUPPORTED;
+               return -EINVAL;
        }
 
-       return ret;
+       return 0;
 }
 
 static struct hw_module_methods_t gralloc0_module_methods = {.open = gralloc0_open };