aboutsummaryrefslogtreecommitdiff
path: root/render/drm_format_set.c
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-12-12 22:26:14 +0100
committerIlia Bozhinov <ammen99@gmail.com>2020-12-18 09:41:12 +0100
commitd37214cb1622458b4d2009a98279b67edcda15b5 (patch)
treef0ac957805e40c9e30da36afddda5094b11d8382 /render/drm_format_set.c
parent253f447329550bdb97904fababde83d0d8d6ef3e (diff)
render/drm_format_set: add wlr_drm_format_{create,add}
Diffstat (limited to 'render/drm_format_set.c')
-rw-r--r--render/drm_format_set.c87
1 files changed, 48 insertions, 39 deletions
diff --git a/render/drm_format_set.c b/render/drm_format_set.c
index a4c31494..634d9070 100644
--- a/render/drm_format_set.c
+++ b/render/drm_format_set.c
@@ -60,52 +60,18 @@ bool wlr_drm_format_set_has(const struct wlr_drm_format_set *set,
bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
uint64_t modifier) {
assert(format != DRM_FORMAT_INVALID);
- struct wlr_drm_format **ptr = format_set_get_ref(set, format);
+ struct wlr_drm_format **ptr = format_set_get_ref(set, format);
if (ptr) {
- struct wlr_drm_format *fmt = *ptr;
-
- if (modifier == DRM_FORMAT_MOD_INVALID) {
- return true;
- }
-
- for (size_t i = 0; i < fmt->len; ++i) {
- if (fmt->modifiers[i] == modifier) {
- return true;
- }
- }
-
- if (fmt->len == fmt->cap) {
- size_t cap = fmt->cap ? fmt->cap * 2 : 4;
-
- fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
- if (!fmt) {
- wlr_log_errno(WLR_ERROR, "Allocation failed");
- return false;
- }
-
- fmt->cap = cap;
- *ptr = fmt;
- }
-
- fmt->modifiers[fmt->len++] = modifier;
- return true;
+ return wlr_drm_format_add(ptr, modifier);
}
- size_t cap = modifier != DRM_FORMAT_MOD_INVALID ? 4 : 0;
-
- struct wlr_drm_format *fmt =
- calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
+ struct wlr_drm_format *fmt = wlr_drm_format_create(format);
if (!fmt) {
- wlr_log_errno(WLR_ERROR, "Allocation failed");
return false;
}
-
- fmt->format = format;
- if (cap) {
- fmt->cap = cap;
- fmt->len = 1;
- fmt->modifiers[0] = modifier;
+ if (!wlr_drm_format_add(&fmt, modifier)) {
+ return false;
}
if (set->len == set->cap) {
@@ -127,6 +93,49 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
return true;
}
+struct wlr_drm_format *wlr_drm_format_create(uint32_t format) {
+ size_t cap = 4;
+ struct wlr_drm_format *fmt =
+ calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
+ if (!fmt) {
+ wlr_log_errno(WLR_ERROR, "Allocation failed");
+ return NULL;
+ }
+ fmt->format = format;
+ fmt->cap = cap;
+ return fmt;
+}
+
+bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) {
+ struct wlr_drm_format *fmt = *fmt_ptr;
+
+ if (modifier == DRM_FORMAT_MOD_INVALID) {
+ return true;
+ }
+
+ for (size_t i = 0; i < fmt->len; ++i) {
+ if (fmt->modifiers[i] == modifier) {
+ return true;
+ }
+ }
+
+ if (fmt->len == fmt->cap) {
+ size_t cap = fmt->cap ? fmt->cap * 2 : 4;
+
+ fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
+ if (!fmt) {
+ wlr_log_errno(WLR_ERROR, "Allocation failed");
+ return false;
+ }
+
+ fmt->cap = cap;
+ *fmt_ptr = fmt;
+ }
+
+ fmt->modifiers[fmt->len++] = modifier;
+ return true;
+}
+
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format) {
assert(format->len <= format->cap);
size_t format_size = sizeof(struct wlr_drm_format) +