From 70d3635985464052b7081420ff93dbb7a715d44f Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 7 Nov 2024 15:40:43 +0100 Subject: [PATCH] drm_format_set: Add wlr_drm_format_set_remove wlr_drm_format_set_remove lets you remove a modifier from the specified format, useful for filtering implicit modifiers. --- include/wlr/render/drm_format_set.h | 3 +++ render/drm_format_set.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/wlr/render/drm_format_set.h b/include/wlr/render/drm_format_set.h index cc38bbd23..16dcfe9fd 100644 --- a/include/wlr/render/drm_format_set.h +++ b/include/wlr/render/drm_format_set.h @@ -69,6 +69,9 @@ void wlr_drm_format_set_finish(struct wlr_drm_format_set *set); const struct wlr_drm_format *wlr_drm_format_set_get( const struct wlr_drm_format_set *set, uint32_t format); +bool wlr_drm_format_set_remove(struct wlr_drm_format_set *set, uint32_t format, + uint64_t modifier); + bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set, uint32_t format, uint64_t modifier); diff --git a/render/drm_format_set.c b/render/drm_format_set.c index dc57ad9bc..9749a0093 100644 --- a/render/drm_format_set.c +++ b/render/drm_format_set.c @@ -86,6 +86,23 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format, return true; } +bool wlr_drm_format_set_remove(struct wlr_drm_format_set *set, uint32_t format, + uint64_t modifier) { + struct wlr_drm_format *fmt = format_set_get(set, format); + if (fmt == NULL) { + return false; + } + + for (size_t idx = 0; idx < fmt->len; idx++) { + if (fmt->modifiers[idx] == modifier) { + memmove(&fmt->modifiers[idx], &fmt->modifiers[idx+1], fmt->len - idx - 1); + fmt->len--; + return true; + } + } + return false; +} + void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format) { *fmt = (struct wlr_drm_format){ .format = format,