minigbm: Add drv_bo_get_pixel_stride function

Some drivers may copy/convert the buffer during mapping and
in some cases stride of copied image can be different from
original. Android uses pixel_stride for CPU access and need
map_time stride instead of original stride in this cases.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
This commit is contained in:
Roman Stratiienko 2022-09-08 18:41:09 +03:00 committed by Brendan Szymanski
parent 4e28ceda1c
commit 446588514a
4 changed files with 21 additions and 3 deletions

View file

@ -286,7 +286,6 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
size_t num_fds;
size_t num_ints;
uint32_t resolved_format;
uint32_t bytes_per_pixel;
uint64_t resolved_use_flags;
struct bo *bo;
struct cros_gralloc_handle *hnd;
@ -352,8 +351,7 @@ int32_t cros_gralloc_driver::allocate(const struct cros_gralloc_buffer_descripto
hnd->tiling = drv_bo_get_tiling(bo);
hnd->format_modifier = drv_bo_get_format_modifier(bo);
hnd->use_flags = drv_bo_get_use_flags(bo);
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->pixel_stride = drv_bo_get_pixel_stride(bo);
hnd->magic = cros_gralloc_magic;
hnd->droid_format = descriptor->droid_format;
hnd->usage = descriptor->droid_usage;

17
drv.c
View file

@ -768,6 +768,23 @@ void drv_bo_log_info(const struct bo *bo, const char *prefix)
}
}
uint32_t drv_bo_get_pixel_stride(struct bo *bo)
{
struct driver *drv = bo->drv;
uint32_t bytes_per_pixel = 0;
uint32_t map_stride = 0;
bytes_per_pixel = drv_bytes_per_pixel_from_format(bo->meta.format, 0);
if ((bo->meta.use_flags & BO_USE_SW_MASK) && drv->backend->bo_get_map_stride)
map_stride = drv->backend->bo_get_map_stride(bo);
if (!map_stride)
map_stride = bo->meta.strides[0];
return DIV_ROUND_UP(map_stride, bytes_per_pixel);
}
/*
* Map internal fourcc codes back to standard fourcc codes.
*/

2
drv.h
View file

@ -220,6 +220,8 @@ size_t drv_bo_get_total_size(struct bo *bo);
void drv_bo_log_info(const struct bo *bo, const char *prefix);
uint32_t drv_bo_get_pixel_stride(struct bo *bo);
uint32_t drv_get_standard_fourcc(uint32_t fourcc_internal);
uint32_t drv_bytes_per_pixel_from_format(uint32_t format, size_t plane);

View file

@ -98,6 +98,7 @@ struct backend {
int (*bo_invalidate)(struct bo *bo, struct mapping *mapping);
int (*bo_flush)(struct bo *bo, struct mapping *mapping);
int (*bo_get_plane_fd)(struct bo *bo, size_t plane);
uint32_t (*bo_get_map_stride)(struct bo *bo);
void (*resolve_format_and_use_flags)(struct driver *drv, uint32_t format,
uint64_t use_flags, uint32_t *out_format,
uint64_t *out_use_flags);