diff options
author | Leo Li <sunpeng.li@amd.com> | 2024-01-31 12:30:16 -0500 |
---|---|---|
committer | Leo Li <sunpeng.li@amd.com> | 2024-01-31 13:47:17 -0500 |
commit | 71fb55f3bf4341d250b580cb2d6a7acf21cfce39 (patch) | |
tree | db4857073939915043ebbe7e319b7c37c75613be /render/pixel_format.c | |
parent | 3a91dc1b483fbcb480c69b4dd2af1073cf69b52f (diff) |
render/pixel-format: Move has_alpha into it's own array
Some opaque pixel formats (nv12, p010) require per-plane bytes_per_block
info. However, it doesn't make sense to store them in
wlr_pixel_format_info, as they will never be useful (currently, this
info is used for shm, which doesn't have a concept of multi-planar
buffers.)
Let's define a separate array and function for determining whether a
pixel format has alpha.
Diffstat (limited to 'render/pixel_format.c')
-rw-r--r-- | render/pixel_format.c | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/render/pixel_format.c b/render/pixel_format.c index b81f561d..7befbf08 100644 --- a/render/pixel_format.c +++ b/render/pixel_format.c @@ -12,7 +12,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ARGB8888, .opaque_substitute = DRM_FORMAT_XRGB8888, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_XBGR8888, @@ -22,7 +21,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ABGR8888, .opaque_substitute = DRM_FORMAT_XBGR8888, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_RGBX8888, @@ -32,7 +30,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_RGBA8888, .opaque_substitute = DRM_FORMAT_RGBX8888, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_BGRX8888, @@ -42,7 +39,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_BGRA8888, .opaque_substitute = DRM_FORMAT_BGRX8888, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_R8, @@ -68,7 +64,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_RGBA4444, .opaque_substitute = DRM_FORMAT_RGBX4444, .bytes_per_block = 2, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_BGRX4444, @@ -78,7 +73,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_BGRA4444, .opaque_substitute = DRM_FORMAT_BGRX4444, .bytes_per_block = 2, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_RGBX5551, @@ -88,7 +82,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_RGBA5551, .opaque_substitute = DRM_FORMAT_RGBX5551, .bytes_per_block = 2, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_BGRX5551, @@ -98,7 +91,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_BGRA5551, .opaque_substitute = DRM_FORMAT_BGRX5551, .bytes_per_block = 2, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_XRGB1555, @@ -108,7 +100,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ARGB1555, .opaque_substitute = DRM_FORMAT_XRGB1555, .bytes_per_block = 2, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_RGB565, @@ -126,7 +117,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ARGB2101010, .opaque_substitute = DRM_FORMAT_XRGB2101010, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_XBGR2101010, @@ -136,7 +126,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ABGR2101010, .opaque_substitute = DRM_FORMAT_XBGR2101010, .bytes_per_block = 4, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_XBGR16161616F, @@ -146,7 +135,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ABGR16161616F, .opaque_substitute = DRM_FORMAT_XBGR16161616F, .bytes_per_block = 8, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_XBGR16161616, @@ -156,7 +144,6 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { .drm_format = DRM_FORMAT_ABGR16161616, .opaque_substitute = DRM_FORMAT_XBGR16161616, .bytes_per_block = 8, - .has_alpha = true, }, { .drm_format = DRM_FORMAT_YVYU, @@ -172,9 +159,38 @@ static const struct wlr_pixel_format_info pixel_format_info[] = { }, }; +static const uint32_t opaque_pixel_formats[] = { + DRM_FORMAT_XRGB8888, + DRM_FORMAT_XBGR8888, + DRM_FORMAT_RGBX8888, + DRM_FORMAT_BGRX8888, + DRM_FORMAT_R8, + DRM_FORMAT_GR88, + DRM_FORMAT_RGB888, + DRM_FORMAT_BGR888, + DRM_FORMAT_RGBX4444, + DRM_FORMAT_BGRX4444, + DRM_FORMAT_RGBX5551, + DRM_FORMAT_BGRX5551, + DRM_FORMAT_XRGB1555, + DRM_FORMAT_RGB565, + DRM_FORMAT_BGR565, + DRM_FORMAT_XRGB2101010, + DRM_FORMAT_XBGR2101010, + DRM_FORMAT_XBGR16161616F, + DRM_FORMAT_XBGR16161616, + DRM_FORMAT_YVYU, + DRM_FORMAT_VYUY, + DRM_FORMAT_NV12, + DRM_FORMAT_P010, +}; + static const size_t pixel_format_info_size = sizeof(pixel_format_info) / sizeof(pixel_format_info[0]); +static const size_t opaque_pixel_formats_size = + sizeof(opaque_pixel_formats) / sizeof(opaque_pixel_formats[0]); + const struct wlr_pixel_format_info *drm_get_pixel_format_info(uint32_t fmt) { for (size_t i = 0; i < pixel_format_info_size; ++i) { if (pixel_format_info[i].drm_format == fmt) { @@ -250,3 +266,12 @@ bool pixel_format_info_check_stride(const struct wlr_pixel_format_info *fmt, return true; } + +bool pixel_format_has_alpha(uint32_t fmt) { + for (size_t i = 0; i < opaque_pixel_formats_size; i++) { + if (fmt == opaque_pixel_formats[i]) { + return false; + } + } + return true; +} |