From d78cb808b1b051eae443e368c0b88bc90258fd02 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 31 Mar 2021 16:50:17 +0200 Subject: [PATCH] render/drm_format_set: add wlr_drm_format_has --- include/render/drm_format_set.h | 1 + render/drm_format_set.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/render/drm_format_set.h b/include/render/drm_format_set.h index c438722b..c94c2af2 100644 --- a/include/render/drm_format_set.h +++ b/include/render/drm_format_set.h @@ -4,6 +4,7 @@ #include struct wlr_drm_format *wlr_drm_format_create(uint32_t format); +bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier); bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier); struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format); /** diff --git a/render/drm_format_set.c b/render/drm_format_set.c index 3edc1925..ef2929b7 100644 --- a/render/drm_format_set.c +++ b/render/drm_format_set.c @@ -48,13 +48,7 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set, return true; } - for (size_t i = 0; i < fmt->len; ++i) { - if (fmt->modifiers[i] == modifier) { - return true; - } - } - - return false; + return wlr_drm_format_has(fmt, modifier); } bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format, @@ -106,6 +100,15 @@ struct wlr_drm_format *wlr_drm_format_create(uint32_t format) { return fmt; } +bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier) { + for (size_t i = 0; i < fmt->len; ++i) { + if (fmt->modifiers[i] == modifier) { + return true; + } + } + return false; +} + bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) { struct wlr_drm_format *fmt = *fmt_ptr; @@ -113,10 +116,8 @@ bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) { return true; } - for (size_t i = 0; i < fmt->len; ++i) { - if (fmt->modifiers[i] == modifier) { - return true; - } + if (wlr_drm_format_has(fmt, modifier)) { + return true; } if (fmt->len == fmt->capacity) {