OSDN Git Service

minigbm: cros_gralloc: Fix type mismatch on 64-bit builds
[android-x86/external-minigbm.git] / cros_gralloc / cros_alloc_device.cc
index e9cadd2..990ccee 100644 (file)
@@ -6,8 +6,7 @@
 
 #include "cros_gralloc.h"
 
-static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
-                                                     int width, int height,
+static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv, int width, int height,
                                                      int format, int usage)
 {
        uint64_t drv_usage;
@@ -27,16 +26,14 @@ static struct cros_gralloc_bo *cros_gralloc_bo_create(struct driver *drv,
        }
 
        if (!combo) {
-               cros_gralloc_error("Unsupported combination -- HAL format: %u, "
-                                  "HAL flags: %u, drv_format: %4.4s, "
-                                  "drv_flags: %llu", format, usage,
-                                   reinterpret_cast<char*>(&drv_format),
-                                   drv_usage);
+               cros_gralloc_error("Unsupported combination -- HAL format: %u, HAL flags: %u, "
+                                  "drv_format: %4.4s, drv_flags: %llu",
+                                  format, usage, reinterpret_cast<char *>(&drv_format),
+                                  static_cast<unsigned long long>(drv_usage));
                return NULL;
        }
 
        bo = new cros_gralloc_bo();
-       memset(bo, 0, sizeof(*bo));
 
        bo->bo = drv_bo_create(drv, width, height, drv_format, drv_usage);
        if (!bo->bo) {
@@ -69,13 +66,12 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
        struct cros_gralloc_handle *hnd;
 
        hnd = new cros_gralloc_handle();
-       memset(hnd, 0, sizeof(*hnd));
 
        num_planes = drv_bo_get_num_planes(bo);
 
        hnd->base.version = sizeof(hnd->base);
        hnd->base.numFds = num_planes;
-       hnd->base.numInts = num_ints_handle() - num_planes;
+       hnd->base.numInts = num_ints_handle - num_planes;
 
        for (size_t p = 0; p < num_planes; p++) {
                hnd->fds[p] = drv_bo_get_plane_fd(bo, p);
@@ -84,26 +80,24 @@ static struct cros_gralloc_handle *cros_gralloc_handle_from_bo(struct bo *bo)
                hnd->sizes[p] = drv_bo_get_plane_size(bo, p);
 
                mod = drv_bo_get_plane_format_modifier(bo, p);
-               hnd->format_modifiers[p] = static_cast<uint32_t>(mod >> 32);
-               hnd->format_modifiers[p+1] = static_cast<uint32_t>(mod);
+               hnd->format_modifiers[2 * p] = static_cast<uint32_t>(mod >> 32);
+               hnd->format_modifiers[2 * p + 1] = static_cast<uint32_t>(mod);
        }
 
        hnd->width = drv_bo_get_width(bo);
        hnd->height = drv_bo_get_height(bo);
        hnd->format = drv_bo_get_format(bo);
+       hnd->pixel_stride = drv_bo_get_stride_in_pixels(bo);
 
-       hnd->magic = cros_gralloc_magic();
-
-       hnd->pixel_stride = hnd->strides[0];
-       hnd->pixel_stride /= drv_stride_from_format(hnd->format, 1, 0);
+       hnd->magic = cros_gralloc_magic;
 
        return hnd;
 }
 
-static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
-                             int usage, buffer_handle_t *handle, int *stride)
+static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format, int usage,
+                             buffer_handle_t *handle, int *stride)
 {
-       auto mod = (struct cros_gralloc_module *) dev->common.module;
+       auto mod = (struct cros_gralloc_module *)dev->common.module;
        std::lock_guard<std::mutex> lock(mod->mutex);
 
        auto bo = cros_gralloc_bo_create(mod->drv, w, h, format, usage);
@@ -129,8 +123,8 @@ static int cros_gralloc_alloc(alloc_device_t *dev, int w, int h, int format,
 static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
 {
        struct cros_gralloc_bo *bo;
-       auto hnd = (struct cros_gralloc_handle *) handle;
-       auto mod = (struct cros_gralloc_module *) dev->common.module;
+       auto hnd = (struct cros_gralloc_handle *)handle;
+       auto mod = (struct cros_gralloc_module *)dev->common.module;
        std::lock_guard<std::mutex> lock(mod->mutex);
 
        if (cros_gralloc_validate_handle(hnd)) {
@@ -153,8 +147,8 @@ static int cros_gralloc_free(alloc_device_t *dev, buffer_handle_t handle)
 
 static int cros_gralloc_close(struct hw_device_t *dev)
 {
-       auto mod = (struct cros_gralloc_module *) dev->module;
-       auto alloc = (struct alloc_device_t *) dev;
+       auto mod = (struct cros_gralloc_module *)dev->module;
+       auto alloc = (struct alloc_device_t *)dev;
        std::lock_guard<std::mutex> lock(mod->mutex);
 
        if (mod->drv) {
@@ -170,10 +164,9 @@ static int cros_gralloc_close(struct hw_device_t *dev)
        return CROS_GRALLOC_ERROR_NONE;
 }
 
-int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
-                     struct hw_device_t **dev)
+int cros_gralloc_open(const struct hw_module_t *mod, const char *name, struct hw_device_t **dev)
 {
-       auto module = (struct cros_gralloc_module *) mod;
+       auto module = (struct cros_gralloc_module *)mod;
        std::lock_guard<std::mutex> lock(module->mutex);
 
        if (module->drv)
@@ -190,13 +183,12 @@ int cros_gralloc_open(const struct hw_module_t *mod, const char *name,
        }
 
        auto alloc = new alloc_device_t();
-       memset(alloc, 0, sizeof(*alloc));
 
        alloc->alloc = cros_gralloc_alloc;
        alloc->free = cros_gralloc_free;
        alloc->common.tag = HARDWARE_DEVICE_TAG;
        alloc->common.version = 0;
-       alloc->common.module = (hw_module_t*) mod;
+       alloc->common.module = (hw_module_t *)mod;
        alloc->common.close = cros_gralloc_close;
 
        *dev = &alloc->common;