2019-11-25 03:22:18 +00:00
|
|
|
#include "main.h"
|
2020-05-04 15:05:52 +00:00
|
|
|
#include <vector>
|
2019-11-25 03:22:18 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("Multimedia") {
|
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
return;
|
2019-11-25 03:22:18 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.inhibit_alternate_screen = true;
|
2019-12-28 23:37:44 +00:00
|
|
|
nopts.suppress_banner = true;
|
2019-12-27 22:20:20 +00:00
|
|
|
FILE* outfp_ = fopen("/dev/tty", "wb");
|
|
|
|
REQUIRE(outfp_);
|
|
|
|
notcurses* nc_ = notcurses_init(&nopts, outfp_);
|
|
|
|
REQUIRE(nc_);
|
|
|
|
ncplane* ncp_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(ncp_);
|
2019-11-25 03:22:18 +00:00
|
|
|
|
2020-04-23 11:09:54 +00:00
|
|
|
#ifndef USE_MULTIMEDIA
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("LibavDisabled"){
|
|
|
|
REQUIRE(!notcurses_canopen(nc_));
|
|
|
|
}
|
2019-12-27 10:13:29 +00:00
|
|
|
#else
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("LibavEnabled"){
|
|
|
|
REQUIRE(notcurses_canopen(nc_));
|
|
|
|
}
|
2019-12-27 10:13:29 +00:00
|
|
|
|
2020-01-15 17:06:35 +00:00
|
|
|
SUBCASE("LoadImageCreatePlane") {
|
2020-04-24 06:23:06 +00:00
|
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
2020-01-15 17:06:35 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
2020-05-04 08:55:10 +00:00
|
|
|
auto ncv = ncvisual_from_file(nc_, find_data("changes.jpg"), &ncerr, 0, 0, NCSCALE_STRETCH);
|
2020-01-15 17:06:35 +00:00
|
|
|
REQUIRE(ncv);
|
2020-04-24 06:23:06 +00:00
|
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
|
|
ncerr = ncvisual_decode(ncv);
|
|
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
|
|
CHECK(dimx == frame->width); FIXME */
|
2020-03-24 22:43:10 +00:00
|
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
2020-01-15 17:06:35 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
2020-04-24 04:04:23 +00:00
|
|
|
CHECK(NCERR_EOF == ncerr);
|
2020-01-15 17:06:35 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("LoadImage") {
|
2020-04-24 05:26:29 +00:00
|
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
2019-12-27 22:20:20 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
2020-04-24 04:04:23 +00:00
|
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("changes.jpg"), &ncerr);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(ncv);
|
2020-04-24 04:04:23 +00:00
|
|
|
REQUIRE(0 == ncerr);
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
|
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
|
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
|
|
CHECK(dimx == frame->width); FIXME */
|
2020-03-24 22:43:10 +00:00
|
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
2020-04-24 04:04:23 +00:00
|
|
|
CHECK(NCERR_EOF == ncerr);
|
2019-12-27 22:20:20 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
}
|
2019-12-27 10:13:29 +00:00
|
|
|
|
2020-01-15 17:22:10 +00:00
|
|
|
SUBCASE("PlaneDuplicate") {
|
2020-04-24 05:26:29 +00:00
|
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
2019-12-27 22:20:20 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
2020-04-24 04:04:23 +00:00
|
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("changes.jpg"), &ncerr);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(ncv);
|
2020-04-24 05:26:29 +00:00
|
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
2020-04-24 05:26:29 +00:00
|
|
|
REQUIRE(NCERR_SUCCESS == ncerr);
|
2020-04-24 06:23:06 +00:00
|
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
|
|
CHECK(dimx == frame->width); FIXME */
|
2020-03-24 22:43:10 +00:00
|
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
2020-01-15 17:22:10 +00:00
|
|
|
void* needle = malloc(1);
|
|
|
|
REQUIRE(nullptr != needle);
|
|
|
|
struct ncplane* newn = ncplane_dup(ncvisual_plane(ncv), needle);
|
|
|
|
int ndimx, ndimy;
|
|
|
|
REQUIRE(nullptr != newn);
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
ncplane_erase(ncp_);
|
|
|
|
// should still have the image
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-01-15 17:22:10 +00:00
|
|
|
ncplane_dim_yx(newn, &ndimy, &ndimx);
|
|
|
|
CHECK(ndimy == dimy);
|
|
|
|
CHECK(ndimx == dimx);
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("LoadVideo") {
|
2020-04-24 05:26:29 +00:00
|
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
2020-01-15 17:22:10 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
2020-04-29 01:23:36 +00:00
|
|
|
auto ncv = ncplane_visual_open(ncp_, find_data("notcursesI.avi"), &ncerr);
|
2020-01-15 17:22:10 +00:00
|
|
|
REQUIRE(ncv);
|
2020-04-24 05:26:29 +00:00
|
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
2020-01-15 17:22:10 +00:00
|
|
|
for(;;){ // run at the highest speed we can
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
|
|
|
if(NCERR_EOF == ncerr){
|
2020-01-15 17:22:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2020-04-24 06:23:06 +00:00
|
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
|
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
|
|
CHECK(dimx == frame->width); FIXME */
|
2020-03-24 22:43:10 +00:00
|
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
2020-01-15 17:22:10 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
}
|
2019-11-27 01:19:16 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("LoadVideoCreatePlane") {
|
2020-04-24 05:26:29 +00:00
|
|
|
nc_err_e ncerr = NCERR_SUCCESS;
|
2019-12-27 22:20:20 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
2020-05-04 08:55:10 +00:00
|
|
|
auto ncv = ncvisual_from_file(nc_, find_data("notcursesI.avi"), &ncerr, 0, 0, NCSCALE_STRETCH);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(ncv);
|
2020-04-24 05:26:29 +00:00
|
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
2020-04-24 06:23:06 +00:00
|
|
|
ncerr = ncvisual_decode(ncv);
|
2020-04-24 05:26:29 +00:00
|
|
|
CHECK(NCERR_SUCCESS == ncerr);
|
2020-04-24 06:23:06 +00:00
|
|
|
/*CHECK(dimy * 2 == frame->height);
|
|
|
|
CHECK(dimx == frame->width); FIXME */
|
2020-03-24 22:43:10 +00:00
|
|
|
CHECK(0 < ncvisual_render(ncv, 0, 0, -1, -1));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
}
|
|
|
|
#endif
|
Per-line damage map, ~50% increase in FPS on notcurses-demo (#144)
Implement a fairly conservative, line-granularity, two-level damage map. One on the overall notcurses object is dirtied by planar moves, creations, deletions, and resizes. One on each ncplane is dirtied by glyph output, media rendering, fades, and erasure. #83 This has some definite false positives: a hidden plane which moves will damage a bunch of lines unnecessarily. For now, don't do things like that :D.
Extra byte per line per plane, shouldn't be a problem.
Two new stats for cell elisions and emissions
Allow keypress to interrupt view-demo
ncvisual_stream() now allows a callback per frame
Allow ncvisual_open() to create its own, perfectly-sized, ncplane #128
Typical performance prior to this PR:
4655 renders, 18.3s total (0.000305s min, 0.196s max, 0.0039s avg 253.9 fps)
401046.505KB total (9.688KB min, 139.697KB max, 86.15KB avg)
Emits/elides: def 1082115/116196 fg 10547624/7236460 bg 10602717/6208644
Elide rates: 9.70% 40.69% 36.93%
4680 renders, 18.4s total (0.000285s min, 0.15s max, 0.0039s avg 255.0 fps)
403078.188KB total (9.688KB min, 139.697KB max, 86.13KB avg)
Emits/elides: def 1088994/116196 fg 10604983/7267750 bg 10655426/6237472
Elide rates: 9.64% 40.66% 36.92%
4699 renders, 17.8s total (0.000227s min, 0.192s max, 0.0038s avg 263.8 fps)
403266.907KB total (9.688KB min, 139.697KB max, 85.82KB avg)
Emits/elides: def 1086511/116196 fg 10601709/7359116 bg 10661910/6326744
Elide rates: 9.66% 40.97% 37.24%
After this PR:
5625 renders, 15s total (9.36e-05s min, 0.187s max, 0.0027s avg 375.2 fps)
168365.640KB total (0.930KB min, 139.600KB max, 29.93KB avg)
Emits/elides: def 310575/116196 fg 4486002/4473416 bg 4116835/4630666
Elide rates: 27.23% 49.93% 52.94%
Cells emitted; 9928000 elided: 12572000 (55.88%)
5642 renders, 14.2s total (9.17e-05s min, 0.154s max, 0.0025s avg 397.0 fps)
168669.009KB total (0.605KB min, 139.600KB max, 29.90KB avg)
Emits/elides: def 310819/116196 fg 4499833/4482134 bg 4118562/4652470
Elide rates: 27.21% 49.90% 53.04%
Cells emitted; 9962160 elided: 12605840 (55.86%)
5650 renders, 14.3s total (0.000118s min, 0.143s max, 0.0025s avg 395.7 fps)
169461.884KB total (0.860KB min, 139.600KB max, 29.99KB avg)
Emits/elides: def 305431/116196 fg 4515396/4456376 bg 4149967/4613668
Elide rates: 27.56% 49.67% 52.65%
Cells emitted; 9945200 elided: 12654800 (55.99%)
on netcurses-demo, we're eliding about half of the total cells via this damage map. that's pretty fucking sweet! FPS increase of about 50% -- I'll take that any day of the fuckin' week, boyo. w00t!
https://www.youtube.com/watch?v=XbGs_qK2PQA
2019-12-15 18:46:47 +00:00
|
|
|
|
2020-05-04 15:05:52 +00:00
|
|
|
SUBCASE("LoadRGBAFromMemory") {
|
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
|
|
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
|
|
|
auto ncv = ncvisual_from_rgba(nc_, rgba.data(), dimy * 2, dimx * 4, dimx);
|
|
|
|
REQUIRE(ncv);
|
|
|
|
CHECK(dimx * dimy == ncvisual_render(ncv, 0, 0, -1, -1));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("LoadBGRAFromMemory") {
|
|
|
|
int dimy, dimx;
|
|
|
|
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
|
|
|
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
|
|
|
auto ncv = ncvisual_from_bgra(nc_, rgba.data(), dimy * 2, dimx * 4, dimx);
|
|
|
|
REQUIRE(ncv);
|
|
|
|
CHECK(dimx * dimy == ncvisual_render(ncv, 0, 0, -1, -1));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncvisual_destroy(ncv);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(!notcurses_stop(nc_));
|
|
|
|
CHECK(!fclose(outfp_));
|
2019-11-25 03:22:18 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|