summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorManuel Stoeckl <code@mstoeckl.com>2021-05-15 12:44:31 -0400
committerSimon Ser <contact@emersion.fr>2021-07-19 11:41:24 +0200
commit69827e97dbdee569f0e0987cf6e24acb48217301 (patch)
tree735b9e1c727a960b91d4d2de47179088ca495dbf /main.c
parentb9bf8d4b28ab174be722eb617eb18c0b63721c66 (diff)
downloadswaybg-69827e97dbdee569f0e0987cf6e24acb48217301.tar.gz
swaybg-69827e97dbdee569f0e0987cf6e24acb48217301.tar.bz2
Create/destroy a new shm buffer per frame
Caching these actually increased memory usage after startup; compositors like Sway tend to release the buffer on receipt (since they have already copied the shm buffer to an OpenGL equivalent) so the shm buffer is no longer needed after being used. Outputs (when not in nested mode) are generally only configured/drawn once, so there is no point in caching data for the future.
Diffstat (limited to '')
-rw-r--r--main.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/main.c b/main.c
index e43dbcb..d42c596 100644
--- a/main.c
+++ b/main.c
@@ -72,8 +72,6 @@ struct swaybg_output {
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;
- struct pool_buffer buffers[2];
- struct pool_buffer *current_buffer;
uint32_t width, height;
int32_t scale;
@@ -105,12 +103,13 @@ bool is_valid_color(const char *color) {
static void render_frame(struct swaybg_output *output) {
int buffer_width = output->width * output->scale,
buffer_height = output->height * output->scale;
- output->current_buffer = get_next_buffer(output->state->shm,
- output->buffers, buffer_width, buffer_height);
- if (!output->current_buffer) {
+ struct pool_buffer buffer;
+ if (!create_buffer(&buffer, output->state->shm,
+ buffer_width, buffer_height, WL_SHM_FORMAT_ARGB8888)) {
return;
}
- cairo_t *cairo = output->current_buffer->cairo;
+
+ cairo_t *cairo = buffer.cairo;
cairo_save(cairo);
cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
cairo_paint(cairo);
@@ -130,9 +129,11 @@ static void render_frame(struct swaybg_output *output) {
}
wl_surface_set_buffer_scale(output->surface, output->scale);
- wl_surface_attach(output->surface, output->current_buffer->buffer, 0, 0);
+ wl_surface_attach(output->surface, buffer.buffer, 0, 0);
wl_surface_damage_buffer(output->surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(output->surface);
+ // we will not reuse the buffer, so destroy it immediately
+ destroy_buffer(&buffer);
}
static void destroy_swaybg_image(struct swaybg_image *image) {
@@ -168,8 +169,6 @@ static void destroy_swaybg_output(struct swaybg_output *output) {
}
zxdg_output_v1_destroy(output->xdg_output);
wl_output_destroy(output->wl_output);
- destroy_buffer(&output->buffers[0]);
- destroy_buffer(&output->buffers[1]);
free(output->name);
free(output->identifier);
free(output);