int GGI_lcd823_getapi(struct ggi_visual *vis, int num, char *apiname, char *arguments) { int size = GT_SIZE(LIBGGI_GT(vis)); *arguments = '\0'; switch(num) { case 0: strcpy(apiname, "display-lcd823"); return 0; case 1: strcpy(apiname, "generic-stubs"); return 0; case 2: strcpy(apiname, "generic-color"); return 0; case 3: if (GT_SCHEME(LIBGGI_GT(vis)) == GT_TEXT) { snprintf(apiname, GGI_MAX_APILEN, "generic-text-%d", size); return 0; } snprintf(apiname, GGI_MAX_APILEN, "generic-linear-%d", size); return 0; } return GGI_ENOMATCH; }
static void get_mode_info(ggi_visual_t vis, int *r, int *g, int *b, GLboolean *rgb, GLboolean *db, int *ci) { unsigned int i; *r = 0; *g = 0; *b = 0; for(i = 0; i < sizeof(ggi_pixel)*8; ++i) { int mask = 1 << i; if (LIBGGI_PIXFMT(vis)->red_mask & mask) ++(*r); if (LIBGGI_PIXFMT(vis)->green_mask & mask) ++(*g); if (LIBGGI_PIXFMT(vis)->blue_mask & mask) ++(*b); } *rgb = GT_SCHEME(LIBGGI_MODE(vis)->graphtype) == GT_TRUECOLOR; *db = LIBGGI_MODE(vis)->frames > 1; *ci = GT_SIZE(LIBGGI_MODE(vis)->graphtype); printf("rgb (%d, %d, %d) db %d, rgb %d ci %d\n",*r,*g,*b,*db,*rgb,*ci); }
int GGI_vgl_getapi(ggi_visual *vis, int num, char *apiname, char *arguments) { struct vgl_priv *priv = VGL_PRIV(vis); *arguments = '\0'; switch(num) { case 0: strcpy(apiname, "display-vgl"); return 0; case 1: strcpy(apiname, "generic-stubs"); return 0; case 2: strcpy(apiname, "generic-color"); return 0; case 3: if (!priv->vgl_use_db) break; if (GT_SCHEME(LIBGGI_GT(vis)) == GT_TEXT) { sprintf(apiname, "generic-text-%d", GT_SIZE(LIBGGI_GT(vis))); } else { sprintf(apiname, "generic-linear-%d%s", GT_SIZE(LIBGGI_GT(vis)), (LIBGGI_GT(vis) & GT_SUB_HIGHBIT_RIGHT) ? "-r" : ""); } return 0; default: break; } return GGI_ENOMATCH; }
static int GGIopen(struct ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t *dlret) { int err; DPRINT("generic-ramdac: Init.\n"); vis->palette = malloc(256*sizeof(ggi_color)); if (vis->palette == NULL) return GGI_ENOMEM; if ((GT_SCHEME(LIBGGI_GT(vis)) != GT_TRUECOLOR) && (GT_DEPTH(LIBGGI_GT(vis)) > 8)) { fprintf(stderr, "generic-ramdac: too many colors (%d)\n", 1 << GT_DEPTH(LIBGGI_GT(vis))); return GGI_ENOMATCH; } err = _ggiSendKGICommand(vis, (int)RAMDAC_GETCLUT, vis->palette); if (err < 0) { fprintf(stderr,"generic-ramdac: Can't get default colormap\n"); return GGI_ENODEVICE; } #if 0 /* rely on generic-color */ vis->opcolor->getpalvec=GGI_ramdac_getpalvec; #endif vis->opcolor->setpalvec=GGI_ramdac_setpalvec; *dlret = GGI_DL_OPCOLOR; return 0; }
static int do_dbstuff(struct ggi_visual *vis) { ggi_palemu_priv *priv = PALEMU_PRIV(vis); int i; /* allocate memory */ priv->frame_size = LIBGGI_FB_SIZE(LIBGGI_MODE(vis)); priv->fb_size = priv->frame_size * LIBGGI_MODE(vis)->frames; priv->fb_ptr = malloc((size_t)priv->fb_size); DPRINT_MODE("display-palemu: fb=%p size=%d frame=%d\n", priv->fb_ptr, priv->fb_size, priv->frame_size); if (priv->fb_ptr == NULL) { fprintf(stderr, "display-palemu: Out of memory.\n"); return GGI_ENOMEM; } /* clear all frames */ memset(priv->fb_ptr, 0, (size_t)priv->fb_size); /* set up pixel format */ memset(LIBGGI_PIXFMT(vis), 0, sizeof(ggi_pixelformat)); setup_pixfmt(LIBGGI_PIXFMT(vis), LIBGGI_GT(vis)); _ggi_build_pixfmt(LIBGGI_PIXFMT(vis)); /* set up direct buffers */ for (i=0; i < LIBGGI_MODE(vis)->frames; i++) { ggi_directbuffer *buf; _ggi_db_add_buffer(LIBGGI_PRIVLIST(vis), _ggi_db_get_new()); buf = LIBGGI_PRIVBUFS(vis)[i]; buf->frame = i; buf->type = GGI_DB_NORMAL | GGI_DB_SIMPLE_PLB; buf->read = (char *) priv->fb_ptr + i * priv->frame_size; buf->write = buf->read; buf->layout = blPixelLinearBuffer; buf->buffer.plb.stride = GT_ByPPP(LIBGGI_VIRTX(vis), LIBGGI_GT(vis)); buf->buffer.plb.pixelformat = LIBGGI_PIXFMT(vis); } /* Set up palette */ if (LIBGGI_PAL(vis)->clut.data) { free(LIBGGI_PAL(vis)->clut.data); LIBGGI_PAL(vis)->clut.data = NULL; } if (GT_SCHEME(LIBGGI_GT(vis)) == GT_PALETTE) { LIBGGI_PAL(vis)->clut.data = _ggi_malloc((1 << GT_DEPTH(LIBGGI_GT(vis))) * sizeof(ggi_color)); LIBGGI_PAL(vis)->clut.size = 1 << GT_DEPTH(LIBGGI_GT(vis)); } return 0; }
static int do_setmode(struct ggi_visual *vis) { char libname[GGI_MAX_APILEN], libargs[GGI_MAX_APILEN]; ggi_graphtype gt; int err, id; err = do_mmap(vis); if (err) return err; _ggiZapMode(vis, 0); for (id=1; GGI_lcd823_getapi(vis, id, libname, libargs) == 0; id++) { if (_ggiOpenDL(vis, libggi->config, libname, libargs, NULL) != 0) { fprintf(stderr,"display-lcd823: Error opening the " "%s (%s) library.\n", libname, libargs); return GGI_EFATAL; } DPRINT_LIBS("Success in loading %s (%s)\n", libname, libargs); } /* Set up palette */ gt = LIBGGI_GT(vis); if ((GT_SCHEME(gt) == GT_PALETTE) || (GT_SCHEME(gt) == GT_TEXT)) { int nocols = 1 << GT_DEPTH(gt); LIBGGI_PAL(vis)->clut.size = nocols; LIBGGI_PAL(vis)->clut.data = _ggi_malloc(nocols * sizeof(ggi_color)); LIBGGI_PAL(vis)->priv = _ggi_malloc(256 * sizeof(uint16_t)); LIBGGI_PAL(vis)->setPalette = GGI_lcd823_setPalette; LIBGGI_PAL(vis)->getPrivSize = GGI_lcd823_getPrivSize; /* Initialize palette */ ggiSetColorfulPalette(vis); } ggiIndicateChange(vis, GGI_CHG_APILIST); DPRINT_MODE("display-lcd823: do_setmode SUCCESS\n"); return 0; }
static int query_format(uint32_t format) { ggi_mode mode; uint32_t vfcap; vfcap = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_ACCEPT_STRIDE; if ((!vo_depthonscreen || !vo_dbpp) && ggi_conf.vis) { if (ggiGetMode(ggi_conf.vis, &mode) == 0) { vo_depthonscreen = GT_DEPTH(mode.graphtype); vo_dbpp = GT_SIZE(mode.graphtype); } if (GT_SCHEME(mode.graphtype) == GT_AUTO) { ggiCheckMode(ggi_conf.vis, &mode); } if (GT_SCHEME(mode.graphtype) != GT_TRUECOLOR) { mode.graphtype = GT_32BIT; vo_depthonscreen = GT_DEPTH(mode.graphtype); vo_dbpp = GT_SIZE(mode.graphtype); } } if ((IMGFMT_IS_BGR(format) && (IMGFMT_BGR_DEPTH(format) == vo_dbpp)) || (IMGFMT_IS_RGB(format) && (IMGFMT_RGB_DEPTH(format) == vo_dbpp))) { return vfcap; } if (IMGFMT_IS_BGR(format) || IMGFMT_IS_RGB(format)) { set_graphtype(format, &mode); if (ggiCheckMode(ggi_conf.drawvis, &mode) < 0) { return 0; } else { return vfcap; } } 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 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); }
int GGI_vcsa_checkmode(struct ggi_visual *vis, ggi_mode *mode) { ggi_vcsa_priv *priv = VCSA_PRIV(vis); int err; DPRINT_MODE("display-vcsa: checkmode %dx%d#%dx%dF%d[0x%02x]\n", mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); /* handle GT_AUTO in graphtype */ if (GT_SCHEME(mode->graphtype) == GT_AUTO) { GT_SETSCHEME(mode->graphtype, GT_TEXT); } if (GT_DEPTH(mode->graphtype) == GT_AUTO) { GT_SETDEPTH(mode->graphtype, 4); } if (GT_SIZE(mode->graphtype) == GT_AUTO) { GT_SETSIZE(mode->graphtype, 16); } /* handle GGI_AUTO in ggi_mode */ if ((mode->dpp.x != 1 && mode->dpp.x != GGI_AUTO) || (mode->dpp.y != 1 && mode->dpp.y != GGI_AUTO)) { err = -1; } mode->dpp.x = mode->dpp.y = 1; _GGIhandle_ggiauto(mode, priv->width, priv->height); /* now check stuff */ err = 0; if (GT_SCHEME(mode->graphtype) != GT_TEXT) { GT_SETSCHEME(mode->graphtype, GT_TEXT); err = -1; } if (GT_DEPTH(mode->graphtype) != 4) { GT_SETDEPTH(mode->graphtype, 4); err = -1; } if (GT_SIZE(mode->graphtype) != 16) { GT_SETSIZE(mode->graphtype, 16); err = -1; } if (mode->visible.x != priv->width) { mode->visible.x = priv->width; err = -1; } if (mode->visible.y != priv->height) { mode->visible.y = priv->height; err = -1; } if (mode->virt.x != priv->width) { mode->virt.x = priv->width; err = -1; } if (mode->virt.y != priv->height) { mode->virt.y = priv->height; err = -1; } if (mode->frames != 1) { mode->frames = 1; err = -1; } err = _ggi_physz_figure_size(mode, priv->physzflags, &(priv->physz), 0, 0, mode->visible.x, mode->visible.y); DPRINT_MODE("display-vcsa: result %d %dx%d#%dx%dF%d[0x%02x]\n", err, mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); return err; }
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 GGI_palemu_checkmode(struct ggi_visual *vis, ggi_mode *mode) { ggi_palemu_priv *priv = PALEMU_PRIV(vis); ggi_mode par_mode; int tmperr, err = 0; DPRINT_MODE("display-palemu: checkmode %dx%d#%dx%dF%d[0x%02x]\n", mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); /* Handle graphtype */ if (GT_SCHEME(mode->graphtype) == GT_AUTO) { GT_SETSCHEME(mode->graphtype, GT_PALETTE); } mode->graphtype = _GGIhandle_gtauto(mode->graphtype); if (GT_SCHEME(mode->graphtype) != GT_PALETTE) { GT_SETSCHEME(mode->graphtype, GT_PALETTE); err = -1; } if (GT_DEPTH(mode->graphtype) > 8) { GT_SETDEPTH(mode->graphtype, 8); err = -1; } if (GT_SIZE(mode->graphtype) != GT_DEPTH(mode->graphtype)) { GT_SETSIZE(mode->graphtype, GT_DEPTH(mode->graphtype)); err = -1; } /* Handle geometry */ if (mode->visible.x == GGI_AUTO) { mode->visible.x = priv->parent_defmode.visible.x; } if (mode->visible.y == GGI_AUTO) { mode->visible.y = priv->parent_defmode.visible.y; } if (mode->virt.x == GGI_AUTO) { mode->virt.x = priv->parent_defmode.virt.x; } if (mode->virt.y == GGI_AUTO) { mode->virt.y = priv->parent_defmode.virt.y; } if (mode->dpp.x == GGI_AUTO) { mode->dpp.x = priv->parent_defmode.dpp.x; } if (mode->dpp.y == GGI_AUTO) { mode->dpp.y = priv->parent_defmode.dpp.y; } if (mode->size.x == GGI_AUTO) { mode->size.x = priv->parent_defmode.size.x; } if (mode->size.y == GGI_AUTO) { mode->size.y = priv->parent_defmode.size.y; } if (mode->frames == GGI_AUTO) { mode->frames = 1; } /* Now check mode against the parent target (letting the parent * target handle any remaining GT_AUTO and GGI_AUTO values). */ par_mode = *mode; par_mode.graphtype = priv->parent_defmode.graphtype; tmperr = ggiCheckMode(priv->parent, &par_mode); if (tmperr) err = tmperr; mode->visible = par_mode.visible; mode->virt = par_mode.virt; mode->dpp = par_mode.dpp; mode->size = par_mode.size; /* When the parent is palettized, we must limit the * resulting depth to be <= the parent depth. */ if ((GT_SCHEME(par_mode.graphtype) == GT_PALETTE) && (GT_DEPTH(par_mode.graphtype) < GT_DEPTH(mode->graphtype))) { GT_SETDEPTH(mode->graphtype, GT_DEPTH(par_mode.graphtype)); GT_SETSIZE(mode->graphtype, GT_DEPTH(par_mode.graphtype)); err = -1; } DPRINT_MODE("display-palemu: result %d %dx%d#%dx%dF%d[0x%02x]\n", err, mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); return err; }
int GGI_trueemu_checkmode(struct ggi_visual *vis, ggi_mode *mode) { ggi_trueemu_priv *priv = TRUEEMU_PRIV(vis); ggi_mode par_mode; int tmperr, err = 0; DPRINT_MODE("display-trueemu: checkmode %dx%d#%dx%dF%d[0x%02x]\n", mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); /* Handle graphtype */ if (GT_SCHEME(mode->graphtype) == GT_AUTO) { GT_SETSCHEME(mode->graphtype, GT_TRUECOLOR); } mode->graphtype = _GGIhandle_gtauto(mode->graphtype); if (GT_SCHEME(mode->graphtype) != GT_TRUECOLOR) { GT_SETSCHEME(mode->graphtype, GT_TRUECOLOR); err = -1; } if (GT_DEPTH(mode->graphtype) != 24) { GT_SETDEPTH(mode->graphtype, 24); err = -1; } if ((GT_SIZE(mode->graphtype) != GT_DEPTH(mode->graphtype)) && (GT_SIZE(mode->graphtype) != 32)) { GT_SETSIZE(mode->graphtype, GT_DEPTH(mode->graphtype)); err = -1; } /* Handle geometry */ if (mode->visible.x == GGI_AUTO) { mode->visible.x = priv->mode.visible.x; } if (mode->visible.y == GGI_AUTO) { mode->visible.y = priv->mode.visible.y; } if (mode->virt.x == GGI_AUTO) { mode->virt.x = priv->mode.virt.x; } if (mode->virt.y == GGI_AUTO) { mode->virt.y = priv->mode.virt.y; } if (mode->dpp.x == GGI_AUTO) { mode->dpp.x = priv->mode.dpp.x; } if (mode->dpp.y == GGI_AUTO) { mode->dpp.y = priv->mode.dpp.y; } if (mode->size.x == GGI_AUTO) { mode->size.x = priv->mode.size.x; } if (mode->size.y == GGI_AUTO) { mode->size.y = priv->mode.size.y; } if (mode->frames == GGI_AUTO) { mode->frames = 1; } /* Now let the parent target have it's say in the checkmode * process. It can deal with any remaining GGI_AUTO or GT_AUTO * values that came from priv->mode. */ par_mode = *mode; par_mode.graphtype = priv->mode.graphtype; tmperr = ggiCheckMode(priv->parent, &par_mode); if (tmperr) err = tmperr; mode->visible = par_mode.visible; mode->virt = par_mode.virt; mode->dpp = par_mode.dpp; mode->size = par_mode.size; DPRINT_MODE("display-trueemu: upgraded to %dx%d#%dx%dF%d[0x%02x]\n", mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); return err; }
int GGI_vgl_setmode(ggi_visual *vis, ggi_mode *tm) { struct vgl_priv *priv = VGL_PRIV(vis); ggi_graphtype gt = tm->graphtype; video_info_t modeinfo; unsigned long modenum = 0; char sugname[GGI_MAX_APILEN]; char args[GGI_MAX_APILEN]; int err = 0; int id, i; int pixelBytes; err = GGI_vgl_checkmode(vis, tm); if (err) return err; /* reset the modeinfo structure as expected by query_mode */ memset(&modeinfo, 0, sizeof(modeinfo)); switch(gt) { case GT_1BIT : modeinfo.vi_depth = 1; pixelBytes = 1; break; case GT_4BIT : modeinfo.vi_depth = 4; pixelBytes = 1; break; case GT_8BIT : modeinfo.vi_depth = 8; pixelBytes = 1; break; case GT_16BIT: modeinfo.vi_depth = 16; pixelBytes = 2; break; case GT_32BIT: modeinfo.vi_depth = 32; pixelBytes = 4; break; /* Unsupported mode depths */ case GT_15BIT: case GT_24BIT: default: return GGI_ENOMATCH; } modeinfo.vi_width = tm->visible.x; modeinfo.vi_height = tm->visible.y; /* XXX should be added to libvgl */ if (ioctl(0, FBIO_FINDMODE, &modeinfo)) return -1; DPRINT("Setting VGLlib mode %d (0x%x)\n", modeinfo.vi_mode, modeinfo.vi_mode); /* Terminate any current mode before initialising another */ if (priv->vgl_init_done) { priv->vgl_init_done = 0; VGLEnd(); } /* XXX should be in VGL */ if ((modeinfo.vi_mode >= M_B40x25) && (modeinfo.vi_mode <= M_VGA_M90x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_TEXT_80x25) && (modeinfo.vi_mode <= M_TEXT_132x60)) modenum = _IO('S', modeinfo.vi_mode); if ((modeinfo.vi_mode >= M_VESA_CG640x400) && (modeinfo.vi_mode <= M_VESA_FULL_1280)) modenum = _IO('V', modeinfo.vi_mode - M_VESA_BASE); if ((err = VGLInit(modenum)) != 0) { DPRINT("display-vgl: setting mode 0x%x failed with error %d\n", modeinfo.vi_mode, err); return GGI_EFATAL; } priv->vgl_init_done = 1; if (priv->vgl_use_db) { _GGI_vgl_freedbs(vis); /* Set up DirectBuffer(s) */ for (i = 0; i<tm->frames; i++) { if (LIBGGI_FB_SIZE(tm) > (unsigned)(VGLDisplay->Xsize*VGLDisplay->Ysize* pixelBytes)) { fprintf(stderr, "display-vgl: framebuffer too large! (%d > %d*%d*%d)\n", LIBGGI_FB_SIZE(tm), VGLDisplay->Xsize, VGLDisplay->Ysize, pixelBytes); return GGI_ENOMEM; } _ggi_db_add_buffer(LIBGGI_APPLIST(vis), _ggi_db_get_new()); LIBGGI_APPBUFS(vis)[i]->frame = i; LIBGGI_APPBUFS(vis)[i]->type = GGI_DB_NORMAL | GGI_DB_SIMPLE_PLB; LIBGGI_APPBUFS(vis)[i]->read = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->write = VGLDisplay->Bitmap; LIBGGI_APPBUFS(vis)[i]->layout = blPixelLinearBuffer; LIBGGI_APPBUFS(vis)[i]->buffer.plb.stride = GT_ByPPP(tm->virt.x, tm->graphtype); } } /* Save mode info returned by the VESA driver */ bcopy(&modeinfo, &priv->modeinfo, sizeof(priv->modeinfo)); /* Palette */ if (vis->palette) { free(vis->palette); vis->palette = NULL; } if (priv->savepalette) { free(priv->savepalette); priv->savepalette = NULL; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { int len = 1 << GT_DEPTH(tm->graphtype); vis->palette = malloc(len * sizeof(ggi_color)); if (vis->palette == NULL) return GGI_EFATAL; priv->savepalette = malloc(sizeof(int) * (len*3)); if (priv->savepalette == NULL) return GGI_EFATAL; /* Set an initial palette */ ggiSetColorfulPalette(vis); } /* Set up pixel format */ memset(LIBGGI_PIXFMT(vis), 0, sizeof(ggi_pixelformat)); LIBGGI_PIXFMT(vis)->size = GT_SIZE(gt); LIBGGI_PIXFMT(vis)->depth = GT_DEPTH(gt); switch (GT_SCHEME(gt)) { case GT_PALETTE: case GT_GREYSCALE: LIBGGI_PIXFMT(vis)->clut_mask = (1 << GT_DEPTH(gt)) - 1; break; case GT_TRUECOLOR: DPRINT_MODE("display-vgl: RGB %d:%d:%d offsets %d:%d:%d\n", priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX], priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX], priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX], priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]); LIBGGI_PIXFMT(vis)->red_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_RED_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_RED_INDEX]; LIBGGI_PIXFMT(vis)->green_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_GREEN_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_GREEN_INDEX]; LIBGGI_PIXFMT(vis)->blue_mask = ((1 << priv->modeinfo.vi_pixel_fsizes[VGL_BLUE_INDEX]) - 1) << priv->modeinfo.vi_pixel_fields[VGL_BLUE_INDEX]; break; case GT_TEXT: /* Assumes VGA text */ LIBGGI_PIXFMT(vis)->texture_mask = 0x00ff; LIBGGI_PIXFMT(vis)->fg_mask = 0x0f00; LIBGGI_PIXFMT(vis)->bg_mask = 0xf000; break; } _ggi_build_pixfmt(LIBGGI_PIXFMT(vis)); memcpy(LIBGGI_MODE(vis),tm,sizeof(ggi_mode)); _ggiZapMode(vis, 0); for(id = 1; 0 == GGI_vgl_getapi(vis, id, sugname, args); id++) { if (_ggiOpenDL(vis, _ggiGetConfigHandle(), sugname, args, NULL)) { fprintf(stderr,"display-vgl: Can't open the %s (%s) library.\n", sugname, args); return GGI_EFATAL; } else { DPRINT("Success in loading %s (%s)\n", sugname, args); } } if (!priv->vgl_use_db) { vis->opdraw->putpixel = GGI_vgl_putpixel; vis->opdraw->putpixel_nc = GGI_vgl_putpixel_nc; vis->opdraw->getpixel = GGI_vgl_getpixel; vis->opdraw->drawpixel = GGI_vgl_drawpixel; vis->opdraw->drawpixel_nc = GGI_vgl_drawpixel_nc; vis->opdraw->drawhline = GGI_vgl_drawhline; vis->opdraw->drawhline_nc = GGI_vgl_drawhline_nc; vis->opdraw->drawvline = GGI_vgl_drawvline; vis->opdraw->drawvline_nc = GGI_vgl_drawvline_nc; vis->opdraw->drawbox = GGI_vgl_drawbox; vis->opdraw->drawline = GGI_vgl_drawline; vis->opdraw->puthline = GGI_vgl_puthline; vis->opdraw->putbox = GGI_vgl_putbox; } else { vis->opdraw->setorigin = GGI_vgl_setorigin; } if (GT_SCHEME(tm->graphtype) == GT_PALETTE) { vis->opcolor->setpalvec = GGI_vgl_setpalvec; } if(priv->vgl_use_db) { for(i = 0; i<tm->frames; i++) LIBGGI_APPBUFS(vis)[i]->buffer.plb.pixelformat = LIBGGI_PIXFMT(vis); } ggiIndicateChange(vis, GGI_CHG_APILIST); return 0; }
static int GGIopen(ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32_t *dlret) { ggi_fbdev_priv *fbdevpriv = FBDEV_PRIV(vis); struct m2164w_priv *priv; unsigned long usedmemend; size_t fontlen; int pixbytes; int fd = LIBGGI_FD(vis); int i; if (GT_SIZE(LIBGGI_GT(vis)) % 8 != 0 || GT_SIZE(LIBGGI_GT(vis)) > 32 || GT_SIZE(LIBGGI_GT(vis)) < 8) { /* Unsupported mode */ return GGI_ENOFUNC; } pixbytes = GT_ByPP(LIBGGI_GT(vis)); priv = malloc(sizeof(struct m2164w_priv)); if (priv == NULL) { return GGI_ENOMEM; } fbdevpriv->mmioaddr = mmap(NULL, fbdevpriv->orig_fix.mmio_len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (signed)fbdevpriv->orig_fix.smem_len); if (fbdevpriv->mmioaddr == MAP_FAILED) { /* Can't mmap() MMIO region - bail out */ DPRINT_LIBS("mga-2164w: Unable to map MMIO region: %s\n" " fd: %d, len: %ld, offset: %ld\n", strerror(errno), fd, fbdevpriv->orig_fix.mmio_len, fbdevpriv->orig_fix.smem_len); fbdevpriv->mmioaddr = NULL; free(priv); return GGI_ENODEVICE; } DPRINT_MISC("mga-2164w: Mapped MMIO region at %p\n", fbdevpriv->mmioaddr); /* Set up DirectBuffers */ for (i=0; i < LIBGGI_MODE(vis)->frames; i++) { ggi_directbuffer *buf = LIBGGI_APPBUFS(vis)[i]; ggi_resource *res; res = malloc(sizeof(ggi_resource)); if (res == NULL) { do_cleanup(vis); return GGI_ENOMEM; } buf->resource = res; buf->resource->acquire = m2164w_acquire; buf->resource->release = m2164w_release; buf->resource->self = buf; buf->resource->priv = vis; buf->resource->count = 0; buf->resource->curactype = 0; } priv->drawboxcmd = BOP_COPY | SHFTZERO | SGNZERO | ARZERO | SOLID | OP_TRAP; if (pixbytes != 3) { switch (fbdevpriv->orig_fix.accel) { case FB_ACCEL_MATROX_MGA2064W: case FB_ACCEL_MATROX_MGA1064SG: case FB_ACCEL_MATROX_MGA2164W: case FB_ACCEL_MATROX_MGA2164W_AGP: /* Use block mode */ priv->drawboxcmd |= ATYPE_BLK; break; default: /* For now - assume SDRAM for other cards */ break; } } priv->dwgctl = 0; priv->oldfgcol = LIBGGI_GC(vis)->fg_color - 1; priv->oldbgcol = LIBGGI_GC(vis)->bg_color - 1; priv->oldtl.x = -1; priv->oldtl.y = -1; priv->oldbr.x = -1; priv->oldbr.y = -1; priv->oldyadd = -1; priv->curopmode = priv->origopmode = mga_in16(fbdevpriv->mmioaddr, OPMODE); /* Use the 7k Pseudo-DMA window */ priv->dmaaddr = (void*)fbdevpriv->mmioaddr; priv->dma_len = 0x1c00; vis->needidleaccel = 1; fbdevpriv->idleaccel = m2164w_idleaccel; /* Accelerate fonts if possible */ priv->font = (uint8_t *)(font); usedmemend = LIBGGI_MODE(vis)->frames * fbdevpriv->fix.line_length * LIBGGI_VIRTY(vis); fontlen = 256*8; priv->fontoffset = fbdevpriv->orig_fix.smem_len - fontlen; priv->fontoffset &= ~127; /* Align */ DPRINT_MISC("mga-2164w: usedmemend: %ld, fontoffset: %ld\n", usedmemend, priv->fontoffset); if (usedmemend <= priv->fontoffset) { memcpy((uint8_t*)fbdevpriv->fb_ptr + priv->fontoffset, font, fontlen); priv->fontoffset *= 8; /* In bits */ priv->charadd = FWIDTH*FHEIGHT; vis->opdraw->putc = GGI_m2164w_fastputc; vis->opdraw->puts = GGI_m2164w_fastputs; DPRINT_MISC("mga-2164w: Using fast chars\n"); } else { priv->fontoffset = 0; vis->opdraw->putc = GGI_m2164w_putc; vis->opdraw->puts = GGI_m2164w_puts; DPRINT_MISC("mga-2164w: Using slow chars\n"); } /* Save previous function pointers */ priv->crossblit = vis->opdraw->crossblit; /* Initialize function pointers */ vis->opdraw->getcharsize= GGI_m2164w_getcharsize; vis->opdraw->drawhline = GGI_m2164w_drawhline; vis->opdraw->drawvline = GGI_m2164w_drawvline; vis->opdraw->drawline = GGI_m2164w_drawline; vis->opdraw->drawbox = GGI_m2164w_drawbox; vis->opdraw->copybox = GGI_m2164w_copybox; vis->opdraw->fillscreen = GGI_m2164w_fillscreen; /* The crossblit in linear-* is faster on truecolor modes! */ if (GT_SCHEME(LIBGGI_GT(vis)) == GT_PALETTE || GT_SCHEME(LIBGGI_GT(vis)) == GT_STATIC_PALETTE) { vis->opdraw->crossblit = GGI_m2164w_crossblit; } FBDEV_PRIV(vis)->accelpriv = priv; /* Register cleanup handler */ ggRegisterCleanup((ggcleanup_func *)do_cleanup, vis); *dlret = GGI_DL_OPDRAW; return 0; }