diff --git a/backend/x11/output.c b/backend/x11/output.c index 0b63a7088..181c2de14 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -20,6 +20,7 @@ #include "backend/x11.h" #include "util/time.h" +#include "types/wlr_buffer.h" #include "types/wlr_output.h" static const uint32_t SUPPORTED_OUTPUT_STATE = @@ -166,15 +167,8 @@ static bool output_test(struct wlr_output *wlr_output, if (state->committed & WLR_OUTPUT_STATE_BUFFER) { struct wlr_buffer *buffer = state->buffer; - struct wlr_dmabuf_attributes dmabuf_attrs; - struct wlr_shm_attributes shm_attrs; - uint32_t format = DRM_FORMAT_INVALID; - if (wlr_buffer_get_dmabuf(buffer, &dmabuf_attrs)) { - format = dmabuf_attrs.format; - } else if (wlr_buffer_get_shm(buffer, &shm_attrs)) { - format = shm_attrs.format; - } - if (format != x11->x11_format->drm) { + + if (buffer_get_drm_format(buffer) != x11->x11_format->drm) { wlr_log(WLR_DEBUG, "Unsupported buffer format"); return false; } diff --git a/include/types/wlr_buffer.h b/include/types/wlr_buffer.h index 9d882d47d..45acf7a1d 100644 --- a/include/types/wlr_buffer.h +++ b/include/types/wlr_buffer.h @@ -65,4 +65,10 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, struct wlr_buffer *next, const pixman_region32_t *damage); +/** + * Return the DRM format of the buffer. If this buffer isn't shared + * memory or a DMA-BUF, returns DRM_FORMAT_INVALID. + */ +uint32_t buffer_get_drm_format(struct wlr_buffer *buffer); + #endif diff --git a/types/buffer/buffer.c b/types/buffer/buffer.c index d56255b0d..48a10d9f0 100644 --- a/types/buffer/buffer.c +++ b/types/buffer/buffer.c @@ -109,14 +109,11 @@ bool wlr_buffer_get_shm(struct wlr_buffer *buffer, bool wlr_buffer_is_opaque(struct wlr_buffer *buffer) { void *data; - uint32_t format; + uint32_t format = buffer_get_drm_format(buffer); size_t stride; - struct wlr_dmabuf_attributes dmabuf; - struct wlr_shm_attributes shm; - if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { - format = dmabuf.format; - } else if (wlr_buffer_get_shm(buffer, &shm)) { - format = shm.format; + + if (format != DRM_FORMAT_INVALID) { + // pass } else if (wlr_buffer_begin_data_ptr_access(buffer, WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) { bool opaque = false; @@ -135,3 +132,15 @@ bool wlr_buffer_is_opaque(struct wlr_buffer *buffer) { return !pixel_format_has_alpha(format); } + +uint32_t buffer_get_drm_format(struct wlr_buffer *buffer) { + uint32_t format = DRM_FORMAT_INVALID; + struct wlr_dmabuf_attributes dmabuf; + struct wlr_shm_attributes shm; + if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { + format = dmabuf.format; + } else if (wlr_buffer_get_shm(buffer, &shm)) { + format = shm.format; + } + return format; +} diff --git a/types/wlr_color_representation_v1.c b/types/wlr_color_representation_v1.c index 432511b91..ab7df30b0 100644 --- a/types/wlr_color_representation_v1.c +++ b/types/wlr_color_representation_v1.c @@ -11,6 +11,7 @@ #include "color-representation-v1-protocol.h" #include "render/pixel_format.h" +#include "types/wlr_buffer.h" #include "util/mem.h" #define WP_COLOR_REPRESENTATION_VERSION 1 @@ -240,14 +241,14 @@ static void surface_synced_commit(struct wlr_surface_synced *synced) { return; } - struct wlr_dmabuf_attributes dmabuf; - - if (!color_repr->surface->buffer || - !wlr_buffer_get_dmabuf(&color_repr->surface->buffer->base, &dmabuf)) { + uint32_t drm_format = DRM_FORMAT_INVALID; + if (!color_repr->surface->buffer){ + drm_format = buffer_get_drm_format(&color_repr->surface->buffer->base); + } + if (drm_format == DRM_FORMAT_INVALID) { return; } - - bool is_ycbcr = pixel_format_is_ycbcr(dmabuf.format); + bool is_ycbcr = pixel_format_is_ycbcr(drm_format); bool is_identity_full = color_repr->current.coefficients == WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_IDENTITY &&