aboutsummaryrefslogtreecommitdiff
path: root/render.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-10-09 14:17:22 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-10-10 15:19:18 +0000
commit298f210ed93a83a531a44f772172da7f64510217 (patch)
tree7830b31070c56144007bed74d8014aa6cf6bde7e /render.c
parentrender: resize: do delayed reflow immediately when failing to arm tiocswinsz timer (diff)
render: rename term->render.resizing -> term->interactive_resizing
But also, more importantly, logical fixes: * Stash the number of new scrollback lines the stashed ‘normal’ grid should be resized *to*. There’s also a couple of performance changes here: * When doing a delayed reflow (tiocswinsz timer), call sixel_reflow_grid(term, &term->normal) - there’s no need to reflow sixels in the ‘alt’ screen. * When doing a delayed reflow, free all scroll damage. It’s not needed, since we’re damaging the entire window anyway. * Use minimum size for the temporary ‘normal’ grid (that contains the current viewport). We just need it to be large enough to fit the current viewport, and be a valid grid row count (power of 2). This just so happens to be the current ‘alt’ grid’s row count...
Diffstat (limited to 'render.c')
-rw-r--r--render.c68
1 files changed, 39 insertions, 29 deletions
diff --git a/render.c b/render.c
index 2f79c6c1..d50606cb 100644
--- a/render.c
+++ b/render.c
@@ -3666,9 +3666,11 @@ tiocswinsz(struct terminal *term)
static void
delayed_reflow_of_normal_grid(struct terminal *term)
{
- if (term->render.resizing.grid == NULL)
+ if (term->interactive_resizing.grid == NULL)
return;
+ xassert(term->interactive_resizing.new_rows > 0);
+
struct coord *const tracking_points[] = {
&term->selection.coords.start,
&term->selection.coords.end,
@@ -3677,27 +3679,31 @@ delayed_reflow_of_normal_grid(struct terminal *term)
/* Reflow the original (since before the resize was started) grid,
* to the *current* dimensions */
grid_resize_and_reflow(
- term->render.resizing.grid,
- term->grid->num_rows, term->grid->num_cols,
- term->render.resizing.screen_rows, term->rows,
+ term->interactive_resizing.grid,
+ term->interactive_resizing.new_rows, term->normal.num_cols,
+ term->interactive_resizing.old_screen_rows, term->rows,
term->selection.coords.end.row >= 0 ? ALEN(tracking_points) : 0,
tracking_points);
/* Replace the current, truncated, “normal” grid with the
* correctly reflowed one */
grid_free(&term->normal);
- term->normal = *term->render.resizing.grid;
- free(term->render.resizing.grid);
+ term->normal = *term->interactive_resizing.grid;
+ free(term->interactive_resizing.grid);
/* Reset */
- term->render.resizing.grid = NULL;
- term->render.resizing.screen_rows = 0;
+ term->interactive_resizing.grid = NULL;
+ term->interactive_resizing.old_screen_rows = 0;
+ term->interactive_resizing.new_rows = 0;
/* Invalidate render pointers */
shm_unref(term->render.last_buf);
term->render.last_buf = NULL;
term->render.last_cursor.row = NULL;
+ tll_free(term->normal.scroll_damage);
+ sixel_reflow_grid(term, &term->normal);
+
if (term->grid == &term->normal) {
term_damage_view(term);
render_refresh(term);
@@ -3895,8 +3901,6 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
const uint32_t scrollback_lines = term->render.scrollback_lines;
/*
- * Snapshot the “normal” grid.
- *
* Since text reflow is slow, don’t do it *while* resizing. Only
* do it when done, or after “pausing” the resize for sufficiently
* long. We re-use the TIOCSWINSZ timer to handle this. See
@@ -3905,25 +3909,30 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
* To be able to do the final reflow correctly, we need a copy of
* the original grid, before the resize started.
*/
- if (term->window->is_resizing && term->render.resizing.grid == NULL) {
+ if (term->window->is_resizing && term->interactive_resizing.grid == NULL) {
+ term_ptmx_pause(term);
+
/* Stash the current ‘normal’ grid, as-is, to be used when
* doing the final reflow */
- term->render.resizing.screen_rows = term->rows;
- term->render.resizing.grid = xmalloc(sizeof(*term->render.resizing.grid));
- *term->render.resizing.grid = term->normal;
-
+ term->interactive_resizing.old_screen_rows = term->rows;
+ term->interactive_resizing.grid = xmalloc(sizeof(*term->interactive_resizing.grid));
+ *term->interactive_resizing.grid = term->normal;
/*
* Copy the current viewport to a new grid that will be used
* during the resize. For now, throw away sixels and OSC-8
* URLs. They’ll be "restored" when we do the final reflow.
*
+ * We use the ‘alt’ screen’s row count, since we don’t want to
+ * instantiate an unnecessarily large grid.
+ *
* TODO:
* - sixels?
* - OSC-8?
*/
+ xassert(1 << (32 - __builtin_clz(term->rows)) == term->alt.num_rows);
struct grid g = {
- .num_rows = 1 << (32 - __builtin_clz(term->rows - 1)),
+ .num_rows = term->alt.num_rows,
.num_cols = term->cols,
.offset = 0,
.view = 0,
@@ -3945,7 +3954,6 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
}
term->normal = g;
- term_ptmx_pause(term);
}
/* Screen rows/cols before resize */
@@ -3985,9 +3993,10 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
xassert(term->margins.bottom >= pad_y);
if (new_cols == old_cols && new_rows == old_rows &&
- (term->render.resizing.grid == NULL || term->window->is_resizing))
+ (term->interactive_resizing.grid == NULL || term->window->is_resizing))
{
LOG_DBG("grid layout unaffected; skipping reflow");
+ term->interactive_resizing.new_rows = new_normal_grid_rows;
goto damage_view;
}
@@ -4014,27 +4023,28 @@ maybe_resize(struct terminal *term, int width, int height, bool force)
if (term->window->is_resizing) {
/* Simple truncating resize, *while* an interactive resize is
* ongoing. */
- xassert(term->render.resizing.grid != NULL);
+ xassert(term->interactive_resizing.grid != NULL);
+ xassert(new_normal_grid_rows > 0);
+ term->interactive_resizing.new_rows = new_normal_grid_rows;
+
grid_resize_without_reflow(
- &term->normal,
- new_normal_grid_rows, new_cols,
- old_rows,
- new_rows);
+ &term->normal, new_alt_grid_rows, new_cols, old_rows, new_rows);
} else {
/* Full text reflow */
- if (term->render.resizing.grid != NULL) {
+ if (term->interactive_resizing.grid != NULL) {
/* Throw away the current, truncated, “normal” grid, and
* use the original grid instead (from before the resize
* started) */
grid_free(&term->normal);
- term->normal = *term->render.resizing.grid;
- free(term->render.resizing.grid);
+ term->normal = *term->interactive_resizing.grid;
+ free(term->interactive_resizing.grid);
- old_rows = term->render.resizing.screen_rows;
+ old_rows = term->interactive_resizing.old_screen_rows;
- term->render.resizing.grid = NULL;
- term->render.resizing.screen_rows = 0;
+ term->interactive_resizing.grid = NULL;
+ term->interactive_resizing.old_screen_rows = 0;
+ term->interactive_resizing.new_rows = 0;
term_ptmx_resume(term);
}