[kitty] free and release sprixel on commit to destroy #1890

pull/1895/head
nick black 3 years ago committed by Nick Black
parent 2e7079a69e
commit 56433a1a7f

@ -922,7 +922,9 @@ rasterize_scrolls(ncpile* p, FILE* out){
static int64_t
rasterize_sprixels(notcurses* nc, ncpile* p, FILE* out){
int64_t bytesemitted = 0;
for(sprixel* s = p->sprixelcache ; s ; s = s->next){
sprixel* s;
sprixel** parent = &p->sprixelcache;
while( (s = *parent) ){
//fprintf(stderr, "YARR HARR HARR SPIRXLE %u STATE %d\n", s->id, s->invalidated);
if(s->invalidated == SPRIXEL_INVALIDATED){
//fprintf(stderr, "3 DRAWING BITMAP %d STATE %d AT %d/%d for %p\n", s->id, s->invalidated, y + nc->margin_t, x + nc->margin_l, s->n);
@ -955,8 +957,14 @@ rasterize_sprixels(notcurses* nc, ncpile* p, FILE* out){
if(nc->tcache.pixel_remove(s->id, out) < 0){
return -1;
}
if( (*parent = s->next) ){
s->next->prev = s->prev;
}
sprixel_free(s);
continue;
}
}
parent = &s->next;
}
return bytesemitted;
}
@ -1094,7 +1102,7 @@ rasterize_core(notcurses* nc, const ncpile* p, FILE* out, unsigned phase){
// 'asu' on input is non-0 if application-synchronized updates are permitted
// (they are not, for instance, when rendering to a non-tty). on output,
// assuming success, it is non-0 if application-synchronized updates are
// desired; in this case, an ASU footer is present at the end of the buffer.
// desired; in this case, a SUM footer is present at the end of the buffer.
static int
notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out, unsigned* asu){
//fprintf(stderr, "pile %p ymax: %d xmax: %d\n", p, p->dimy + nc->margin_t, p->dimx + nc->margin_l);
@ -1129,13 +1137,13 @@ notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out, unsigned* asu){
if(rasterize_core(nc, p, out, 1)){
return -1;
}
#define MIN_ASU_SIZE 4096 // FIXME
#define MIN_SUMODE_SIZE 4096 // FIXME
if(*asu){
if(nc->rstate.mstrsize >= MIN_ASU_SIZE){
if(nc->rstate.mstrsize >= MIN_SUMODE_SIZE){
const char* endasu = get_escape(&nc->tcache, ESCAPE_ESUM);
if(endasu){
if(fprintf(out, "%s", endasu) < 0){
return -1;
*asu = 0;
}
}else{
*asu = 0;
@ -1144,7 +1152,7 @@ notcurses_rasterize_inner(notcurses* nc, ncpile* p, FILE* out, unsigned* asu){
*asu = 0;
}
}
#undef MIN_ASU_SIZE
#undef MIN_SUMODE_SIZE
if(ncflush(out)){
return -1;
}
@ -1156,12 +1164,12 @@ static int
raster_and_write(notcurses* nc, ncpile* p, FILE* out){
fseeko(out, 0, SEEK_SET);
// will we be using application-synchronized updates? if this comes back as
// non-zero, we are, and must emit the header. no ASU without a tty, and we
// non-zero, we are, and must emit the header. no SUM without a tty, and we
// can't have the escape without being connected to one...
const char* basu = get_escape(&nc->tcache, ESCAPE_BSUM);
unsigned useasu = basu ? 1 : 0;
// if we have ASU support, emit a BSU speculatively. if we do so, but don't
// actually use an ESU, this BASU must be skipped on write.
// if we have SUM support, emit a BSU speculatively. if we do so, but don't
// actually use an ESU, this BSUM must be skipped on write.
if(useasu){
if(ncfputs(basu, out) == EOF){
return -1;
@ -1426,7 +1434,7 @@ int ncpile_render_to_buffer(ncplane* p, char** buf, size_t* buflen){
return -1;
}
notcurses* nc = ncplane_notcurses(p);
unsigned useasu = false; // no ASU to file
unsigned useasu = false; // no SUM with file
fseeko(nc->rstate.mstreamfp, 0, SEEK_SET);
int bytes = notcurses_rasterize_inner(nc, ncplane_pile(p), nc->rstate.mstreamfp, &useasu);
pthread_mutex_lock(&nc->statlock);

@ -218,8 +218,8 @@ void summarize_stats(notcurses* nc){
(stats->bgemissions + stats->bgelisions) == 0 ? 0 :
(stats->bgelisions * 100.0) / (stats->bgemissions + stats->bgelisions));
char totalbuf[BPREFIXSTRLEN + 1];
qprefix(stats->sprixelbytes, 1, totalbuf, 1);
fprintf(stderr, "Sprixel emits:elides: %ju:%ju (%.2f%%) %sB ASUs: %ju (%.2f%%)\n",
bprefix(stats->sprixelbytes, 1, totalbuf, 1);
fprintf(stderr, "Sprixel emits:elides: %ju:%ju (%.2f%%) %sB SUM: %ju (%.2f%%)\n",
stats->sprixelemissions, stats->sprixelelisions,
(stats->sprixelemissions + stats->sprixelelisions) == 0 ? 0 :
(stats->sprixelelisions * 100.0) / (stats->sprixelemissions + stats->sprixelelisions),

Loading…
Cancel
Save