Merge commit 'origin/gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / s3v / s3v_xmesa.c
index b012c1b9cc3bdecc5dfdce02ef921516ef35a45d..b18c8763c3aed3b7f3fd4130620f1a24c0282c5d 100644 (file)
@@ -4,20 +4,21 @@
 
 #include "s3v_context.h"
 #include "s3v_vb.h"
-#include "context.h"
-#include "mmath.h"
-#include "matrix.h"
+#include "main/context.h"
+#include "main/matrix.h"
 #include "s3v_dri.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
 
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 
 /* #define DEBUG(str) printf str */
 
-static GLboolean 
-s3vInitDriver(__DRIscreenPrivate *sPriv)
+static const __DRIconfig **
+s3vInitScreen(__DRIscreen *sPriv)
 {
     sPriv->private = (void *) s3vCreateScreen( sPriv );
 
@@ -26,7 +27,7 @@ s3vInitDriver(__DRIscreenPrivate *sPriv)
        return GL_FALSE;
     }
 
-    return GL_TRUE;
+   return NULL;
 }
 
 static void 
@@ -37,7 +38,7 @@ s3vDestroyContext(__DRIcontextPrivate *driContextPriv)
     if (vmesa) {
       _swsetup_DestroyContext( vmesa->glCtx );
       _tnl_DestroyContext( vmesa->glCtx );
-      _ac_DestroyContext( vmesa->glCtx );
+      _vbo_DestroyContext( vmesa->glCtx );
       _swrast_DestroyContext( vmesa->glCtx );
 
       s3vFreeVB( vmesa->glCtx );
@@ -46,30 +47,82 @@ s3vDestroyContext(__DRIcontextPrivate *driContextPriv)
       vmesa->glCtx->DriverCtx = NULL;
       _mesa_destroy_context(vmesa->glCtx);
 
-      Xfree(vmesa);
+      _mesa_free(vmesa);
       driContextPriv->driverPrivate = NULL;
     }
 }
 
 
 static GLboolean
-s3vCreateBuffer( Display *dpy,
-                   __DRIscreenPrivate *driScrnPriv,
+s3vCreateBuffer( __DRIscreenPrivate *driScrnPriv,
                    __DRIdrawablePrivate *driDrawPriv,
                    const __GLcontextModes *mesaVis,
                    GLboolean isPixmap )
 {
+   s3vScreenPtr screen = (s3vScreenPtr) driScrnPriv->private;
+
    if (isPixmap) {
       return GL_FALSE; /* not implemented */
    }
    else {
-      driDrawPriv->driverPrivate = (void *) 
-         _mesa_create_framebuffer(mesaVis,
-                                  GL_FALSE,  /* software depth buffer? */
-                                  mesaVis->stencilBits > 0,
-                                  mesaVis->accumRedBits > 0,
-                                  mesaVis->alphaBits > 0
-                                  );
+      struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
+
+      {
+         driRenderbuffer *frontRb
+            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+                                 screen->frontOffset, screen->frontPitch,
+                                 driDrawPriv);
+         s3vSetSpanFunctions(frontRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
+      }
+
+      if (mesaVis->doubleBufferMode) {
+         driRenderbuffer *backRb
+            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+                                 screen->backOffset, screen->backPitch,
+                                 driDrawPriv);
+         s3vSetSpanFunctions(backRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
+         backRb->backBuffer = GL_TRUE;
+      }
+
+      if (mesaVis->depthBits == 16) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, NULL, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch,
+                                 driDrawPriv);
+         s3vSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+      else if (mesaVis->depthBits == 24) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, NULL, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch,
+                                 driDrawPriv);
+         s3vSetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+
+      /* no h/w stencil yet?
+      if (mesaVis->stencilBits > 0) {
+         driRenderbuffer *stencilRb
+            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, NULL,
+                                 screen->cpp, screen->depthOffset,
+                                 screen->depthPitch, driDrawPriv);
+         s3vSetSpanFunctions(stencilRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
+      }
+      */
+
+      _mesa_add_soft_renderbuffers(fb,
+                                   GL_FALSE, /* color */
+                                   GL_FALSE, /* depth */
+                                   mesaVis->stencilBits > 0,
+                                   mesaVis->accumRedBits > 0,
+                                   GL_FALSE, /* alpha */
+                                   GL_FALSE /* aux */);
+      driDrawPriv->driverPrivate = (void *) fb;
+
       return (driDrawPriv->driverPrivate != NULL);
    }
 }
@@ -78,11 +131,11 @@ s3vCreateBuffer( Display *dpy,
 static void
 s3vDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void
-s3vSwapBuffers(Display *dpy, void *drawablePrivate)
+s3vSwapBuffers(__DRIdrawablePrivate *drawablePrivate)
 {
    __DRIdrawablePrivate *dPriv = (__DRIdrawablePrivate *) drawablePrivate;
    __DRIscreenPrivate *sPriv;
@@ -99,14 +152,14 @@ s3vSwapBuffers(Display *dpy, void *drawablePrivate)
 
 /* DMAFLUSH(); */
 
-   _mesa_swapbuffers( ctx );
+   _mesa_notifySwapBuffers( ctx );
 
    vmesa = (s3vContextPtr) dPriv->driContextPriv->driverPrivate;
 /*    driScrnPriv = vmesa->driScreen; */
 
 /*    if (vmesa->EnabledFlags & S3V_BACK_BUFFER) */
 
-/*     _mesa_swapbuffers( ctx );  */
+/*     _mesa_notifySwapBuffers( ctx );  */
 #if 1
 {      
        int x0, y0, x1, y1;
@@ -174,6 +227,7 @@ s3vMakeCurrent(__DRIcontextPrivate *driContextPriv,
 
        s3vContextPtr vmesa;
        __DRIdrawablePrivate *dPriv = driDrawPriv;
+       vmesa = (s3vContextPtr) dPriv->driContextPriv->driverPrivate;
        
        DEBUG(("s3vMakeCurrent\n"));
 
@@ -206,7 +260,7 @@ s3vMakeCurrent(__DRIcontextPrivate *driContextPriv,
 */
 
 /*
-       _mesa_make_current2( newVirgeCtx->glCtx,
+       _mesa_make_current( newVirgeCtx->glCtx,
                           (GLframebuffer *) driDrawPriv->driverPrivate,
                           (GLframebuffer *) driReadPriv->driverPrivate );
 
@@ -222,13 +276,11 @@ s3vMakeCurrent(__DRIcontextPrivate *driContextPriv,
        WRITE(newVirgeCtx->buf, S3VWindow, newVirgeCtx->Window);
 #endif
 
-
-
        newVirgeCtx->new_state |= S3V_NEW_WINDOW; /* FIXME */
 
-       _mesa_make_current2( newVirgeCtx->glCtx, 
-                         (GLframebuffer *) driDrawPriv->driverPrivate,
-                         (GLframebuffer *) driReadPriv->driverPrivate );
+       _mesa_make_current( newVirgeCtx->glCtx, 
+                            (GLframebuffer *) driDrawPriv->driverPrivate,
+                            (GLframebuffer *) driReadPriv->driverPrivate );
 
        if (!newVirgeCtx->glCtx->Viewport.Width) {
            _mesa_set_viewport(newVirgeCtx->glCtx, 0, 0, 
@@ -246,23 +298,23 @@ s3vMakeCurrent(__DRIcontextPrivate *driContextPriv,
 
        newVirgeCtx->new_state |= S3V_NEW_CLIP;
 
-    if (1) {
-        cx = dPriv->x;
-        cw = dPriv->w;
-        cy = dPriv->y;
-        ch = dPriv->h;
-    }
-
-    x1 = y1 = 0;
-    x2 = cw-1;
-    y2 = ch-1;
-
-/*  src_stride = vmesa->s3vScreen->w * vmesa->s3vScreen->cpp; 
-    dest_stride = ((x2+31)&~31) * vmesa->s3vScreen->cpp; */
-    src_stride = vmesa->driScreen->fbWidth * 2;
-    dest_stride = ((x2+31)&~31) * 2;
+        if (1) {
+           cx = dPriv->x;
+           cw = dPriv->w;
+           cy = dPriv->y;
+           ch = dPriv->h;
+        }
+        
+        x1 = y1 = 0;
+        x2 = cw-1;
+        y2 = ch-1;
+
+        /*  src_stride = vmesa->s3vScreen->w * vmesa->s3vScreen->cpp; 
+            dest_stride = ((x2+31)&~31) * vmesa->s3vScreen->cpp; */
+        src_stride = vmesa->driScreen->fbWidth * 2;
+        dest_stride = ((x2+31)&~31) * 2;
     } else {
-    _mesa_make_current( 0, 0 );
+       _mesa_make_current( NULL, NULL, NULL );
     }
 
     return GL_TRUE;
@@ -275,52 +327,14 @@ s3vUnbindContext( __DRIcontextPrivate *driContextPriv )
    return GL_TRUE;
 }
 
-static GLboolean
-s3vOpenFullScreen(__DRIcontextPrivate *driContextPriv)
-{
-    return GL_TRUE;
-}
-
-static GLboolean
-s3vCloseFullScreen(__DRIcontextPrivate *driContextPriv)
-{
-    return GL_TRUE;
-}
-
-
-static struct __DriverAPIRec s3vAPI = {
-   s3vInitDriver,
-   s3vDestroyScreen,
-   s3vCreateContext,
-   s3vDestroyContext,
-   s3vCreateBuffer,
-   s3vDestroyBuffer,
-   s3vSwapBuffers,
-   s3vMakeCurrent,
-   s3vUnbindContext,
-   s3vOpenFullScreen,
-   s3vCloseFullScreen
+const struct __DriverAPIRec driDriverAPI = {
+   .InitScreen    = s3vInitScreen,
+   .DestroyScreen  = s3vDestroyScreen,
+   .CreateContext  = s3vCreateContext,
+   .DestroyContext = s3vDestroyContext,
+   .CreateBuffer   = s3vCreateBuffer,
+   .DestroyBuffer  = s3vDestroyBuffer,
+   .SwapBuffers           = s3vSwapBuffers,
+   .MakeCurrent           = s3vMakeCurrent,
+   .UnbindContext  = s3vUnbindContext,
 };
-
-
-
-/*
- * This is the bootstrap function for the driver.
- * The __driCreateScreen name is the symbol that libGL.so fetches.
- * Return:  pointer to a __DRIscreenPrivate.
- */
-void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
-                        int numConfigs, __GLXvisualConfig *config)
-{
-   __DRIscreenPrivate *psp=NULL;
-
-   DEBUG(("__driCreateScreen: psp = %p\n", psp));
-   psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &s3vAPI);
-   DEBUG(("__driCreateScreen: psp = %p\n", psp));
-   return (void *) psp;
-}
-
-void __driRegisterExtensions(void)
-{
-   /* No extensions */
-}