static int changed(ggi_visual_t vis, int whatchanged) { GGIMESADPRINT_CORE("Entered ggimesa_genkgi_changed\n"); switch (whatchanged) { case GGI_CHG_APILIST: { char api[256]; char args[256]; int i; const char *fname; ggi_dlhandle *lib; for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++) { strcat(api, "-mesa"); GGIMESADPRINT_CORE("ggimesa_genkgi_changed: api=%s, i=%d\n", api, i); fname = ggMatchConfig(_configHandle, api, NULL); if (fname == NULL) { /* No special implementation for this sublib */ continue; } lib = ggiExtensionLoadDL(vis, fname, args, NULL); } } break; } return 0; }
int GGIMesa_fbdev_setmode(ggi_visual *vis, ggi_mode *mode) { int err; if ((err = ggiCheckMode(vis, mode)) != 0) { return err; } GGIMESADPRINT_CORE("display-fbdev-mesa: setmode %dx%d#%dx%dF%d[0x%02x]\n", mode->visible.x, mode->visible.y, mode->virt.x, mode->virt.y, mode->frames, mode->graphtype); memcpy(LIBGGI_MODE(vis), mode, sizeof(ggi_mode)); /* Now actually set the mode */ err = do_setmode(vis); if (err != 0) { return err; } GGIMESADPRINT_CORE("display-fbdev-mesa: setmode success.\n"); return 0; }
static int do_setmode(ggi_visual *vis) { struct fbdev_priv_mesa *priv = GGIMESA_PRIV(vis); int err, id; char libname[GGI_API_MAXLEN], libargs[GGI_API_MAXLEN]; ggi_graphtype gt; _ggiZapMode(vis, ~GGI_DL_OPDISPLAY); priv->have_accel = 0; for (id = 1; GGIMesa_fbdev_getapi(vis, id, libname, libargs) == 0; id++) { if (_ggiOpenDL(vis, libname, libargs, NULL) == 0) { GGIMESADPRINT_LIBS(stderr, "display-fbdev-mesa: Error opening the " "%s (%s) library.\n", libname, libargs); return GGI_EFATAL; } GGIMESADPRINT_CORE("Success in loading %s (%s)\n", libname, libargs); } if (priv->oldpriv->accel && _ggiOpenDL(vis, priv->accel, NULL, NULL) != 0) { priv->have_accel = 1; } else { priv->have_accel = 0; } vis->accelactive = 0; ggiIndicateChange(vis, GGI_CHG_APILIST); GGIMESADPRINT_CORE("display-fbdev-mesa: do_setmode SUCCESS\n"); return 0; }
static int changed(ggi_visual_t vis, int whatchanged) { GLcontext *ctx; ctx = _mesa_get_current_context(); GGIMESADPRINT_CORE("changed() called\n"); switch (whatchanged) { case GGI_CHG_APILIST: { char api[GGI_MAX_APILEN]; char args[GGI_MAX_APILEN]; int i; const char *fname; ggi_dlhandle *lib; GLvisual *gl_vis = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual); GLframebuffer *gl_fb = &(LIBGGI_MESAEXT(vis)->mesa_buffer); /* Initialize the framebuffer to provide all necessary buffers in software. The target libraries that are loaded next are free to modify this according to their capabilities. */ /* FIXME: if the target changes capabilities we'll leak swrast's memory !!! Need to deallocate first */ _mesa_initialize_framebuffer(gl_fb, gl_vis, gl_vis->depthBits > 0, gl_vis->stencilBits > 0, gl_vis->accumRedBits > 0, gl_vis->alphaBits > 0); for (i = 0; ggiGetAPI(vis, i, api, args) == 0; i++) { strcat(api, "-mesa"); GGIMESADPRINT_CORE("GGIMesa: looking for" "a sublib named %s\n", api); fname = ggMatchConfig(_ggimesaConfigHandle, api, NULL); if (fname == NULL) { /* No special implementation for this sublib */ continue; } lib = ggiExtensionLoadDL(vis, fname, args, NULL, SUBLIB_PREFIX); } /* The targets have cleared everything they can do from the framebuffer structure so we provide the rest in sw */ /*_swrast_alloc_buffers(gl_fb);*/ break; } } return 0; }
int ggiMesaInit() { int err; char *str; char *conffile; GGIMESADPRINT_CORE("ggiMesaInit() called\n"); _ggimesaLibIsUp++; if (_ggimesaLibIsUp > 1) return 0; /* Initialize only at first call */ str = getenv("GGIMESA_DEBUGSYNC"); if (str != NULL) { _ggimesaDebugSync = 1; } str = getenv("GGIMESA_DEBUG"); if (str != NULL) { _ggimesaDebugState = atoi(str); GGIMESADPRINT_CORE("%s Debugging=%d\n", _ggimesaDebugSync ? "sync" : "async", _ggimesaDebugState); } conffile = malloc(strlen(ggiMesaGetConfDir()) + 1 + strlen(GGIMESACONFFILE) +1); if (conffile == NULL) { fprintf(stderr, "GGIMesa: unable to allocate memory for config filename.\n"); return GGI_ENOMEM; } sprintf(conffile, "%s%c%s", ggiMesaGetConfDir(), '/', GGIMESACONFFILE); err = ggLoadConfig(conffile, &_ggimesaConfigHandle); if (err != GGI_OK) { fprintf(stderr, "GGIMesa: Couldn't open %s\n", conffile); free(conffile); _ggimesaLibIsUp--; return err; } free(conffile); _ggiMesaID = ggiExtensionRegister("GGIMesa", sizeof(struct ggi_mesa_ext), changed); if (_ggiMesaID < 0) { fprintf(stderr, "GGIMesa: failed to register as extension\n"); _ggimesaLibIsUp--; ggFreeConfig(_ggimesaConfigHandle); return _ggiMesaID; } return 0; }
void ggiMesaMakeCurrent(ggi_mesa_context_t ctx, ggi_visual_t vis) { GGIMESADPRINT_CORE("ggiMesaMakeCurrent(ctx = %p) called\n", ctx); /* FIXME: clean up where are ggi_vis */ if (ctx->ggi_visual != vis) { GGIMESADPRINT_CORE("Cannot migrate GL contexts\n"); return; } _mesa_make_current(ctx->gl_ctx, &LIBGGI_MESAEXT(vis)->mesa_buffer); }
ggi_mesa_context_t ggiMesaCreateContext(ggi_visual_t vis) { ggi_mesa_context_t ctx; int err; GGIMESADPRINT_CORE("ggiMesaCreateContext() called\n"); ctx = (ggi_mesa_context_t)malloc(sizeof(struct ggi_mesa_context)); if (!ctx) return NULL; ctx->ggi_visual = vis; ctx->color = 0; ctx->gl_ctx = _mesa_create_context(&(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual), NULL, (void *) ctx, GL_FALSE); if (!ctx->gl_ctx) goto free_context; _mesa_enable_sw_extensions(ctx->gl_ctx); _swrast_CreateContext(ctx->gl_ctx); _vbo_CreateContext(ctx->gl_ctx); _tnl_CreateContext(ctx->gl_ctx); _swsetup_CreateContext(ctx->gl_ctx); gl_ggiSetupPointers(ctx->gl_ctx); /* Make sure that an appropriate sublib has been loaded */ if (!LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver){ GGIMESADPRINT_CORE("setup_driver==NULL!\n"); GGIMESADPRINT_CORE("Please check your config files!\n"); goto free_context; } /* Set up the sublib driver */ err = LIBGGI_MESAEXT(ctx->ggi_visual)->setup_driver(ctx); if (err){ GGIMESADPRINT_CORE("setup_driver failed (err = %d)", err); goto free_gl_context; } return ctx; free_gl_context: _mesa_destroy_context(ctx->gl_ctx); free_context: free(ctx); return NULL; }
int ggiMesaAttach(ggi_visual_t vis) { int rc; GGIMESADPRINT_CORE("ggiMesaAttach() called\n"); rc = ggiExtensionAttach(vis, _ggiMesaID); if (rc == 0) { int r, g, b, ci; GLboolean rgb, db; GLvisual *gl_visual; /* We are creating the primary instance */ memset(LIBGGI_MESAEXT(vis), 0, sizeof(struct ggi_mesa_ext)); LIBGGI_MESAEXT(vis)->update_state = (void *)_ggi_error; LIBGGI_MESAEXT(vis)->setup_driver = (void *)_ggi_error; /* Initialize default mesa visual */ get_mode_info(vis, &r, &g, &b, &rgb, &db, &ci); gl_visual = &(LIBGGI_MESAEXT(vis)->mesa_visual.gl_visual); _mesa_initialize_visual(gl_visual, rgb, db, 0 /* No stereo */, r, g, b, 0 /* No alpha */, ci, 0 /* No depth */, 0 /* No stencil */, 0, 0, 0, 0 /* No accum */, 0); /* Now fake an "API change" so the right libs get loaded */ changed(vis, GGI_CHG_APILIST); } return rc; }
/* XXX support for separate read/draw buffers hasn't been tested */ static GLboolean gl_ggiSetBuffer(GLcontext *ctx, GLframebuffer *buffer, GLuint bufferBit) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; printf("set read %d\n", bufferBit); GGIMESADPRINT_CORE("gl_ggiSetBuffer() called\n"); if (bufferBit == DD_FRONT_LEFT_BIT) { ggiSetReadFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)); ggiSetWriteFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)); return GL_TRUE; } else if (bufferBit == DD_BACK_LEFT_BIT) { ggiSetReadFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1); ggiSetWriteFrame(ggi_ctx->ggi_visual, ggiGetDisplayFrame(ggi_ctx->ggi_visual)?0 : 1); return GL_TRUE; } else return GL_FALSE; }
static void gl_ggiClear(GLcontext *ctx, GLbitfield mask) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; int x = ctx->DrawBuffer->_Xmin; int y = ctx->DrawBuffer->_Ymin; int w = ctx->DrawBuffer->_Xmax - x; int h = ctx->DrawBuffer->_Ymax - y; GLboolean all = (w == ctx->DrawBuffer->Width && h == ctx->DrawBuffer->height) GGIMESADPRINT_CORE("gl_ggiClear() called\n"); if (mask & (DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT)) { ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->clearcolor); if (all) { int w, h; w = LIBGGI_VIRTX(ggi_ctx->ggi_visual); h = LIBGGI_VIRTX(ggi_ctx->ggi_visual); ggiDrawBox(ggi_ctx->ggi_visual, 0, 0, w, h); } else { ggiDrawBox(ggi_ctx->ggi_visual, x, y, //FLIP(y), width, height); } ggiSetGCForeground(ggi_ctx->ggi_visual, ggi_ctx->color); mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT); } _swrast_Clear(ctx, mask); }
static void gl_ggiSetupPointers(GLcontext *ctx) { TNLcontext *tnl; GGIMESADPRINT_CORE("gl_ggiSetupPointers() called\n"); /* Plug in default driver functions */ _mesa_init_driver_functions(&ctx->Driver); /* Plug in ggi-specific functions */ ctx->Driver.GetString = gl_ggiGetString; ctx->Driver.GetBufferSize = gl_ggiGetSize; ctx->Driver.Viewport = gl_ggiViewport; ctx->Driver.Finish = gl_ggiFlush; ctx->Driver.Flush = gl_ggiFlush; ctx->Driver.Clear = gl_ggiClear; ctx->Driver.ClearIndex = gl_ggiSetClearIndex; ctx->Driver.ClearColor = gl_ggiSetClearColor; ctx->Driver.IndexMask = gl_ggiIndexMask; ctx->Driver.ColorMask = gl_ggiColorMask; ctx->Driver.Enable = gl_ggiEnable; ctx->Driver.UpdateState = gl_ggiUpdateState; /* Initialize TNL driver interface */ tnl = TNL_CONTEXT(ctx); tnl->Driver.RunPipeline = _tnl_run_pipeline; /* Install setup for tnl */ _swsetup_Wakeup(ctx); }
static void gl_ggiFlush(GLcontext *ctx) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiFlush() called\n"); ggiFlush(ggi_ctx->ggi_visual); }
static void gl_ggiSetClearIndex(GLcontext *ctx, GLuint ci) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiSetClearIndex() called\n"); ggiSetGCForeground(ggi_ctx->ggi_visual, ci); ggi_ctx->clearcolor = (ggi_pixel)ci; }
static const GLubyte * gl_ggiGetString(GLcontext *ctx, GLenum name) { GGIMESADPRINT_CORE("gl_ggiGetString() called\n"); if (name == GL_RENDERER) { return (GLubyte *) "Mesa GGI"; } else { return NULL; } }
void ggiMesaDestroyContext(ggi_mesa_context_t ctx) { GGIMESADPRINT_CORE("ggiMesaDestroyContext() called\n"); if(!ctx) return; _mesa_destroy_context(ctx->gl_ctx); free(ctx); }
static void gl_ggiUpdateState(GLcontext *ctx, GLuint new_state) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiUpdateState() called\n"); /* Propogate statechange information to swrast and swrast_setup * modules. The GGI driver has no internal GL-dependent state. */ _swrast_InvalidateState(ctx, new_state); _swsetup_InvalidateState(ctx, new_state); _tnl_InvalidateState(ctx, new_state); /* XXX: Better use an assertion that bails out here on failure */ if (!LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state) { GGIMESADPRINT_CORE("update_state == NULL!\n"); GGIMESADPRINT_CORE("Please check your config files!\n"); ggiPanic(""); } LIBGGI_MESAEXT(ggi_ctx->ggi_visual)->update_state(ggi_ctx); }
static void gl_ggiGetSize(GLframebuffer *fb, GLuint *width, GLuint *height) { /* FIXME: this is a hack to work around the new interface */ GLcontext *ctx; ggi_mesa_context_t ggi_ctx; ctx = _mesa_get_current_context(); ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("gl_ggiGetSize() called\n"); *width = LIBGGI_VIRTX(ggi_ctx->ggi_visual); *height = LIBGGI_VIRTY(ggi_ctx->ggi_visual); printf("returning %d, %d\n", *width, *height); }
/* * Swap front/back buffers for current context if double buffered. */ void ggiMesaSwapBuffers(void) { GLcontext *ctx; ggi_mesa_context_t ggi_ctx; ctx = _mesa_get_current_context(); ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; GGIMESADPRINT_CORE("ggiMesaSwapBuffers() called\n"); _mesa_notifySwapBuffers(ctx); gl_ggiFlush(ctx); ggiSetDisplayFrame(ggi_ctx->ggi_visual, !ggiGetDisplayFrame(ggi_ctx->ggi_visual)); ggiSetWriteFrame(ggi_ctx->ggi_visual, !ggiGetWriteFrame(ggi_ctx->ggi_visual)); ggiSetReadFrame(ggi_ctx->ggi_visual, !ggiGetReadFrame(ggi_ctx->ggi_visual)); GGIMESADPRINT_CORE("swap disp: %d, write %d\n", ggiGetDisplayFrame(ggi_ctx->ggi_visual), ggiGetWriteFrame(ggi_ctx->ggi_visual)); }
static void gl_ggiSetClearColor(GLcontext *ctx, const GLfloat color[4]) { ggi_mesa_context_t ggi_ctx = (ggi_mesa_context_t)ctx->DriverCtx; ggi_color rgb; ggi_pixel col; GLubyte byteColor[3]; GGIMESADPRINT_CORE("gl_ggiSetClearColor() called\n"); CLAMPED_FLOAT_TO_UBYTE(byteColor[0], color[0]); CLAMPED_FLOAT_TO_UBYTE(byteColor[1], color[1]); CLAMPED_FLOAT_TO_UBYTE(byteColor[2], color[2]); rgb.r = (uint16)byteColor[0] << SHIFT; rgb.g = (uint16)byteColor[1] << SHIFT; rgb.b = (uint16)byteColor[2] << SHIFT; col = ggiMapColor(ggi_ctx->ggi_visual, &rgb); ggiSetGCForeground(ggi_ctx->ggi_visual, col); ggi_ctx->clearcolor = col; }
int ggiMesaExit(void) { int rc; GGIMESADPRINT_CORE("ggiMesaExit() called\n"); if (!_ggimesaLibIsUp) return -1; if (_ggimesaLibIsUp > 1) { /* Exit only at last call */ _ggimesaLibIsUp--; return 0; } rc = ggiExtensionUnregister(_ggiMesaID); ggFreeConfig(_ggimesaConfigHandle); _ggimesaLibIsUp = 0; return rc; }
int ggiMesaDetach(ggi_visual_t vis) { GGIMESADPRINT_CORE("ggiMesaDetach() called\n"); return ggiExtensionDetach(vis, _ggiMesaID); }
static int GGIdlinit(ggi_visual *vis, struct ggi_dlhandle *dlh, const char *args, void *argptr, uint32 *dlret) { struct genkgi_priv_mesa *priv; char libname[256], libargs[256]; int id, err; struct stat junk; ggifunc_getapi *oldgetapi; GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: GGIdlinit start\n"); GENKGI_PRIV_MESA(vis) = priv = malloc(sizeof(struct genkgi_priv_mesa)); if (priv == NULL) { fprintf(stderr, "Failed to allocate genkgi private data\n"); return GGI_DL_ERROR; } priv->oldpriv = GENKGI_PRIV(vis); #if 0 err = ggLoadConfig(conffile, &_configHandle); if (err != GGI_OK) { gl_ggiPrint("display-fbdev-kgicon-mesa: Couldn't open %s\n", conffile); return err; } /* Hack city here. We need to probe the KGI driver properly for * suggest-strings to discover the acceleration type(s). */ priv->have_accel = 0; if (stat("/proc/gfx0", &junk) == 0) { sprintf(priv->accel, "%s%s", accel_prefix, "d3dim"); priv->have_accel = 1; GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: Using accel: \"%s\"\n", priv->accel); } /* Mode management */ vis->opdisplay->getapi = GGIMesa_genkgi_getapi; ggiIndicateChange(vis, GGI_CHG_APILIST); /* Give the accel sublibs a chance to set up a driver */ if (priv->have_accel == 1) { oldgetapi = vis->opdisplay->getapi; vis->opdisplay->getapi = GGIMesa_genkgi_getapi; changed(vis, GGI_CHG_APILIST); /* If the accel sublibs didn't produce, back up * and keep looking */ if ((LIBGGI_MESAEXT(vis)->update_state == NULL) || (LIBGGI_MESAEXT(vis)->setup_driver == NULL)) vis->opdisplay->getapi = oldgetapi; } LIBGGI_MESAEXT(vis)->update_state = genkgi_update_state; LIBGGI_MESAEXT(vis)->setup_driver = genkgi_setup_driver; #endif GGIMESADPRINT_CORE("display-fbdev-kgicon-mesa: GGIdlinit finished\n"); *dlret = GGI_DL_OPDRAW; return 0; }
/* Dummy function which returns -1 We use this to reset the function pointers */ static int _ggi_error(void) { GGIMESADPRINT_CORE("_ggi_error() called\n"); return -1; }
static void gl_ggiIndexMask(GLcontext *ctx, GLuint mask) { GGIMESADPRINT_CORE("gl_ggiIndexMask() called\n"); }
static void gl_ggiColorMask(GLcontext *ctx, GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask) { GGIMESADPRINT_CORE("gl_ggiColorMask() called\n"); }
static void gl_ggiEnable(GLcontext *ctx, GLenum pname, GLboolean state) { GGIMESADPRINT_CORE("gl_ggiEnable() called\n"); }