wlr_drm_format: Change wlr_drm_format_dup to copy

This commit is contained in:
Alexander Orzechowski 2023-05-10 16:00:22 -04:00 committed by Simon Ser
parent 099a147439
commit 340700cb70
6 changed files with 31 additions and 24 deletions

View File

@ -6,7 +6,7 @@
void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format); void wlr_drm_format_init(struct wlr_drm_format *fmt, uint32_t format);
bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier); bool wlr_drm_format_has(const struct wlr_drm_format *fmt, uint64_t modifier);
bool wlr_drm_format_add(struct wlr_drm_format *fmt, uint64_t modifier); bool wlr_drm_format_add(struct wlr_drm_format *fmt, uint64_t modifier);
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format); bool wlr_drm_format_copy(struct wlr_drm_format *dst, const struct wlr_drm_format *src);
/** /**
* Intersect modifiers for two DRM formats. * Intersect modifiers for two DRM formats.
* *

View File

@ -19,7 +19,7 @@ struct wlr_swapchain {
struct wlr_allocator *allocator; // NULL if destroyed struct wlr_allocator *allocator; // NULL if destroyed
int width, height; int width, height;
struct wlr_drm_format *format; struct wlr_drm_format format;
struct wlr_swapchain_slot slots[WLR_SWAPCHAIN_CAP]; struct wlr_swapchain_slot slots[WLR_SWAPCHAIN_CAP];

View File

@ -130,26 +130,22 @@ bool wlr_drm_format_add(struct wlr_drm_format *fmt, uint64_t modifier) {
return true; return true;
} }
struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format) { bool wlr_drm_format_copy(struct wlr_drm_format *dst, const struct wlr_drm_format *src) {
assert(format->len <= format->capacity); assert(src->len <= src->capacity);
uint64_t *modifiers = malloc(sizeof(*format->modifiers) * format->capacity); uint64_t *modifiers = malloc(sizeof(*modifiers) * src->len);
if (!modifiers) { if (!modifiers) {
return NULL; return false;
} }
memcpy(modifiers, format->modifiers, sizeof(*format->modifiers) * format->len); memcpy(modifiers, src->modifiers, sizeof(*modifiers) * src->len);
struct wlr_drm_format *dst = calloc(1, sizeof(*dst)); wlr_drm_format_finish(dst);
if (!dst) { dst->capacity = src->len;
return NULL; dst->len = src->len;
} dst->format = src->format;
dst->capacity = format->capacity;
dst->len = format->len;
dst->modifiers = modifiers; dst->modifiers = modifiers;
return true;
return dst;
} }
bool wlr_drm_format_set_copy(struct wlr_drm_format_set *dst, const struct wlr_drm_format_set *src) { bool wlr_drm_format_set_copy(struct wlr_drm_format_set *dst, const struct wlr_drm_format_set *src) {
@ -166,7 +162,15 @@ bool wlr_drm_format_set_copy(struct wlr_drm_format_set *dst, const struct wlr_dr
size_t i; size_t i;
for (i = 0; i < src->len; i++) { for (i = 0; i < src->len; i++) {
out.formats[out.len] = wlr_drm_format_dup(src->formats[i]); struct wlr_drm_format *fmt = calloc(1, sizeof(*fmt));
if (!fmt) {
wlr_drm_format_set_finish(&out);
return false;
}
wlr_drm_format_copy(fmt, src->formats[i]);
out.formats[out.len] = fmt;
if (out.formats[out.len] == NULL) { if (out.formats[out.len] == NULL) {
wlr_drm_format_set_finish(&out); wlr_drm_format_set_finish(&out);
return false; return false;

View File

@ -26,8 +26,7 @@ struct wlr_swapchain *wlr_swapchain_create(
swapchain->width = width; swapchain->width = width;
swapchain->height = height; swapchain->height = height;
swapchain->format = wlr_drm_format_dup(format); if (!wlr_drm_format_copy(&swapchain->format, format)) {
if (swapchain->format == NULL) {
free(swapchain); free(swapchain);
return NULL; return NULL;
} }
@ -54,8 +53,7 @@ void wlr_swapchain_destroy(struct wlr_swapchain *swapchain) {
slot_reset(&swapchain->slots[i]); slot_reset(&swapchain->slots[i]);
} }
wl_list_remove(&swapchain->allocator_destroy.link); wl_list_remove(&swapchain->allocator_destroy.link);
wlr_drm_format_finish(swapchain->format); wlr_drm_format_finish(&swapchain->format);
free(swapchain->format);
free(swapchain); free(swapchain);
} }
@ -107,7 +105,7 @@ struct wlr_buffer *wlr_swapchain_acquire(struct wlr_swapchain *swapchain,
wlr_log(WLR_DEBUG, "Allocating new swapchain buffer"); wlr_log(WLR_DEBUG, "Allocating new swapchain buffer");
free_slot->buffer = wlr_allocator_create_buffer(swapchain->allocator, free_slot->buffer = wlr_allocator_create_buffer(swapchain->allocator,
swapchain->width, swapchain->height, swapchain->format); swapchain->width, swapchain->height, &swapchain->format);
if (free_slot->buffer == NULL) { if (free_slot->buffer == NULL) {
wlr_log(WLR_ERROR, "Failed to allocate buffer"); wlr_log(WLR_ERROR, "Failed to allocate buffer");
return NULL; return NULL;

View File

@ -210,8 +210,13 @@ struct wlr_drm_format *output_pick_format(struct wlr_output *output,
} }
format = wlr_drm_format_intersect(display_format, render_format); format = wlr_drm_format_intersect(display_format, render_format);
} else { } else {
format = calloc(1, sizeof(*format));
if (!format) {
return false;
}
// The output can display any format // The output can display any format
format = wlr_drm_format_dup(render_format); wlr_drm_format_copy(format, render_format);
} }
if (format == NULL) { if (format == NULL) {

View File

@ -76,7 +76,7 @@ bool wlr_output_configure_primary_swapchain(struct wlr_output *output,
struct wlr_swapchain *old_swapchain = *swapchain_ptr; struct wlr_swapchain *old_swapchain = *swapchain_ptr;
if (old_swapchain != NULL && if (old_swapchain != NULL &&
old_swapchain->width == width && old_swapchain->height == height && old_swapchain->width == width && old_swapchain->height == height &&
old_swapchain->format->format == output->render_format) { old_swapchain->format.format == output->render_format) {
return true; return true;
} }