swaynag: reduce roundtrips when rendering frames

This reduces flicker when toggling the detail view.
This commit is contained in:
Manuel Stoeckl 2024-11-08 21:45:15 -05:00
parent 2535a2e9f9
commit 131026b190

View file

@ -260,17 +260,24 @@ void render_frame(struct swaynag *swaynag) {
cairo_paint(cairo); cairo_paint(cairo);
cairo_restore(cairo); cairo_restore(cairo);
uint32_t height = render_to_cairo(cairo, swaynag); uint32_t height = render_to_cairo(cairo, swaynag);
if (height != swaynag->height) { if (swaynag->height == 0) {
// for first commit, set required size but do not attach a buffer
zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height); zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height);
zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface, zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface,
height); height);
wl_surface_commit(swaynag->surface); wl_surface_commit(swaynag->surface);
wl_display_roundtrip(swaynag->display); goto cleanup;
} else { }
if (height != swaynag->height) {
zwlr_layer_surface_v1_set_size(swaynag->layer_surface, 0, height);
zwlr_layer_surface_v1_set_exclusive_zone(swaynag->layer_surface,
height);
}
swaynag->current_buffer = get_next_buffer(swaynag->shm, swaynag->current_buffer = get_next_buffer(swaynag->shm,
swaynag->buffers, swaynag->buffers,
swaynag->width * swaynag->scale, swaynag->width * swaynag->scale,
swaynag->height * swaynag->scale); height * swaynag->scale);
if (!swaynag->current_buffer) { if (!swaynag->current_buffer) {
sway_log(SWAY_DEBUG, "Failed to get buffer. Skipping frame."); sway_log(SWAY_DEBUG, "Failed to get buffer. Skipping frame.");
goto cleanup; goto cleanup;
@ -290,8 +297,6 @@ void render_frame(struct swaynag *swaynag) {
wl_surface_damage(swaynag->surface, 0, 0, wl_surface_damage(swaynag->surface, 0, 0,
swaynag->width, swaynag->height); swaynag->width, swaynag->height);
wl_surface_commit(swaynag->surface); wl_surface_commit(swaynag->surface);
wl_display_roundtrip(swaynag->display);
}
cleanup: cleanup:
cairo_surface_destroy(recorder); cairo_surface_destroy(recorder);