summaryrefslogtreecommitdiff
path: root/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c
diff options
context:
space:
mode:
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.c260
1 files changed, 60 insertions, 200 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 c0d1697c6..a337b6ea7 100644
--- a/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c
+++ b/xc/lib/GL/mesa/src/drv/r128/r128_xmesa.c
@@ -34,37 +34,26 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifdef GLX_DIRECT_RENDERING
-/* r128 DDX driver includes */
-#include "r128_dri.h"
-#include "r128_reg.h"
-
/* r128 Mesa driver includes */
#include "r128_init.h"
#include "r128_context.h"
#include "r128_xmesa.h"
-#include "r128_dd.h"
#include "r128_state.h"
-#include "r128_span.h"
-#include "r128_depth.h"
#include "r128_tex.h"
#include "r128_swap.h"
-#include "r128_tris.h"
-#include "r128_vb.h"
/* Mesa src includes */
#include "context.h"
-#if 0
-#include "vbxform.h"
-#include "matrix.h"
-#endif
+#include "simple_list.h"
#ifdef DEBUG_LOCKING
char *prevLockFile = NULL;
int prevLockLine = 0;
#endif
-r128ContextPtr r128Context = NULL;
+static r128ContextPtr r128Context = NULL;
+/* Count the number of bits set */
static int count_bits(unsigned int n)
{
int bits = 0;
@@ -76,100 +65,24 @@ static int count_bits(unsigned int n)
return bits;
}
+/* FIXME: */
+
+/* Initialize the driver specific screen private data */
GLboolean XMesaInitDriver(__DRIscreenPrivate *sPriv)
{
- r128ScreenPtr r128Screen;
- R128DRIPtr r128DRIPriv = (R128DRIPtr)sPriv->pDevPriv;
-
- /* Allocate the private area */
- r128Screen = (r128ScreenPtr)Xmalloc(sizeof(*r128Screen));
- if (!r128Screen) return GL_FALSE;
-
- r128Screen->mmioRgn.handle = r128DRIPriv->registerHandle;
- r128Screen->mmioRgn.size = r128DRIPriv->registerSize;
- if (drmMap(sPriv->fd,
- r128Screen->mmioRgn.handle,
- r128Screen->mmioRgn.size,
- (drmAddressPtr)&r128Screen->mmio)) {
- Xfree(r128Screen);
- return GL_FALSE;
- }
-
- r128Screen->agpRgn.handle = r128DRIPriv->agpHandle;
- r128Screen->agpRgn.size = r128DRIPriv->agpSize;
- if (drmMap(sPriv->fd,
- r128Screen->agpRgn.handle,
- r128Screen->agpRgn.size,
- (drmAddressPtr)&r128Screen->agp)) {
- drmUnmap((drmAddress)r128Screen->mmio, r128Screen->mmioRgn.size);
- Xfree(r128Screen);
- return GL_FALSE;
- }
-
- r128Screen->deviceID = r128DRIPriv->deviceID;
-
- r128Screen->width = r128DRIPriv->width;
- r128Screen->height = r128DRIPriv->height;
- r128Screen->depth = r128DRIPriv->depth;
- r128Screen->bpp = r128DRIPriv->bpp;
-
- r128Screen->fb = sPriv->pFB;
- r128Screen->fbOffset = sPriv->fbOrigin;
- r128Screen->fbStride = sPriv->fbStride;
- r128Screen->fbSize = sPriv->fbSize;
-
- r128Screen->fbX = r128DRIPriv->fbX;
- r128Screen->fbY = r128DRIPriv->fbY;
- r128Screen->backX = r128DRIPriv->backX;
- r128Screen->backY = r128DRIPriv->backY;
- r128Screen->depthX = r128DRIPriv->depthX;
- r128Screen->depthY = r128DRIPriv->depthY;
- r128Screen->textureX = r128DRIPriv->textureX;
- r128Screen->textureY = r128DRIPriv->textureY;
- r128Screen->textureSize = r128DRIPriv->textureSize;
-
-#if 0
- r128Screen->backX = 0;
- r128Screen->backY = r128DRIPriv->height/2;
- r128Screen->depthX = r128DRIPriv->width/2;
- r128Screen->depthY = r128DRIPriv->height/2;
-#endif
-
- r128Screen->CCEMode = r128DRIPriv->CCEMode;
- r128Screen->CCEFifoSize = r128DRIPriv->CCEFifoSize;
-
- r128Screen->ringStart = r128DRIPriv->ringStart;
- r128Screen->ringSize = r128DRIPriv->ringSize;
- r128Screen->ringWritePtr = &r128DRIPriv->ringWrite;
- r128Screen->ringReadPtr = (int *)(r128Screen->agp
- + r128DRIPriv->ringReadOffset);
-
- r128Screen->MMIOFifoSlots = 0;
- r128Screen->CCEFifoSlots = 0;
-
- r128Screen->CCEFifoAddr = R128_PM4_FIFO_DATA_EVEN;
-
- r128Screen->driScreen = sPriv;
-
- sPriv->private = (void *)r128Screen;
-
- r128TriangleFuncsInit();
- r128SetupInit();
+ sPriv->private = (void *)r128CreateScreen(sPriv);
+ if (!sPriv->private) return GL_FALSE;
return GL_TRUE;
}
+/* Reset the driver specific screen private data */
void XMesaResetDriver(__DRIscreenPrivate *sPriv)
{
- r128ScreenPtr r128Screen = (r128ScreenPtr)sPriv->private;
-
- drmUnmap((drmAddress)r128Screen->mmio, r128Screen->mmioRgn.size);
- drmUnmap((drmAddress)r128Screen->agp, r128Screen->agpRgn.size);
-
- Xfree(r128Screen);
- sPriv->private = NULL;
+ r128DestroyScreen(sPriv);
}
+/* Create and initialize the Mesa and driver specific visual data */
XMesaVisual XMesaCreateVisual(XMesaDisplay *display,
XMesaVisualInfo visinfo,
GLboolean rgb_flag,
@@ -223,6 +136,7 @@ XMesaVisual XMesaCreateVisual(XMesaDisplay *display,
return v;
}
+/* Destroy the Mesa and driver specific visual data */
void XMesaDestroyVisual(XMesaVisual v)
{
Xfree(v->gl_visual);
@@ -230,91 +144,40 @@ void XMesaDestroyVisual(XMesaVisual v)
Xfree(v);
}
+/* Create and initialize the Mesa and driver specific context data */
XMesaContext XMesaCreateContext(XMesaVisual v, XMesaContext share_list,
__DRIcontextPrivate *driContextPriv)
{
XMesaContext c;
- r128ContextPtr r128ctx;
- GLcontext *shareCtx, *glCtx;
c = (XMesaContext)Xmalloc(sizeof(*c));
if (!c) {
return NULL;
}
- r128ctx = (r128ContextPtr)Xmalloc(sizeof(*r128ctx));
- if (!r128ctx) {
- Xfree(c);
- return NULL;
- }
-
/* Initialize XMesaContext */
c->display = v->display;
c->xm_visual = v;
c->xm_buffer = NULL; /* Set by MakeCurrent */
c->driContextPriv = driContextPriv;
- c->private = (void *)r128ctx;
-
- if (share_list)
- shareCtx = ((r128ContextPtr)(share_list->private))->glCtx;
- else
- shareCtx = NULL;
-
- /* Initialize r128Context */
- r128ctx->xmCtx = c;
- r128ctx->glCtx = gl_create_context(v->gl_visual,
- shareCtx,
- (void *)r128ctx,
- GL_TRUE);
- r128ctx->display = v->display;
- r128ctx->driContext = driContextPriv;
- r128ctx->driDrawable = NULL; /* Set by XMesaMakeCurrent */
- r128ctx->dirty = R128_ALL_DIRTY;
- r128ctx->needClip = GL_TRUE;
- r128ctx->r128Screen =
- (r128ScreenPtr)(driContextPriv->driScreenPriv->private);
-
- /* Initialize GLcontext */
- glCtx = r128ctx->glCtx;
-
- r128DDInitExtensions(glCtx);
-
- r128DDInitDriverFuncs(glCtx);
- r128DDInitStateFuncs(glCtx);
- r128DDInitSpanFuncs(glCtx);
- r128DDInitDepthFuncs(glCtx);
- r128DDInitTextureFuncs(glCtx);
-
-#if 1
- /* FIXME: Move to r128_tris.c */
- glCtx->Driver.TriangleCaps = (DD_TRI_CULL
- | DD_TRI_LIGHT_TWOSIDE
- | DD_TRI_OFFSET);
- glCtx->TriangleCaps |= DD_CLIP_FOG_COORD;
-
- if (glCtx->VB) r128DDRegisterVB(glCtx->VB);
-#endif
-
- r128DDInitState(r128ctx);
+ c->private = (void *)r128CreateContext(v->gl_visual, c, share_list);
+ if (!c->private) {
+ Xfree(c);
+ return NULL;
+ }
return c;
}
+/* Destroy the Mesa and driver specific context data */
void XMesaDestroyContext(XMesaContext c)
{
- r128ContextPtr r128ctx = (r128ContextPtr)c->private;
-
- if (r128ctx) {
- gl_destroy_context(r128ctx->glCtx);
- Xfree(r128ctx);
- c->private = NULL;
- }
-
- if (c->private == (void *)r128Context) {
- r128Context = NULL;
- }
+ if (c->private == (void *)r128Context) r128Context = NULL;
+ r128DestroyContext((r128ContextPtr)c->private);
+ Xfree(c);
}
+/* Create and initialize the Mesa and driver specific window buffer data */
XMesaBuffer XMesaCreateWindowBuffer(XMesaVisual v,
XMesaWindow w,
__DRIdrawablePrivate *driDrawPriv)
@@ -328,6 +191,7 @@ XMesaBuffer XMesaCreateWindowBuffer(XMesaVisual v,
return xm_buf;
}
+/* Create and initialize the Mesa and driver specific pixmap buffer data */
XMesaBuffer XMesaCreatePixmapBuffer(XMesaVisual v,
XMesaPixmap p,
XMesaColormap c,
@@ -342,12 +206,14 @@ XMesaBuffer XMesaCreatePixmapBuffer(XMesaVisual v,
return xm_buf;
}
+/* Destroy the Mesa and driver specific color buffer data */
void XMesaDestroyBuffer(XMesaBuffer b)
{
gl_destroy_framebuffer(b->gl_buffer);
Xfree(b);
}
+/* Copy the back color buffer to the front color buffer */
void XMesaSwapBuffers(XMesaBuffer b)
{
/*
@@ -356,36 +222,29 @@ void XMesaSwapBuffers(XMesaBuffer b)
*/
if (r128Context == NULL) return;
+ /* FIXME: Only swap buffers when a back buffer exists */
+
+ FLUSH_VB(R128_MESACTX(r128Context), "swap buffers");
r128SwapBuffers(r128Context);
}
+/* Force the context `c' to be the current context and associate with it
+ buffer `b' */
GLboolean XMesaMakeCurrent(XMesaContext c, XMesaBuffer b)
{
if (c) {
- r128ContextPtr oldCtx = r128Context;
-
- if (r128Context
- && c->private == (void *)r128Context
- && b->driDrawPriv == r128Context->driDrawable) return GL_TRUE;
-
- r128Context = (r128ContextPtr)c->private;
-
- if (oldCtx) {
- r128Context->dirty = R128_REQUIRE_QUIESCENCE | R128_START_CCE;
- if (oldCtx != r128Context)
- r128Context->dirty |= R128_UPDATE_CONTEXT;
- if (oldCtx->driDrawable != b->driDrawPriv)
- r128Context->dirty |= R128_UPDATE_CLIPRECTS;
- } else {
- r128Context->dirty = R128_ALL_DIRTY;
- }
+ if (r128Context &&
+ c->private == (void *)r128Context &&
+ b->driDrawPriv == R128_DRIDRAWABLE(r128Context))
+ return GL_TRUE;
- r128Context->driDrawable = b->driDrawPriv;
+ r128Context = r128MakeCurrent(r128Context, (r128ContextPtr)c->private,
+ b->driDrawPriv);
- gl_make_current(r128Context->glCtx, b->gl_buffer);
+ gl_make_current(R128_MESACTX(r128Context), b->gl_buffer);
- if (!r128Context->glCtx->Viewport.Width) {
- gl_Viewport(r128Context->glCtx, 0, 0,
+ if (!R128_MESACTX(r128Context)->Viewport.Width) {
+ gl_Viewport(R128_MESACTX(r128Context), 0, 0,
b->driDrawPriv->w, b->driDrawPriv->h);
}
} else {
@@ -396,29 +255,30 @@ GLboolean XMesaMakeCurrent(XMesaContext c, XMesaBuffer b)
return GL_TRUE;
}
+/* Update the hardware state. This is called if another context has
+ grabbed the hardware lock, which includes the X server. This
+ function also updates the driver's window state after the X server
+ moves, resizes or restacks a window -- the change will be reflected
+ in the drawable position and clip rects. Since the X server grabs
+ the hardware lock when it changes the window state, this routine will
+ automatically be called after such a change. */
+/* NOTE: This routine is only called while holding the hardware lock. */
void XMesaUpdateState(XMesaContext c)
{
- r128ContextPtr r128ctx = (r128ContextPtr)c->private;
- __DRIdrawablePrivate *dPriv = r128ctx->driDrawable;
- __DRIscreenPrivate *sPriv = r128ctx->r128Screen->driScreen;
- int stamp = dPriv->lastStamp;
+ __DRIscreenPrivate *sPriv = R128_DRISCREEN((r128ContextPtr)c->private);
+ __DRIdrawablePrivate *dPriv = R128_DRIDRAWABLE((r128ContextPtr)c->private);
+ int stamp = dPriv->lastStamp;
- /*
- * The window might have moved, so we might need to get new
- * cliprects.
- *
- * NOTE: This releases and regrabs the hw lock, so all state
- * checking must be done *after* this call.
- */
- XMESA_VALIDATE_DRAWABLE_INFO(r128ctx->display, sPriv, dPriv);
-
- r128ctx->dirty |= R128_ALL_DIRTY; /* FIXME: Optimize this!! */
-
- if (stamp != dPriv->lastStamp) { /* FIXME??: handle window moves */
- r128ctx->dirty |= R128_UPDATE_CLIPRECTS;
- }
+ /* The window might have moved, so we might need to get new clip
+ rects.
+
+ NOTE: This releases and regrabs the hw lock to allow the X server
+ to respond to the DRI protocol request for new drawable info.
+ Since the hardware state depends on having the latest drawable
+ clip rects, all state checking must be done _after_ this call. */
+ XMESA_VALIDATE_DRAWABLE_INFO(c->display, sPriv, dPriv);
- if (r128ctx->dirty) r128UpdateStateLocked(r128ctx);
+ r128UpdateState((r128ContextPtr)c->private, (stamp != dPriv->lastStamp));
}
#endif