aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/render/pixel_format.h8
-rw-r--r--render/gles2/texture.c5
-rw-r--r--render/pixel_format.c51
-rw-r--r--render/vulkan/texture.c2
-rw-r--r--types/buffer/buffer.c8
5 files changed, 46 insertions, 28 deletions
diff --git a/include/render/pixel_format.h b/include/render/pixel_format.h
index a024ff9d..e0b500c7 100644
--- a/include/render/pixel_format.h
+++ b/include/render/pixel_format.h
@@ -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
diff --git a/render/gles2/texture.c b/render/gles2/texture.c
index 1cfd7bab..e4caf6ca 100644
--- a/render/gles2/texture.c
+++ b/render/gles2/texture.c
@@ -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);
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;
+}
diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c
index 61c14626..a3fede04 100644
--- a/render/vulkan/texture.c
+++ b/render/vulkan/texture.c
@@ -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);
diff --git a/types/buffer/buffer.c b/types/buffer/buffer.c
index a8e9c54d..b85518c1 100644
--- a/types/buffer/buffer.c
+++ b/types/buffer/buffer.c
@@ -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);
}