diff --git a/cros_gralloc/cros_gralloc_buffer.cc b/cros_gralloc/cros_gralloc_buffer.cc index 783180f..2f4ceb0 100644 --- a/cros_gralloc/cros_gralloc_buffer.cc +++ b/cros_gralloc/cros_gralloc_buffer.cc @@ -116,9 +116,10 @@ int32_t cros_gralloc_buffer::unlock() } int32_t cros_gralloc_buffer::resource_info(uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]) + uint32_t offsets[DRV_MAX_PLANES], + uint64_t *format_modifier) { - return drv_resource_info(bo_, strides, offsets); + return drv_resource_info(bo_, strides, offsets, format_modifier); } int32_t cros_gralloc_buffer::invalidate() diff --git a/cros_gralloc/cros_gralloc_buffer.h b/cros_gralloc/cros_gralloc_buffer.h index cb6cb4b..9bc0ef0 100644 --- a/cros_gralloc/cros_gralloc_buffer.h +++ b/cros_gralloc/cros_gralloc_buffer.h @@ -27,7 +27,8 @@ class cros_gralloc_buffer int32_t lock(const struct rectangle *rect, uint32_t map_flags, uint8_t *addr[DRV_MAX_PLANES]); int32_t unlock(); - int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES]); + int32_t resource_info(uint32_t strides[DRV_MAX_PLANES], uint32_t offsets[DRV_MAX_PLANES], + uint64_t *format_modifier); int32_t invalidate(); int32_t flush(); diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 107f153..f0c0392 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -465,7 +465,8 @@ int32_t cros_gralloc_driver::get_backing_store(buffer_handle_t handle, uint64_t } int32_t cros_gralloc_driver::resource_info(buffer_handle_t handle, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]) + uint32_t offsets[DRV_MAX_PLANES], + uint64_t *format_modifier) { std::lock_guard lock(mutex_); @@ -481,7 +482,7 @@ int32_t cros_gralloc_driver::resource_info(buffer_handle_t handle, uint32_t stri return -EINVAL; } - return buffer->resource_info(strides, offsets); + return buffer->resource_info(strides, offsets, format_modifier); } int32_t cros_gralloc_driver::get_reserved_region(buffer_handle_t handle, diff --git a/cros_gralloc/cros_gralloc_driver.h b/cros_gralloc/cros_gralloc_driver.h index 37692ac..ef9e21f 100644 --- a/cros_gralloc/cros_gralloc_driver.h +++ b/cros_gralloc/cros_gralloc_driver.h @@ -37,7 +37,7 @@ class cros_gralloc_driver int32_t get_backing_store(buffer_handle_t handle, uint64_t *out_store); int32_t resource_info(buffer_handle_t handle, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]); + uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); int32_t get_reserved_region(buffer_handle_t handle, void **reserved_region_addr, uint64_t *reserved_region_size); diff --git a/cros_gralloc/gralloc0/gralloc0.cc b/cros_gralloc/gralloc0/gralloc0.cc index 72df260..e8b5f7c 100644 --- a/cros_gralloc/gralloc0/gralloc0.cc +++ b/cros_gralloc/gralloc0/gralloc0.cc @@ -279,6 +279,7 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...) uint32_t *out_width, *out_height, *out_stride; uint32_t strides[DRV_MAX_PLANES] = { 0, 0, 0, 0 }; uint32_t offsets[DRV_MAX_PLANES] = { 0, 0, 0, 0 }; + uint64_t format_modifier = 0; struct cros_gralloc0_buffer_info *info; auto mod = (struct gralloc0_module const *)module; @@ -306,7 +307,7 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...) switch (op) { case GRALLOC_DRM_GET_STRIDE: out_stride = va_arg(args, uint32_t *); - ret = mod->driver->resource_info(handle, strides, offsets); + ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier); if (ret) break; @@ -336,11 +337,20 @@ static int gralloc0_perform(struct gralloc_module_t const *module, int op, ...) info = va_arg(args, struct cros_gralloc0_buffer_info *); info->drm_fourcc = drv_get_standard_fourcc(hnd->format); info->num_fds = hnd->num_planes; - info->modifier = hnd->format_modifier; + ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier); + if (ret) + break; + + info->modifier = format_modifier ? format_modifier : hnd->format_modifier; for (uint32_t i = 0; i < hnd->num_planes; i++) { info->fds[i] = hnd->fds[i]; - info->offset[i] = hnd->offsets[i]; - info->stride[i] = hnd->strides[i]; + if (strides[i]) { + info->stride[i] = strides[i]; + info->offset[i] = offsets[i]; + } else { + info->stride[i] = hnd->strides[i]; + info->offset[i] = hnd->offsets[i]; + } } break; default: @@ -407,6 +417,7 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff uint32_t map_flags; uint32_t strides[DRV_MAX_PLANES] = { 0, 0, 0, 0 }; uint32_t offsets[DRV_MAX_PLANES] = { 0, 0, 0, 0 }; + uint64_t format_modifier = 0; uint8_t *addr[DRV_MAX_PLANES] = { nullptr, nullptr, nullptr, nullptr }; auto mod = (struct gralloc0_module const *)module; struct rectangle rect = { .x = static_cast(l), @@ -437,7 +448,7 @@ static int gralloc0_lock_async_ycbcr(struct gralloc_module_t const *module, buff return ret; if (!map_flags) { - ret = mod->driver->resource_info(handle, strides, offsets); + ret = mod->driver->resource_info(handle, strides, offsets, &format_modifier); if (ret) return ret; diff --git a/drv.c b/drv.c index 2f8d547..9b43e9f 100644 --- a/drv.c +++ b/drv.c @@ -683,15 +683,16 @@ void drv_log_prefix(const char *prefix, const char *file, int line, const char * } int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]) + uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier) { for (uint32_t plane = 0; plane < bo->meta.num_planes; plane++) { strides[plane] = bo->meta.strides[plane]; offsets[plane] = bo->meta.offsets[plane]; } + *format_modifier = bo->meta.format_modifier; if (bo->drv->backend->resource_info) - return bo->drv->backend->resource_info(bo, strides, offsets); + return bo->drv->backend->resource_info(bo, strides, offsets, format_modifier); return 0; } diff --git a/drv.h b/drv.h index 656e883..4689558 100644 --- a/drv.h +++ b/drv.h @@ -184,7 +184,7 @@ size_t drv_num_planes_from_modifier(struct driver *drv, uint32_t format, uint64_ uint32_t drv_num_buffers_per_bo(struct bo *bo); int drv_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]); + uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); #define drv_log(format, ...) \ do { \ diff --git a/drv_priv.h b/drv_priv.h index 7327a3c..c720077 100644 --- a/drv_priv.h +++ b/drv_priv.h @@ -93,7 +93,7 @@ struct backend { uint32_t (*resolve_format)(struct driver *drv, uint32_t format, uint64_t use_flags); size_t (*num_planes_from_modifier)(struct driver *drv, uint32_t format, uint64_t modifier); int (*resource_info)(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]); + uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier); }; // clang-format off diff --git a/virtgpu_virgl.c b/virtgpu_virgl.c index 2fb1603..cbfb812 100644 --- a/virtgpu_virgl.c +++ b/virtgpu_virgl.c @@ -952,7 +952,7 @@ static uint32_t virgl_resolve_format(struct driver *drv, uint32_t format, uint64 } } static int virgl_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], - uint32_t offsets[DRV_MAX_PLANES]) + uint32_t offsets[DRV_MAX_PLANES], uint64_t *format_modifier) { int ret; struct drm_virtgpu_resource_info_cros res_info = { 0 }; @@ -978,6 +978,7 @@ static int virgl_resource_info(struct bo *bo, uint32_t strides[DRV_MAX_PLANES], offsets[plane] = res_info.offsets[plane]; } } + *format_modifier = res_info.format_modifier; return 0; }