OSDN Git Service

minigbm: Revert "minigbm: flush buffer instead of unmapping"
[android-x86/external-minigbm.git] / cros_gralloc / cros_gralloc_driver.cc
index 761895d..3a0b013 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);
 }
 
@@ -94,9 +94,9 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
        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.");
                return -ENOMEM;
@@ -124,7 +124,6 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
                hnd->fds[plane] = drv_bo_get_plane_fd(bo, plane);
                hnd->strides[plane] = drv_bo_get_plane_stride(bo, plane);
                hnd->offsets[plane] = drv_bo_get_plane_offset(bo, plane);
-               hnd->sizes[plane] = drv_bo_get_plane_size(bo, plane);
 
                mod = drv_bo_get_plane_format_modifier(bo, plane);
                hnd->format_modifiers[2 * plane] = static_cast<uint32_t>(mod >> 32);
@@ -134,6 +133,8 @@ 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->use_flags[0] = static_cast<uint32_t>(descriptor->use_flags >> 32);
+       hnd->use_flags[1] = static_cast<uint32_t>(descriptor->use_flags);
        hnd->pixel_stride = drv_bo_get_stride_in_pixels(bo);
        hnd->magic = cros_gralloc_magic;
        hnd->droid_format = descriptor->droid_format;
@@ -181,11 +182,12 @@ int32_t cros_gralloc_driver::retain(buffer_handle_t handle)
                data.format = hnd->format;
                data.width = hnd->width;
                data.height = hnd->height;
+               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));
                memcpy(data.offsets, hnd->offsets, sizeof(data.offsets));
-               memcpy(data.sizes, hnd->sizes, sizeof(data.sizes));
                for (uint32_t plane = 0; plane < DRV_MAX_PLANES; plane++) {
                        data.format_modifiers[plane] =
                            static_cast<uint64_t>(hnd->format_modifiers[2 * plane]) << 32;
@@ -233,11 +235,14 @@ 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])
 {
-       std::lock_guard<std::mutex> lock(mutex_);
+       int32_t ret = cros_gralloc_sync_wait(acquire_fence);
+       if (ret)
+               return ret;
 
+       std::lock_guard<std::mutex> lock(mutex_);
        auto hnd = cros_gralloc_convert_handle(handle);
        if (!hnd) {
                cros_gralloc_error("Invalid handle.");
@@ -250,15 +255,10 @@ int32_t cros_gralloc_driver::lock(buffer_handle_t handle, int32_t acquire_fence,
                return -EINVAL;
        }
 
-       if (acquire_fence >= 0) {
-               cros_gralloc_error("Sync wait not yet supported.");
-               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 cros_gralloc_driver::unlock(buffer_handle_t handle, int32_t *release_fence)
 {
        std::lock_guard<std::mutex> lock(mutex_);
 
@@ -274,6 +274,13 @@ int32_t cros_gralloc_driver::unlock(buffer_handle_t handle)
                return -EINVAL;
        }
 
+       /*
+        * From the ANativeWindow::dequeueBuffer documentation:
+        *
+        * "A value of -1 indicates that the caller may access the buffer immediately without
+        * waiting on a fence."
+        */
+       *release_fence = -1;
        return buffer->unlock();
 }