Skip to content

Commit

Permalink
minigbm: Add drv_bo_get_pixel_stride function
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
rsglobal committed Sep 14, 2022
1 parent 0c35bd9 commit a9d8ec3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 1 addition & 3 deletions cros_gralloc/cros_gralloc_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,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;
Expand Down Expand Up @@ -310,8 +309,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;
Expand Down
17 changes: 17 additions & 0 deletions drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,23 @@ size_t drv_bo_get_total_size(struct bo *bo)
return bo->meta.total_size;
}

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.
*/
Expand Down
2 changes: 2 additions & 0 deletions drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ uint64_t drv_bo_get_use_flags(struct bo *bo);

size_t drv_bo_get_total_size(struct bo *bo);

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);
Expand Down
1 change: 1 addition & 0 deletions drv_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,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);
Expand Down

0 comments on commit a9d8ec3

Please sign in to comment.