mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-10-29 23:20:57 +00:00
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.
This commit is contained in:
parent
3a91dc1b48
commit
71fb55f3bf
@ -27,9 +27,6 @@ struct wlr_pixel_format_info {
|
||||
uint32_t bytes_per_block;
|
||||
/* Size of a block in pixels (zero for 1×1) */
|
||||
uint32_t block_width, block_height;
|
||||
|
||||
/* True if the format has an alpha channel */
|
||||
bool has_alpha;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -61,4 +58,9 @@ uint32_t convert_wl_shm_format_to_drm(enum wl_shm_format fmt);
|
||||
*/
|
||||
enum wl_shm_format convert_drm_format_to_wl_shm(uint32_t fmt);
|
||||
|
||||
/**
|
||||
* Return true if the DRM FourCC fmt has an alpha channel, false otherwise.
|
||||
*/
|
||||
bool pixel_format_has_alpha(uint32_t fmt);
|
||||
|
||||
#endif
|
||||
|
@ -381,13 +381,10 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const struct wlr_pixel_format_info *drm_fmt =
|
||||
drm_get_pixel_format_info(attribs->format);
|
||||
|
||||
texture->target = buffer->external_only ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
|
||||
texture->buffer = buffer;
|
||||
texture->drm_format = DRM_FORMAT_INVALID; // texture can't be written anyways
|
||||
texture->has_alpha = drm_fmt ? drm_fmt->has_alpha : true;
|
||||
texture->has_alpha = pixel_format_has_alpha(attribs->format);
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -382,7 +382,7 @@ static void texture_set_format(struct wlr_vk_texture *texture,
|
||||
const struct wlr_pixel_format_info *format_info =
|
||||
drm_get_pixel_format_info(format->drm);
|
||||
if (format_info != NULL) {
|
||||
texture->has_alpha = format_info->has_alpha;
|
||||
texture->has_alpha = pixel_format_has_alpha(format->drm);
|
||||
} else {
|
||||
// We don't have format info for multi-planar formats
|
||||
assert(texture->format->is_ycbcr);
|
||||
|
@ -116,11 +116,5 @@ bool buffer_is_opaque(struct wlr_buffer *buffer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const struct wlr_pixel_format_info *format_info =
|
||||
drm_get_pixel_format_info(format);
|
||||
if (format_info == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !format_info->has_alpha;
|
||||
return !pixel_format_has_alpha(format);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user