From ed8c369d4e0e9b7f73da5404b99d2b9238b351ab Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 4 Jul 2021 03:29:32 -0400 Subject: [PATCH] on pile change, clear old sprixels #1875 --- src/lib/internal.h | 6 ++++++ src/lib/notcurses.c | 1 + src/lib/render.c | 14 +++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index d453c96b9..a03a8a964 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -472,6 +472,12 @@ typedef struct notcurses { // we keep a copy of the last rendered frame. this facilitates O(1) // notcurses_at_yx() and O(1) damage detection (at the cost of some memory). nccell* lastframe;// last rasterized framebuffer, NULL until first raster + // the last pile we rasterized. NULL until we've rasterized once. might + // be invalid due to the pile being destroyed; you are only allowed to + // evaluate it for equality to the pile being currently rasterized. when + // we switch piles, we need to clear all displayed sprixels, and + // invalidate the new pile's, pursuant to their display. + ncpile* last_pile; egcpool pool; // egcpool for lastframe int lfdimx; // dimensions of lastframe, unchanged by screen resize diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index e092b21a8..353fc2a76 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1036,6 +1036,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){ if(ret == NULL){ return ret; } + ret->last_pile = NULL; ret->rstate.mstream = NULL; ret->rstate.mstreamfp = NULL; ret->loglevel = opts->loglevel; diff --git a/src/lib/render.c b/src/lib/render.c index 474833bee..6dcfd1228 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -1119,12 +1119,16 @@ raster_and_write(notcurses* nc, ncpile* p, FILE* out){ return -1; } } + // if the last pile was different from this one, we need clear all old + // sprixels (and invalidate all those of the current pile -- FIXME). + if(nc->last_pile != p){ + if(sprite_clear_all(&nc->tcache, out)){ + return -1; + } + } if(notcurses_rasterize_inner(nc, p, out, &useasu) < 0){ return -1; } - int ret = 0; - sigset_t oldmask; - block_signals(&oldmask); // if we loaded a BSU into the front, but don't actually want to use it, // we start printing after the BSU. size_t moffset = 0; @@ -1135,6 +1139,9 @@ raster_and_write(notcurses* nc, ncpile* p, FILE* out){ moffset = strlen(basu); } } + int ret = 0; + sigset_t oldmask; + block_signals(&oldmask); if(blocking_write(fileno(nc->ttyfp), nc->rstate.mstream + moffset, nc->rstate.mstrsize - moffset)){ ret = -1; @@ -1165,6 +1172,7 @@ notcurses_rasterize(notcurses* nc, ncpile* p, FILE* out){ if(cursory >= 0){ notcurses_cursor_enable(nc, cursory, cursorx); } + nc->last_pile = p; return ret; }