From 5568053e9648be16e3da0bb9fbb01c4bf635c739 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sat, 28 Feb 2026 13:07:26 -0800 Subject: [PATCH] [digesting_libdecor] simplifying shared memory buffer --- digesting_libdecor.c | 55 ++++++++++++++------------------------------ digesting_libdecor.h | 4 ---- 2 files changed, 17 insertions(+), 42 deletions(-) diff --git a/digesting_libdecor.c b/digesting_libdecor.c index c8e214c..84b5a49 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -1834,12 +1834,7 @@ toggle_maximized(void){ static void buffer_release(void *user_data, struct wl_buffer *wl_buffer){ struct buffer *buffer = user_data; - if (buffer->is_detached){ - buffer_free(buffer); - } - else{ - buffer->in_use = false; - } + buffer->in_use = false; } const struct wl_buffer_listener buffer_listener = { @@ -1848,13 +1843,11 @@ const struct wl_buffer_listener buffer_listener = { static void buffer_free(struct buffer *buffer){ - if (buffer->wl_buffer) { + if (buffer->wl_buffer != 0){ wl_buffer_destroy(buffer->wl_buffer); munmap(buffer->data, buffer->data_size); - buffer->wl_buffer = NULL; - buffer->in_use = false; } - free(buffer); + memset(buffer, 0, sizeof *buffer); } static void @@ -2152,7 +2145,6 @@ set_component_input_region(enum component_slot slot){ static void draw_border_component(enum component_slot slot){ - struct buffer *old_buffer; struct buffer *buffer = 0; if (slot < COMPONENT_SLOT_COUNT && @@ -2160,11 +2152,11 @@ draw_border_component(enum component_slot slot){ Extent2D extent = extent2d_from_component_slot(slot); set_component_input_region(slot); - old_buffer = ctx.component_slot[slot].buffer; + struct buffer *old_buffer = ctx.component_slot[slot].buffer; if (old_buffer != 0){ if (!old_buffer->in_use && - old_buffer->buffer_width == extent.w && - old_buffer->buffer_height == extent.h){ + old_buffer->width == extent.w && + old_buffer->height == extent.h){ buffer = old_buffer; } else{ @@ -2176,30 +2168,20 @@ draw_border_component(enum component_slot slot){ if (buffer == 0){ int width = extent.w; int height = extent.h; - bool opaque = ctx.component_slot[slot].opaque; + int stride = 4*width; + int size = stride*height; - struct wl_shm_pool *pool; - int fd, size, buffer_width, buffer_height, stride; - void *data; - enum wl_shm_format buf_fmt; - - buffer_width = width; - buffer_height = height; - stride = buffer_width * 4; - size = stride * buffer_height; - - fd = libdecor_os_create_anonymous_file(size); + int fd = libdecor_os_create_anonymous_file(size); if (fd >= 0){ - data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (data != MAP_FAILED){ - buf_fmt = opaque ? WL_SHM_FORMAT_XRGB8888 : WL_SHM_FORMAT_ARGB8888; + enum wl_shm_format buf_fmt = (ctx.component_slot[slot].opaque ? + WL_SHM_FORMAT_XRGB8888 : + WL_SHM_FORMAT_ARGB8888); - pool = wl_shm_create_pool(ctx.wl_shm, fd, size); + struct wl_shm_pool *pool = wl_shm_create_pool(ctx.wl_shm, fd, size); buffer = calloc(1, sizeof *buffer); - buffer->wl_buffer = wl_shm_pool_create_buffer(pool, 0, - buffer_width, buffer_height, - stride, - buf_fmt); + buffer->wl_buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride, buf_fmt); wl_buffer_add_listener(buffer->wl_buffer, &buffer_listener, buffer); wl_shm_pool_destroy(pool); @@ -2207,8 +2189,6 @@ draw_border_component(enum component_slot slot){ buffer->data_size = size; buffer->width = width; buffer->height = height; - buffer->buffer_width = buffer_width; - buffer->buffer_height = buffer_height; } close(fd); @@ -2218,9 +2198,8 @@ draw_border_component(enum component_slot slot){ memset(buffer->data, 0, buffer->data_size); { - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, buffer->buffer_width); - cairo_surface_t *surface = cairo_image_surface_create_for_data(buffer->data, CAIRO_FORMAT_ARGB32, - buffer->buffer_width, buffer->buffer_height, stride); + int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, buffer->width); + cairo_surface_t *surface = cairo_image_surface_create_for_data(buffer->data, CAIRO_FORMAT_ARGB32, buffer->width, buffer->height, stride); cairo_t *cr = cairo_create(surface); cairo_surface_set_device_scale(surface, 1, 1); diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 35c7ad5..7fd6687 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -166,14 +166,10 @@ enum component_slot { struct buffer { struct wl_buffer *wl_buffer; bool in_use; - bool is_detached; - void *data; size_t data_size; int width; int height; - int buffer_width; - int buffer_height; }; struct border_component {