render: delay reflow for ‘resize-delay-ms’ milliseconds

Reflowing a large scrollback is *slow*. During an interactive resize,
it can easily take long enough that the compositor fills the Wayland
socket with configure events. Eventually, the socket becomes full and
the compositor terminates the connection, causing foot to exit.

This patch is work-in-progress, and the first step towards alleviating
this.

It delays the reflow by:

* Snapshotting (copying) the original grid when an interactive resize
  is started.
* While resizing, we apply a simple truncation resize of the
  grid (like we handle the alt screen).
* When the resize is done, or paused for ‘resize-delay-ms’, the grid
  is reflowed.

TODO: we *must* not allow any changes to the temporary (truncated)
grid during the resize. Any changes to the grid would be lost when the
final reflow is applied. That is, we must completely pause the ptmx
pipe while a resize is in progress.

Future improvements:

The initial copy can be slow. We should be able to avoid it by
rewriting the reflow algorithm to not free anything. This is
complicated by the fact that some resources (e.g. sixel images) are
currently *moved* to the new grid. They’d instead have to be copied.
This commit is contained in:
Daniel Eklöf 2022-10-05 17:05:44 +02:00
parent a9fc7ce180
commit 8179d73daa
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 123 additions and 20 deletions

2
grid.c
View file

@ -210,6 +210,8 @@ grid_snapshot(const struct grid *grid)
clone->offset = grid->offset;
clone->view = grid->view;
clone->cursor = grid->cursor;
clone->saved_cursor = grid->saved_cursor;
clone->kitty_kbd = grid->kitty_kbd;
clone->rows = xcalloc(grid->num_rows, sizeof(clone->rows[0]));
memset(&clone->scroll_damage, 0, sizeof(clone->scroll_damage));
memset(&clone->sixel_images, 0, sizeof(clone->sixel_images));