render: last_buf may point to a free:d buffer

So, store last buf's width/height separately
This commit is contained in:
Daniel Eklöf 2019-11-02 00:48:07 +01:00
parent 5812242405
commit 4d3251a93b
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 23 additions and 9 deletions

View file

@ -451,25 +451,33 @@ grid_render(struct terminal *term)
bool all_clean = tll_length(term->grid->scroll_damage) == 0;
/* If we resized the window, or is flashing, or just stopped flashing */
if (term->render.last_buf != buf ||
if (term->render.last_shm.buf != buf ||
term->flash.active || term->render.was_flashing ||
term->is_searching != term->render.was_searching)
{
if (term->render.last_buf != NULL &&
term->render.last_buf->width == buf->width &&
term->render.last_buf->height == buf->height &&
/*
* TODO: shm buffers may be purged, meaning our last_buf (when
* != buf) may point to a free:d buffer.
*
* It *shouldn't*, as long as the sizes match... but would
* still be good to find a better solution for this.
*/
if (term->render.last_shm.buf != NULL &&
term->render.last_shm.width == buf->width &&
term->render.last_shm.height == buf->height &&
!term->flash.active &&
!term->render.was_flashing &&
term->is_searching == term->render.was_searching)
{
static bool has_warned = false;
if (!has_warned) {
LOG_WARN("it appears your Wayland compositor does not support buffer re-use for SHM clients; expect lower performance.");
LOG_WARN(
"it appears your Wayland compositor does not support "
"buffer re-use for SHM clients; expect lower performance.");
has_warned = true;
}
assert(term->render.last_buf->size == buf->size);
memcpy(buf->mmapped, term->render.last_buf->mmapped, buf->size);
memcpy(buf->mmapped, term->render.last_shm.buf->mmapped, buf->size);
}
else {
@ -505,7 +513,9 @@ grid_render(struct terminal *term)
term_damage_view(term);
}
term->render.last_buf = buf;
term->render.last_shm.buf = buf;
term->render.last_shm.width = buf->width;
term->render.last_shm.height = buf->height;
term->render.was_flashing = term->flash.active;
term->render.was_searching = term->is_searching;
}

View file

@ -276,7 +276,11 @@ struct terminal {
struct cell *cell; /* For easy access to content */
} last_cursor;
struct buffer *last_buf; /* Buffer we rendered to last time */
struct {
struct buffer *buf; /* Buffer we rendered to last time */
int width;
int height;
} last_shm;
bool was_flashing; /* Flash was active last time we rendered */
bool was_searching;
} render;