diff --git a/src/demo/yield.c b/src/demo/yield.c index fad929903..9884feae3 100644 --- a/src/demo/yield.c +++ b/src/demo/yield.c @@ -12,13 +12,23 @@ int yield_demo(struct notcurses* nc){ if(wmv == NULL){ return -1; } - struct ncvisual_options vopts = { + ncscale_e scale = NCSCALE_STRETCH; + struct ncplane_options nopts = { .y = 1, - .scaling = NCSCALE_STRETCH, + .rows = dimy - 2, + .cols = dimx, + }; + struct ncvisual_options vopts = { + .scaling = scale, .blitter = NCBLIT_PIXEL, }; - struct ncplane* n; - if((n = ncvisual_render(nc, wmv, &vopts)) == NULL){ + vopts.n = ncplane_create(std, &nopts); + if(vopts.n == NULL){ + ncvisual_destroy(wmv); + return -1; + } + if(ncvisual_render(nc, wmv, &vopts) == NULL){ + ncplane_destroy(vopts.n); ncvisual_destroy(wmv); return -1; } @@ -26,13 +36,13 @@ int yield_demo(struct notcurses* nc){ int vy, vx, vscaley, vscalex; vopts.scaling = NCSCALE_NONE; ncvisual_geom(nc, wmv, &vopts, &vy, &vx, &vscaley, &vscalex); - vopts.scaling = NCSCALE_STRETCH; + vopts.scaling = scale; struct timespec scaled; const long total = vy * vx; // less than this, and we exit almost immediately. more than this, and we // run closer to twenty seconds. 11/50 it is, then. const long threshold_painted = total * 11 / 50; - const int MAXITER = 512; + const int MAXITER = 256; timespec_div(&demodelay, MAXITER, &scaled); long tfilled = 0; @@ -46,7 +56,7 @@ int yield_demo(struct notcurses* nc){ struct ncplane* label = ncplane_create(std, &labopts); if(label == NULL){ ncvisual_destroy(wmv); - ncplane_destroy(n); + ncplane_destroy(vopts.n); return -1; } uint64_t basechan = 0; @@ -73,7 +83,7 @@ int yield_demo(struct notcurses* nc){ uint32_t pixel = 0; if(ncvisual_at_yx(wmv, y, x, &pixel) < 0){ ncvisual_destroy(wmv); - ncplane_destroy(n); + ncplane_destroy(vopts.n); return -1; } if(ncpixel_a(pixel) != 0xff){ // don't do areas we've already done @@ -87,7 +97,7 @@ int yield_demo(struct notcurses* nc){ pfilled = ncvisual_polyfill_yx(wmv, y, x, pixel); if(pfilled < 0){ ncvisual_destroy(wmv); - ncplane_destroy(n); + ncplane_destroy(vopts.n); return -1; } // it's possible that nothing changed (pfilled == 0), but render anyway @@ -95,8 +105,7 @@ int yield_demo(struct notcurses* nc){ DEMO_RENDER(nc); }while(pfilled == 0); tfilled += pfilled; - ncplane_destroy(n); - if((n = ncvisual_render(nc, wmv, &vopts)) == NULL){ + if(ncvisual_render(nc, wmv, &vopts) == NULL){ ncvisual_destroy(wmv); return -1; } @@ -110,7 +119,7 @@ int yield_demo(struct notcurses* nc){ } ncplane_destroy(label); ncvisual_destroy(wmv); - ncplane_destroy(n); + ncplane_destroy(vopts.n); ncplane_erase(std); return 0; } diff --git a/src/lib/visual.c b/src/lib/visual.c index 7772eece6..7b9897c22 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -481,7 +481,7 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse return n; } -ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blitset* bset, +ncplane* ncvisual_render_pixels(tinfo* tcache, ncvisual* ncv, const struct blitset* bset, int placey, int placex, int begy, int begx, ncplane* n, ncscale_e scaling, ncplane* stdn){ int disprows, dispcols; @@ -489,41 +489,47 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits dispcols = ncv->cols; disprows = ncv->rows; } - if(n){ - logerror(nc, "Can't blit bitmaps to existing planes\n"); - return NULL; - } //fprintf(stderr, "INPUT N: %p\n", vopts ? vopts->n : NULL); - if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){ - ncplane_dim_yx(stdn, &disprows, &dispcols); - dispcols *= nc->tcache.cellpixx; - disprows *= nc->tcache.cellpixy; - } + if(n == NULL){ // create plane + if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){ + ncplane_dim_yx(stdn, &disprows, &dispcols); + dispcols *= tcache->cellpixx; + disprows *= tcache->cellpixy; + } //fprintf(stderr, "PLACING NEW PLANE: %d/%d @ %d/%d\n", disprows, dispcols, placey, placex); - struct ncplane_options nopts = { - .y = placey, - .x = placex, - .rows = disprows / nc->tcache.cellpixy + !!(disprows % nc->tcache.cellpixy), - .cols = dispcols / nc->tcache.cellpixx + !!(dispcols % nc->tcache.cellpixx), - .userptr = NULL, - .name = "rgba", - .resizecb = NULL, - .flags = 0, - }; - if((n = ncplane_create(stdn, &nopts)) == NULL){ - return NULL; + struct ncplane_options nopts = { + .y = placey, + .x = placex, + .rows = disprows / tcache->cellpixy + !!(disprows % tcache->cellpixy), + .cols = dispcols / tcache->cellpixx + !!(dispcols % tcache->cellpixx), + .userptr = NULL, + .name = "rgba", + .resizecb = NULL, + .flags = 0, + }; + if((n = ncplane_create(stdn, &nopts)) == NULL){ + return NULL; + } + placey = 0; + placex = 0; + }else{ + if(scaling != NCSCALE_NONE && scaling != NCSCALE_NONE_HIRES){ + ncplane_dim_yx(n, &disprows, &dispcols); + dispcols *= tcache->cellpixx; + disprows *= tcache->cellpixy; + dispcols -= (placex * tcache->cellpixx + 1); + disprows -= (placey * tcache->cellpixy + 1); + } } - placey = 0; - placex = 0; if(scaling == NCSCALE_SCALE || scaling == NCSCALE_SCALE_HIRES){ scale_visual(ncv, &disprows, &dispcols); } -//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data, ncplane_notcurses(stdn)->nc->tcache.cellpixx); +//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data, ncplane_notcurses(stdn)->tcache.cellpixx); blitterargs bargs; - bargs.pixel.celldimx = nc->tcache.cellpixx; - bargs.pixel.celldimy = nc->tcache.cellpixy; - bargs.pixel.colorregs = nc->tcache.color_registers; - bargs.pixel.sprixelid = nc->tcache.sprixelnonce++; + bargs.pixel.celldimx = ncplane_notcurses(stdn)->tcache.cellpixx; + bargs.pixel.celldimy = ncplane_notcurses(stdn)->tcache.cellpixy; + bargs.pixel.colorregs = ncplane_notcurses(stdn)->tcache.color_registers; + bargs.pixel.sprixelid = tcache->sprixelnonce++; if(ncvisual_blit(ncv, disprows, dispcols, n, bset, begy, begx, disprows, dispcols, &bargs)){ ncplane_destroy(n); @@ -579,7 +585,7 @@ ncplane* ncvisual_render(notcurses* nc, ncvisual* ncv, const struct ncvisual_opt n, scaling, vopts && (vopts->flags & NCVISUAL_OPTION_BLEND)); }else{ - n = ncvisual_render_pixels(nc, ncv, bset, placey, placex, begy, begx, + n = ncvisual_render_pixels(&nc->tcache, ncv, bset, placey, placex, begy, begx, n, scaling, notcurses_stdplane(nc)); } return n;