Move mipmap generation functions, texture scaling functions into new
[mesa.git] / src / mesa / drivers / dri / unichrome / via_screen.c
index 8de73539259ac96eb2b36cc07953060bd1eefcf7..4f137c8ceb863d37b8a3333e166cd96fdd9c6f6a 100644 (file)
@@ -44,6 +44,7 @@
 #include "via_dri.h"
 
 #include "GL/internal/dri_interface.h"
+#include "drirenderbuffer.h"
 
 /* Radeon configuration
  */
@@ -61,6 +62,7 @@ DRI_CONF_BEGIN
 DRI_CONF_END;
 static const GLuint __driNConfigOptions = 3;
 
+extern const struct dri_extension card_extensions[];
 
 static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
 
@@ -100,12 +102,11 @@ viaInitDriver(__DRIscreenPrivate *sPriv)
       (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
     void * const psc = sPriv->psc->screenConfigs;
 
-
-    if ( glx_enable_extension == NULL ) {
-       return GL_FALSE;
+    if (sPriv->devPrivSize != sizeof(VIADRIRec)) {
+      fprintf(stderr,"\nERROR!  sizeof(VIADRIRec) does not match passed size from device driver\n");
+      return GL_FALSE;
     }
 
-
     /* Allocate the private area */
     viaScreen = (viaScreenPrivate *) CALLOC(sizeof(viaScreenPrivate));
     if (!viaScreen) {
@@ -150,7 +151,7 @@ viaInitDriver(__DRIscreenPrivate *sPriv)
     if (drmMap(sPriv->fd,
                gDRIPriv->regs.handle,
                gDRIPriv->regs.size,
-               (drmAddress *)&viaScreen->reg) != 0) {
+               &viaScreen->reg) != 0) {
         FREE(viaScreen);
         sPriv->private = NULL;
         __driUtilMessage("viaInitDriver: drmMap regs failed");
@@ -162,25 +163,28 @@ viaInitDriver(__DRIscreenPrivate *sPriv)
                    gDRIPriv->agp.handle,
                    gDRIPriv->agp.size,
                   (drmAddress *)&viaScreen->agpLinearStart) != 0) {
+           drmUnmap(viaScreen->reg, gDRIPriv->regs.size);
            FREE(viaScreen);
-           drmUnmap(viaScreen->reg, gDRIPriv->agp.size);
            sPriv->private = NULL;
            __driUtilMessage("viaInitDriver: drmMap agp failed");
            return GL_FALSE;
-       }           
-       viaScreen->agpBase = (GLuint *)gDRIPriv->agp.handle;
+       }
+
+       viaScreen->agpBase = drmAgpBase(sPriv->fd);
     } else
        viaScreen->agpLinearStart = 0;
 
     viaScreen->sareaPrivOffset = gDRIPriv->sarea_priv_offset;
 
-    if ( viaScreen->irqEnabled ) {
-       (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );
-       (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );
-       (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );
-    }
+    if ( glx_enable_extension != NULL ) {
+       if ( viaScreen->irqEnabled ) {
+         (*glx_enable_extension)( psc, "GLX_SGI_swap_control" );
+         (*glx_enable_extension)( psc, "GLX_SGI_video_sync" );
+         (*glx_enable_extension)( psc, "GLX_MESA_swap_control" );
+       }
 
-    (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );
+       (*glx_enable_extension)( psc, "GLX_MESA_swap_frame_usage" );
+    }
 
     return GL_TRUE;
 }
@@ -212,7 +216,7 @@ viaCreateBuffer(__DRIscreenPrivate *driScrnPriv,
 
     GLboolean swStencil = (mesaVis->stencilBits > 0 && 
                           mesaVis->depthBits != 24);
-
+    GLboolean swAccum = mesaVis->accumRedBits > 0;
 
     if (isPixmap) {
        /* KW: This needs work, disabled for now:
@@ -230,73 +234,83 @@ viaCreateBuffer(__DRIscreenPrivate *driScrnPriv,
        return GL_FALSE;
     }
     else {
-#if 0
-        driDrawPriv->driverPrivate = (void *)
-            _mesa_create_framebuffer(mesaVis,
-                                     GL_FALSE, /* software depth buffer? */
-                                     swStencil,
-                                     mesaVis->accumRedBits > 0,
-                                     GL_FALSE  /* s/w alpha planes */);
-#else
       struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
 
+      /* The front color, back color and depth renderbuffers are
+       * set up later in calculate_buffer_parameters().
+       * Only create/connect software-based buffers here.
+       */
+
+#if 000
+      /* This code _should_ be put to use.  We have to move the
+       * viaRenderbuffer members out of the via_context structure.
+       * Those members should just be the renderbuffers hanging off the
+       * gl_framebuffer object.
+       */
       /* XXX check/fix the offset/pitch parameters! */
       {
          driRenderbuffer *frontRb
-            = driNewRenderbuffer(GL_RGBA, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_RGBA, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(frontRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontRb->Base);
       }
 
       if (mesaVis->doubleBufferMode) {
          driRenderbuffer *backRb
-            = driNewRenderbuffer(GL_RGBA, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_RGBA, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(backRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
       }
 
       if (mesaVis->depthBits == 16) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(depthRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
       }
       else if (mesaVis->depthBits == 24) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(depthRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
       }
       else if (mesaVis->depthBits == 32) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT32, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT32, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(depthRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
       }
 
       if (mesaVis->stencilBits > 0 && !swStencil) {
          driRenderbuffer *stencilRb
-            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, screen->bytesPerPixel,
-                                 0, screen->width);
+            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT, NULL,
+                                 screen->bytesPerPixel,
+                                 0, screen->width, driDrawPriv);
          viaSetSpanFunctions(stencilRb, mesaVis);
          _mesa_add_renderbuffer(fb, BUFFER_STENCIL, &stencilRb->Base);
       }
+#endif
 
       _mesa_add_soft_renderbuffers(fb,
                                    GL_FALSE, /* color */
                                    GL_FALSE, /* depth */
                                    swStencil,
-                                   mesaVis->accumRedBits > 0,
+                                   swAccum,
                                    GL_FALSE, /* alpha */
                                    GL_FALSE /* aux */);
       driDrawPriv->driverPrivate = (void *) fb;
-#endif
-        return (driDrawPriv->driverPrivate != NULL);
+
+      return (driDrawPriv->driverPrivate != NULL);
    }
 }
 
@@ -402,7 +416,7 @@ viaFillInModes( unsigned pixel_bits, GLboolean have_back_buffer )
  *         failure.
  */
 PUBLIC
-void * __driCreateNewScreen_20050725( __DRInativeDisplay *dpy, int scrn,
+void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn,
                             __DRIscreen *psc,
                             const __GLcontextModes * modes,
                             const __DRIversion * ddx_version,
@@ -416,16 +430,19 @@ void * __driCreateNewScreen_20050725( __DRInativeDisplay *dpy, int scrn,
                             
 {
    __DRIscreenPrivate *psp;
-   static const __DRIversion ddx_expected = { 4, 0, 0 };
+   static const __DRIversion ddx_expected = { VIA_DRIDDX_VERSION_MAJOR,
+                                              VIA_DRIDDX_VERSION_MINOR,
+                                              VIA_DRIDDX_VERSION_PATCH };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 2, 3, 0 };
+   static const char *driver_name = "Unichrome";
 
    dri_interface = interface;
 
-   if ( ! driCheckDriDdxDrmVersions2( "Unichrome",
+   if ( ! driCheckDriDdxDrmVersions2( driver_name,
                                      dri_version, & dri_expected,
                                      ddx_version, & ddx_expected,
-                                     drm_version, & drm_expected ) ) {
+                                     drm_version, & drm_expected) ) {
       return NULL;
    }
       
@@ -437,9 +454,18 @@ void * __driCreateNewScreen_20050725( __DRInativeDisplay *dpy, int scrn,
       VIADRIPtr dri_priv = (VIADRIPtr) psp->pDevPriv;
       *driver_modes = viaFillInModes( dri_priv->bytesPerPixel * 8,
                                      GL_TRUE );
+
+      /* 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 );
    }
 
-   fprintf(stderr, "%s - succeeded\n", __FUNCTION__);
    return (void *) psp;
 }