diff options
| author | Kenny Levinsen <kl@kl.wtf> | 2024-09-07 00:27:37 +0200 |
|---|---|---|
| committer | Alexander Orzechowski <alex@ozal.ski> | 2024-09-06 19:46:24 -0400 |
| commit | cca2436ba535d17c49b7d7ba75ebfa6a18ec9209 (patch) | |
| tree | 8b3f4cfc3ff55e5b8aad29d6629bb6f5664a2506 /main.c | |
| parent | de0731de6a44d99532fcd46c5894cff5f10e65a6 (diff) | |
Improve frame callback and commit handling
The few places that required a surface commit relied on render_frame and
render_frame_background to form it form them after they had set up frame
callback events. This would fail if render_frame ran out of buffers and
exited early, as the caller would still wait indefinitely on the frame
callback.
swaylock would quite consistently run out of buffers when rendering
immediately after a configure event, such as when the keypress causing
render also caused outputs to be enabled from idle.
Restructure the render and commit handling slightly so that the whole
frame callback and commit setup is handled by the render code, which now
has a single render entrypoint. This both avoids stalls from lacking
commits, but also fixes the case the configure path to respect frame
callbacks so we do not run out of buffers in the first place.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 54 |
1 files changed, 8 insertions, 46 deletions
@@ -163,59 +163,19 @@ static void ext_session_lock_surface_v1_handle_configure(void *data, surface->width = width; surface->height = height; ext_session_lock_surface_v1_ack_configure(lock_surface, serial); - render_frame_background(surface); - render_frame(surface); + surface->dirty = true; + render(surface); } static const struct ext_session_lock_surface_v1_listener ext_session_lock_surface_v1_listener = { .configure = ext_session_lock_surface_v1_handle_configure, }; -static const struct wl_callback_listener surface_frame_listener; - -static void surface_frame_handle_done(void *data, struct wl_callback *callback, - uint32_t time) { - struct swaylock_surface *surface = data; - - wl_callback_destroy(callback); - surface->frame_pending = false; - - if (surface->dirty) { - // Schedule a frame in case the surface is damaged again - struct wl_callback *callback = wl_surface_frame(surface->surface); - wl_callback_add_listener(callback, &surface_frame_listener, surface); - surface->frame_pending = true; - - render_frame(surface); - surface->dirty = false; - } -} - -static const struct wl_callback_listener surface_frame_listener = { - .done = surface_frame_handle_done, -}; - -void damage_surface(struct swaylock_surface *surface) { - if (surface->width == 0 || surface->height == 0) { - // Not yet configured - return; - } - - surface->dirty = true; - if (surface->frame_pending) { - return; - } - - struct wl_callback *callback = wl_surface_frame(surface->surface); - wl_callback_add_listener(callback, &surface_frame_listener, surface); - surface->frame_pending = true; - wl_surface_commit(surface->surface); -} - void damage_state(struct swaylock_state *state) { struct swaylock_surface *surface; wl_list_for_each(surface, &state->surfaces, link) { - damage_surface(surface); + surface->dirty = true; + render(surface); } } @@ -226,7 +186,8 @@ static void handle_wl_output_geometry(void *data, struct wl_output *wl_output, struct swaylock_surface *surface = data; surface->subpixel = subpixel; if (surface->state->run_display) { - damage_surface(surface); + surface->dirty = true; + render(surface); } } @@ -247,7 +208,8 @@ static void handle_wl_output_scale(void *data, struct wl_output *output, struct swaylock_surface *surface = data; surface->scale = factor; if (surface->state->run_display) { - damage_surface(surface); + surface->dirty = true; + render(surface); } } |
