From 021fc052fc14b22cbe5cbad221d5d72bf3b41e49 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 1 Apr 2021 22:03:32 -0400 Subject: [PATCH] [render] end kitty flicker #1493 --- src/lib/internal.h | 1 + src/lib/notcurses.c | 8 +++++--- src/lib/render.c | 8 ++++---- src/lib/sprite.c | 12 +++++++++++- src/lib/visual.c | 2 ++ 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/lib/internal.h b/src/lib/internal.h index 53cd80f94..c0bf1acf5 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -812,6 +812,7 @@ int kitty_draw(const notcurses* n, const ncpile *p, sprixel* s, FILE* out); int sixel_draw(const notcurses* n, const ncpile *p, sprixel* s, FILE* out); // dimy and dimx are cell geometry, not pixel. takes ownership of s on success. sprixel* sprixel_alloc(ncplane* n, int dimy, int dimx); +sprixel* sprixel_recycle(ncplane* n); int sprixel_load(sprixel* spx, char* s, int bytes, int placey, int placex, int pixy, int pixx, int parse_start); int sprite_wipe_cell(const notcurses* nc, sprixel* s, int y, int x); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index fdcd8ab51..39432b572 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -1984,9 +1984,11 @@ void ncplane_yx(const ncplane* n, int* y, int* x){ } void ncplane_erase(ncplane* n){ - /*if(n->sprite){ - sprixel_hide(n->sprite); - }*/ + if(n->sprite){ + // FIXME ideally we'd clear out the sprixel here, necessary for multiframe + // media with transparency, but it leads to intense flicker in sixel...=[ + return; + } // we must preserve the background, but a pure cell_duplicate() would be // wiped out by the egcpool_dump(). do a duplication (to get the stylemask // and channels), and then reload. diff --git a/src/lib/render.c b/src/lib/render.c index 86c3b69f3..83840f415 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -1085,19 +1085,19 @@ notcurses_rasterize_inner(notcurses* nc, const ncpile* p, FILE* out){ // we explicitly move the cursor at the beginning of each output line, so no // need to home it expliticly. update_palette(nc, out); -fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->stdplane->absy, p->dimx + nc->stdplane->absx); +//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->stdplane->absy, p->dimx + nc->stdplane->absx); if(clean_sprixels(nc, p, out) < 0){ return -1; } -fprintf(stderr, "RASTERIZE CORE\n"); +//fprintf(stderr, "RASTERIZE CORE\n"); if(rasterize_core(nc, p, out)){ return -1; } -fprintf(stderr, "RASTERIZE SPRIXELS\n"); +//fprintf(stderr, "RASTERIZE SPRIXELS\n"); if(rasterize_sprixels(nc, p, out) < 0){ return -1; } -fprintf(stderr, "RASTERIZE CORE\n"); +//fprintf(stderr, "RASTERIZE CORE\n"); if(rasterize_core(nc, p, out)){ return -1; } diff --git a/src/lib/sprite.c b/src/lib/sprite.c index 3a0225523..e40d73589 100644 --- a/src/lib/sprite.c +++ b/src/lib/sprite.c @@ -10,6 +10,17 @@ void sprixel_free(sprixel* s){ } } +sprixel* sprixel_recycle(ncplane* n){ + const notcurses* nc = ncplane_notcurses(n); + if(nc->tcache.pixel_destroy == sprite_kitty_annihilate){ + int dimy = n->sprite->dimy; + int dimx = n->sprite->dimx; + sprixel_hide(n->sprite); + return sprixel_alloc(n, dimy, dimx); + } + return n->sprite; +} + // store the original (absolute) coordinates from which we moved, so that // we can invalidate them in sprite_draw(). void sprixel_movefrom(sprixel* s, int y, int x){ @@ -52,7 +63,6 @@ sprixel* sprixel_by_id(const notcurses* nc, uint32_t id){ sprixel* sprixel_alloc(ncplane* n, int dimy, int dimx){ sprixel* ret = malloc(sizeof(sprixel)); if(ret){ -fprintf(stderr, "LOADING UP %p with %p\n", ret, n); memset(ret, 0, sizeof(*ret)); ret->n = n; ret->dimy = dimy; diff --git a/src/lib/visual.c b/src/lib/visual.c index 43d835f98..4dca586fb 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -608,6 +608,8 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits if((ncv->spx = sprixel_alloc(n, rows, cols)) == NULL){ goto err; } + }else{ + ncv->spx = sprixel_recycle(n); } bargs.u.pixel.spx = ncv->spx; if(ncvisual_blit(ncv, disprows, dispcols, n, bset, disprows, dispcols, &bargs)){