OSDN Git Service

minigbm: Drop drv_bo_get_stride_in_pixels() helper
[android-x86/external-minigbm.git] / cros_gralloc / cros_gralloc_driver.cc
index 805c123..a68023e 100644 (file)
@@ -78,8 +78,8 @@ bool cros_gralloc_driver::is_supported(const struct cros_gralloc_buffer_descript
 {
        struct combination *combo;
        uint32_t resolved_format;
-       resolved_format = drv_resolve_format(drv_, descriptor->drm_format, descriptor->drv_usage);
-       combo = drv_get_combination(drv_, resolved_format, descriptor->drv_usage);
+       resolved_format = drv_resolve_format(drv_, descriptor->drm_format, descriptor->use_flags);
+       combo = drv_get_combination(drv_, resolved_format, descriptor->use_flags);
        return (combo != nullptr);
 }
 
@@ -90,15 +90,16 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        uint64_t mod;
        size_t num_planes;
        uint32_t resolved_format;
+       uint32_t bytes_per_pixel;
 
        struct bo *bo;
        struct cros_gralloc_handle *hnd;
 
-       resolved_format = drv_resolve_format(drv_, descriptor->drm_format, descriptor->drv_usage);
+       resolved_format = drv_resolve_format(drv_, descriptor->drm_format, descriptor->use_flags);
        bo = drv_bo_create(drv_, descriptor->width, descriptor->height, resolved_format,
-                          descriptor->drv_usage);
+                          descriptor->use_flags);
        if (!bo) {
-               cros_gralloc_error("Failed to create bo.");
+               drv_log("Failed to create bo.\n");
                return -ENOMEM;
        }
 
@@ -109,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.");
+               drv_log("Can only support one buffer per bo.\n");
                return -EINVAL;
        }
 
@@ -133,9 +134,10 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        hnd->width = drv_bo_get_width(bo);
        hnd->height = drv_bo_get_height(bo);
        hnd->format = drv_bo_get_format(bo);
-       hnd->flags[0] = static_cast<uint32_t>(descriptor->drv_usage >> 32);
-       hnd->flags[1] = static_cast<uint32_t>(descriptor->drv_usage);
-       hnd->pixel_stride = drv_bo_get_stride_in_pixels(bo);
+       hnd->use_flags[0] = static_cast<uint32_t>(descriptor->use_flags >> 32);
+       hnd->use_flags[1] = static_cast<uint32_t>(descriptor->use_flags);
+       bytes_per_pixel = drv_bytes_per_pixel_from_format(hnd->format, 0);
+       hnd->pixel_stride = DIV_ROUND_UP(hnd->strides[0], bytes_per_pixel);
        hnd->magic = cros_gralloc_magic;
        hnd->droid_format = descriptor->droid_format;
        hnd->usage = descriptor->producer_usage;
@@ -157,7 +159,7 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
 
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
-               cros_gralloc_error("Invalid handle.");
+               drv_log("Invalid handle.\n");
                return -EINVAL;
        }
 
@@ -169,7 +171,7 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
        }
 
        if (drmPrimeFDToHandle(drv_get_fd(drv_), hnd->fds[0], &id)) {
-               cros_gralloc_error("drmPrimeFDToHandle failed.");
+               drv_log("drmPrimeFDToHandle failed.\n");
                return -errno;
        }
 
@@ -182,8 +184,8 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
                data.format = hnd->format;
                data.width = hnd->width;
                data.height = hnd->height;
-               data.flags = static_cast<uint64_t>(hnd->flags[0]) << 32;
-               data.flags |= hnd->flags[1];
+               data.use_flags = static_cast<uint64_t>(hnd->use_flags[0]) << 32;
+               data.use_flags |= hnd->use_flags[1];
 
                memcpy(data.fds, hnd->fds, sizeof(data.fds));
                memcpy(data.strides, hnd->strides, sizeof(data.strides));
@@ -214,13 +216,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.");
+               drv_log("Invalid handle.\n");
                return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
-               cros_gralloc_error("Invalid Reference.");
+               drv_log("Invalid Reference.\n");
                return -EINVAL;
        }
 
@@ -235,7 +237,8 @@ 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,
+                                 const struct rectangle *rect, uint32_t map_flags,
                                  uint8_t *addr[DRV_MAX_PLANES])
 {
        int32_t ret = cros_gralloc_sync_wait(acquire_fence);
@@ -245,17 +248,17 @@ int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence,
        std::lock_guard<std::mutex> lock(mutex_);
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
-               cros_gralloc_error("Invalid handle.");
+               drv_log("Invalid handle.\n");
                return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
-               cros_gralloc_error("Invalid Reference.");
+               drv_log("Invalid Reference.\n");
                return -EINVAL;
        }
 
-       return buffer->lock(flags, addr);
+       return buffer->lock(rect, map_flags, addr);
 }
 
 int32_t cros_gralloc_driver::unlock(buffer_handle_t handle, int32_t *release_fence)
@@ -264,13 +267,13 @@ int32_t cros_gralloc_driver::unlock(buffer_handle_t handle, int32_t *release_fen
 
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
-               cros_gralloc_error("Invalid handle.");
+               drv_log("Invalid handle.\n");
                return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
-               cros_gralloc_error("Invalid Reference.");
+               drv_log("Invalid Reference.\n");
                return -EINVAL;
        }
 
@@ -290,13 +293,13 @@ 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.");
+               drv_log("Invalid handle.\n");
                return -EINVAL;
        }
 
        auto buffer = get_buffer(hnd);
        if (!buffer) {
-               cros_gralloc_error("Invalid Reference.");
+               drv_log("Invalid Reference.\n");
                return -EINVAL;
        }