From 5158be86d2a1be657260c3283548e9fde17ddd7f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 28 Jun 2020 10:45:30 +0200 Subject: render: sixels: break out of loop when we're sure there aren't any more visible images The sixel list is sorted, with the most recent images *first* in the list (and thus the "oldest" images are at the back). This means we can break out of the loop when we see a sixel that *ends before* the current view starts. As a minor optimization, we also recognize sixels that *start after* the current view ends. We can't break out of the loop, but we can skip trying to render them (they wouldn't have been rendered, but more work would have been done in render_sixel() to reach this conclusion). --- render.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 8fd7d42e..8bb85f9d 100644 --- a/render.c +++ b/render.c @@ -795,8 +795,32 @@ render_sixel(struct terminal *term, pixman_image_t *pix, static void render_sixel_images(struct terminal *term, pixman_image_t *pix) { - tll_foreach(term->grid->sixel_images, it) + const int view_start = term->grid->view; + const int view_end = view_start + term->rows; + + LOG_DBG("SIXELS: %zu images, view=%d-%d", + tll_length(term->grid->sixel_images), view_start, view_end); + + tll_foreach(term->grid->sixel_images, it) { + const struct sixel *six = &it->item; + const int start = six->pos.row; + const int end = start + six->rows - 1; + + /* Sixels aren't allowed to cross the wrap-around */ + assert(end < term->grid->num_rows); + + //LOG_DBG(" sixel: %d-%d", start, end); + if (start > view_end) { + /* Sixel starts after view ends, no need to try to render it */ + continue; + } else if (end < view_start) { + /* Image ends before view starts. Since the image list is + * sorted, we can safely stop here */ + break; + } + render_sixel(term, pix, &it->item); + } } static void -- cgit v1.3 From c7b2dcc0f4ba6ec451bbfe2b51ac1096aa1505d8 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 28 Jun 2020 14:19:43 +0200 Subject: render: sixel: regression: need to take current offset into account when early-quitting sixel rendering The sixel images are sorted, that's true. But in order for our row numer comparisons to actually work, we need to rebase all numbers against the current scrollback offset (or, the scrollback *end*, to be precise). --- render.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 8bb85f9d..391115d6 100644 --- a/render.c +++ b/render.c @@ -795,20 +795,30 @@ render_sixel(struct terminal *term, pixman_image_t *pix, static void render_sixel_images(struct terminal *term, pixman_image_t *pix) { - const int view_start = term->grid->view; - const int view_end = view_start + term->rows; + if (likely(tll_length(term->grid->sixel_images)) == 0) + return; + + const int scrollback_end + = (term->grid->offset + term->rows) & (term->grid->num_rows - 1); + + const int view_start + = (term->grid->view + - scrollback_end + + term->grid->num_rows) & (term->grid->num_rows - 1); - LOG_DBG("SIXELS: %zu images, view=%d-%d", - tll_length(term->grid->sixel_images), view_start, view_end); + const int view_end = view_start + term->rows - 1; + + //LOG_DBG("SIXELS: %zu images, view=%d-%d", + // tll_length(term->grid->sixel_images), view_start, view_end); tll_foreach(term->grid->sixel_images, it) { const struct sixel *six = &it->item; - const int start = six->pos.row; + const int start + = (six->pos.row + - scrollback_end + + term->grid->num_rows) & (term->grid->num_rows - 1); const int end = start + six->rows - 1; - /* Sixels aren't allowed to cross the wrap-around */ - assert(end < term->grid->num_rows); - //LOG_DBG(" sixel: %d-%d", start, end); if (start > view_end) { /* Sixel starts after view ends, no need to try to render it */ -- cgit v1.3