Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / tdfx / tdfx_screen.c
index 776166439444ec94b481b24b8afdb038d4ddeba7..9f6b35faa28f09fa9ed397a45b1a2bbc1d45f37b 100644 (file)
 #include "tdfx_dri.h"
 #include "tdfx_context.h"
 #include "tdfx_lock.h"
-#include "tdfx_vb.h"
 #include "tdfx_span.h"
-#include "tdfx_tris.h"
 
-#include "framebuffer.h"
-#include "renderbuffer.h"
+#include "main/framebuffer.h"
+#include "main/renderbuffer.h"
 #include "xmlpool.h"
 
 #include "utils.h"
@@ -62,19 +60,18 @@ DRI_CONF_BEGIN
     DRI_CONF_SECTION_END
 DRI_CONF_END;
 
-static const GLuint __driNConfigOptions = 1;
+static const __DRIextension *tdfxExtensions[] = {
+    &driReadDrawableExtension,
+    NULL
+};
 
-extern const struct dri_extension card_extensions[];
-extern const struct dri_extension napalm_extensions[];
+static const GLuint __driNConfigOptions = 1;
 
 static GLboolean
-tdfxCreateScreen( __DRIscreenPrivate *sPriv )
+tdfxCreateScreen( __DRIscreen *sPriv )
 {
    tdfxScreenPrivate *fxScreen;
    TDFXDRIPtr fxDRIPriv = (TDFXDRIPtr) sPriv->pDevPriv;
-   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
-     (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
-   void *const psc = sPriv->psc->screenConfigs;
 
    if (sPriv->devPrivSize != sizeof(TDFXDRIRec)) {
       fprintf(stderr,"\nERROR!  sizeof(TDFXDRIRec) does not match passed size from device driver\n");
@@ -115,16 +112,14 @@ tdfxCreateScreen( __DRIscreenPrivate *sPriv )
       return GL_FALSE;
    }
 
-   if (glx_enable_extension != NULL) {
-      (*glx_enable_extension)(psc, "GLX_SGI_make_current_read");
-   }
+   sPriv->extensions = tdfxExtensions;
 
    return GL_TRUE;
 }
 
 
 static void
-tdfxDestroyScreen( __DRIscreenPrivate *sPriv )
+tdfxDestroyScreen( __DRIscreen *sPriv )
 {
    tdfxScreenPrivate *fxScreen = (tdfxScreenPrivate *) sPriv->private;
 
@@ -142,7 +137,7 @@ tdfxDestroyScreen( __DRIscreenPrivate *sPriv )
 
 
 static GLboolean
-tdfxInitDriver( __DRIscreenPrivate *sPriv )
+tdfxInitDriver( __DRIscreen *sPriv )
 {
    if ( TDFX_DEBUG & DEBUG_VERBOSE_DRI ) {
       fprintf( stderr, "%s( %p )\n", __FUNCTION__, (void *)sPriv );
@@ -158,8 +153,8 @@ tdfxInitDriver( __DRIscreenPrivate *sPriv )
 
 
 static GLboolean
-tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
-                  __DRIdrawablePrivate *driDrawPriv,
+tdfxCreateBuffer( __DRIscreen *driScrnPriv,
+                  __DRIdrawable *driDrawPriv,
                   const __GLcontextModes *mesaVis,
                   GLboolean isPixmap )
 {
@@ -173,7 +168,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       {
          driRenderbuffer *frontRb
-            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+            = driNewRenderbuffer(MESA_FORMAT_ARGB8888, NULL, screen->cpp,
                                  screen->fbOffset, screen->width, driDrawPriv);
          tdfxSetSpanFunctions(frontRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
@@ -181,7 +176,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->doubleBufferMode) {
          driRenderbuffer *backRb
-            = driNewRenderbuffer(GL_RGBA, NULL, screen->cpp,
+            = driNewRenderbuffer(MESA_FORMAT_ARGB8888, NULL, screen->cpp,
                                  screen->backOffset, screen->width,
                                  driDrawPriv);
          tdfxSetSpanFunctions(backRb, mesaVis);
@@ -191,7 +186,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->depthBits == 16) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, NULL, screen->cpp,
+            = driNewRenderbuffer(MESA_FORMAT_Z16, NULL, screen->cpp,
                                  screen->depthOffset, screen->width,
                                  driDrawPriv);
          tdfxSetSpanFunctions(depthRb, mesaVis);
@@ -199,7 +194,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
       }
       else if (mesaVis->depthBits == 24) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, NULL, screen->cpp,
+            = driNewRenderbuffer(MESA_FORMAT_Z24_S8, NULL, screen->cpp,
                                  screen->depthOffset, screen->width,
                                  driDrawPriv);
          tdfxSetSpanFunctions(depthRb, mesaVis);
@@ -208,7 +203,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->stencilBits > 0) {
          driRenderbuffer *stencilRb
-            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, NULL, screen->cpp,
+            = driNewRenderbuffer(MESA_FORMAT_S8, NULL, screen->cpp,
                                  screen->depthOffset, screen->width,
                                  driDrawPriv);
          tdfxSetSpanFunctions(stencilRb, mesaVis);
@@ -230,14 +225,14 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
 
 static void
-tdfxDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
+tdfxDestroyBuffer(__DRIdrawable *driDrawPriv)
 {
-   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+   _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
 }
 
 
 static void
-tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
+tdfxSwapBuffers( __DRIdrawable *driDrawPriv )
 
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -256,7 +251,7 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
     * we have to do a glFinish (per the GLX spec).
     */
    if ( ctx ) {
-      __DRIdrawablePrivate *curDrawPriv;
+      __DRIdrawable *curDrawPriv;
       fxMesa = TDFX_CONTEXT(ctx);
       curDrawPriv = fxMesa->driContext->driDrawablePriv;
 
@@ -343,36 +338,14 @@ tdfxSwapBuffers( __DRIdrawablePrivate *driDrawPriv )
    }
 }
 
-
-static const struct __DriverAPIRec tdfxAPI = {
-   .InitDriver      = tdfxInitDriver,
-   .DestroyScreen   = tdfxDestroyScreen,
-   .CreateContext   = tdfxCreateContext,
-   .DestroyContext  = tdfxDestroyContext,
-   .CreateBuffer    = tdfxCreateBuffer,
-   .DestroyBuffer   = tdfxDestroyBuffer,
-   .SwapBuffers     = tdfxSwapBuffers,
-   .MakeCurrent     = tdfxMakeCurrent,
-   .UnbindContext   = tdfxUnbindContext,
-   .GetSwapInfo     = NULL,
-   .GetMSC          = NULL,
-   .WaitForMSC      = NULL,
-   .WaitForSBC      = NULL,
-   .SwapBuffersMSC  = NULL
-};
-
-
-static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
-                                        unsigned depth_bits,
-                                        unsigned stencil_bits,
-                                        GLboolean have_back_buffer)
+static const __DRIconfig **
+tdfxFillInModes(__DRIscreen *psp,
+               unsigned pixel_bits,
+               unsigned depth_bits,
+               unsigned stencil_bits,
+               GLboolean have_back_buffer)
 {
-       __GLcontextModes *modes;
-       __GLcontextModes *m;
-       unsigned num_modes;
-       unsigned vis[2] = { GLX_TRUE_COLOR, GLX_DIRECT_COLOR };
        unsigned deep = (depth_bits > 17);
-       unsigned i, db, depth, accum, stencil;
 
        /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
         * enough to add support.  Basically, if a context is created with an
@@ -380,120 +353,95 @@ static __GLcontextModes *tdfxFillInModes(unsigned pixel_bits,
         * will never be used.
         */
 
-       num_modes = (depth_bits == 16) ? 32 : 16;
-
-       modes = (*dri_interface->createContextModes)(num_modes, sizeof(__GLcontextModes));
-       m = modes;
-
-       for (i = 0; i <= 1; i++) {
-           for (db = 0; db <= 1; db++) {
-               for (depth = 0; depth <= 1; depth++) {
-                   for (accum = 0; accum <= 1; accum++) {
-                       for (stencil = 0; stencil <= !deep; stencil++) {
-                           if (deep) stencil = depth;
-                           m->redBits          = deep ? 8 : 5;
-                           m->greenBits        = deep ? 8 : 6;
-                           m->blueBits         = deep ? 8 : 5;
-                           m->alphaBits        = deep ? 8 : 0;
-                           m->redMask          = deep ?0xFF000000 :0x0000F800;
-                           m->greenMask        = deep ?0x00FF0000 :0x000007E0;
-                           m->blueMask         = deep ?0x0000FF00 :0x0000001F;
-                           m->alphaMask        = deep ? 0x000000FF : 0;
-                           m->rgbBits          = m->redBits + m->greenBits +
-                                                 m->blueBits + m->alphaBits;
-                           m->accumRedBits     = accum ? 16 : 0;
-                           m->accumGreenBits   = accum ? 16 : 0;
-                           m->accumBlueBits    = accum ? 16 : 0;
-                           m->accumAlphaBits   = (accum && deep) ? 16 : 0;
-                           m->stencilBits      = stencil ? 8 : 0;
-                           m->depthBits        = deep
-                                                 ? (depth ? 24 : 0)
-                                                 : (depth ? 0 : depth_bits);
-                           m->visualType       = vis[i];
-                           m->renderType       = GLX_RGBA_BIT;
-                           m->drawableType     = GLX_WINDOW_BIT;
-                           m->rgbMode          = GL_TRUE;
-                           m->doubleBufferMode = db ? GL_TRUE : GL_FALSE;
-                           if (db)
-                               m->swapMethod = GLX_SWAP_UNDEFINED_OML;
-                           m->visualRating     = ((stencil && !deep) || accum)
-                                                 ? GLX_SLOW_CONFIG
-                                                 : GLX_NONE;
-                           m = m->next;
-                           if (deep) stencil = 0;
-                       }
-                   }
-               }
-           }
+       static const GLenum db_modes[2] = { GLX_NONE, GLX_SWAP_UNDEFINED_OML };
+       uint8_t depth_bits_array[4];
+       uint8_t stencil_bits_array[4];
+        uint8_t msaa_samples_array[1];
+       if(deep) {
+               depth_bits_array[0] = 0;
+               depth_bits_array[1] = 24;
+               stencil_bits_array[0] = 0;
+               stencil_bits_array[1] = 8;
+       } else {
+               depth_bits_array[0] = depth_bits;
+               depth_bits_array[1] = 0;
+               depth_bits_array[2] = depth_bits;
+               depth_bits_array[3] = 0;
+               stencil_bits_array[0] = 0;
+               stencil_bits_array[1] = 0;
+               stencil_bits_array[2] = 8;
+               stencil_bits_array[3] = 8;
        }
 
-       return modes;
+       msaa_samples_array[0] = 0;
+
+       return (const __DRIconfig **)
+          driCreateConfigs(deep ? GL_RGBA : GL_RGB,
+                           deep ? GL_UNSIGNED_INT_8_8_8_8 :
+                                  GL_UNSIGNED_SHORT_5_6_5,
+                           depth_bits_array,
+                           stencil_bits_array,
+                           deep ? 2 : 4,
+                           db_modes, 2,
+                           msaa_samples_array, 1);
 }
 
 /**
- * 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_20050727( __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,
-                            const __DRIinterfaceMethods * interface,
-                            __GLcontextModes ** driver_modes )
+static const __DRIconfig **
+tdfxInitScreen(__DRIscreen *psp)
 {
-   __DRIscreenPrivate *psp;
    static const __DRIversion ddx_expected = { 1, 1, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 1, 0, 0 };
 
-   dri_interface = interface;
+   /* 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);
-
-   if (psp != NULL) {
-      /* divined from tdfx_dri.c, sketchy */
-      TDFXDRIPtr dri_priv = (TDFXDRIPtr) psp->pDevPriv;
-      int bpp = (dri_priv->cpp > 2) ? 24 : 16;
-
-      /* 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));
-
-      /* 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 );
-   }
-
-   return (void *)psp;
+   return tdfxFillInModes(psp,
+                         bpp, (bpp == 16) ? 16 : 24,
+                         (bpp == 16) ? 0 : 8,
+                         (dri_priv->backOffset!=dri_priv->depthOffset));
 }
+
+const struct __DriverAPIRec driDriverAPI = {
+   .InitScreen      = tdfxInitScreen,
+   .DestroyScreen   = tdfxDestroyScreen,
+   .CreateContext   = tdfxCreateContext,
+   .DestroyContext  = tdfxDestroyContext,
+   .CreateBuffer    = tdfxCreateBuffer,
+   .DestroyBuffer   = tdfxDestroyBuffer,
+   .SwapBuffers     = tdfxSwapBuffers,
+   .MakeCurrent     = tdfxMakeCurrent,
+   .UnbindContext   = tdfxUnbindContext,
+   .GetSwapInfo     = NULL,
+   .GetDrawableMSC  = NULL,
+   .WaitForMSC      = NULL,
+   .WaitForSBC      = NULL,
+   .SwapBuffersMSC  = NULL
+};
+
+/* This is the table of extensions that the loader will dlsym() for. */
+PUBLIC const __DRIextension *__driDriverExtensions[] = {
+    &driCoreExtension.base,
+    &driLegacyExtension.base,
+    NULL
+};