types/wlr_buffer: add buffer_get_drm_format helper function

This commit is contained in:
Steve Williams 2026-02-05 21:26:29 +04:00 committed by Simon Ser
parent bb78861ca9
commit ef88246642
4 changed files with 32 additions and 22 deletions

View file

@ -20,6 +20,7 @@
#include "backend/x11.h" #include "backend/x11.h"
#include "util/time.h" #include "util/time.h"
#include "types/wlr_buffer.h"
#include "types/wlr_output.h" #include "types/wlr_output.h"
static const uint32_t SUPPORTED_OUTPUT_STATE = 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) { if (state->committed & WLR_OUTPUT_STATE_BUFFER) {
struct wlr_buffer *buffer = state->buffer; struct wlr_buffer *buffer = state->buffer;
struct wlr_dmabuf_attributes dmabuf_attrs;
struct wlr_shm_attributes shm_attrs; if (buffer_get_drm_format(buffer) != x11->x11_format->drm) {
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) {
wlr_log(WLR_DEBUG, "Unsupported buffer format"); wlr_log(WLR_DEBUG, "Unsupported buffer format");
return false; return false;
} }

View file

@ -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, bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
struct wlr_buffer *next, const pixman_region32_t *damage); 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 #endif

View file

@ -109,14 +109,11 @@ bool wlr_buffer_get_shm(struct wlr_buffer *buffer,
bool wlr_buffer_is_opaque(struct wlr_buffer *buffer) { bool wlr_buffer_is_opaque(struct wlr_buffer *buffer) {
void *data; void *data;
uint32_t format; uint32_t format = buffer_get_drm_format(buffer);
size_t stride; size_t stride;
struct wlr_dmabuf_attributes dmabuf;
struct wlr_shm_attributes shm; if (format != DRM_FORMAT_INVALID) {
if (wlr_buffer_get_dmabuf(buffer, &dmabuf)) { // pass
format = dmabuf.format;
} else if (wlr_buffer_get_shm(buffer, &shm)) {
format = shm.format;
} else if (wlr_buffer_begin_data_ptr_access(buffer, } else if (wlr_buffer_begin_data_ptr_access(buffer,
WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) { WLR_BUFFER_DATA_PTR_ACCESS_READ, &data, &format, &stride)) {
bool opaque = false; bool opaque = false;
@ -135,3 +132,15 @@ bool wlr_buffer_is_opaque(struct wlr_buffer *buffer) {
return !pixel_format_has_alpha(format); 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;
}

View file

@ -11,6 +11,7 @@
#include "color-representation-v1-protocol.h" #include "color-representation-v1-protocol.h"
#include "render/pixel_format.h" #include "render/pixel_format.h"
#include "types/wlr_buffer.h"
#include "util/mem.h" #include "util/mem.h"
#define WP_COLOR_REPRESENTATION_VERSION 1 #define WP_COLOR_REPRESENTATION_VERSION 1
@ -240,14 +241,14 @@ static void surface_synced_commit(struct wlr_surface_synced *synced) {
return; return;
} }
struct wlr_dmabuf_attributes dmabuf; uint32_t drm_format = DRM_FORMAT_INVALID;
if (!color_repr->surface->buffer){
if (!color_repr->surface->buffer || drm_format = buffer_get_drm_format(&color_repr->surface->buffer->base);
!wlr_buffer_get_dmabuf(&color_repr->surface->buffer->base, &dmabuf)) { }
if (drm_format == DRM_FORMAT_INVALID) {
return; return;
} }
bool is_ycbcr = pixel_format_is_ycbcr(drm_format);
bool is_ycbcr = pixel_format_is_ycbcr(dmabuf.format);
bool is_identity_full = bool is_identity_full =
color_repr->current.coefficients == WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_IDENTITY && color_repr->current.coefficients == WP_COLOR_REPRESENTATION_SURFACE_V1_COEFFICIENTS_IDENTITY &&