|
|
|
@ -60,70 +60,79 @@ 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;
|
|
|
|
|
return wlr_drm_format_add(ptr, modifier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < fmt->len; ++i) {
|
|
|
|
|
if (fmt->modifiers[i] == modifier) {
|
|
|
|
|
return true;
|
|
|
|
|
struct wlr_drm_format *fmt = wlr_drm_format_create(format);
|
|
|
|
|
if (!fmt) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!wlr_drm_format_add(&fmt, modifier)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fmt->len == fmt->cap) {
|
|
|
|
|
size_t cap = fmt->cap ? fmt->cap * 2 : 4;
|
|
|
|
|
if (set->len == set->cap) {
|
|
|
|
|
size_t new = set->cap ? set->cap * 2 : 4;
|
|
|
|
|
|
|
|
|
|
fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
|
|
|
|
if (!fmt) {
|
|
|
|
|
struct wlr_drm_format **tmp = realloc(set->formats,
|
|
|
|
|
sizeof(*fmt) + sizeof(fmt->modifiers[0]) * new);
|
|
|
|
|
if (!tmp) {
|
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
|
free(fmt);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt->cap = cap;
|
|
|
|
|
*ptr = fmt;
|
|
|
|
|
set->cap = new;
|
|
|
|
|
set->formats = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt->modifiers[fmt->len++] = modifier;
|
|
|
|
|
set->formats[set->len++] = fmt;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t cap = modifier != DRM_FORMAT_MOD_INVALID ? 4 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 false;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt->format = format;
|
|
|
|
|
if (cap) {
|
|
|
|
|
fmt->cap = cap;
|
|
|
|
|
fmt->len = 1;
|
|
|
|
|
fmt->modifiers[0] = modifier;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (set->len == set->cap) {
|
|
|
|
|
size_t new = set->cap ? set->cap * 2 : 4;
|
|
|
|
|
for (size_t i = 0; i < fmt->len; ++i) {
|
|
|
|
|
if (fmt->modifiers[i] == modifier) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_format **tmp = realloc(set->formats,
|
|
|
|
|
sizeof(*fmt) + sizeof(fmt->modifiers[0]) * new);
|
|
|
|
|
if (!tmp) {
|
|
|
|
|
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");
|
|
|
|
|
free(fmt);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set->cap = new;
|
|
|
|
|
set->formats = tmp;
|
|
|
|
|
fmt->cap = cap;
|
|
|
|
|
*fmt_ptr = fmt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set->formats[set->len++] = fmt;
|
|
|
|
|
fmt->modifiers[fmt->len++] = modifier;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|