|
|
@ -15,7 +15,7 @@ void wlr_drm_format_set_finish(struct wlr_drm_format_set *set) {
|
|
|
|
free(set->formats);
|
|
|
|
free(set->formats);
|
|
|
|
|
|
|
|
|
|
|
|
set->len = 0;
|
|
|
|
set->len = 0;
|
|
|
|
set->cap = 0;
|
|
|
|
set->capacity = 0;
|
|
|
|
set->formats = NULL;
|
|
|
|
set->formats = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -74,8 +74,8 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (set->len == set->cap) {
|
|
|
|
if (set->len == set->capacity) {
|
|
|
|
size_t new = set->cap ? set->cap * 2 : 4;
|
|
|
|
size_t new = set->capacity ? set->capacity * 2 : 4;
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_format **tmp = realloc(set->formats,
|
|
|
|
struct wlr_drm_format **tmp = realloc(set->formats,
|
|
|
|
sizeof(*fmt) + sizeof(fmt->modifiers[0]) * new);
|
|
|
|
sizeof(*fmt) + sizeof(fmt->modifiers[0]) * new);
|
|
|
@ -85,7 +85,7 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set->cap = new;
|
|
|
|
set->capacity = new;
|
|
|
|
set->formats = tmp;
|
|
|
|
set->formats = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -94,15 +94,15 @@ bool wlr_drm_format_set_add(struct wlr_drm_format_set *set, uint32_t format,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_drm_format *wlr_drm_format_create(uint32_t format) {
|
|
|
|
struct wlr_drm_format *wlr_drm_format_create(uint32_t format) {
|
|
|
|
size_t cap = 4;
|
|
|
|
size_t capacity = 4;
|
|
|
|
struct wlr_drm_format *fmt =
|
|
|
|
struct wlr_drm_format *fmt =
|
|
|
|
calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
|
|
|
calloc(1, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * capacity);
|
|
|
|
if (!fmt) {
|
|
|
|
if (!fmt) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt->format = format;
|
|
|
|
fmt->format = format;
|
|
|
|
fmt->cap = cap;
|
|
|
|
fmt->capacity = capacity;
|
|
|
|
return fmt;
|
|
|
|
return fmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -119,16 +119,16 @@ bool wlr_drm_format_add(struct wlr_drm_format **fmt_ptr, uint64_t modifier) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fmt->len == fmt->cap) {
|
|
|
|
if (fmt->len == fmt->capacity) {
|
|
|
|
size_t cap = fmt->cap ? fmt->cap * 2 : 4;
|
|
|
|
size_t capacity = fmt->capacity ? fmt->capacity * 2 : 4;
|
|
|
|
|
|
|
|
|
|
|
|
fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * cap);
|
|
|
|
fmt = realloc(fmt, sizeof(*fmt) + sizeof(fmt->modifiers[0]) * capacity);
|
|
|
|
if (!fmt) {
|
|
|
|
if (!fmt) {
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
wlr_log_errno(WLR_ERROR, "Allocation failed");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fmt->cap = cap;
|
|
|
|
fmt->capacity = capacity;
|
|
|
|
*fmt_ptr = fmt;
|
|
|
|
*fmt_ptr = fmt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -137,9 +137,9 @@ 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) {
|
|
|
|
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format) {
|
|
|
|
assert(format->len <= format->cap);
|
|
|
|
assert(format->len <= format->capacity);
|
|
|
|
size_t format_size = sizeof(struct wlr_drm_format) +
|
|
|
|
size_t format_size = sizeof(struct wlr_drm_format) +
|
|
|
|
format->cap * sizeof(format->modifiers[0]);
|
|
|
|
format->capacity * sizeof(format->modifiers[0]);
|
|
|
|
struct wlr_drm_format *duped_format = malloc(format_size);
|
|
|
|
struct wlr_drm_format *duped_format = malloc(format_size);
|
|
|
|
if (duped_format == NULL) {
|
|
|
|
if (duped_format == NULL) {
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
@ -171,12 +171,12 @@ struct wlr_drm_format *wlr_drm_format_intersect(
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
format->format = a->format;
|
|
|
|
format->format = a->format;
|
|
|
|
format->cap = format_cap;
|
|
|
|
format->capacity = format_cap;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < a->len; i++) {
|
|
|
|
for (size_t i = 0; i < a->len; i++) {
|
|
|
|
for (size_t j = 0; j < b->len; j++) {
|
|
|
|
for (size_t j = 0; j < b->len; j++) {
|
|
|
|
if (a->modifiers[i] == b->modifiers[j]) {
|
|
|
|
if (a->modifiers[i] == b->modifiers[j]) {
|
|
|
|
assert(format->len < format->cap);
|
|
|
|
assert(format->len < format->capacity);
|
|
|
|
format->modifiers[format->len] = a->modifiers[i];
|
|
|
|
format->modifiers[format->len] = a->modifiers[i];
|
|
|
|
format->len++;
|
|
|
|
format->len++;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|