Remove GetMSC DriverAPI function.
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_screen.c
index 500d5d3f3dd2f06bc082c73df12cb1fd4af9db5f..53c04e7bb14a9d1527285fed777df0cc197dcf7d 100644 (file)
 #include "tdfx_vb.h"
 #include "tdfx_span.h"
 #include "tdfx_tris.h"
-#include "utils.h"
+
 #include "framebuffer.h"
 #include "renderbuffer.h"
+#include "xmlpool.h"
+
+#include "utils.h"
 
 #ifdef DEBUG_LOCKING
 char *prevLockFile = 0;
@@ -50,18 +53,24 @@ int prevLockLine = 0;
 #endif
 
 #ifndef TDFX_DEBUG
-int TDFX_DEBUG = (0
-/*               | DEBUG_ALWAYS_SYNC */
-/*               | DEBUG_VERBOSE_API */
-/*               | DEBUG_VERBOSE_MSG */
-/*               | DEBUG_VERBOSE_LRU */
-/*               | DEBUG_VERBOSE_DRI */
-/*               | DEBUG_VERBOSE_IOCTL */
-/*               | DEBUG_VERBOSE_2D */
-   );
+int TDFX_DEBUG = 0;
 #endif
 
+PUBLIC const char __driConfigOptions[] =
+DRI_CONF_BEGIN
+    DRI_CONF_SECTION_DEBUG
+        DRI_CONF_NO_RAST(false)
+    DRI_CONF_SECTION_END
+DRI_CONF_END;
+
+static const __DRIextension *tdfxExtensions[] = {
+    &driReadDrawableExtension,
+};
+
+static const GLuint __driNConfigOptions = 1;
 
+extern const struct dri_extension card_extensions[];
+extern const struct dri_extension napalm_extensions[];
 
 static GLboolean
 tdfxCreateScreen( __DRIscreenPrivate *sPriv )
@@ -69,11 +78,20 @@ tdfxCreateScreen( __DRIscreenPrivate *sPriv )
    tdfxScreenPrivate *fxScreen;
    TDFXDRIPtr fxDRIPriv = (TDFXDRIPtr) sPriv->pDevPriv;
 
+   if (sPriv->devPrivSize != sizeof(TDFXDRIRec)) {
+      fprintf(stderr,"\nERROR!  sizeof(TDFXDRIRec) does not match passed size from device driver\n");
+      return GL_FALSE;
+   }
+
    /* Allocate the private area */
    fxScreen = (tdfxScreenPrivate *) CALLOC( sizeof(tdfxScreenPrivate) );
    if ( !fxScreen )
       return GL_FALSE;
 
+   /* parse information in __driConfigOptions */
+   driParseOptionInfo (&fxScreen->optionCache,
+                      __driConfigOptions, __driNConfigOptions);
+
    fxScreen->driScrnPriv = sPriv;
    sPriv->private = (void *) fxScreen;
 
@@ -99,6 +117,8 @@ tdfxCreateScreen( __DRIscreenPrivate *sPriv )
       return GL_FALSE;
    }
 
+   sPriv->extensions = tdfxExtensions;
+
    return GL_TRUE;
 }
 
@@ -108,12 +128,16 @@ tdfxDestroyScreen( __DRIscreenPrivate *sPriv )
 {
    tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private;
 
-   if ( fxScreen ) {
-      drmUnmap( fxScreen->regs.map, fxScreen->regs.size );
+   if (!fxScreen)
+      return;
 
-      FREE( fxScreen );
-      sPriv->private = NULL;
-   }
+   drmUnmap( fxScreen->regs.map, fxScreen->regs.size );
+
+   /* free all option information */
+   driDestroyOptionInfo (&fxScreen->optionCache);
+
+   FREE( fxScreen );
+   sPriv->private = NULL;
 }
 
 
@@ -145,51 +169,48 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
       return GL_FALSE; /* not implemented */
    }
    else {
-#if 0
-      driDrawPriv->driverPrivate = (void *) 
-         _mesa_create_framebuffer( mesaVis,
-                                   GL_FALSE, /* software depth buffer? */
-                                   mesaVis->stencilBits > 0,
-                                   mesaVis->accumRedBits > 0,
-                                   GL_FALSE /* software alpha channel? */ );
-#else
       struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
 
       {
          driRenderbuffer *frontRb
-            = driNewRenderbuffer(GL_RGBA, screen->cpp,
-                                 screen->fbOffset, screen->width);
+            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+                                 screen->fbOffset, screen->width, driDrawPriv);
          tdfxSetSpanFunctions(frontRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
       }
 
       if (mesaVis->doubleBufferMode) {
          driRenderbuffer *backRb
-            = driNewRenderbuffer(GL_RGBA8, screen->cpp,
-                                 screen->backOffset, screen->width);
+            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+                                 screen->backOffset, screen->width,
+                                 driDrawPriv);
          tdfxSetSpanFunctions(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, screen->cpp,
-                                 screen->depthOffset, screen->width);
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, NULL, screen->cpp,
+                                 screen->depthOffset, screen->width,
+                                 driDrawPriv);
          tdfxSetSpanFunctions(depthRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
       }
       else if (mesaVis->depthBits == 24) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, screen->cpp,
-                                 screen->depthOffset, screen->width);
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, NULL, screen->cpp,
+                                 screen->depthOffset, screen->width,
+                                 driDrawPriv);
          tdfxSetSpanFunctions(depthRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
       }
 
       if (mesaVis->stencilBits > 0) {
          driRenderbuffer *stencilRb
-            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, screen->cpp,
-                                 screen->depthOffset, screen->width);
+            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, NULL, screen->cpp,
+                                 screen->depthOffset, screen->width,
+                                 driDrawPriv);
          tdfxSetSpanFunctions(stencilRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
       }
@@ -202,7 +223,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
                                    GL_FALSE, /* alpha */
                                    GL_FALSE /* aux */);
       driDrawPriv->driverPrivate = (void *) fb;
-#endif
+
       return (driDrawPriv->driverPrivate != NULL);
    }
 }
@@ -211,7 +232,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 tdfxDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
@@ -251,7 +272,9 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
             return;
         LOCK_HARDWARE( fxMesa );
         fxMesa->Glide.grSstSelect( fxMesa->Glide.Board );
+#ifdef DEBUG
          printf("SwapBuf SetState 1\n");
+#endif
         fxMesa->Glide.grGlideSetState(fxMesa->Glide.State );
       }
    }
@@ -311,7 +334,9 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
       if (ctx->DriverCtx != fxMesa) {
          fxMesa = TDFX_CONTEXT(ctx);
         fxMesa->Glide.grSstSelect( fxMesa->Glide.Board );
+#ifdef DEBUG
          printf("SwapBuf SetState 2\n");
+#endif
         fxMesa->Glide.grGlideSetState(fxMesa->Glide.State );
       }
       UNLOCK_HARDWARE( fxMesa );
@@ -320,7 +345,6 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
 
 
 static const struct __DriverAPIRec tdfxAPI = {
-   .InitDriver      = tdfxInitDriver,
    .DestroyScreen   = tdfxDestroyScreen,
    .CreateContext   = tdfxCreateContext,
    .DestroyContext  = tdfxDestroyContext,
@@ -330,18 +354,12 @@ static const struct __DriverAPIRec tdfxAPI = {
    .MakeCurrent     = tdfxMakeCurrent,
    .UnbindContext   = tdfxUnbindContext,
    .GetSwapInfo     = NULL,
-   .GetMSC          = NULL,
+   .GetDrawableMSC  = NULL,
    .WaitForMSC      = NULL,
    .WaitForSBC      = NULL,
    .SwapBuffersMSC  = NULL
 };
 
-#ifdef USE_NEW_INTERFACE
-/*
- * new interface code, derived from radeon_screen.c
- * XXX this may still be wrong
- */
-static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
 
 static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
                                         unsigned depth_bits,
@@ -363,7 +381,7 @@ static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
 
        num_modes = (depth_bits == 16) ? 32 : 16;
 
-       modes = (*create_context_modes)(num_modes, sizeof(__GLcontextModes));
+       modes = (*dri_interface->createContextModes)(num_modes, sizeof(__GLcontextModes));
        m = modes;
 
        for (i = 0; i <= 1; i++) {
@@ -385,7 +403,7 @@ static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
                            m->accumRedBits     = accum ? 16 : 0;
                            m->accumGreenBits   = accum ? 16 : 0;
                            m->accumBlueBits    = accum ? 16 : 0;
-                           m->accumAlphaBits   = accum ? 16 : 0;
+                           m->accumAlphaBits   = (accum && deep) ? 16 : 0;
                            m->stencilBits      = stencil ? 8 : 0;
                            m->depthBits        = deep
                                                  ? (depth ? 24 : 0)
@@ -412,75 +430,50 @@ static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
 }
 
 /**
- * This is the bootstrap function for the driver.  libGL supplies all of the
- * requisite information about the system, and the driver initializes itself.
- * This routine also fills in the linked list pointed to by \c driver_modes
- * with the \c __GLcontextModes that the driver can support for windows or
- * pbuffers.
+ * This is the driver specific part of the createNewScreen entry point.
+ * 
+ * \todo maybe fold this into intelInitDriver
  *
- * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on
- *         failure.
+ * \return the __GLcontextModes supported by this driver
  */
-PUBLIC
-void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
-                            const __GLcontextModes * modes,
-                            const __DRIversion * ddx_version,
-                            const __DRIversion * dri_version,
-                            const __DRIversion * drm_version,
-                            const __DRIframebuffer * frame_buffer,
-                            drmAddress pSAREA, int fd,
-                            int internal_api_version,
-                            __GLcontextModes ** driver_modes )
+__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
 {
-   __DRIscreenPrivate *psp;
-   static const __DRIversion ddx_expected = { 1, 0, 0 };
+   static const __DRIversion ddx_expected = { 1, 1, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 1, 0, 0 };
 
+   /* divined from tdfx_dri.c, sketchy */
+   TDFXDRIPtr dri_priv = (TDFXDRIPtr) psp->pDevPriv;
+
+   /* XXX i wish it was like this */
+   /* bpp = dri_priv->bpp */
+   int bpp = (dri_priv->cpp > 2) ? 24 : 16;
+
    if ( ! driCheckDriDdxDrmVersions2( "tdfx",
-                                     dri_version, & dri_expected,
-                                     ddx_version, & ddx_expected,
-                                     drm_version, & drm_expected ) ) {
+                                     &psp->dri_version, & dri_expected,
+                                     &psp->ddx_version, & ddx_expected,
+                                     &psp->drm_version, & drm_expected ) )
       return NULL;
-   }
-
-   psp = __driUtilCreateNewScreen(dpy, scrn, psc, NULL,
-                                 ddx_version, dri_version, drm_version,
-                                 frame_buffer, pSAREA, fd,
-                                 internal_api_version, &tdfxAPI);
 
-   create_context_modes = (PFNGLXCREATECONTEXTMODES)
-      glXGetProcAddress((const GLubyte *)"__glXCreateContextModes");
-      
-   if (create_context_modes != NULL) {
-      /* divined from tdfx_dri.c, sketchy */
-      TDFXDRIPtr dri_priv = (TDFXDRIPtr) psp->pDevPriv;
-      int bpp = (dri_priv->cpp > 2) ? 24 : 16;
+   psp->DriverAPI = tdfxAPI;
+
+   /* Calling driInitExtensions here, with a NULL context pointer,
+    * does not actually enable the extensions.  It just makes sure
+    * that all the dispatch offsets for all the extensions that
+    * *might* be enables are known.  This is needed because the
+    * dispatch offsets need to be known when _mesa_context_create is
+    * called, but we can't enable the extensions until we have a
+    * context pointer.
+    *
+    * Hello chicken.  Hello egg.  How are you two today?
+    */
+   driInitExtensions( NULL, card_extensions, GL_FALSE );
+   driInitExtensions( NULL, napalm_extensions, GL_FALSE );
 
-      /* XXX i wish it was like this */
-      /* bpp = dri_priv->bpp */
+   if (!tdfxInitDriver(psp))
+      return NULL;
       
-      *driver_modes = tdfxFillInModes(bpp, (bpp == 16) ? 16 : 24,
-                               (bpp == 16) ? 0 : 8,
-                               (dri_priv->backOffset!=dri_priv->depthOffset));
-   }
-
-   return (void *)psp;
-}
-#endif /* USE_NEW_INTERFACE */
-
-
-/*
- * This is the bootstrap function for the driver.
- * The __driCreateScreen name is the symbol that libGL.so fetches.
- * Return:  pointer to a __DRIscreenPrivate.
- */
-#if !defined(DRI_NEW_INTERFACE_ONLY)
-void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
-                        int numConfigs, __GLXvisualConfig *config)
-{
-   __DRIscreenPrivate *psp;
-   psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &tdfxAPI);
-   return (void *) psp;
+   return tdfxFillInModes(bpp, (bpp == 16) ? 16 : 24,
+                         (bpp == 16) ? 0 : 8,
+                         (dri_priv->backOffset!=dri_priv->depthOffset));
 }
-#endif /* !defined(DRI_NEW_INTERFACE_ONLY) */