From 2dd32c7adb7116f1ad9ab2632d9fcf57a31e9fa2 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 21 Nov 2011 08:44:10 +0000 Subject: Improve API to allow for RAM surfaces instead of direct blitting Improve and update tests Fix RAM surface Fix VNC surface svn path=/trunk/libnsfb/; revision=13158 --- test/Makefile | 2 +- test/bezier.c | 55 ++++++++++++++---- test/bitmap.c | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/frontend.c | 52 ++++++++++++----- test/path.c | 59 +++++++++++++++---- test/plottest.c | 106 ++++++++++++++++++++++++----------- test/polygon.c | 55 ++++++++++++++---- test/polystar.c | 56 +++++++++++++++---- test/polystar2.c | 56 +++++++++++++++---- test/runtest.sh | 17 +++--- 10 files changed, 518 insertions(+), 108 deletions(-) create mode 100644 test/bitmap.c (limited to 'test') diff --git a/test/Makefile b/test/Makefile index b2320e3..7f2d40e 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,3 +1,3 @@ -DIR_TEST_ITEMS := plottest:plottest.c;nsglobe.c frontend:frontend.c bezier:bezier.c path:path.c polygon:polygon.c polystar:polystar.c polystar2:polystar2.c +DIR_TEST_ITEMS := plottest:plottest.c bitmap:bitmap.c;nsglobe.c frontend:frontend.c bezier:bezier.c path:path.c polygon:polygon.c polystar:polystar.c polystar2:polystar2.c include build/makefiles/Makefile.subdir diff --git a/test/bezier.c b/test/bezier.c index d686349..630c4a8 100644 --- a/test/bezier.c +++ b/test/bezier.c @@ -13,8 +13,12 @@ int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; nsfb_event_t event; + int waitloop = 3; + nsfb_bbox_t box; nsfb_bbox_t box2; uint8_t *fbptr; @@ -24,25 +28,35 @@ int main(int argc, char **argv) int loop; nsfb_plot_pen_t pen; - UNUSED(argc); - UNUSED(argv); + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); /* claim the whole screen for update */ nsfb_claim(nsfb, &box); @@ -115,8 +129,29 @@ int main(int argc, char **argv) nsfb_update(nsfb, &box); - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/bitmap.c b/test/bitmap.c new file mode 100644 index 0000000..b14f2f6 --- /dev/null +++ b/test/bitmap.c @@ -0,0 +1,168 @@ +/* libnsfb plotter test program */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "libnsfb.h" +#include "libnsfb_plot.h" +#include "libnsfb_event.h" + +#define UNUSED(x) ((x) = (x)) + +extern const struct { + unsigned int width; + unsigned int height; + unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ + unsigned char pixel_data[132 * 135 * 4 + 1]; +} nsglobe; + +static bool +dump(nsfb_t *nsfb, const char *filename) +{ + int fd; + + if (filename == NULL) + return false; + + fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU); + if (fd < 0) + return false; + + nsfb_dump(nsfb, fd); + + close(fd); + + return true; +} + +int main(int argc, char **argv) +{ + const char *fename; + enum nsfb_type_e fetype; + nsfb_t *nsfb; + nsfb_t *bmp; + nsfb_event_t event; + int waitloop = 3; + + nsfb_bbox_t box; + nsfb_bbox_t box2; + nsfb_bbox_t box3; + uint8_t *fbptr; + int fbstride; + const char *dumpfile = NULL; + + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + if (argc >= 3) { + dumpfile = argv[2]; + } + } + + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); + return 1; + } + + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); + return 2; + } + + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + + + bmp = nsfb_new(NSFB_SURFACE_RAM); + nsfb_set_geometry(bmp, nsglobe.width, nsglobe.height, NSFB_FMT_ABGR8888); + nsfb_init(bmp); + nsfb_get_buffer(bmp, &fbptr, &fbstride); + + memcpy(fbptr, nsglobe.pixel_data, nsglobe.width * nsglobe.height * 4); + + /* get the geometry of the whole screen */ + box.x0 = box.y0 = 0; + nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); + + /* claim the whole screen for update */ + nsfb_claim(nsfb, &box); + + nsfb_plot_clg(nsfb, 0xffffffff); + + box3.x0 = 0; + box3.y0 = 0; + box3.x1 = 132; + box3.y1 = 135; + + nsfb_plot_copy(bmp, &box3, nsfb, &box3); + + box3.x0 = 132; + box3.y0 = 135; + box3.x1 = box3.x0 + 264; + box3.y1 = box3.y0 + 135; + + nsfb_plot_copy(bmp, &box3, nsfb, &box3); + + box3.x0 = 396; + box3.y0 = 270; + box3.x1 = box3.x0 + 264; + box3.y1 = box3.y0 + 270; + + nsfb_plot_copy(bmp, &box3, nsfb, &box3); + + box2.x0 = 64; + box2.y0 = 64; + box2.x1 = 128; + box2.y1 = 128; + + box3.x0 = 270; + box3.y0 = 270; + box3.x1 = box3.x0 + 64; + box3.y1 = box3.y0 + 64; + + nsfb_plot_copy(nsfb, &box2, nsfb, &box3); + + nsfb_update(nsfb, &box); + + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + dump(nsfb, dumpfile); + + nsfb_free(bmp); + + nsfb_free(nsfb); + + return 0; +} + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/frontend.c b/test/frontend.c index 3d72229..5cf0651 100644 --- a/test/frontend.c +++ b/test/frontend.c @@ -4,12 +4,16 @@ #include #include "libnsfb.h" +#include "libnsfb_event.h" int main(int argc, char **argv) { nsfb_t *nsfb; const char *fename; - enum nsfb_frontend_e fetype; + enum nsfb_type_e fetype; + nsfb_event_t event; + + int waitloop = 3; if (argc < 2) { fename="sdl"; @@ -17,32 +21,52 @@ int main(int argc, char **argv) fename = argv[1]; } - fetype = nsfb_frontend_from_name(fename); - if (fetype == NSFB_FRONTEND_NONE) { - fprintf(stderr, "Unable to initialise nsfb with %s frontend\n", fename); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - nsfb = nsfb_init(fetype); + nsfb = nsfb_new(fetype); if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with %s frontend\n", fename); + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } - if (nsfb_set_geometry(nsfb, 0, 0, 32) == -1) { - fprintf(stderr, "Unable to set geometry\n"); - nsfb_finalise(nsfb); + if (nsfb_set_geometry(nsfb, 0, 0, NSFB_FMT_ANY) == -1) { + fprintf(stderr, "Unable to set surface geometry\n"); + nsfb_free(nsfb); return 3; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); - nsfb_finalise(nsfb); + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); return 4; } - sleep(2); + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } - nsfb_finalise(nsfb); + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/path.c b/test/path.c index 16a8ce2..7f1c6d1 100644 --- a/test/path.c +++ b/test/path.c @@ -39,7 +39,12 @@ static int fill_shape(nsfb_plot_pathop_t *path, int xoff, int yoff) int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; + + int waitloop = 3; + nsfb_event_t event; nsfb_bbox_t box; uint8_t *fbptr; @@ -47,25 +52,35 @@ int main(int argc, char **argv) nsfb_plot_pen_t pen; nsfb_plot_pathop_t path[20]; - UNUSED(argc); - UNUSED(argv); + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); /* claim the whole screen for update */ nsfb_claim(nsfb, &box); @@ -87,11 +102,31 @@ int main(int argc, char **argv) nsfb_plot_path(nsfb, fill_shape(path, 100, 350), path, &pen); - nsfb_update(nsfb, &box); - - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/plottest.c b/test/plottest.c index 74134c4..a4cde36 100644 --- a/test/plottest.c +++ b/test/plottest.c @@ -1,8 +1,12 @@ -/* libnsfb plotetr test program */ +/* libnsfb plotter test program */ #include #include #include +#include +#include +#include +#include #include "libnsfb.h" #include "libnsfb_plot.h" @@ -10,13 +14,6 @@ #define UNUSED(x) ((x) = (x)) -extern const struct { - unsigned int width; - unsigned int height; - unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ - unsigned char pixel_data[132 * 135 * 4 + 1]; -} nsglobe; - const struct { unsigned int w; unsigned int h; @@ -67,11 +64,34 @@ const struct { } }; + +static bool +dump(nsfb_t *nsfb, const char *filename) +{ + int fd; + + if (filename == NULL) + return false; + + fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU); + if (fd < 0) + return false; + + nsfb_dump(nsfb, fd); + + close(fd); + + return true; +} + int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; - int bpp; nsfb_event_t event; + int waitloop = 3; + nsfb_bbox_t box; nsfb_bbox_t box2; nsfb_bbox_t box3; @@ -80,37 +100,40 @@ int main(int argc, char **argv) int p[] = { 300,300, 350,350, 400,300, 450,250, 400,200}; int loop; nsfb_plot_pen_t pen; + const char *dumpfile = NULL; if (argc < 2) { - bpp = 32; + fename="sdl"; } else { - bpp = atoi(argv[1]); - if (bpp == 0) - bpp = 32; + fename = argv[1]; + if (argc >= 3) { + dumpfile = argv[2]; + } } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_set_geometry(nsfb, 0, 0, bpp) == -1) { - fprintf(stderr, "Unable to set geometry\n"); - nsfb_finalise(nsfb); - return 3; + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); + return 2; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); - return 2; + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; } /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); /* claim the whole screen for update */ nsfb_claim(nsfb, &box); @@ -219,14 +242,7 @@ int main(int argc, char **argv) box3.x1 = 700; box3.y1 = 300; - nsfb_plot_copy(nsfb, &box2, &box3); - - box3.x0 = 50; - box3.x1 = 200; - box3.y0 = 300; - box3.y1 = 500; - - nsfb_plot_bitmap(nsfb, &box3, (nsfb_colour_t *)nsglobe.pixel_data, nsglobe.width, nsglobe.height, nsglobe.width, true); + nsfb_plot_copy(nsfb, &box2, nsfb, &box3); /* test glyph plotting */ for (loop = 100; loop < 200; loop+= Mglyph1.w) { @@ -270,9 +286,31 @@ int main(int argc, char **argv) nsfb_update(nsfb, &box2); } + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + dump(nsfb, dumpfile); + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/polygon.c b/test/polygon.c index cd7efd8..e91846f 100644 --- a/test/polygon.c +++ b/test/polygon.c @@ -14,8 +14,12 @@ int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; nsfb_event_t event; + int waitloop = 3; + nsfb_bbox_t box; uint8_t *fbptr; int fbstride; @@ -26,25 +30,35 @@ int main(int argc, char **argv) int loop; // nsfb_plot_pen_t pen; - UNUSED(argc); - UNUSED(argv); + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); /* claim the whole screen for update */ nsfb_claim(nsfb, &box); @@ -72,8 +86,29 @@ int main(int argc, char **argv) nsfb_update(nsfb, &box); - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/polystar.c b/test/polystar.c index 6963cfb..c71ba41 100644 --- a/test/polystar.c +++ b/test/polystar.c @@ -24,7 +24,12 @@ static void sleepMilli(long ms) int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; + + int waitloop = 3; + nsfb_event_t event; nsfb_bbox_t box; uint8_t *fbptr; @@ -38,25 +43,35 @@ int main(int argc, char **argv) double rotate; - UNUSED(argc); - UNUSED(argv); + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); pen.stroke_colour = 0xff000000; @@ -99,8 +114,29 @@ int main(int argc, char **argv) sleepMilli(100); } - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/polystar2.c b/test/polystar2.c index 479a45b..afff5a0 100644 --- a/test/polystar2.c +++ b/test/polystar2.c @@ -25,7 +25,12 @@ static void sleepMilli(long ms) int main(int argc, char **argv) { + const char *fename; + enum nsfb_type_e fetype; nsfb_t *nsfb; + + int waitloop = 3; + nsfb_event_t event; nsfb_bbox_t box; uint8_t *fbptr; @@ -38,24 +43,34 @@ int main(int argc, char **argv) int counter; int colour; - UNUSED(argc); - UNUSED(argv); + if (argc < 2) { + fename="sdl"; + } else { + fename = argv[1]; + } - nsfb = nsfb_init(NSFB_FRONTEND_SDL); - if (nsfb == NULL) { - fprintf(stderr, "Unable to initialise nsfb with SDL frontend\n"); + fetype = nsfb_type_from_name(fename); + if (fetype == NSFB_SURFACE_NONE) { + fprintf(stderr, "Unable to convert \"%s\" to nsfb surface type\n", fename); return 1; } - if (nsfb_init_frontend(nsfb) == -1) { - fprintf(stderr, "Unable to initialise nsfb frontend\n"); + nsfb = nsfb_new(fetype); + if (nsfb == NULL) { + fprintf(stderr, "Unable to allocate \"%s\" nsfb surface\n", fename); return 2; } + if (nsfb_init(nsfb) == -1) { + fprintf(stderr, "Unable to initialise nsfb surface\n"); + nsfb_free(nsfb); + return 4; + } + /* get the geometry of the whole screen */ box.x0 = box.y0 = 0; nsfb_get_geometry(nsfb, &box.x1, &box.y1, NULL); - nsfb_get_framebuffer(nsfb, &fbptr, &fbstride); + nsfb_get_buffer(nsfb, &fbptr, &fbstride); radius = (box.x1 / 3); sides = 5; @@ -92,8 +107,29 @@ int main(int argc, char **argv) sleepMilli(400); } - while (event.type != NSFB_EVENT_CONTROL) - nsfb_event(nsfb, &event, -1); + /* wait for quit event or timeout */ + while (waitloop > 0) { + if (nsfb_event(nsfb, &event, 1000) == false) { + break; + } + if (event.type == NSFB_EVENT_CONTROL) { + if (event.value.controlcode == NSFB_CONTROL_TIMEOUT) { + /* timeout */ + waitloop--; + } else if (event.value.controlcode == NSFB_CONTROL_QUIT) { + break; + } + } + } + + nsfb_free(nsfb); return 0; } + +/* + * Local variables: + * c-basic-offset: 4 + * tab-width: 8 + * End: + */ diff --git a/test/runtest.sh b/test/runtest.sh index f2eb0a4..5d131ab 100755 --- a/test/runtest.sh +++ b/test/runtest.sh @@ -2,11 +2,14 @@ TEST_PATH=$1 -${TEST_PATH}/test_frontend -${TEST_PATH}/test_plottest -${TEST_PATH}/test_bezier -${TEST_PATH}/test_path -${TEST_PATH}/test_polygon -${TEST_PATH}/test_polystar -${TEST_PATH}/test_polystar2 +TEST_FRONTEND=x + +${TEST_PATH}/test_frontend ${TEST_FRONTEND} +${TEST_PATH}/test_plottest ${TEST_FRONTEND} +${TEST_PATH}/test_bitmap ${TEST_FRONTEND} +${TEST_PATH}/test_bezier ${TEST_FRONTEND} +${TEST_PATH}/test_path ${TEST_FRONTEND} +${TEST_PATH}/test_polygon ${TEST_FRONTEND} +${TEST_PATH}/test_polystar ${TEST_FRONTEND} +${TEST_PATH}/test_polystar2 ${TEST_FRONTEND} -- cgit v1.2.3