diff options
Diffstat (limited to 'xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c')
-rw-r--r-- | xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c | 299 |
1 files changed, 194 insertions, 105 deletions
diff --git a/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c b/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c index 07450e3c0..53908e3bf 100644 --- a/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c +++ b/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c,v 1.4 2000/12/12 17:17:08 dawes Exp $ */ +/* $XFree86: xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c,v 1.7 2001/01/23 18:14:38 alanh Exp $ */ /************************************************************************** Copyright 1999, 2000 ATI Technologies Inc. and Precision Insight, Inc., @@ -48,42 +48,79 @@ USE OR OTHER DEALINGS IN THE SOFTWARE. extern void __driRegisterExtensions( void ); -static r128ContextPtr r128Context = NULL; +static r128ContextPtr r128Ctx = NULL; -/* Initialize the driver specific screen private data */ -GLboolean XMesaInitDriver(__DRIscreenPrivate *sPriv) +/* Initialize the driver specific screen private data. + */ +GLboolean XMesaInitDriver( __DRIscreenPrivate *sPriv ) { - sPriv->private = (void *)r128CreateScreen(sPriv); - if (!sPriv->private) { - r128DestroyScreen(sPriv); - return GL_FALSE; - } - - return GL_TRUE; + sPriv->private = (void *) r128CreateScreen( sPriv ); + + /* Check the DRI version */ + { + int major, minor, patch; + if (XF86DRIQueryVersion(sPriv->display, &major, &minor, &patch)) { + if (major != 3 || minor != 1 || patch < 0) { + char msg[1000]; + sprintf(msg, "R128 DRI driver expected DRI version 3.1.x but got version %d.%d.%d", major, minor, patch); + __driMesaMessage(msg); + return GL_FALSE; + } + } + } + + /* Check that the DDX driver version is compatible */ + if (sPriv->ddxMajor != 4 || + sPriv->ddxMinor != 0 || + sPriv->ddxPatch < 0) { + char msg[1000]; + sprintf(msg, "R128 DRI driver expected DDX driver version 4.0.x but got version %d.%d.%d", sPriv->ddxMajor, sPriv->ddxMinor, sPriv->ddxPatch); + __driMesaMessage(msg); + return GL_FALSE; + } + + /* Check that the DRM driver version is compatible */ + if (sPriv->drmMajor != 2 || + sPriv->drmMinor != 1 || + sPriv->drmPatch < 4) { + char msg[1000]; + sprintf(msg, "R128 DRI driver expected DRM driver version 2.1.x (x>=4) but got version %d.%d.%d", sPriv->drmMajor, sPriv->drmMinor, sPriv->drmPatch); + __driMesaMessage(msg); + return GL_FALSE; + } + + if ( !sPriv->private ) { + r128DestroyScreen( sPriv ); + return GL_FALSE; + } + + return GL_TRUE; } -/* Reset the driver specific screen private data */ -void XMesaResetDriver(__DRIscreenPrivate *sPriv) +/* Reset the driver specific screen private data. + */ +void XMesaResetDriver( __DRIscreenPrivate *sPriv ) { - r128DestroyScreen(sPriv); + r128DestroyScreen( sPriv ); } -/* Create and initialize the Mesa and driver specific visual data */ -GLvisual *XMesaCreateVisual(Display *dpy, - __DRIscreenPrivate *driScrnPriv, - const XVisualInfo *visinfo, - const __GLXvisualConfig *config) +/* Create and initialize the Mesa and driver specific visual data. + */ +GLvisual *XMesaCreateVisual( Display *dpy, + __DRIscreenPrivate *driScrnPriv, + const XVisualInfo *visinfo, + const __GLXvisualConfig *config ) { - /* Drivers may change the args to _mesa_create_visual() in order to - * setup special visuals. + /* Drivers may change the args to _mesa_create_visual() in order to + * setup special visuals. */ - return _mesa_create_visual(config->rgba, + return _mesa_create_visual( config->rgba, config->doubleBuffer, config->stereo, - _mesa_bitcount(visinfo->red_mask), - _mesa_bitcount(visinfo->green_mask), - _mesa_bitcount(visinfo->blue_mask), + _mesa_bitcount( visinfo->red_mask ), + _mesa_bitcount( visinfo->green_mask ), + _mesa_bitcount( visinfo->blue_mask ), config->alphaSize, 0, /* index bits */ config->depthSize, @@ -92,134 +129,186 @@ GLvisual *XMesaCreateVisual(Display *dpy, config->accumGreenSize, config->accumBlueSize, config->accumAlphaSize, - 0 /* num samples */); + 0 /* num samples */ ); } -/* Create and initialize the Mesa and driver specific context data */ -GLboolean XMesaCreateContext(Display *dpy, GLvisual *mesaVis, - __DRIcontextPrivate *driContextPriv) +/* Create and initialize the Mesa and driver specific context data. + */ +GLboolean XMesaCreateContext( Display *dpy, GLvisual *mesaVis, + __DRIcontextPrivate *driContextPriv ) { - return r128CreateContext(dpy, mesaVis, driContextPriv); + return r128CreateContext( dpy, mesaVis, driContextPriv ); } -/* Destroy the Mesa and driver specific context data */ +/* Destroy the Mesa and driver specific context data. + */ void XMesaDestroyContext(__DRIcontextPrivate *driContextPriv) { - r128ContextPtr r128ctx = (r128ContextPtr)driContextPriv->driverPrivate; + r128ContextPtr rmesa = (r128ContextPtr)driContextPriv->driverPrivate; - if (r128ctx == (void *)r128Context) r128Context = NULL; - r128DestroyContext(r128ctx); + if ( rmesa == r128Ctx ) r128Ctx = NULL; + r128DestroyContext(rmesa); } -/* Create and initialize the Mesa and driver specific pixmap buffer data */ -GLframebuffer *XMesaCreateWindowBuffer(Display *dpy, - __DRIscreenPrivate *driScrnPriv, - __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis) +/* Create and initialize the Mesa and driver specific pixmap buffer + * data. + */ +GLframebuffer *XMesaCreateWindowBuffer( Display *dpy, + __DRIscreenPrivate *driScrnPriv, + __DRIdrawablePrivate *driDrawPriv, + GLvisual *mesaVis ) { - return gl_create_framebuffer(mesaVis, - GL_FALSE, /* software depth buffer? */ - mesaVis->StencilBits > 0, - mesaVis->AccumRedBits > 0, - mesaVis->AlphaBits > 0 - ); + return gl_create_framebuffer( mesaVis, + GL_FALSE, /* software depth buffer? */ + mesaVis->StencilBits > 0, + mesaVis->AccumRedBits > 0, + mesaVis->AlphaBits > 0 ); } -/* Create and initialize the Mesa and driver specific pixmap buffer data */ +/* Create and initialize the Mesa and driver specific pixmap buffer + * data. + */ GLframebuffer *XMesaCreatePixmapBuffer( Display *dpy, __DRIscreenPrivate *driScrnPriv, __DRIdrawablePrivate *driDrawPriv, - GLvisual *mesaVis) + GLvisual *mesaVis ) { #if 0 - /* Different drivers may have different combinations of hardware and - * software ancillary buffers. - */ - return gl_create_framebuffer(mesaVis, + /* Different drivers may have different combinations of hardware and + * software ancillary buffers. + */ + return gl_create_framebuffer( mesaVis, GL_FALSE, /* software depth buffer? */ mesaVis->StencilBits > 0, mesaVis->AccumRedBits > 0, - mesaVis->AlphaBits > 0); + mesaVis->AlphaBits > 0 ); #else - return NULL; /* not implemented yet */ + return NULL; /* not implemented yet */ #endif } /* Copy the back color buffer to the front color buffer */ -void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv) +void XMesaSwapBuffers( __DRIdrawablePrivate *driDrawPriv ) { - /* FIXME: This assumes buffer is currently bound to a context. This - needs to be able to swap buffers when not currently bound. Also, - this needs to swap according to buffer, and NOT according to - context! */ - if (r128Context == NULL) return; - - /* Only swap buffers when a back buffer exists */ - if (R128_MESACTX(r128Context)->Visual->DBflag) { - FLUSH_VB(R128_MESACTX(r128Context), "swap buffers"); - r128SwapBuffers(r128Context); - } + /* FIXME: This assumes buffer is currently bound to a context. This + * needs to be able to swap buffers when not currently bound. Also, + * this needs to swap according to buffer, and NOT according to + * context! + */ + if ( r128Ctx == NULL ) + return; + + /* Only swap buffers when a back buffer exists. + */ + if ( r128Ctx->glCtx->Visual->DBflag ) { + FLUSH_VB( r128Ctx->glCtx, "swap buffers" ); + if ( !r128Ctx->doPageFlip ) { + r128SwapBuffers( r128Ctx ); + } else { + r128PageFlip( r128Ctx ); + } + } } /* Force the context `c' to be the current context and associate with it - buffer `b' */ -GLboolean XMesaMakeCurrent(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv) + * buffer `b'. + */ +GLboolean XMesaMakeCurrent( __DRIcontextPrivate *driContextPriv, + __DRIdrawablePrivate *driDrawPriv, + __DRIdrawablePrivate *driReadPriv ) { - if (driContextPriv) { - r128ContextPtr r128ctx = (r128ContextPtr)driContextPriv->driverPrivate; - - r128Context = r128MakeCurrent(r128Context, r128ctx, driDrawPriv); - - gl_make_current2(R128_MESACTX(r128Context), - driDrawPriv->mesaBuffer, driReadPriv->mesaBuffer); - - if (r128Context->driDrawable != driDrawPriv) { - r128Context->driDrawable = driDrawPriv; - r128Context->dirty = R128_UPLOAD_ALL; - } - - /* GH: We need this to correctly calculate the window offset - * and aux scissor rects. - */ - r128Context->new_state = R128_NEW_WINDOW | R128_NEW_CLIP; - - if (!R128_MESACTX(r128Context)->Viewport.Width) { - gl_Viewport(R128_MESACTX(r128Context), 0, 0, - driDrawPriv->w, driDrawPriv->h); - } - } else { - gl_make_current(0,0); - r128Context = NULL; - } - - return GL_TRUE; + if ( driContextPriv ) { + r128ContextPtr rmesa = (r128ContextPtr)driContextPriv->driverPrivate; + + r128Ctx = r128MakeCurrent( r128Ctx, rmesa, driDrawPriv ); + + gl_make_current2( r128Ctx->glCtx, + driDrawPriv->mesaBuffer, + driReadPriv->mesaBuffer ); + + if ( r128Ctx->driDrawable != driDrawPriv ) { + r128Ctx->driDrawable = driDrawPriv; + r128Ctx->dirty = R128_UPLOAD_ALL; + } + + /* GH: We need this to correctly calculate the window offset + * and aux scissor rects. + */ + r128Ctx->new_state = R128_NEW_WINDOW | R128_NEW_CLIP; + + if ( !r128Ctx->glCtx->Viewport.Width ) { + gl_Viewport( r128Ctx->glCtx, 0, 0, driDrawPriv->w, driDrawPriv->h ); + } + } else { + gl_make_current( 0, 0 ); + r128Ctx = NULL; + } + + return GL_TRUE; } -/* Force the context `c' to be unbound from its buffer */ -GLboolean XMesaUnbindContext(__DRIcontextPrivate *driContextPriv) +/* Force the context `c' to be unbound from its buffer. + */ +GLboolean XMesaUnbindContext( __DRIcontextPrivate *driContextPriv ) { - return GL_TRUE; + return GL_TRUE; } /* This function is called by libGL.so as soon as libGL.so is loaded. - * This is where we'd register new extension functions with the dispatcher. + * This is where we'd register new extension functions with the + * dispatcher. */ void __driRegisterExtensions( void ) { } +/* Initialize the fullscreen mode. + */ GLboolean -XMesaOpenFullScreen(__DRIcontextPrivate *driContextPriv) +XMesaOpenFullScreen( __DRIcontextPrivate *driContextPriv ) { - return GL_TRUE; + r128ContextPtr rmesa = (r128ContextPtr)driContextPriv->driverPrivate; + GLint ret; + + /* FIXME: Do we need to check this? + */ + if ( !r128Ctx->glCtx->Visual->DBflag ) + return GL_TRUE; + + LOCK_HARDWARE( rmesa ); + r128WaitForIdleLocked( rmesa ); + + /* Ignore errors. If this fails, we simply don't do page flipping. + */ + ret = drmR128FullScreen( rmesa->driFd, GL_TRUE ); + + UNLOCK_HARDWARE( rmesa ); + + rmesa->doPageFlip = ( ret == 0 ); + + return GL_TRUE; } +/* Shut down the fullscreen mode. + */ GLboolean -XMesaCloseFullScreen(__DRIcontextPrivate *driContextPriv) +XMesaCloseFullScreen( __DRIcontextPrivate *driContextPriv ) { - return GL_TRUE; + r128ContextPtr rmesa = (r128ContextPtr)driContextPriv->driverPrivate; + + LOCK_HARDWARE( rmesa ); + r128WaitForIdleLocked( rmesa ); + + /* Don't care if this fails, we're not page flipping anymore. + */ + drmR128FullScreen( rmesa->driFd, GL_FALSE ); + + UNLOCK_HARDWARE( rmesa ); + + rmesa->doPageFlip = GL_FALSE; + rmesa->currentPage = 0; + + return GL_TRUE; } #endif |