static void testcase7(const char *desc) { int err; ggi_visual_t vis; ggi_mode mode; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); /* sync mode enables mansync if used */ /* Get the default mode */ err = ggiCheckGraphMode (vis, 640, 480, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode); if (err != GGI_OK) { printfailure("ggiCheckGraphMode: #1: No 640x480 mode available\n"); ggiClose(vis); ggiExit(); return; } err = ggiSetMode(vis, &mode); if (err != GGI_OK) { printfailure("ggiSetMode() #1: failed although ggiCheckGraphMode() was OK!\n"); ggiClose(vis); ggiExit(); return; } err = ggiCheckGraphMode(vis, 320, 200, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode); if (err != GGI_OK) { printfailure("ggiCheckGraphMode: #2: No 320x200 mode available\n"); ggiClose(vis); ggiExit(); return; } err = ggiSetMode(vis, &mode); if (err != GGI_OK) { printfailure("ggiSetMode() #2: resetting a mode failed although ggiCheckGraphMode() was OK!\n"); ggiClose(vis); ggiExit(); return; } ggiClose(vis); ggiExit(); printsuccess(); return; }
static void testcase5(const char *desc) { int err; ggi_visual_t vis; ggi_mode sug_mode, final_mode; int visible_w, visible_h; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); ggiSetFlags(vis, GGIFLAG_ASYNC); /* Get the default mode */ err = ggiCheckGraphMode (vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &sug_mode); if (err != GGI_OK) { printfailure("ggiCheckGraphMode: No graphic mode available\n"); ggiClose(vis); ggiExit(); return; } visible_w = sug_mode.visible.x; visible_h = sug_mode.visible.y; err = ggiCheckGraphMode(vis, visible_w, visible_h, visible_w, visible_h*2, GT_AUTO, &final_mode); if (!err) { /* actually print an info output */ printassert(0 == 1, "Info: Applications may assume now," " panning via ggiSetOrigin() is available\n"); /* Note, Applications have no other way to figure out if * ggiSetOrigin() is available or not */ } else { final_mode = sug_mode; } err = ggiSetMode(vis, &final_mode); if (err) { printfailure("ggiSetMode() failed although ggiCheckGraphMode() was OK!\n"); ggiClose(vis); ggiExit(); } ggiClose(vis); ggiExit(); printsuccess(); return; }
static void testcase1(const char *desc) { ggi_visual_t vis; ggi_color green, back; int err; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_8BIT); if(err < 0) { printassert(0, "Palettized mode not available.\n"); printsuccess(); ggiClose(vis); ggiExit(); return; } green.r = 100; green.g = 40000; green.b = 4000; err = ggiSetPalette(vis, GGI_PALETTE_DONTCARE, 1, &green); if (err < 0) { printfailure("Unable to install colormap with one entry.\n"); ggiClose(vis); ggiExit(); return; } printassert(err == (int)ggiMapColor(vis, &green), "ggiMapColor inconsistent with retval of ggiSetPalette.\n"); ggiUnmapPixel(vis, err, &back); if(green.r != back.r || green.g != back.g || green.b != back.b) { printfailure("Unexpected color from ggiUnmapPixel.\n"); ggiClose(vis); ggiExit(); return; } ggiSetGCForeground(vis, err); ggiDrawBox(vis, 0, 0, 3000, 3000); ggiFlush(vis); /* You should see a green square, how to test this? */ ggUSleep(5000000); printsuccess(); ggiClose(vis); ggiExit(); }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowPosition(0, 0); glutInitWindowSize(300, 300); glutCreateWindow("asc-view"); init(); glutDisplayFunc(draw); glutReshapeFunc(reshape); glutKeyboardFunc(key); glutSpecialFunc(special); glutVisibilityFunc(visible); glutMainLoop(); #if 0 GLuint l; char *file; int maxframes=0; double len; Init(); file=(argc>1) ? argv[1] : "asc/box.asc"; if (argc>2) maxframes=atoi(argv[2]); if (argc==1) { printf("usage: %s filename.asc\n",argv[0]); } LoadAsc(&l,file); len=Display(l,&maxframes); printf("\ttime: %.3f sec\n",len); printf("\tframes: %i\n",maxframes); printf("\tfps: %.3f \n",(double)maxframes/len); GGIMesaDestroyContext(ctx); ggiClose(vis); ggiClose(vis_mem); ggiExit(); #endif return 0; }
static int GGIclose_monotext(struct ggi_visual *vis, struct ggi_dlhandle *dlh) { ggi_palemu_priv *priv = PALEMU_PRIV(vis); struct gg_api *api; DPRINT("display-monotext: GGIclose start.\n"); if (priv->fb_ptr != NULL) { _ggi_monotext_Close(vis); free(priv->fb_ptr); } if (priv->parent != NULL) { ggiClose(priv->parent); ggiDetach(priv->parent); /* XXX What if gii has been detached before close? */ api = ggGetAPIByName("gii"); if (api && STEM_HAS_API(priv->parent, api)) { ggDetach(api, priv->parent); } ggDelStem(priv->parent); priv->parent = NULL; } ggLockDestroy(priv->flush_lock); free(priv->opmansync); free(priv); free(LIBGGI_GC(vis)); DPRINT("display-monotext: GGIclose done.\n"); return 0; }
static void uninit(void) { if (ggi_conf.driver) free(ggi_conf.driver); #ifdef HAVE_GGIWMH ggiWmhDetach(ggi_conf.vis); ggiWmhExit(); #endif if (ggi_conf.drawvis != NULL && ggi_conf.drawvis != ggi_conf.vis) ggiClose(ggi_conf.drawvis); ggiClose(ggi_conf.vis); ggiExit(); }
static void testcase2(const char *desc) { int err; ggi_visual_t vis; ggi_mode mode; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode); err = ggiSetMode(vis, &mode); if (err != GGI_OK) { printfailure("ggiSetMode: expected return value: GGI_OK\n" "actual return value: %i\n", err); return; } ggiClose(vis); ggiExit(); printsuccess(); return; }
/* XImage allocation for normal client-side buffer */ void _ggi_x_freefb(struct ggi_visual *vis) { ggi_x_priv *priv = GGIX_PRIV(vis); if (priv->slave) { struct gg_stem *stem = priv->slave->instance.stem; ggiClose(priv->slave->instance.stem); ggDelStem(stem); priv->slave = NULL; } if (priv->ximage) { #ifndef HAVE_XINITIMAGE XFree(priv->ximage); #else free(priv->ximage); #endif priv->ximage = NULL; } if (priv->fb) { free(priv->fb); priv->fb = NULL; } LIB_ASSERT(priv->slave == NULL, "priv->slave: wild pointer\n"); LIB_ASSERT(priv->ximage == NULL, "priv->ximage: wild pointer\n"); LIB_ASSERT(priv->fb == NULL, "priv->fb: wild pointer\n"); _ggi_free_dbs(vis); }
void gr_close () { if (gr_installed==1) { ggiClose(screenvis); ggiExit(); gr_installed = 0; free(grd_curscreen); } }
static void testcase8(const char *desc) { int err; ggi_visual_t vis; ggi_mode mode; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); mode.virt.x = mode.virt.y = GGI_AUTO; mode.visible.x = mode.visible.y = GGI_AUTO; mode.frames = GGI_AUTO; mode.graphtype = GT_AUTO; mode.dpp.x = mode.dpp.y = 1; mode.size.x = -19493; mode.size.y = 31831; /* Get the default mode */ ggiCheckMode(vis, &mode); err = ggiSetMode(vis, &mode); if (err != GGI_OK) { printfailure("ggiSetMode() failed even though ggiCheckMode() was called!\n"); ggiClose(vis); ggiExit(); return; } ggiClose(vis); ggiExit(); printsuccess(); return; }
static int GGI_Available(void) { ggi_visual_t *vis; vis = NULL; if (ggiInit() == 0) { vis = ggiOpen(NULL); if (vis != NULL) { ggiClose(vis); } } return (vis != NULL); }
static void close_connection(int abnormal) { if (abnormal) { fprintf(stderr, "Client vanished... connection closed.\n"); /* Only run once for now. */ quit = 1; } if (user) { tserver_close(user); user = NULL; ggiClose(vis); mode_up = 0; } }
static void handle_connection(void) { TeleUser *u; static int numcon=0; u = malloc(sizeof(TeleUser)); numcon++; fprintf(stderr, "Connection %d received.\n", numcon); if (user != NULL) { fprintf(stderr, "Connection refused.\n"); /* tserver_refuse() ??? */ if (tserver_open(&serv, u) == 0) { tserver_close(u); } return; } if (NULL == target_name) vis = ggiOpen(NULL); else vis = ggiOpen(target_name, NULL); if (vis == NULL) { fprintf(stderr, "teleserver: Couldn't open GGI visual.\n"); ggiExit(); exit(2); } if (tserver_open(&serv, u) < 0) { fprintf(stderr, "tserver_open < 0\n"); ggiClose(vis); return; } user = u; }
/* XImage allocation for normal client-side buffer */ static void _ggi_xshm_free_ximage(struct ggi_visual *vis) { ggi_x_priv *priv; XShmSegmentInfo *myshminfo; priv = GGIX_PRIV(vis); myshminfo = priv->priv; if (myshminfo == NULL) return; if (priv->slave) { struct gg_stem *stem = priv->slave->instance.stem; ggiClose(priv->slave->instance.stem); ggDelStem(stem); priv->slave = NULL; } if (priv->ximage) { XShmDetach(priv->disp, myshminfo); /* Seems OK to destroy image before fb for SHM */ XDestroyImage(priv->ximage); shmdt(myshminfo->shmaddr); /* shmid has already been removed, see below. */ priv->ximage = NULL; priv->fb = NULL; } if (priv->fb) { free(priv->fb); priv->fb = NULL; } LIB_ASSERT(priv->slave == NULL, "priv->slave: wild pointer\n"); LIB_ASSERT(priv->ximage == NULL, "priv->ximage: wild pointer\n"); LIB_ASSERT(priv->fb == NULL, "priv->fb: wild pointer\n"); free(myshminfo); priv->priv = NULL; _ggi_free_dbs(vis); }
SDL_Surface *GGI_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { ggi_mode mode = { 1, { GGI_AUTO, GGI_AUTO }, { GGI_AUTO, GGI_AUTO }, { 0, 0 }, GT_AUTO, { GGI_AUTO, GGI_AUTO } }; const ggi_directbuffer *db; ggi_color pal[256]; int err; fprintf(stderr, "GGI_SetVideoMode()\n"); mode.visible.x = mode.virt.x = width; mode.visible.y = mode.virt.y = height; /* Translate requested SDL bit depth into a GGI mode */ switch (bpp) { case 1: mode.graphtype = GT_1BIT; break; case 2: mode.graphtype = GT_2BIT; break; case 4: mode.graphtype = GT_4BIT; break; case 8: mode.graphtype = GT_8BIT; break; case 15: mode.graphtype = GT_15BIT; break; case 16: mode.graphtype = GT_16BIT; break; case 24: mode.graphtype = GT_24BIT; break; case 32: mode.graphtype = GT_32BIT; break; default: SDL_SetError("Unknown SDL bit depth, using GT_AUTO....\n"); mode.graphtype = GT_AUTO; } /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ ggiCheckMode(VIS, &mode); /* At this point we should have a valid mode - try to set it */ err = ggiSetMode(VIS, &mode); /* If we couldn't set _any_ modes, something is very wrong */ if (err) { SDL_SetError("Can't set a mode!\n"); ggiClose(VIS); ggiExit(); GGI_VideoQuit(NULL); } /* Set a palette for palletized modes */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(VIS); ggiGetPalette(VIS, 0, 1 << bpp, pal); } db = ggiDBGetBuffer(VIS, 0); /* Set up the new mode framebuffer */ current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE); current->w = mode.virt.x; current->h = mode.virt.y; current->pitch = db->buffer.plb.stride; current->pixels = db->read; /* Set the blit function */ this->UpdateRects = GGI_DirectUpdate; /* We're done */ return(current); }
int GGI_VideoInit(_THIS, SDL_PixelFormat *vformat) { ggi_mode mode = { 1, { GGI_AUTO, GGI_AUTO }, { GGI_AUTO, GGI_AUTO }, { 0, 0 }, GT_AUTO, { GGI_AUTO, GGI_AUTO } }; struct private_hwdata *priv; ggi_color pal[256], map[256]; const ggi_directbuffer *db; int err, num_bufs; ggi_pixel white, black; priv = SDL_malloc(sizeof(struct private_hwdata)); if (priv == NULL) { SDL_SetError("Unhandled GGI mode type!\n"); GGI_VideoQuit(NULL); } if (ggiInit() != 0) { SDL_SetError("Unable to initialize GGI!\n"); GGI_VideoQuit(NULL); } VIS = ggiOpen(NULL); if (VIS == NULL) { SDL_SetError("Unable to open default GGI visual!\n"); ggiExit(); GGI_VideoQuit(NULL); } ggiSetFlags(VIS, GGIFLAG_ASYNC); /* Validate mode, autodetecting any GGI_AUTO or GT_AUTO fields */ ggiCheckMode(VIS, &mode); /* At this point we should have a valid mode - try to set it */ err = ggiSetMode(VIS, &mode); /* If we couldn't set _any_ modes, something is very wrong */ if (err) { SDL_SetError("Can't set a mode!\n"); ggiClose(VIS); ggiExit(); GGI_VideoQuit(NULL); } /* Determine the current screen size */ this->info.current_w = mode.virt.x; this->info.current_h = mode.virt.y; /* Set a palette for palletized modes */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(VIS); ggiGetPalette(VIS, 0, 1 << vformat->BitsPerPixel, pal); } /* Now we try to get the DirectBuffer info, which determines whether * SDL can access hardware surfaces directly. */ num_bufs = ggiDBGetNumBuffers(VIS); if (num_bufs > 0) { db = ggiDBGetBuffer(VIS, 0); /* Only handle one DB for now */ vformat->BitsPerPixel = db->buffer.plb.pixelformat->depth; vformat->Rmask = db->buffer.plb.pixelformat->red_mask; vformat->Gmask = db->buffer.plb.pixelformat->green_mask; vformat->Bmask = db->buffer.plb.pixelformat->blue_mask; /* Fill in our hardware acceleration capabilities */ this->info.wm_available = 0; this->info.hw_available = 1; this->info.video_mem = db->buffer.plb.stride * mode.virt.y; } video_mode.x = 0; video_mode.y = 0; video_mode.w = mode.virt.x; video_mode.h = mode.virt.y; SDL_modelist[((vformat->BitsPerPixel + 7) / 8) - 1] = &video_mode; /* We're done! */ return(0); }
int main(int argc, char *argv[]) { int i; long binit, a_binit; long prev, curr; long aprev, acurr; fill_info(); binit = get_size(); a_binit = _get_ggi_alloced(); if (ggiInit() != 0) err("first ggiInit() failed!\n"); prev = get_size(); aprev = _get_ggi_alloced(); for (i=2; i <= 80; i++) { putchar('.'); fflush(stdout); ggiExit(); if (ggiInit() != 0) err("ggiInit() number %d failed\n", i); } curr = get_size(); acurr = _get_ggi_alloced(); inform_mem("\nggiInit()\n", prev, curr, aprev, acurr); if ((vis = ggiOpen(NULL)) == NULL) err("first ggiOpen() failed!\n"); prev = get_size(); aprev = _get_ggi_alloced(); for (i=2; i < 20; i++) { putchar('.'); fflush(stdout); ggiClose(vis); if ((vis = ggiOpen(NULL)) == NULL) err("ggiOpen() number %d failed\n", i); } curr = get_size(); acurr = _get_ggi_alloced(); inform_mem("\nggiOpen()\n", prev, curr, aprev, acurr); prev = get_size(); aprev = _get_ggi_alloced(); for (i=2; i < 20; i++) { putchar('.'); fflush(stdout); ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, NULL); } curr = get_size(); acurr = _get_ggi_alloced(); inform_mem("\nggiCheckSimpleMode()\n", prev, curr, aprev, acurr); ggiSetFlags(vis, GGIFLAG_ASYNC); if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO) != 0) { err("Unable to set default mode!\n"); } prev = get_size(); aprev = _get_ggi_alloced(); for (i=2; i < 20; i++) { putchar('.'); fflush(stdout); if (ggiSetSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO) != 0) { err("Unable to set default mode %d!\n", i); } } curr = get_size(); acurr = _get_ggi_alloced(); inform_mem("\nggiSetSimpleMode()\n", prev, curr, aprev, acurr); ggiExit(); curr = get_size(); acurr = _get_ggi_alloced(); inform_mem("\nggiExit()\n", binit, curr, a_binit, acurr); return 0; }
static void testcase4(const char *desc) { int err; ggi_visual_t vis; ggi_mode mode; ggi_coord size; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiCheckSimpleMode( vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode); printassert(err == GGI_OK, "ggiCheckSimpleMode: can't find a mode\n"); if(err != GGI_OK) { ggiClose(vis); ggiExit(); printsuccess(); return; } printassert(mode.size.x != GGI_AUTO && mode.size.y != GGI_AUTO, "physical size is apparently not supported\n"); if(mode.size.x == GGI_AUTO || mode.size.y == GGI_AUTO) { ggiClose(vis); ggiExit(); printsuccess(); return; } /* Clear out all but the physical size */ mode.frames = GGI_AUTO; mode.visible.x = GGI_AUTO; mode.visible.y = GGI_AUTO; mode.virt.x = GGI_AUTO; mode.virt.y = GGI_AUTO; mode.graphtype = GT_AUTO; mode.dpp.x = GGI_AUTO; mode.dpp.y = GGI_AUTO; size = mode.size; /* This mode should be there */ err = ggiCheckMode(vis, &mode); ggiClose(vis); ggiExit(); if (err != GGI_OK) { printfailure("ggiCheckMode: expected return value: GGI_OK\n" "actual return value: %i\n", err); return; } if (mode.size.x != size.x) { printfailure( "ggiCheckMode: size.x: expected return value: %i\n" "actual return value: %i\n", size.x, mode.size.x); return; } if (mode.size.y != size.y) { printfailure( "ggiCheckMode: size.y: expected return value: %i\n" "actual return value: %i\n", size.y, mode.size.y); return; } printsuccess(); }
/* Set the default mode and do all the work. We might want to split * that later ... */ static int setup_mode(void) { int i; ggi_color col; const ggi_directbuffer *buf; ggi_mode gmode; if ((visual=ggNewStem(NULL)) == NULL) { fprintf(stderr, "unable to create stem, exiting.\n"); return -1; } if (ggiAttach(visual) < 0) { fprintf(stderr, "unable to attach ggi api, exiting.\n"); return -1; } if (ggiOpen(visual, NULL) < 0) { fprintf(stderr, "unable to open default visual, exiting.\n"); return -1; } ggiCheckSimpleMode(visual, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &gmode); if (ggiSetMode(visual, &gmode) == 0) { printf("Graph mode %dx%d (%dx%d virt)\n", gmode.visible.x, gmode.visible.y, gmode.virt.x, gmode.virt.y); } else { fprintf(stderr, "Unable to set any mode at all!\n"); ggiClose(visual); return -1; } col.r = 0xFFFF; col.g = 0xFFFF; col.b = 0xFFFF; printf("white = 0x%"PRIx32"\n", ggiMapColor(visual, &col)); col.r = 0x0000; col.g = 0x0000; col.b = 0x0000; printf("black = 0x%"PRIx32"\n", ggiMapColor(visual, &col)); printf("Pixelformat for Get/Put buffers:\n"); print_pixfmt(ggiGetPixelFormat(visual)); for (i = 0; ; i++) { int acquired = 0; buf = ggiDBGetBuffer(visual, i); if (buf == NULL) break; printf("DirectBuffer (frame #%d):\n", buf->frame); if (ggiResourceMustAcquire(buf->resource)) { switch (db_doacquire(buf)) { case 2: printf("Acquired DirectBuffer read/write\n"); acquired = 1; break; case 1: printf("Acquired DirectBuffer for writing\n"); acquired = 1; break; case 0: printf("Acquired DirectBuffer for read-only\n"); acquired = 1; break; default: printf("DirectBuffer can not be Acquired!\n"); break; } } else { printf("Does not need to be acquired\n"); } printf("Mapped at read:%p, write:%p (paged %u)\n", buf->read, buf->write, buf->page_size); switch (buf->layout) { case blPixelLinearBuffer: printf("Layout: Linear Pixel Buffer\n"); printf("Stride=%d\n", buf->buffer.plb.stride); printf("Pixelformat:\n"); print_pixfmt(buf->buffer.plb.pixelformat); break; default: printf("Layout: Unknown\n"); break; /* Skip it. Don't know it. */ } if (acquired) ggiResourceRelease(buf->resource); } return 0; }
int main(int argc, const char *argv[]) { ggi_visual_t vis; ggi_mode mode; int i, j, cx, cy, c; char buf[80]; /* Set up the random number generator */ srandom((unsigned)time(NULL)); /* Initialize LibGGI */ if (giiInit() < 0) { fprintf(stderr, "Cannot initialize LibGII!\n"); return 1; } if (ggiInit() < 0) { fprintf(stderr, "Cannot initialize LibGGI!\n"); giiExit(); return 1; } vis = ggNewStem(NULL); if (!vis) { fprintf(stderr, "Cannot open create stem!\n"); ggiExit(); giiExit(); return 1; } if (giiAttach(vis) < 0) { fprintf(stderr, "Cannot attach LibGII!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } if (ggiAttach(vis) < 0) { fprintf(stderr, "Cannot attach LibGGI!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } /* Open default visual */ if (ggiOpen(vis, NULL) < 0) { fprintf(stderr, "Cannot open default visual!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } /* Set visual to async mode (drawing not immediate) */ ggiSetFlags(vis, GGIFLAG_ASYNC); /* Set default mode, but with multiple buffering */ if (argc > 1) { ggiParseMode(argv[1], &mode); } else { ggiParseMode("", &mode); if (mode.frames < 2) mode.frames = 2; } if (ggiSetMode(vis, &mode)) { fprintf(stderr, "Cannot set mode!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } ggiGetCharSize(vis, &cx, &cy); /* Setup palette */ if (GT_SCHEME(mode.graphtype) == GT_PALETTE) { ggiSetColorfulPalette(vis); } /* Write something into each frame */ for (i = 0; i < mode.frames; i++) { if (ggiSetWriteFrame(vis, i)) { fprintf(stderr, "Cannot set write frame!\n"); ggDelStem(vis); ggiExit(); giiExit(); return 1; } ggiSetGCBackground(vis, ggiMapColor(vis, &white)); ggiSetGCForeground(vis, ggiMapColor(vis, &white)); ggiFillscreen(vis); } /* Clip a small border so that clipping can be verified. */ ggiSetGCClipping(vis, 5, 5, mode.virt.x - 5, mode.virt.y - 5); /* Write something into each frame */ for (i = 0; i < mode.frames; i++) { ggiSetWriteFrame(vis, i); ggiSetGCBackground(vis, ggiMapColor(vis, &black)); ggiSetGCForeground(vis, ggiMapColor(vis, &black)); ggiFillscreen(vis); snprintf(buf, sizeof(buf), "Hello World #%d!", i); for (j = 0; j < mode.virt.y; j += cy) { ggi_color col; int x = random() % mode.virt.x; int h = (random() & 0x7fff) + 0x8000; int l = (random() & 0x7fff); /* Use different colors for different frames */ col.r = ((i + 1) & 1) ? h : l; col.g = ((i + 1) & 2) ? h : l; col.b = ((i + 1) & 4) ? h : l; ggiSetGCForeground(vis, ggiMapColor(vis, &col)); ggiPuts(vis, x, j, buf); } /* Flush commands before proceeding to the next frame */ ggiFlush(vis); } /* Cycle through frames */ i = 0; j = 0; do { if (ggiSetDisplayFrame(vis, i)) { ggPanic("Cannot set display frame!\n"); } /* Wait */ c = GIIK_VOID; do { struct timeval tv = { 0, 0 }; int key; /* Flush command before waiting for input */ ggiFlush(vis); key = giiEventPoll(vis, emKeyPress, &tv); if (key & emKeyPress) c = giiGetc(vis); ggUSleep(50000); animate(vis, &mode, j); j++; } while (c == GIIK_VOID || GII_KTYP(c) == GII_KT_MOD); i = (i + 1) % mode.frames; } while (c != 'q' && c != 'Q' && c != 'x' && c != 'X' && c != GIIUC_Escape); ggiClose(vis); ggDelStem(vis); ggiExit(); giiExit(); return 0; }
static void testcase1(const char *desc) { int err; ggi_visual_t vis; ggi_mode mode; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; err = ggiInit(); printassert(err == GGI_OK, "ggiInit failed with %i\n", err); vis = ggiOpen(NULL); printassert(vis != NULL, "ggiOpen() failed\n"); err = ggiCheckSimpleMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GT_AUTO, &mode); if (err == GGI_OK) { if (mode.visible.x == GGI_AUTO) { printfailure("visible.x: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.visible.y == GGI_AUTO) { printfailure("visible.y: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.virt.x == GGI_AUTO) { printfailure("virt.x: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.virt.y == GGI_AUTO) { printfailure("virt.y: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.size.x == GGI_AUTO) { printfailure("size.x: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.size.y == GGI_AUTO) { printfailure("size.y: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.frames == GGI_AUTO) { printfailure("frames: expected return value: != GGI_AUTO\n" "actual return value: GGI_AUTO\n"); return; } if (mode.graphtype == GT_AUTO) { printfailure("graphtype: expected return value: != GT_AUTO\n" "actual return value: GT_AUTO\n"); return; } } ggiClose(vis); ggiExit(); printsuccess(); return; }