コード例 #1
0
ファイル: libggi.c プロジェクト: channinglan/MINIGUI_1.3.3
BOOL InitLibGGIInput (INPUT* input, const char* mdev, const char* mtype)
{
    char* str;

	_ggigsw_visual = PHYSICALGC.visual;

    ggiSetEventMask (VIS, emKeyPress | emKeyRelease | emPointer);

    if ((str = getenv("GSW_ASYNC"))) {
        /* We call ggiFlush() in mouse_update() or keyboard_update() */
        ggiSetFlags(VIS, GGIFLAG_ASYNC);
        if (strcmp(str, "mouse") == 0) {
            _ggigsw_async = GSW_ASYNCMOUSE;
            _GSWPRINT("Using async-mouse mode\n");
        } else {
            _ggigsw_async = GSW_ASYNCKEY;
            _GSWPRINT("Using async-key mode\n");
        }
    }
    if (getenv("GSW_BUT2KEY")) {
        _ggigsw_but2key = GSW_HAVEIT;
    }

    input->update_mouse = mouse_update;
    input->get_mouse_xy = mouse_getxy;
    input->set_mouse_xy = mouse_setposition;
    input->get_mouse_button = mouse_getbutton;
    input->set_mouse_range = mouse_setrange;
    input->update_keyboard = keyboard_update;
    input->get_keyboard_state = keyboard_getstate;
    input->set_leds = NULL;
    input->wait_event = wait_event;

	return TRUE;
}
コード例 #2
0
ファイル: mode.c プロジェクト: Nekrofage/DoomRPi
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;
}
コード例 #3
0
ファイル: mode.c プロジェクト: Nekrofage/DoomRPi
int GGI_sub_setflags(ggi_visual *vis,ggi_flags flags)
{
	int rc;
	ggi_sub_priv *priv = SUB_PRIV(vis);

	rc = ggiSetFlags(priv->parent, flags);
	if (rc < 0) return rc;

	LIBGGI_FLAGS(vis) = flags;
	LIBGGI_FLAGS(vis) &= GGIFLAG_ASYNC; /* Unkown flags don't take. */

	return 0;	
}
コード例 #4
0
ファイル: pageflip.c プロジェクト: antrik/libggi
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;
}
コード例 #5
0
ファイル: vo_ggi.c プロジェクト: batman52/dingux-code
static int config(uint32_t width, uint32_t height, uint32_t d_width,
                  uint32_t d_height, uint32_t flags, char *title,
                  uint32_t format)
{
    ggi_mode mode = {
        1,                      /* frames */
        {width, height},        /* visible */
        {GGI_AUTO, GGI_AUTO},   /* virt */
        {GGI_AUTO, GGI_AUTO},   /* size */
        GT_AUTO,                /* graphtype */
        {GGI_AUTO, GGI_AUTO}    /* dots per pixel */
    };


    set_graphtype(format, &mode);

#if 0
    printf("[ggi] mode: ");
    ggiPrintMode(&mode);
    printf("\n");
#endif

    ggiCheckMode(ggi_conf.vis, &mode);

    if (ggiSetMode(ggi_conf.vis, &mode) < 0) {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to set display mode\n");
        return (-1);
    }
    if (ggiGetMode(ggi_conf.vis, &mode) < 0) {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to get display mode\n");
        return (-1);
    }
    if ((mode.graphtype == GT_INVALID)
       || (mode.graphtype == GT_AUTO))
    {
        mp_msg(MSGT_VO, MSGL_ERR, "[ggi] not supported depth/bpp\n");
        return (-1);
    }

#if 0
    printf("[ggi] mode: ");
    ggiPrintMode(&mode);
    printf("\n");
#endif


#ifdef HAVE_GGIWMH
    ggiWmhSetTitle(ggi_conf.vis, title);
    if (vo_ontop) window_ontop();
#endif

    ggiSetFlags(ggi_conf.vis, GGIFLAG_ASYNC);

    if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
        ggiSetColorfulPalette(ggi_conf.vis);

    if (GT_SCHEME(mode.graphtype) != GT_TRUECOLOR) {
        ggi_mode drawmode;

        ggi_conf.drawvis = ggiOpen("display-memory", NULL);
        if (ggi_conf.drawvis == NULL) {
            mp_msg(MSGT_VO, MSGL_ERR,
                   "[ggi] unable to get backbuffer for conversion\n");
            return -1;
        }
        memcpy(&drawmode, &mode, sizeof(ggi_mode));
        drawmode.graphtype = GT_32BIT;
        drawmode.size.x = GGI_AUTO;
        drawmode.size.y = GGI_AUTO;
        ggiCheckMode(ggi_conf.drawvis, &drawmode);
        if (ggiSetMode(ggi_conf.drawvis, &drawmode) < 0) {
            mp_msg(MSGT_VO, MSGL_ERR,
                   "[ggi] unable to set backbuffer mode\n");
            return -1;
        }
        mode.graphtype = drawmode.graphtype;

        ggiSetFlags(ggi_conf.drawvis, GGIFLAG_ASYNC);
    }
    vo_depthonscreen = GT_DEPTH(mode.graphtype);
    vo_screenwidth = mode.virt.x;
    vo_screenheight = mode.virt.y;

    vo_dwidth = width;
    vo_dheight = height;
    vo_dbpp = GT_SIZE(mode.graphtype);


    /* calculate top, left corner */
    vo_dx = (vo_screenwidth - vo_dwidth) / 2;
    vo_dy = (vo_screenheight - vo_dheight) / 2;


    ggi_conf.srcwidth = width;
    ggi_conf.srcheight = height;
    ggi_conf.srcformat = format;

    ggi_conf.voflags = flags;

    if (IMGFMT_IS_RGB(ggi_conf.srcformat)) {
        ggi_conf.srcdepth = IMGFMT_RGB_DEPTH(ggi_conf.srcformat);
    } else if (IMGFMT_IS_BGR(ggi_conf.srcformat)) {
        ggi_conf.srcdepth = IMGFMT_BGR_DEPTH(ggi_conf.srcformat);
    } else {
        mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] Unknown image format: %s\n",
               vo_format_name(ggi_conf.srcformat));
        return (-1);
    }

    mp_msg(MSGT_VO, MSGL_INFO, "[ggi] input: %dx%dx%d, output: %dx%dx%d\n",
           ggi_conf.srcwidth, ggi_conf.srcheight, ggi_conf.srcdepth,
           mode.virt.x, mode.virt.y, vo_dbpp);

    ggi_conf.srcbpp = (ggi_conf.srcdepth + 7) / 8;

    ggi_conf.flushregion.x1 = vo_dx;
    ggi_conf.flushregion.y1 = vo_dy;
    ggi_conf.flushregion.x2 = vo_dwidth;
    ggi_conf.flushregion.y2 = vo_dheight;

    return (0);
}
コード例 #6
0
ファイル: visual.c プロジェクト: antrik/libggi
static int GGIopen_monotext(struct ggi_visual *vis, struct ggi_dlhandle *dlh,
				const char *args, void *argptr, uint32_t *dlret)
{
	ggi_palemu_priv *priv;
	gg_option options[MONOTEXT_NUM_OPTS];
	char target[1024];
	struct gg_api *api;
	struct gg_observer *obs = NULL;
	int val;
	int err = 0;

	DPRINT("display-monotext: GGIopen start.\n");

	memcpy(options, monotext_optlist, sizeof(options));
	if (args) {
		args = ggParseOptions(args, options, MONOTEXT_NUM_OPTS);
		if (args == NULL) {
			fprintf(stderr,
				"display-monotext: error in arguments\n");
			return GGI_EARGINVAL;
		}
	}

	/* open the parent visual */
	DPRINT("display-monotext: opening target: %s\n", args);

	if (args != NULL) {
		if (ggParseTarget(args, target, sizeof(target)) == NULL) {
			/* error occured */
			return GGI_EARGINVAL;
		}
	}

	/* Find out the parent target */
	while (args && *args && isspace((uint8_t)*args)) {
		args++;
	}

	*target = '\0';
	if (args) {
		if (ggParseTarget(args, target, sizeof(target)) == NULL) {
			return GGI_EARGINVAL;
		}
	}

	if (*target == '\0') {
		strcpy(target, "auto");
	}

	LIBGGI_GC(vis) = malloc(sizeof(ggi_gc));
	if (LIBGGI_GC(vis) == NULL) {
		err = GGI_ENOMEM;
		goto err0;
	}
	LIBGGI_PRIVATE(vis) = priv = malloc(sizeof(ggi_palemu_priv));
	if (priv == NULL) {
		err = GGI_ENOMEM;
		goto err1;
	}

	priv->flush_lock = ggLockCreate();
	if (priv->flush_lock == NULL) {
		err = GGI_ENOMEM;
		goto err2;
	}
	priv->opmansync = malloc(sizeof(_ggi_opmansync));
	if (priv->opmansync == NULL) {
		err = GGI_ENOMEM;
		goto err3;
	}

	priv->flags = 0;
	priv->fb_ptr = NULL;
	priv->target = MONOTEXT_TARGET;


	DPRINT("display-monotext: opening target: %s\n", target);
	priv->parent = ggNewStem(NULL);
	if (priv->parent == NULL) {
		fprintf(stderr,
			"display-monotext: Failed to create stem for target: %s\n",
			target);
		err = GGI_ENODEVICE;
		goto err3;
	}

	/* XXX Should iterate over the apis attached to vis->instance.stem
	 * instead of only looking for ggi and gii.
	 */
	if (ggiAttach(priv->parent) < 0) {
		ggDelStem(priv->parent);
		priv->parent = NULL;
		fprintf(stderr,
			"display-monotext: Failed to attach ggi to stem for target: %s\n",
			target);
		err = GGI_ENODEVICE;
		goto err4;
	}

	api = ggGetAPIByName("gii");
	if (api != NULL) {
		/* XXX This should probably be done in pseudo-stubs-gii */
		if (STEM_HAS_API(vis->instance.stem, api)) {
			if (ggAttach(api, priv->parent) < 0) {
				ggDelStem(priv->parent);
				priv->parent = NULL;
				fprintf(stderr,
					"Failed to attach gii to stem for target: %s\n",
					target);
				err = GGI_ENODEVICE;
				goto err4;
			}
			obs = ggObserve(GG_STEM_API_CHANNEL(priv->parent, api),
					transfer_gii_src, vis->instance.stem);
		}
	}

	if (ggiOpen(priv->parent, target, NULL) < 0) {
		if (obs) {
			ggDelObserver(obs);
			obs = NULL;
		}
		fprintf(stderr,
			"display-monotext: Failed to open target: '%s'\n",
			target);
		ggDelStem(priv->parent);
		priv->parent = NULL;
		err = GGI_ENODEVICE;
		goto err4;
	}
	if (obs) {
		ggDelObserver(obs);
		obs = NULL;
	}

	ggiSetFlags(priv->parent, GGIFLAG_ASYNC);


	/* set defaults */
	priv->parent_defmode.graphtype = GT_TEXT16;
	priv->flags = 0;
	priv->squish.x = priv->squish.y = 1;

	val = strtol(options[OPT_A].result, NULL, 0);	
	if (val != 0) {
		priv->accuracy.x = priv->accuracy.y = val;
	} else {
		priv->accuracy.x = strtol(options[OPT_X].result, NULL, 0);
		priv->accuracy.y = strtol(options[OPT_Y].result, NULL, 0);
	}

	/* Setup mansync */
	MANSYNC_open(vis, priv);
	if (priv->mod_mansync == NULL) {
		fprintf(stderr,
			"display-monotext: Cannot load helper-mansync!\n");
		GGIclose_monotext(vis, dlh);
		goto err4;
	}

	MANSYNC_init(vis);
	if (!(LIBGGI_FLAGS(vis) & GGIFLAG_ASYNC)) {
		MANSYNC_start(vis);
	}

	/* Has mode management */
	vis->opdisplay->getmode   = GGI_palemu_getmode;
	vis->opdisplay->setmode   = GGI_palemu_setmode;
	vis->opdisplay->checkmode = GGI_monotext_checkmode;
	vis->opdisplay->getapi    = GGI_palemu_getapi;
	vis->opdisplay->flush     = GGI_palemu_flush;
	vis->opdisplay->setflags  = GGI_palemu_setflags;

	DPRINT("display-monotext: GGIopen succeeded.\n");

	*dlret = GGI_DL_OPDISPLAY;
	return 0;

err4:
	free(priv->opmansync);
err3:
	ggLockDestroy(priv->flush_lock);
err2:
	free(priv);
err1:
	free(LIBGGI_GC(vis));
err0:
	return err;
}
コード例 #7
0
ファイル: visual.c プロジェクト: antrik/libggi
static int GGIopen_palemu(struct ggi_visual *vis, struct ggi_dlhandle *dlh,
		   const char *args, void *argptr, uint32_t *dlret)
{
	ggi_palemu_priv *priv;
	gg_option options[PALEMU_NUM_OPTS];
	char target[1024];
	int err = GGI_ENOMEM;
	struct gg_api *api;
	struct gg_observer *obs = NULL;

	DPRINT("display-palemu: GGIopen start.\n");

	/* handle arguments */
	memcpy(options, palemu_optlist, sizeof(options));
	if (args) {
		args = ggParseOptions(args, options, PALEMU_NUM_OPTS);

		if (args == NULL) {
			fprintf(stderr,
				"display-palemu: error in arguments.\n");
			return GGI_EARGINVAL;
		}
	}
	if (getenv("GGI_PALEMU_OPTIONS") != NULL) {
		if (ggParseOptions(getenv("GGI_PALEMU_OPTIONS"), options,
				   PALEMU_NUM_OPTS) == NULL) {
			fprintf(stderr, "display-palemu: error in ""$GGI_PALEMU_OPTIONS.\n");
			return GGI_EARGINVAL;
		}
	}

	/* Find out the parent target. */
	while (args && *args && isspace((uint8_t)*args)) {
		args++;
	}

	*target = '\0';
	if (args) {
		if (ggParseTarget(args, target, 1024) == NULL) {
			return GGI_EARGINVAL;
		}
	}
	if (*target == '\0') {
		strcpy(target, "auto");
	}

	LIBGGI_GC(vis) = malloc(sizeof(ggi_gc));
	if (LIBGGI_GC(vis) == NULL) {
		return GGI_ENOMEM;
	}
	LIBGGI_PRIVATE(vis) = priv = malloc(sizeof(*priv));
	if (priv == NULL) {
		goto out_freegc;
	}
	priv->flush_lock = ggLockCreate();
	if (priv->flush_lock == NULL) {
		goto out_freepriv;
	}
	priv->opmansync = malloc(sizeof(_ggi_opmansync));
	if (priv->opmansync == NULL) {
		goto out_freelock;
	}

	priv->flags  = 0;
	priv->fb_ptr = NULL;
	priv->target = PALEMU_TARGET;

	DPRINT("display-palemu: parent mode is '%s'\n",
		  options[OPT_PARENT].result);
	ggiParseMode(options[OPT_PARENT].result, &priv->parent_defmode);

	DPRINT("display-palemu: opening target: %s\n", target);
	priv->parent = ggNewStem(NULL);
	if (priv->parent == NULL) {
		fprintf(stderr,
			"display-palemu: Failed to create stem for target: '%s'\n",
			target);
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	/* FIXME! Should iterate over the apis attached to vis->instance.stem
	 * instead of only looking for ggi and gii.
	 */
	if (ggiAttach(priv->parent) < 0) {
		ggDelStem(priv->parent);
		priv->parent = NULL;
		fprintf(stderr,
			"display-palemu: Failed to attach ggi to stem for target: '%s'\n",
			target);
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	if ((api = ggGetAPIByName("gii")) != NULL) {
		/* FIXME! This should probably be done in pseudo-stubs-gii */
		if (STEM_HAS_API(vis->instance.stem, api)) {
			if (ggAttach(api, priv->parent) < 0) {
				ggDelStem(priv->parent);
				priv->parent = NULL;
				fprintf(stderr,
					"display-palemu: Failed to attach gii to stem for target: '%s'\n",
					target);
				err = GGI_ENODEVICE;
				goto out_freeopmansync;
			}
			obs = ggObserve(GG_STEM_API_CHANNEL(priv->parent, api),
			    transfer_gii_src, vis->instance.stem);
		}
	}
	if (ggiOpen(priv->parent, target, NULL) < 0) {
		if (obs) {
			ggDelObserver(obs);
			obs = NULL;
		}
		fprintf(stderr,
			"display-palemu: Failed to open target: '%s'\n",
			target);
		ggDelStem(priv->parent);
		priv->parent = NULL;
		err = GGI_ENODEVICE;
		goto out_freeopmansync;
	}
	if (obs) {
		ggDelObserver(obs);
		obs = NULL;
	}

	ggiSetFlags(priv->parent, GGIFLAG_ASYNC);

	/* Setup mansync */
	MANSYNC_open(vis, priv);
	if (priv->mod_mansync == NULL) {
		fprintf(stderr,
			"display-palemu: Cannot load helper-mansync!\n");
		GGIclose_palemu(vis, dlh);
		return err;
	}

	MANSYNC_init(vis);
	if (!(LIBGGI_FLAGS(vis) & GGIFLAG_ASYNC)) {
		MANSYNC_start(vis);
	}

	/* Has mode management */
	vis->opdisplay->getmode = GGI_palemu_getmode;
	vis->opdisplay->setmode = GGI_palemu_setmode;
	vis->opdisplay->checkmode = GGI_palemu_checkmode;
	vis->opdisplay->getapi = GGI_palemu_getapi;
	vis->opdisplay->flush = GGI_palemu_flush;
	vis->opdisplay->setflags = GGI_palemu_setflags;

	DPRINT("display-palemu: GGIopen succeeded.\n");

	*dlret = GGI_DL_OPDISPLAY;
	return 0;

  out_freelock:
	ggLockDestroy(priv->flush_lock);
  out_freeopmansync:
	free(priv->opmansync);
  out_freepriv:
	free(priv);
  out_freegc:
	free(LIBGGI_GC(vis));

	return err;
}
コード例 #8
0
ファイル: gr.c プロジェクト: Ringdingcoder/d1x
int gr_set_mode(u_int32_t mode)
{
	unsigned int w, h;
	ggi_mode other_mode;	

#ifdef NOGRAPH
	return 0;
#endif
	if (mode<=0)
		return 0;

	w=SM_W(mode);
	h=SM_H(mode);
	
	
	gr_palette_clear();

	if(ggiCheckGraphMode(screenvis, w, h, GGI_AUTO, GGI_AUTO, GT_8BIT, &other_mode))
		ggiSetMode(screenvis, &other_mode);
	else
		ggiSetGraphMode(screenvis, w, h, GGI_AUTO, GGI_AUTO, GT_8BIT);

	ggiSetFlags(screenvis, GGIFLAG_ASYNC);
		
	if (!ggiDBGetNumBuffers(screenvis))
		use_directbuffer = 0;
	else
	{	
		dbuffer = ggiDBGetBuffer(screenvis, 0);
		if (!(dbuffer->type & GGI_DB_SIMPLE_PLB))
			use_directbuffer = 0;
		else
			use_directbuffer = 1;
	}

        memset(grd_curscreen, 0, sizeof(grs_screen));

	grd_curscreen->sc_mode = mode;
	grd_curscreen->sc_w = w;
	grd_curscreen->sc_h = h;
	grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4);
	grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0;
	grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0;
	grd_curscreen->sc_canvas.cv_bitmap.bm_w = w;
	grd_curscreen->sc_canvas.cv_bitmap.bm_h = h;
	grd_curscreen->sc_canvas.cv_bitmap.bm_type = BM_LINEAR;

	if (use_directbuffer)
	{
	        grd_curscreen->sc_canvas.cv_bitmap.bm_data = dbuffer->write;
        	grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = dbuffer->buffer.plb.stride;
	}
	else
	{
		free(screenbuffer);
		screenbuffer = malloc (w * h);
		grd_curscreen->sc_canvas.cv_bitmap.bm_data = screenbuffer;
		grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = w;
	}

	gr_set_current_canvas(NULL);
	
	gamefont_choose_game_font(w,h);
	
	return 0;
}
コード例 #9
0
ファイル: mansync.inc.c プロジェクト: antrik/libggi
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;
}
コード例 #10
0
ファイル: SDL_ggivideo.c プロジェクト: 3bu1/crossbridge
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);
}
コード例 #11
0
ファイル: findleaks.c プロジェクト: Nekrofage/DoomRPi
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;
}
コード例 #12
0
ファイル: mode.c プロジェクト: Nekrofage/DoomRPi
static void testcase6(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");

	/* async mode disables mansync if used */
	ggiSetFlags(vis, GGIFLAG_ASYNC);

	/* 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;
}