Пример #1
0
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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
static void perf_OPEN(TeleUser *u, TeleEvent *ev)
{
	TeleCmdOpenData *d = (TeleCmdOpenData *) ev->data;

	T_Long reply_sequence;

	int err;


	/* get target to check mode */

	vis_mode.graphtype = (ggi_graphtype) d->graphtype;
	vis_mode.frames    = (uint32_t) d->frames;
	vis_mode.visible.x = (int16_t) d->visible.width;
	vis_mode.visible.y = (int16_t) d->visible.height;
	vis_mode.virt.x    = (int16_t) d->virt.width;
	vis_mode.virt.y    = (int16_t) d->virt.height;
	vis_mode.dpp.x     = (int16_t) d->dot.width;
	vis_mode.dpp.y     = (int16_t) d->dot.height;

	d->error = ggiSetMode(vis, &vis_mode);

	if (! d->error) {
		mode_up = 1;
	}


	/* send result back to client */

	reply_sequence = ev->sequence;

	tserver_new_event(u, ev, TELE_CMD_OPEN,
			  sizeof(TeleCmdOpenData), 0);

	ev->sequence = reply_sequence;

	d->graphtype      = (T_Long) vis_mode.graphtype;
	d->frames         = (T_Long) vis_mode.frames;
	d->visible.width  = (T_Long) vis_mode.visible.x;
	d->visible.height = (T_Long) vis_mode.visible.y;
	d->virt.width     = (T_Long) vis_mode.virt.x;
	d->virt.height    = (T_Long) vis_mode.virt.y;
	d->dot.width      = (T_Long) vis_mode.dpp.x;
	d->dot.height     = (T_Long) vis_mode.dpp.y;

	err = tserver_write(u, ev);

	if (err == TELE_ERROR_SHUTDOWN) {

		/* Client has gone away */

		close_connection(1);
		return;
	}
}
Пример #5
0
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;
}
Пример #6
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;
}
Пример #7
0
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);
}
Пример #8
0
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
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_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);
}
Пример #11
0
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);
}
Пример #12
0
static int GGIopen(struct ggi_visual *vis, struct ggi_dlhandle *dlh,
			const char *args, void *argptr, uint32_t_t_t *dlret)
{
	ggi_mode mode;
	void *memptr=NULL;
  	suid_hook *priv;
	int x, err = GGI_ENOMEM;

	LIBGGI_GC(vis) = malloc(sizeof(ggi_gc));
	if (LIBGGI_GC(vis) == NULL) {	
		return GGI_ENOMEM;
	}

	priv = LIBGGI_PRIVATE(vis) = malloc(sizeof(suid_hook));
	if (priv == NULL) {
		goto out_freegc;
	}
  	
	priv->is_up=0;
	priv->dev_mem=_suidtarget_dev_mem=-1;
	priv->mmap_length=0;

	/* Open GII for input */
	vis->input = giiOpen("input-linux-kbd", NULL);
	if (vis->input == NULL) {
		fprintf(stderr, "display-suidkgi: Couldn't open kbd.\n");
		goto out_freepriv;
	}

	/* Has mode management */
	vis->opdisplay->getmode=GGI_suidkgi_getmode;
	vis->opdisplay->setmode=GGI_suidkgi_setmode;
	vis->opdisplay->checkmode=GGI_suidkgi_checkmode;
	vis->opdisplay->flush=GGI_suidkgi_flush;
	vis->opdisplay->kgicommand=GGI_suidkgi_kgicommand;
	vis->opdisplay->setflags=GGI_suidkgi_setflags;
	vis->opdraw->setorigin=GGI_suidkgi_setorigin;

	vis->w_frame = malloc(sizeof(ggi_directbuffer)); /* FIXME ! */
	vis->r_frame = malloc(sizeof(ggi_directbuffer)); /* FIXME ! */
	LIBGGI_CURWRITE(vis)=NULL;
	LIBGGI_CURREAD(vis)=NULL;

	if (iopl(3)) {perror("iopl");exit(2); }
	DPRINT("IOPL is here.\n");
  
	if (-1 == (priv->dev_mem = _suidtarget_dev_mem = open("/dev/mem",O_RDWR))) { perror("opening /dev/mem");exit(3); }
	memptr=mmap(NULL,64*1024,PROT_READ|PROT_WRITE,MAP_SHARED,priv->dev_mem,0xa0000);
	DPRINT("Have mmap at %p.\n",memptr);

/*	law_base=0xf3000000; */
	if (suidkgi_init_module()) {DPRINT("Init has failed. Tough luck.\n");exit(1); }

	DPRINT("Init was o.k.\n");
	signal(SIGSEGV,get_killed);
	signal(SIGINT,get_killed);
	signal(SIGTERM,get_killed);
	priv->is_up=1;

#if 1
	/* Not sure, if this is needed, but ... */
	mode.frames=1;
	mode.graphtype=GT_TEXT16;
	mode.visible.x=mode.virt.x=80;
	mode.visible.y=mode.virt.y=25;
	mode.dpp.x = 8;mode.dpp.y =16;
	x=GGI_suidkgi_checkmode(vis,&mode);
	DPRINT("TESTMODE1 says %d.\n",x);
	x=GGI_suidkgi_setmode(vis,&mode);
	DPRINT("SETMODE1 says %d.\n",x);
#endif

#undef TESTING_THE_SUID_TARGET
#ifdef TESTING_THE_SUID_TARGET

#ifdef GoneByeBye
	for(x=0;x<480;x++)
	{
		GGI_suidkgi_setsplitline(vis, x);
		ggUSleep(100000);
	}
#endif

	mode.frames=1;
	mode.graphtype=GT_8BIT;
	mode.visible.x=mode.virt.x=320;
	mode.visible.y=mode.virt.y=200;
	mode.dpp.x    =mode.dpp.y =1;
	x=ggiCheckMode(vis,&mode);
	DPRINT("TESTMODE3 says %d.\n",x);
	x=ggiSetMode(vis,&mode);
	DPRINT("SETMODE3 says %d.\n",x);

	sleep(1);

	{ int y;
		for(y=0;y<200;y++)
		{ 
			for(x=0;x<320;x++)
			{ 
				*((unsigned char *)memptr+x+y*320)=x+y; 
			}
			ggUSleep(1);
		}
	}
	sleep(1);

	mode.frames=1;
	mode.graphtype=GT_TEXT16;
	mode.visible.x=mode.virt.x=80;
	mode.visible.y=mode.virt.y=25;
	mode.dpp.x = 8;mode.dpp.y =16;
	x=GGI_suidkgi_checkmode(vis,&mode);
	DPRINT("TESTMODE4 says %d.\n",x);
	x=GGI_suidkgi_setmode(vis,&mode);
	DPRINT("SETMODE4 says %d.\n",x);

	sleep(1);

	suidkgi_cleanup_module();

	DPRINT("Cleanup went well.\n");
	close(priv->dev_mem);
	exit(1);
#endif

	*dlret = GGI_DL_OPDISPLAY|GGI_DL_OPDRAW;
	return 0;

  out_freepriv:
	free(priv);
  out_freegc:
	free(LIBGGI_GC(vis);

	return err;
}
Пример #13
0
int _ggi_palemu_Open(struct ggi_visual *vis)
{
	int rc;
	ggi_palemu_priv *priv = PALEMU_PRIV(vis);


	DPRINT("display-palemu: Open %dx%d#%dx%d\n", LIBGGI_X(vis), 
		LIBGGI_Y(vis), LIBGGI_VIRTX(vis), LIBGGI_VIRTY(vis));


	/* set the parent mode */
	
	rc = ggiSetMode(priv->parent, &priv->parent_mode);
	if (rc < 0) {
		DPRINT("display-palemu: Couldn't set parent mode.\n");
		return rc;
	}

	DPRINT("display-palemu: parent is %d/%d\n",
		GT_DEPTH(priv->parent_mode.graphtype), 
		GT_SIZE(priv->parent_mode.graphtype));
	

	/* setup tables and choose blitter function */

	switch (GT_ByPP(priv->parent_mode.graphtype)) {

	case 1: priv->do_blit = &blitter_1;
		break;
		
	case 2: priv->do_blit = &blitter_2;
		break;
		
	case 3: priv->do_blit = &blitter_3;
		break;
		
	case 4: priv->do_blit = &blitter_4;
		break;
		
	default:
		DPRINT("Unsupported pixel size '%d'.\n",
			GT_SIZE(priv->parent_mode.graphtype));
		return GGI_ENOMATCH;
	}


	priv->palette = _ggi_malloc(256 * sizeof(ggi_color));
	priv->lookup  = _ggi_malloc(256 * sizeof(ggi_pixel));

	priv->red_gamma = priv->green_gamma = priv->blue_gamma = 1.0;

	
	/* clear the 'dirty region' */

	priv->dirty_tl.x = LIBGGI_VIRTX(vis);
	priv->dirty_tl.y = LIBGGI_VIRTY(vis);
	priv->dirty_br.x = 0;
	priv->dirty_br.y = 0;

	return 0;
}
Пример #14
0
/* 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;
}