void x_cleardev(void) { #ifdef GGI ggiSetGCForeground (ggiVis, ggi_getcolor (0)); ggiFillscreen(ggiVis); ggiSetGCForeground (ggiVis, ggi_getcolor (xg_color)); #else vga_clear(); #endif }
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 ret; ggi_visual_t vis; ggi_mode mode; ggi_pixel pixel_color; ggi_color color_color; #if 0 unsigned int j, size; const ggi_directbuffer *dbuf = NULL; #endif color_color.r = 0x0000; color_color.g = 0xffff; color_color.b = 0xffff; printteststart(__FILE__, __PRETTY_FUNCTION__, EXPECTED2PASS, desc); if (dontrun) return; vis = ggNewStem(libggi, NULL); if (vis == NULL) { printfailure("Couldn't create stem for %s", DISPLAYSTR); return; } ret = ggiOpen(vis, DISPLAYSTR, NULL); if (ret != 0) { printfailure("Couldn't open %s", DISPLAYSTR); return; } #if 0 /* Here, XGGI would switch to async mode, * if there were a place to hook in ggiFlush() */ ggiSetFlags(vis, GGIFLAG_ASYNC); #endif /* Now check, if mansync is actually running * - note, we are in sync mode here. */ /* stop mansync. If it runs as it should, * we don't fail with an assertion here */ ret = MANSYNC_stop(STEM_API_DATA(vis, libggi, struct ggi_visual*)); if (ret != 0) { printfailure("BUG: mansync not running - forgot to call " "MANSYNC_start(vis) right after MANSYNC_init(vis)?\n"); goto exit_testcase; } /* now restart it */ ret = MANSYNC_start(STEM_API_DATA(vis, libggi, struct ggi_visual*)); if (ret != 0) { printfailure("BUG: mansync couldn't be relaunched\n"); goto exit_testcase; } ggiParseMode("", &mode); ggiCheckMode(vis, &mode); ret = ggiSetMode(vis, &mode); if (ret != GGI_OK) { printfailure("expected return value: \"%i\"\n" "actual return value: \"%i\"\n", GGI_OK, ret); goto exit_testcase; } /* Disable directbuffer as this is not required to * perform the test */ #if 0 ret = -1; size = GT_SIZE(mode.graphtype); for (j = 0; (dbuf = ggiDBGetBuffer(vis, j)) != NULL; j++) { if ((dbuf->type & GGI_DB_SIMPLE_PLB) && ((8*dbuf->buffer.plb.stride) % size) == 0) { /* found */ ret = GGI_OK; break; } } if (ret != GGI_OK) { printfailure("This mode and target has no suitable DirectBuffer\n"); goto exit_testcase; } if (ggiResourceAcquire(dbuf->resource, GGI_ACTYPE_WRITE | GGI_ACTYPE_READ) != 0) { printfailure("Unable to acquire DirectBuffer\n"); goto exit_testcase; } #endif /* ... and now draw something. */ pixel_color = ggiMapColor(vis, &color_color); ggiSetGCForeground(vis, pixel_color); ggiFillscreen(vis); #if 0 ggiResourceRelease(dbuf->resource); #endif exit_testcase: ggDelStem(vis); printsuccess(); return; }