From 89678ed4125a9a88092ae1e3afa2310bb946d8cd Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 14 Apr 2021 03:35:31 -0400 Subject: [PATCH] [render] only invalidate glyphs when wipe fails --- src/lib/kitty.c | 5 +++++ src/lib/render.c | 2 +- src/lib/sixel.c | 6 ++++-- src/lib/sprite.c | 23 +++++------------------ 4 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/lib/kitty.c b/src/lib/kitty.c index 91e4375c9..4e728a660 100644 --- a/src/lib/kitty.c +++ b/src/lib/kitty.c @@ -149,6 +149,10 @@ kitty_null(char* triplet, int skip, int max, int pleft){ #define RGBA_MAXLEN 768 // 768 base64-encoded pixels in 4096 bytes int sprite_kitty_cell_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell){ + if(s->n->tacache[s->dimx * ycell + xcell] == SPRIXCELL_ANNIHILATED){ +//fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell); + return 0; // already annihilated, needn't draw glyph in kitty + } const int totalpixels = s->pixy * s->pixx; const int xpixels = nc->tcache.cellpixx; const int ypixels = nc->tcache.cellpixy; @@ -199,6 +203,7 @@ int sprite_kitty_cell_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell if(thisrow == 0){ //fprintf(stderr, "CLEARED ROW, TARGY: %d\n", targy - 1); if(--targy == 0){ + s->invalidated = SPRIXEL_INVALIDATED; return 0; } thisrow = targx; diff --git a/src/lib/render.c b/src/lib/render.c index 844928a9a..7c977c25f 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -213,8 +213,8 @@ paint_sprixel(const ncplane* p, const nccell* vis, struct crender* crender, if(sprite_wipe_cell(nc, p->sprite, y, x)){ //fprintf(stderr, "damaging due to wipe %d/%d\n", y, x); crender->s.damaged = 1; - crender->s.p_beats_sprixel = 1; } + crender->s.p_beats_sprixel = 1; }else if(!crender->p){ // if we are a bitmap, and above a cell that has changed (and // will thus be printed), we'll need redraw the sprixel. diff --git a/src/lib/sixel.c b/src/lib/sixel.c index 1b1090c89..13ff8cffd 100644 --- a/src/lib/sixel.c +++ b/src/lib/sixel.c @@ -546,8 +546,10 @@ int sprite_sixel_init(int fd){ // redrawn, it's redrawn using P2=1. int sixel_wipe(const notcurses* nc, sprixel* s, int ycell, int xcell){ (void)nc; - (void)ycell; - (void)xcell; + if(s->n->tacache[s->dimx * ycell + xcell] == SPRIXCELL_ANNIHILATED){ +//fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell); + return 1; // already annihilated, but still must draw glyph + } change_p2(s->glyph, SIXEL_P2_TRANS); return -1; } diff --git a/src/lib/sprite.c b/src/lib/sprite.c index 1b7e783d7..16d75d7a1 100644 --- a/src/lib/sprite.c +++ b/src/lib/sprite.c @@ -112,31 +112,18 @@ int sprixel_load(sprixel* spx, char* s, int bytes, int placey, int placex, return 0; } +// returns 1 if already annihilated, 0 if we successfully annihilated the cell, +// or -1 if we could not annihilate the cell (i.e. we're sixel). int sprite_wipe_cell(const notcurses* nc, sprixel* s, int ycell, int xcell){ if(s->invalidated == SPRIXEL_HIDE){ // no need to do work if we're killing it return 0; } - if(ycell >= s->dimy || ycell < 0){ - logerror(nc, "Bad y coordinate %d (%d)\n", ycell, s->dimy); - return -1; - } - if(xcell >= s->dimx || xcell < 0){ - logerror(nc, "Bad x coordinate %d (%d)\n", xcell, s->dimx); - return -1; - } - if(s->n->tacache[s->dimx * ycell + xcell] == SPRIXCELL_ANNIHILATED){ -//fprintf(stderr, "CACHED WIPE %d %d/%d\n", s->id, ycell, xcell); - return 0; // already annihilated - } - // mark the cell as annihilated whether we actually scrubbed it or not, - // so that we use this fact should we move to another frame - s->n->tacache[s->dimx * ycell + xcell] = SPRIXCELL_ANNIHILATED; //fprintf(stderr, "ANNIHILATED %p %d\n", s->n->tacache, s->dimx * ycell + xcell); int r = nc->tcache.pixel_cell_wipe(nc, s, ycell, xcell); //fprintf(stderr, "WIPED %d %d/%d ret=%d\n", s->id, ycell, xcell, r); - if(r == 0){ - s->invalidated = SPRIXEL_INVALIDATED; - } + // mark the cell as annihilated whether we actually scrubbed it or not, + // so that we use this fact should we move to another frame + s->n->tacache[s->dimx * ycell + xcell] = SPRIXCELL_ANNIHILATED; return r; }