From 0b9434aafdfde5cf429179a5b79ec839911bc350 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 13 Jan 2003 15:31:31 +0000 Subject: [PATCH] Add config file facility and remove hardwired options from minglx.c Move functionality for setting up glx configs into the drivers. Allow the driver to tweak modes (eg for pitch) before setting up fbdev. --- src/mesa/drivers/dri/radeon/radeon_ioctl.c | 4 - src/mesa/drivers/dri/radeon/radeon_state.c | 5 - .../drivers/dri/radeon/radeon_state_init.c | 5 - .../drivers/dri/radeon/server/radeon_dri.c | 114 ++++++---- src/mesa/tnl/t_context.c | 3 +- src/miniglx/Makefile | 2 +- src/miniglx/NOTES | 3 + src/miniglx/drmtest.c | 3 - src/miniglx/miniglx.c | 201 ++++++++---------- src/miniglx/miniglxP.h | 20 +- 10 files changed, 186 insertions(+), 174 deletions(-) diff --git a/src/mesa/drivers/dri/radeon/radeon_ioctl.c b/src/mesa/drivers/dri/radeon/radeon_ioctl.c index 65caf82a578..2eb425b8686 100644 --- a/src/mesa/drivers/dri/radeon/radeon_ioctl.c +++ b/src/mesa/drivers/dri/radeon/radeon_ioctl.c @@ -827,10 +827,6 @@ void radeonPageFlip( const __DRIdrawablePrivate *dPriv ) rmesa->state.color.drawPitch = rmesa->radeonScreen->backPitch; } - fprintf(stderr, "%s: pfCurrentPage %d COLOROFFSET %x\n", __FUNCTION__, - rmesa->sarea->pfCurrentPage, - rmesa->state.color.drawOffset); - RADEON_STATECHANGE( rmesa, ctx ); rmesa->hw.ctx.cmd[CTX_RB3D_COLOROFFSET] = rmesa->state.color.drawOffset; rmesa->hw.ctx.cmd[CTX_RB3D_COLORPITCH] = rmesa->state.color.drawPitch; diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c b/src/mesa/drivers/dri/radeon/radeon_state.c index 0a0d206bd50..a4457a79160 100644 --- a/src/mesa/drivers/dri/radeon/radeon_state.c +++ b/src/mesa/drivers/dri/radeon/radeon_state.c @@ -1604,11 +1604,6 @@ static void radeonDrawBuffer( GLcontext *ctx, GLenum mode ) rmesa->state.color.drawPitch = rmesa->radeonScreen->frontPitch; } - fprintf(stderr, "use_back %d doubleBufferMode %d COLOROFFSET %x\n", - use_back, - ctx->Visual.doubleBufferMode, - rmesa->state.color.drawOffset); - rmesa->state.pixel.readOffset = rmesa->state.color.drawOffset; rmesa->state.pixel.readPitch = rmesa->state.color.drawPitch; } diff --git a/src/mesa/drivers/dri/radeon/radeon_state_init.c b/src/mesa/drivers/dri/radeon/radeon_state_init.c index db043801193..3ef406ec0ca 100644 --- a/src/mesa/drivers/dri/radeon/radeon_state_init.c +++ b/src/mesa/drivers/dri/radeon/radeon_state_init.c @@ -201,11 +201,6 @@ void radeonInitState( radeonContextPtr rmesa ) rmesa->state.color.drawPitch = rmesa->radeonScreen->frontPitch; } - fprintf(stderr, "use_back %d doubleBufferMode %d COLOROFFSET %x\n", - use_back, - ctx->Visual.doubleBufferMode, - rmesa->state.color.drawOffset); - rmesa->state.pixel.readOffset = rmesa->state.color.drawOffset; rmesa->state.pixel.readPitch = rmesa->state.color.drawPitch; } diff --git a/src/mesa/drivers/dri/radeon/server/radeon_dri.c b/src/mesa/drivers/dri/radeon/server/radeon_dri.c index 04a41e35628..9e729438b69 100644 --- a/src/mesa/drivers/dri/radeon/server/radeon_dri.c +++ b/src/mesa/drivers/dri/radeon/server/radeon_dri.c @@ -435,36 +435,6 @@ static void RADEONDRIIrqInit(struct MiniGLXDisplayRec *dpy, - - - - -/* Will fbdev set a pitch appropriate for 3d? - */ -static int RADEONSetPitch (struct MiniGLXDisplayRec *dpy) -{ - int dummy = dpy->VarInfo.xres_virtual; - - /* FIXME: May need to validate line pitch here */ - switch (dpy->VarInfo.bits_per_pixel / 8) { - case 1: dummy = (dpy->VarInfo.xres_virtual + 127) & ~127; break; - case 2: dummy = (dpy->VarInfo.xres_virtual + 31) & ~31; break; - case 3: - case 4: dummy = (dpy->VarInfo.xres_virtual + 15) & ~15; break; - } - - if (dpy->VarInfo.xres_virtual != dummy) { - fprintf(stderr, "Didn't set a good pitch for 3d (Need to move this earlier in fbdev init!?!\n"); - return 0; - } - - dpy->VarInfo.xres_virtual = dummy; - return 1; -} - - - - /* Called at the start of each server generation. */ static int RADEONScreenInit( struct MiniGLXDisplayRec *dpy, RADEONInfoPtr info ) { @@ -849,10 +819,62 @@ static void get_chipfamily_from_chipset( RADEONInfoPtr info ) +/** + * Establish the set of visuals available for the display. + * Requires the ::__GLXvisualConfig data type. + */ +static int __driInitScreenConfigs(int *numConfigs, __GLXvisualConfig **configs) +{ + int i; + + *numConfigs = 1; + *configs = (__GLXvisualConfig *) calloc(*numConfigs, + sizeof(__GLXvisualConfig)); + for (i = 0; i < *numConfigs; i++) { + (*configs)[i].vid = 100 + i; + (*configs)[i].class = TrueColor; + (*configs)[i].rgba = True; + (*configs)[i].redSize = 8; + (*configs)[i].greenSize = 8; + (*configs)[i].blueSize = 8; + (*configs)[i].alphaSize = 8; + (*configs)[i].redMask = 0xff0000; + (*configs)[i].greenMask = 0xff00; + (*configs)[i].blueMask = 0xff; + (*configs)[i].alphaMask = 0xff000000; + (*configs)[i].doubleBuffer = True; + (*configs)[i].stereo = False; + (*configs)[i].bufferSize = 32; + (*configs)[i].depthSize = 24; + (*configs)[i].stencilSize = 8; + (*configs)[i].auxBuffers = 0; + (*configs)[i].level = 0; + /* leave remaining fields zero */ + } + + return 1; +} + +/* Will fbdev set a pitch appropriate for 3d? + */ +static int __driValidateMode( struct MiniGLXDisplayRec *dpy ) +{ + int dummy = dpy->VarInfo.xres_virtual; + + switch (dpy->VarInfo.bits_per_pixel / 8) { + case 1: dummy = (dpy->VarInfo.xres_virtual + 127) & ~127; break; + case 2: dummy = (dpy->VarInfo.xres_virtual + 31) & ~31; break; + case 3: + case 4: dummy = (dpy->VarInfo.xres_virtual + 15) & ~15; break; + } + + dpy->VarInfo.xres_virtual = dummy; + return 1; +} /* */ -int __driInitFBDev( struct MiniGLXDisplayRec *dpy ) +static int __driInitFBDev( struct MiniGLXDisplayRec *dpy ) { RADEONInfoPtr info = calloc(1, sizeof(*info)); @@ -872,14 +894,22 @@ int __driInitFBDev( struct MiniGLXDisplayRec *dpy ) info->LinearAddr = dpy->FixedInfo.smem_start & 0xfc000000; - /* Choose dpy->VarInfo.xres_virtual?? */ - if (!RADEONSetPitch( dpy )) - return 0; - - if (!RADEONScreenInit( dpy, info )) return 0; + + /* Quick hack to clear the front & back buffers. Could also use + * the clear ioctl to do this, but would need to setup hw state + * first. + */ + memset(dpy->FrameBuffer + info->frontOffset, + 0, + info->frontPitch * dpy->cpp * dpy->VarInfo.yres_virtual ); + + memset(dpy->FrameBuffer + info->backOffset, + 0, + info->backPitch * dpy->cpp * dpy->VarInfo.yres_virtual ); + return 1; } @@ -888,9 +918,19 @@ int __driInitFBDev( struct MiniGLXDisplayRec *dpy ) /* The screen is being closed, so clean up any state and free any * resources used by the DRI. */ -void __driHaltFBDev( struct MiniGLXDisplayRec *dpy ) +static void __driHaltFBDev( struct MiniGLXDisplayRec *dpy ) { drmClose(dpy->drmFD); free(dpy->driverInfo); dpy->driverInfo = 0; } + + + +struct MiniGLXDriverRec __driMiniGLXDriver = { + __driInitScreenConfigs, + __driValidateMode, + __driInitFBDev, + __driHaltFBDev +}; + diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c index d86a9fb253f..663065632c0 100644 --- a/src/mesa/tnl/t_context.c +++ b/src/mesa/tnl/t_context.c @@ -1,4 +1,4 @@ -/* $Id: t_context.c,v 1.30.4.1 2002/12/12 14:22:04 keithw Exp $ */ +/* $Id: t_context.c,v 1.30.4.2 2003/01/13 15:31:50 keithw Exp $ */ /* * Mesa 3-D graphics library @@ -56,7 +56,6 @@ _tnl_MakeCurrent( GLcontext *ctx, GLframebuffer *drawBuffer, GLframebuffer *readBuffer ) { - fprintf(stderr, "%s\n", __FUNCTION__); #ifndef THREADS SET_IMMEDIATE( ctx, TNL_CURRENT_IM(ctx) ); #endif diff --git a/src/miniglx/Makefile b/src/miniglx/Makefile index b63f9a97fa2..a55fb0910e4 100644 --- a/src/miniglx/Makefile +++ b/src/miniglx/Makefile @@ -47,7 +47,7 @@ clean: tags: etags *.[ch] -include $(SOURCES:.c=.d) +-include $(SOURCES:.c=.d) .SUFFIXES: .c .d diff --git a/src/miniglx/NOTES b/src/miniglx/NOTES index c27e38a684b..fade1ee7fd9 100644 --- a/src/miniglx/NOTES +++ b/src/miniglx/NOTES @@ -92,3 +92,6 @@ Many, many Xlib and GLX entrypoints, structures and macros are not present in MiniGLX. It will be necessary to find and eliminate all references to non-supported entrypoints. +6) Must create context *after* window. + +This is odd, and should probably be regarded as a bug in miniglx. \ No newline at end of file diff --git a/src/miniglx/drmtest.c b/src/miniglx/drmtest.c index 75642dbaec5..c9dd798e6f2 100644 --- a/src/miniglx/drmtest.c +++ b/src/miniglx/drmtest.c @@ -36,9 +36,6 @@ int client() fprintf(stderr, "DRM_UNLOCK finished\n"); -/* (void)drmUnmap((drmAddress)pSAREA, DRM_PAGE_SIZE); */ - - fprintf(stderr, "Closing client drm: %d\n", fd); ret = drmClose(fd); fprintf(stderr, "done %d\n", ret); diff --git a/src/miniglx/miniglx.c b/src/miniglx/miniglx.c index 7685b805215..fa1d8b7653c 100644 --- a/src/miniglx/miniglx.c +++ b/src/miniglx/miniglx.c @@ -22,7 +22,7 @@ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/* $Id: miniglx.c,v 1.1.4.30 2003/01/10 21:56:04 brianp Exp $ */ +/* $Id: miniglx.c,v 1.1.4.31 2003/01/13 15:31:43 keithw Exp $ */ /** @@ -320,6 +320,11 @@ SetupFBDev( Display *dpy, Window win ) assert(0); } + if (!dpy->driver->validateMode( dpy )) { + fprintf(stderr, "Driver validateMode() failed\n"); + return 0; + } + if (width == 1280 && height == 1024) { /* timing values taken from /etc/fb.modes (1280x1024 @ 75Hz) */ dpy->VarInfo.pixclock = 7408; @@ -354,7 +359,7 @@ SetupFBDev( Display *dpy, Window win ) /* XXX need timings for other screen sizes */ fprintf(stderr, "XXXX screen size %d x %d not supported at this time!\n", width, height); - abort(); + return GL_FALSE; } /* set variable screen info */ @@ -372,7 +377,7 @@ SetupFBDev( Display *dpy, Window win ) if (dpy->FixedInfo.visual != FB_VISUAL_TRUECOLOR && dpy->FixedInfo.visual != FB_VISUAL_DIRECTCOLOR) { - fprintf(stderr, "non-TRUECOLOR visuals not supported by this demo.\n"); + fprintf(stderr, "non-TRUECOLOR visuals not supported.\n"); return GL_FALSE; } @@ -411,25 +416,7 @@ SetupFBDev( Display *dpy, Window win ) } dpy->cpp = dpy->VarInfo.bits_per_pixel / 8; - - if (1) - { - int x, y; - char *scrn = (char *)dpy->FrameBuffer; - - fprintf(stderr, "scrn: %p bottom %p\n", - scrn, scrn+800*599*4); - - for (y = 100 ; y < 200 ; y++) - for (x = 100 ; x < 200 ; x++) { - scrn[(x+y*800)*4+0] = 255; - scrn[(x+y*800)*4+1] = 0; - scrn[(x+y*800)*4+2] = 255; - scrn[(x+y*800)*4+3] = 255; - } - } - /* mmap the MMIO region into our address space */ dpy->MMIOSize = dpy->FixedInfo.mmio_len; dpy->MMIOAddress = (caddr_t) mmap(0, /* start */ @@ -533,44 +520,6 @@ _glthread_GetID(void) return 0; } - -/** - * The idea is to establish the set of visuals available for the display. - * The DRI drivers (or dri_util.c) requires the ::__GLXvisualConfig data type. - * - * \todo XXX This code might be moved into the driver. - */ -static void -InitializeScreenConfigs(int *numConfigs, __GLXvisualConfig **configs) -{ - int i; - - *numConfigs = 1; - *configs = (__GLXvisualConfig *) - CALLOC(*numConfigs * sizeof(__GLXvisualConfig)); - for (i = 0; i < *numConfigs; i++) { - (*configs)[i].vid = 100 + i; - (*configs)[i].class = TrueColor; - (*configs)[i].rgba = True; - (*configs)[i].redSize = 8; - (*configs)[i].greenSize = 8; - (*configs)[i].blueSize = 8; - (*configs)[i].alphaSize = 8; - (*configs)[i].redMask = 0xff0000; - (*configs)[i].greenMask = 0xff00; - (*configs)[i].blueMask = 0xff; - (*configs)[i].alphaMask = 0xff000000; - (*configs)[i].doubleBuffer = True; - (*configs)[i].stereo = False; - (*configs)[i].bufferSize = 32; - (*configs)[i].depthSize = 24; - (*configs)[i].stencilSize = 8; - (*configs)[i].auxBuffers = 0; - (*configs)[i].level = 0; - /* leave remaining fields zero */ - } -} - /*@}*/ @@ -585,42 +534,71 @@ InitializeScreenConfigs(int *numConfigs, __GLXvisualConfig **configs) */ int __read_config_file( Display *dpy ) { - const char *dev = getenv("MINIGLX_DRIVER"); - if (dev && strcmp(dev, "es") == 0) { - dpy->fbdevDevice = "/dev/fb0"; - dpy->clientDriverName = "radeon_es.so"; - dpy->drmModuleName = "radeon"; - dpy->pciBus = 1; - dpy->pciDevice = 0; - dpy->pciFunc = 0; - dpy->chipset = 0x5144; /* radeon qd */ - dpy->pciBusID = malloc(64); - sprintf((char *)dpy->pciBusID, "PCI:%d:%d:%d", - dpy->pciBus, dpy->pciDevice, dpy->pciFunc); - } - else if (dev && strcmp(dev, "radeon") == 0) { - dpy->fbdevDevice = "/dev/fb0"; - dpy->clientDriverName = "radeon_dri.so"; - dpy->drmModuleName = "radeon"; - dpy->pciBus = 1; - dpy->pciDevice = 0; - dpy->pciFunc = 0; - dpy->chipset = 0x5144; /* radeon qd */ - dpy->pciBusID = malloc(64); - sprintf((char *)dpy->pciBusID, "PCI:%d:%d:%d", - dpy->pciBus, dpy->pciDevice, dpy->pciFunc); - } - else { - dpy->fbdevDevice = "/dev/fb0"; - dpy->clientDriverName = "fb_dri.so"; - dpy->drmModuleName = 0; - dpy->pciBus = 0; - dpy->pciDevice = 0; - dpy->pciFunc = 0; - dpy->chipset = 0; - dpy->pciBusID = 0; + FILE *file; + const char *fname; + + /* Fallback/defaults + */ + dpy->fbdevDevice = "/dev/fb0"; + dpy->clientDriverName = "fb_dri.so"; + dpy->drmModuleName = 0; + dpy->pciBus = 0; + dpy->pciDevice = 0; + dpy->pciFunc = 0; + dpy->chipset = 0; + dpy->pciBusID = 0; + + fname = getenv("MINIGLX_CONF"); + if (!fname) fname = "/etc/miniglx.conf"; + + file = fopen(fname, "r"); + if (!file) { + fprintf(stderr, "couldn't open config file %s\n", fname); + return 0; } + + while (!feof(file)) { + char buf[81], *opt = buf, *val, *tmp1, *tmp2; + fgets(buf, sizeof(buf), file); + + /* Parse 'opt = val' -- must be easier ways to do this. + */ + while (isspace(*opt)) opt++; + val = opt; + while (!isspace(*val) && *val != '=' && *val) val++; + tmp1 = val; + while (isspace(*val)) val++; + if (*val != '=') continue; + *tmp1 = 0; + val++; + while (isspace(*val)) val++; + tmp2 = val; + while (!isspace(*tmp2) && *tmp2 != '\n' && *tmp2) tmp2++; + *tmp2 = 0; + + + if (strcmp(opt, "fbdevDevice") == 0) + dpy->fbdevDevice = strdup(val); + else if (strcmp(opt, "clientDriverName") == 0) + dpy->clientDriverName = strdup(val); + else if (strcmp(opt, "drmModuleName") == 0) + dpy->drmModuleName = strdup(val); + else if (strcmp(opt, "pciBusID") == 0) { + if (sscanf(val, "PCI:%d:%d:%d", + &dpy->pciBus, &dpy->pciDevice, &dpy->pciFunc) != 3) { + fprintf(stderr, "malformed bus id: %s\n", val); + continue; + } + dpy->pciBusID = strdup(val); + } + else if (strcmp(opt, "chipset") == 0) { + if (sscanf(val, "0x%x", &dpy->chipset) != 1) + fprintf(stderr, "malformed chipset: %x\n", dpy->chipset); + } + } + + fclose(file); return 1; } @@ -651,21 +629,20 @@ XOpenDisplay( const char *display_name ) if (!dpy) return NULL; - if (!__read_config_file( dpy )) { fprintf(stderr, "Couldn't get configuration details\n"); FREE(dpy); return NULL; } - + /* Open the fbdev device + */ if (!OpenFBDev(dpy)) { fprintf(stderr, "OpenFBDev failed\n"); FREE(dpy); return NULL; } - InitializeScreenConfigs(&dpy->numConfigs, &dpy->configs); /* * Begin DRI setup. @@ -681,26 +658,20 @@ XOpenDisplay( const char *display_name ) return NULL; } - dpy->driverInitFBDev = (InitFBDevFunc) dlsym(dpy->dlHandle, - "__driInitFBDev"); - if (!dpy->driverInitFBDev) { - fprintf(stderr, "Couldn't find __driInitFBDev in %s\n", - dpy->clientDriverName); - dlclose(dpy->dlHandle); - FREE(dpy); - return NULL; - } - - dpy->driverHaltFBDev = (HaltFBDevFunc) dlsym(dpy->dlHandle, - "__driHaltFBDev"); - if (!dpy->driverHaltFBDev) { - fprintf(stderr, "Couldn't find __driHaltFBDev in %s\n", + /* Pull in MiniGLX-specific hooks: + */ + dpy->driver = (struct MiniGLXDriverRec *) dlsym(dpy->dlHandle, + "__driMiniGLXDriver"); + if (!dpy->driver) { + fprintf(stderr, "Couldn't find __driMiniGLXDriver in %s\n", dpy->clientDriverName); dlclose(dpy->dlHandle); FREE(dpy); return NULL; } + /* Pull in standard DRI client-side driver hooks: + */ dpy->createScreen = (CreateScreenFunc) dlsym(dpy->dlHandle, "__driCreateScreen"); if (!dpy->createScreen) { @@ -711,6 +682,10 @@ XOpenDisplay( const char *display_name ) return NULL; } + /* Ask the driver for a list of supported configs: + */ + dpy->driver->initScreenConfigs( &dpy->numConfigs, &dpy->configs ); + return dpy; } @@ -848,7 +823,7 @@ XCreateWindow( Display *display, Window parent, int x, int y, /* Perform the initialization normally done in the X server */ - if (!display->driverInitFBDev( display )) { + if (!display->driver->initFBDev( display )) { fprintf(stderr, "%s: __driInitFBDev failed\n", __FUNCTION__); RestoreFBDev(display); FREE(win); @@ -932,7 +907,7 @@ XDestroyWindow( Display *display, Window w ) /* As this is done in CreateWindow, need to undo it here: */ - (*display->driverHaltFBDev)( display ); + (*display->driver->haltFBDev)( display ); /* put framebuffer back to initial state */ RestoreFBDev(display); @@ -1391,7 +1366,7 @@ glXCreateContext( Display *dpy, XVisualInfo *vis, return NULL; ctx->vid = vis->visualid; - + if (shareList) sharePriv = shareList->driContext.private; else diff --git a/src/miniglx/miniglxP.h b/src/miniglx/miniglxP.h index 475d3ffa488..043f38be377 100644 --- a/src/miniglx/miniglxP.h +++ b/src/miniglx/miniglxP.h @@ -60,8 +60,6 @@ typedef struct __DRIdrawableRec __DRIdrawable; typedef void *(*CreateScreenFunc)(Display *dpy, int scrn, __DRIscreen *psc, int numConfigs, __GLXvisualConfig *config); -typedef void *(*InitFBDevFunc)( Display *dpy ); -typedef void *(*HaltFBDevFunc)( Display *dpy ); /** @@ -177,6 +175,21 @@ struct __DRIdrawableRec { void *private; }; +/** + * \brief Interface to driver. + * + * \internal + * This structure is retrieved from the loadable driver by dlsym + * "__driMiniGLXDriver" to access the miniglx-specific hardware + * initalization and takedown routines. + */ +struct MiniGLXDriverRec { + int (*initScreenConfigs)( int *numConfigs, __GLXvisualConfig **configs ); + int (*validateMode)( struct MiniGLXDisplayRec *dpy ); + int (*initFBDev)( struct MiniGLXDisplayRec *dpy ); + void (*haltFBDev)( struct MiniGLXDisplayRec *dpy ); +}; + /** @@ -288,8 +301,7 @@ struct MiniGLXDisplayRec { * \name New driver hooks */ /*@{*/ - InitFBDevFunc driverInitFBDev; - HaltFBDevFunc driverHaltFBDev; + struct MiniGLXDriverRec *driver; /*@}*/ /**