diff options
author | Geert Uytterhoeven <geert@linux-m68k.org> | 2022-07-08 20:20:46 +0200 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2022-07-09 14:59:22 +0200 |
commit | 96dc635d5538055cb6ccd7b6e9290dfcfc385f97 (patch) | |
tree | 3999cbd2b819bbed8bccd2bb5c5e5c024962ea10 /drivers/gpu/drm/drm_fourcc.c | |
parent | 79abca2b399009eb8d12c652d0f0f7a9c7a06289 (diff) |
drm/fourcc: Add drm_format_info_bpp() helper
Add a helper to retrieve the actual number of bits per pixel for a
plane, taking into account the number of characters and pixels per
block for tiled formats.
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/1cae5ebc28513ec1c91c66b00647ce3ca23bfba7.1657294931.git.geert@linux-m68k.org
Diffstat (limited to 'drivers/gpu/drm/drm_fourcc.c')
-rw-r--r-- | drivers/gpu/drm/drm_fourcc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 07741b678798..cf48ea0b2cb7 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -371,6 +371,25 @@ unsigned int drm_format_info_block_height(const struct drm_format_info *info, EXPORT_SYMBOL(drm_format_info_block_height); /** + * drm_format_info_bpp - number of bits per pixel + * @info: pixel format info + * @plane: plane index + * + * Returns: + * The actual number of bits per pixel, depending on the plane index. + */ +unsigned int drm_format_info_bpp(const struct drm_format_info *info, int plane) +{ + if (!info || plane < 0 || plane >= info->num_planes) + return 0; + + return info->char_per_block[plane] * 8 / + (drm_format_info_block_width(info, plane) * + drm_format_info_block_height(info, plane)); +} +EXPORT_SYMBOL(drm_format_info_bpp); + +/** * drm_format_info_min_pitch - computes the minimum required pitch in bytes * @info: pixel format info * @plane: plane index |