summaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorManuel Stoeckl <code@mstoeckl.com>2023-03-12 16:48:58 -0400
committerSimon Ser <contact@emersion.fr>2023-03-22 10:56:42 +0100
commit1d3e62c67f07a180fca02a6df1cf9648f2b50349 (patch)
tree598dd26d5a62ade9ee705073cad83c8d71b7617f /render.c
parentac3b49b6571ceda3f8db11a98bfe320106996280 (diff)
Stop pooling background surface buffers
The wl_buffers for the background surface only need to be updated when the output dimensions change. Using the fixed pool of two buffers to cache these buffers does not help, since if a new buffer is needed, it will have a different size than whatever buffers were cached. Furthermore, because the pool has fixed size, it is possible to run out of buffers if configure events arrive faster than pool buffers are marked not busy, which can lead to protocol errors when the background surface is committed after acknowledging a new size, but without attaching a buffer that matches that size.
Diffstat (limited to 'render.c')
-rw-r--r--render.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/render.c b/render.c
index 3ce7a80..b7febc1 100644
--- a/render.c
+++ b/render.c
@@ -4,6 +4,7 @@
#include "cairo.h"
#include "background-image.h"
#include "swaylock.h"
+#include "log.h"
#define M_PI 3.14159265358979323846
const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
@@ -41,30 +42,40 @@ void render_frame_background(struct swaylock_surface *surface) {
return; // not yet configured
}
- struct pool_buffer *buffer = get_next_buffer(state->shm,
- surface->buffers, buffer_width, buffer_height);
- if (buffer == NULL) {
- return;
- }
+ if (buffer_width != surface->last_buffer_width ||
+ buffer_height != surface->last_buffer_height) {
+ struct pool_buffer buffer;
+ if (!create_buffer(state->shm, &buffer, buffer_width, buffer_height,
+ WL_SHM_FORMAT_ARGB8888)) {
+ swaylock_log(LOG_ERROR,
+ "Failed to create new buffer for frame background.");
+ return;
+ }
- cairo_t *cairo = buffer->cairo;
- cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
+ cairo_t *cairo = buffer.cairo;
+ cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST);
+
+ cairo_save(cairo);
+ cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_u32(cairo, state->args.colors.background);
+ cairo_paint(cairo);
+ if (surface->image && state->args.mode != BACKGROUND_MODE_SOLID_COLOR) {
+ cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
+ render_background_image(cairo, surface->image,
+ state->args.mode, buffer_width, buffer_height);
+ }
+ cairo_restore(cairo);
+ cairo_identity_matrix(cairo);
- cairo_save(cairo);
- cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_u32(cairo, state->args.colors.background);
- cairo_paint(cairo);
- if (surface->image && state->args.mode != BACKGROUND_MODE_SOLID_COLOR) {
- cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
- render_background_image(cairo, surface->image,
- state->args.mode, buffer_width, buffer_height);
+ wl_surface_attach(surface->surface, buffer.buffer, 0, 0);
+ wl_surface_damage_buffer(surface->surface, 0, 0, INT32_MAX, INT32_MAX);
+ destroy_buffer(&buffer);
+
+ surface->last_buffer_width = buffer_width;
+ surface->last_buffer_height = buffer_height;
}
- cairo_restore(cairo);
- cairo_identity_matrix(cairo);
wl_surface_set_buffer_scale(surface->surface, surface->scale);
- wl_surface_attach(surface->surface, buffer->buffer, 0, 0);
- wl_surface_damage_buffer(surface->surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(surface->surface);
}