From 2c8286c099ced98ca30cf85c36b1e17c2bb9b5e9 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 16 Oct 2021 00:40:14 -0400 Subject: [PATCH] stacking tests: ncvisual_render() -> ncvisual_blit() #1462 --- USAGE.md | 27 ++++----------------------- src/demo/outro.c | 3 ++- src/demo/zoo.c | 1 + src/lib/visual.c | 5 +++++ src/tests/stacking.cpp | 41 +++++++++++++++++++++++++++++------------ 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/USAGE.md b/USAGE.md index c2ea59499..8db2430e2 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3301,8 +3301,8 @@ int ncvisual_set_yx(const struct ncvisual* n, int y, int x, uint32_t pixel); // If a subtitle ought be displayed at this time, return a new plane (bound // to 'parent' containing the subtitle, which might be text or graphics // (depending on the input format). -struct ncplane* ncvisual_subtitle(struct ncplane* parent, - const struct ncvisual* ncv); +struct ncplane* ncvisual_subtitle_plane(struct ncplane* parent, + const struct ncvisual* ncv); ``` And finally, the `ncvisual` can be blitted to one or more `ncplane`s: @@ -3424,27 +3424,8 @@ typedef int (*streamcb)(struct ncplane*, struct ncvisual*, // Shut up and display my frames! Provide as an argument to ncvisual_stream(). // If you'd like subtitles to be decoded, provide an ncplane as the curry. If the // curry is NULL, subtitles will not be displayed. -static inline int -ncvisual_simple_streamer(struct ncplane* n, struct ncvisual* ncv, - const struct timespec* tspec, void* curry){ - if(notcurses_render(ncplane_notcurses(n))){ - return -1; - } - int ret = 0; - if(curry){ - // need a cast for C++ callers - struct ncplane* subncp = (struct ncplane*)curry; - char* subtitle = ncvisual_subtitle(ncv); - if(subtitle){ - if(ncplane_putstr_yx(subncp, 0, 0, subtitle) < 0){ - ret = -1; - } - free(subtitle); - } - } - clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, tspec, NULL); - return ret; -} +int ncvisual_simple_streamer(struct ncvisual* ncv, struct ncvisual_options* vopts, + const struct timespec* tspec, void* curry); // Stream the entirety of the media, according to its own timing. Blocking, // obviously. streamer may be NULL; it is otherwise called for each frame, and diff --git a/src/demo/outro.c b/src/demo/outro.c index a1371aebe..eba8eabda 100644 --- a/src/demo/outro.c +++ b/src/demo/outro.c @@ -198,7 +198,8 @@ int outro(struct notcurses* nc){ return -1; } vopts.scaling = NCSCALE_STRETCH; - vopts.flags = NCVISUAL_OPTION_BLEND; + vopts.flags = NCVISUAL_OPTION_BLEND | NCVISUAL_OPTION_CHILDPLANE; + vopts.n = notcurses_stdplane(nc); if((vopts.n = ncvisual_blit(nc, chncv, &vopts)) == NULL){ ncvisual_destroy(chncv); return -1; diff --git a/src/demo/zoo.c b/src/demo/zoo.c index 6731267b9..3c693ae3a 100644 --- a/src/demo/zoo.c +++ b/src/demo/zoo.c @@ -14,6 +14,7 @@ draw_background(struct notcurses* nc){ struct ncvisual_options vopts = { .scaling = NCSCALE_STRETCH, .n = n, + .flags = NCVISUAL_OPTION_CHILDPLANE, }; if(ncvisual_blit(nc, ncv, &vopts) == NULL){ ncvisual_destroy(ncv); diff --git a/src/lib/visual.c b/src/lib/visual.c index 0ad20b3c8..bd883cd72 100644 --- a/src/lib/visual.c +++ b/src/lib/visual.c @@ -70,6 +70,11 @@ ncplane* ncvisual_subtitle_plane(ncplane* parent, const ncvisual* ncv){ return visual_implementation.visual_subtitle(parent, ncv); } +char* ncvisual_subtitle(const ncvisual* ncv){ + (void)ncv; // FIXME remove for abi3 + return NULL; +} + int ncvisual_blit_internal(ncvisual* ncv, int rows, int cols, ncplane* n, const struct blitset* bset, const blitterargs* barg){ if(!(barg->flags & NCVISUAL_OPTION_NOINTERPOLATE)){ diff --git a/src/tests/stacking.cpp b/src/tests/stacking.cpp index 1d4ec4ec9..54f4aeb02 100644 --- a/src/tests/stacking.cpp +++ b/src/tests/stacking.cpp @@ -45,7 +45,7 @@ TEST_CASE("Stacking") { .leny = 2, .lenx = 1, .blitter = NCBLIT_2x1, .flags = 0, .transcolor = 0, .pxoffy = 0, .pxoffx = 0, }; - CHECK(top == ncvisual_render(nc_, ncv, &vopts)); + CHECK(top == ncvisual_blit(nc_, ncv, &vopts)); ncvisual_destroy(ncv); // create an ncvisual of 2 rows, 1 column, with the top 0xffffff @@ -53,19 +53,24 @@ TEST_CASE("Stacking") { ncv = ncvisual_from_rgba(botv, 2, 4, 1); REQUIRE(nullptr != ncv); vopts.n = n_; - CHECK(n_ == ncvisual_render(nc_, ncv, &vopts)); + vopts.flags |= NCVISUAL_OPTION_CHILDPLANE; + auto newn = ncvisual_blit(nc_, ncv, &vopts); + REQUIRE(nullptr != newn); ncvisual_destroy(ncv); + ncplane_move_below(newn, top); CHECK(0 == notcurses_render(nc_)); uint64_t channels; auto egc = notcurses_at_yx(nc_, 0, 0, nullptr, &channels); REQUIRE(nullptr != egc); +notcurses_debug(nc_, stderr); // ought yield space with white background FIXME currently just yields // a lower half block CHECK(0 == strcmp("\u2584", egc)); CHECK(0xffffff == ncchannels_fg_rgb(channels)); CHECK(0xffffff == ncchannels_bg_rgb(channels)); - ncplane_destroy(top); + CHECK(0 == ncplane_destroy(top)); + CHECK(0 == ncplane_destroy(newn)); } SUBCASE("UpperAtopLowerWhite") { @@ -83,7 +88,7 @@ TEST_CASE("Stacking") { .leny = 2, .lenx = 1, .blitter = NCBLIT_2x1, .flags = 0, .transcolor = 0, .pxoffy = 0, .pxoffx = 0, }; - CHECK(top == ncvisual_render(nc_, ncv, &vopts)); + CHECK(top == ncvisual_blit(nc_, ncv, &vopts)); ncvisual_destroy(ncv); // create an ncvisual of 2 rows, 1 column, with the bottom 0xffffff @@ -91,8 +96,11 @@ TEST_CASE("Stacking") { ncv = ncvisual_from_rgba(botv, 2, 4, 1); REQUIRE(nullptr != ncv); vopts.n = n_; - CHECK(n_ == ncvisual_render(nc_, ncv, &vopts)); + vopts.flags |= NCVISUAL_OPTION_CHILDPLANE; + auto newn = ncvisual_blit(nc_, ncv, &vopts); + REQUIRE(nullptr != newn); ncvisual_destroy(ncv); + ncplane_move_below(newn, top); CHECK(0 == notcurses_render(nc_)); uint64_t channels; @@ -103,7 +111,8 @@ TEST_CASE("Stacking") { CHECK(0 == strcmp("\u2580", egc)); CHECK(0xffffff == ncchannels_fg_rgb(channels)); CHECK(0xffffff == ncchannels_bg_rgb(channels)); - ncplane_destroy(top); + CHECK(0 == ncplane_destroy(top)); + CHECK(0 == ncplane_destroy(newn)); } SUBCASE("StackedQuadHalves") { @@ -122,7 +131,7 @@ TEST_CASE("Stacking") { .leny = 2, .lenx = 2, .blitter = NCBLIT_2x2, .flags = 0, .transcolor = 0, .pxoffy = 0, .pxoffx = 0, }; - CHECK(top == ncvisual_render(nc_, ncv, &vopts)); + CHECK(top == ncvisual_blit(nc_, ncv, &vopts)); ncvisual_destroy(ncv); // create an ncvisual of 2 rows, 2 columns, with the bottom 0xffffff @@ -130,8 +139,11 @@ TEST_CASE("Stacking") { ncv = ncvisual_from_rgba(botv, 2, 8, 2); REQUIRE(nullptr != ncv); vopts.n = n_; - CHECK(n_ == ncvisual_render(nc_, ncv, &vopts)); + vopts.flags = NCVISUAL_OPTION_CHILDPLANE; + auto newn = ncvisual_blit(nc_, ncv, &vopts); + REQUIRE(nullptr != newn); ncvisual_destroy(ncv); + ncplane_move_below(newn, top); CHECK(0 == notcurses_render(nc_)); uint64_t channels; @@ -142,7 +154,8 @@ TEST_CASE("Stacking") { CHECK(0 == strcmp("\u2580", egc)); CHECK(0x00ff00 == ncchannels_fg_rgb(channels)); CHECK(0x00ff00 == ncchannels_bg_rgb(channels)); - ncplane_destroy(top); + CHECK(0 == ncplane_destroy(top)); + CHECK(0 == ncplane_destroy(newn)); } } @@ -164,7 +177,7 @@ TEST_CASE("Stacking") { .leny = 2, .lenx = 2, .blitter = NCBLIT_2x2, .flags = 0, .transcolor = 0, .pxoffy = 0, .pxoffx = 0, }; - CHECK(top == ncvisual_render(nc_, ncv, &vopts)); + CHECK(top == ncvisual_blit(nc_, ncv, &vopts)); ncvisual_destroy(ncv); // create an ncvisual of 2 rows, 2 columns, with the tr, bl 0xffffff @@ -172,8 +185,11 @@ TEST_CASE("Stacking") { ncv = ncvisual_from_rgba(botv, 2, 8, 2); REQUIRE(nullptr != ncv); vopts.n = n_; - CHECK(n_ == ncvisual_render(nc_, ncv, &vopts)); + vopts.flags = NCVISUAL_OPTION_CHILDPLANE; + auto newn = ncvisual_blit(nc_, ncv, &vopts); + REQUIRE(nullptr != newn); ncvisual_destroy(ncv); + ncplane_move_below(newn, top); CHECK(0 == notcurses_render(nc_)); uint64_t channels; @@ -184,7 +200,8 @@ TEST_CASE("Stacking") { CHECK(0 == strcmp("\u259a", egc)); // quadrant upper left and lower right CHECK(0xffffff == ncchannels_fg_rgb(channels)); CHECK(0xffffff == ncchannels_bg_rgb(channels)); - ncplane_destroy(top); + CHECK(0 == ncplane_destroy(top)); + CHECK(0 == ncplane_destroy(newn)); } }