r300: Indented radeon_span.h
[mesa.git] / src / mesa / drivers / dri / mach64 / mach64_screen.c
index 4d36369ce9d2889dadb18ba33d9a566813a8ecb9..4e9e216e7dbd4acb7c83a8c9790947e68e2be3ff 100644 (file)
  * Authors:
  *     Gareth Hughes <gareth@valinux.com>
  *     Leif Delgass <ldelgass@retinalburn.net>
- *     José Fonseca <j_r_fonseca@yahoo.co.uk>
+ *     JosFonseca <j_r_fonseca@yahoo.co.uk>
  */
 
 #include "mach64_context.h"
 #include "mach64_ioctl.h"
 #include "mach64_tris.h"
 #include "mach64_vb.h"
+#include "mach64_span.h"
 
 #include "context.h"
 #include "imports.h"
+#include "framebuffer.h"
+#include "renderbuffer.h"
 
 #include "utils.h"
 #include "vblank.h"
 
-#ifndef _SOLO
 #include "GL/internal/dri_interface.h"
-#endif
 
 /* Mach64 configuration
  */
 #include "xmlpool.h"
 
-const char __driConfigOptions[] =
+PUBLIC const char __driConfigOptions[] =
 DRI_CONF_BEGIN
     DRI_CONF_SECTION_PERFORMANCE
         DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
     DRI_CONF_SECTION_END
-#if ENABLE_PERF_BOXES
     DRI_CONF_SECTION_DEBUG
+        DRI_CONF_NO_RAST(false)
+#if ENABLE_PERF_BOXES
         DRI_CONF_PERFORMANCE_BOXES(false)
-    DRI_CONF_SECTION_END
 #endif
+    DRI_CONF_SECTION_END
 DRI_CONF_END;
 #if ENABLE_PERF_BOXES
-static const GLuint __driNConfigOptions = 2;
+static const GLuint __driNConfigOptions = 3;
 #else
-static const GLuint __driNConfigOptions = 1;
+static const GLuint __driNConfigOptions = 2;
 #endif
 
-#ifdef USE_NEW_INTERFACE
-static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
-#endif /* USE_NEW_INTERFACE */
+extern const struct dri_extension card_extensions[];
 
-#ifdef USE_NEW_INTERFACE
 static __GLcontextModes * fill_in_modes( __GLcontextModes * modes,
                                         unsigned pixel_bits, 
                                         unsigned depth_bits,
@@ -78,12 +77,12 @@ static __GLcontextModes * fill_in_modes( __GLcontextModes * modes,
                                         unsigned num_db_modes,
                                         int visType )
 {
-       static const uint8_t bits[2][4] = {
+       static const u_int8_t bits[2][4] = {
        {          5,          6,          5,          0 },
        {          8,          8,          8,          0 }
     };
 
-    static const uint32_t masks[2][4] = {
+    static const u_int32_t masks[2][4] = {
        { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 },
        { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }
     };
@@ -134,10 +133,8 @@ static __GLcontextModes * fill_in_modes( __GLcontextModes * modes,
     
     return modes;
 }
-#endif /* USE_NEW_INTERFACE */
 
 
-#ifdef USE_NEW_INTERFACE
 static __GLcontextModes *
 mach64FillInModes( unsigned pixel_bits, unsigned depth_bits,
                 unsigned stencil_bits, GLboolean have_back_buffer )
@@ -176,7 +173,7 @@ mach64FillInModes( unsigned pixel_bits, unsigned depth_bits,
 
     num_modes = depth_buffer_factor * back_buffer_factor * 4;
 
-    modes = (*create_context_modes)( num_modes, sizeof( __GLcontextModes ) );
+    modes = (*dri_interface->createContextModes)( num_modes, sizeof( __GLcontextModes ) );
     m = modes;
     for ( i = 0 ; i < depth_buffer_factor ; i++ ) {
        m = fill_in_modes( m, pixel_bits, 
@@ -202,7 +199,6 @@ mach64FillInModes( unsigned pixel_bits, unsigned depth_bits,
 
     return modes;
 }
-#endif /* USE_NEW_INTERFACE */
 
 
 /* Create the device specific screen private data struct.
@@ -212,13 +208,18 @@ mach64CreateScreen( __DRIscreenPrivate *sPriv )
 {
    mach64ScreenPtr mach64Screen;
    ATIDRIPtr serverInfo = (ATIDRIPtr)sPriv->pDevPriv;
+   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
+     (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
+   void * const psc = sPriv->psc->screenConfigs;
+
+   if (sPriv->devPrivSize != sizeof(ATIDRIRec)) {
+      fprintf(stderr,"\nERROR!  sizeof(ATIDRIRec) does not match passed size from device driver\n");
+      return GL_FALSE;
+   }
 
    if ( MACH64_DEBUG & DEBUG_VERBOSE_DRI ) 
       fprintf( stderr, "%s\n", __FUNCTION__ );
 
-   if ( ! driCheckDriDdxDrmVersions( sPriv, "Mach64", 4, 0, 6, 4, 1, 0 ) )
-      return NULL;
-
    /* Allocate the private area */
    mach64Screen = (mach64ScreenPtr) CALLOC( sizeof(*mach64Screen) );
    if ( !mach64Screen ) return NULL;
@@ -230,11 +231,11 @@ mach64CreateScreen( __DRIscreenPrivate *sPriv )
    mach64Screen->IsPCI = serverInfo->IsPCI;
 
    {
-      drmMach64GetParam gp;
+      drm_mach64_getparam_t gp;
       int ret;
 
       gp.param = MACH64_PARAM_IRQ_NR;
-      gp.value = &mach64Screen->irq;
+      gp.value = (void *) &mach64Screen->irq;
 
       ret = drmCommandWriteRead( sPriv->fd, DRM_MACH64_GETPARAM,
                                    &gp, sizeof(gp));
@@ -304,7 +305,7 @@ mach64CreateScreen( __DRIscreenPrivate *sPriv )
       mach64Screen->texSize[MACH64_AGP_HEAP] = 0;
       mach64Screen->logTexGranularity[MACH64_AGP_HEAP] = 0;
    } else {
-      if (mach64Screen->texSize[MACH64_CARD_HEAP] > 0) {
+      if (serverInfo->textureSize > 0) {
         mach64Screen->numTexHeaps = MACH64_NR_TEX_HEAPS;
         mach64Screen->firstTexHeap = MACH64_CARD_HEAP;
       } else {
@@ -317,23 +318,17 @@ mach64CreateScreen( __DRIscreenPrivate *sPriv )
    }
 
    mach64Screen->driScreen = sPriv;
-#ifndef _SOLO
-   if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
-      PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
-          (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( (const GLubyte *) "__glXScrEnableExtension" );
-      void * const psc = sPriv->psc->screenConfigs;
-
-      if ( glx_enable_extension != NULL ) {
-        if ( mach64Screen->irq != 0 ) {
-           (*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" );
+
+   if ( glx_enable_extension != NULL ) {
+      if ( mach64Screen->irq != 0 ) {
+        (*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" );
    }
-#endif
+
    return mach64Screen;
 }
 
@@ -362,22 +357,6 @@ mach64DestroyScreen( __DRIscreenPrivate *driScreen )
    driScreen->private = NULL;
 }
 
-/* Initialize the fullscreen mode.
- */
-static GLboolean
-mach64OpenFullScreen( __DRIcontextPrivate *driContextPriv )
-{
-   return GL_TRUE;
-}
-
-/* Shut down the fullscreen mode.
- */
-static GLboolean
-mach64CloseFullScreen( __DRIcontextPrivate *driContextPriv )
-{
-   return GL_TRUE;
-}
-
 
 /* Create and initialize the Mesa and driver specific pixmap buffer
  * data.
@@ -388,16 +367,66 @@ mach64CreateBuffer( __DRIscreenPrivate *driScrnPriv,
                    const __GLcontextModes *mesaVis,
                    GLboolean isPixmap )
 {
+   mach64ScreenPtr screen = (mach64ScreenPtr) driScrnPriv->private;
+
    if (isPixmap) {
       return GL_FALSE; /* not implemented */
    }
    else {
-      driDrawPriv->driverPrivate = (void *) 
-         _mesa_create_framebuffer( mesaVis,
-                                   GL_FALSE,  /* software depth buffer? */
+      struct gl_framebuffer *fb = _mesa_create_framebuffer(mesaVis);
+
+      {
+         driRenderbuffer *frontRb
+            = driNewRenderbuffer(GL_RGBA,
+                                 NULL,
+                                 screen->cpp,
+                                 screen->frontOffset, screen->frontPitch,
+                                 driDrawPriv);
+         mach64SetSpanFunctions(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);
+         mach64SetSpanFunctions(backRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backRb->Base);
+      }
+
+      if (mesaVis->depthBits == 16) {
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT16,
+                                 NULL, screen->cpp,
+                                 screen->depthOffset, screen->depthPitch,
+                                 driDrawPriv);
+         mach64SetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+      else if (mesaVis->depthBits == 24) {
+         /* XXX I don't think 24-bit Z is supported - so this isn't used */
+         driRenderbuffer *depthRb
+            = driNewRenderbuffer(GL_DEPTH_COMPONENT24,
+                                 NULL,
+                                 screen->cpp,
+                                 screen->depthOffset, screen->depthPitch,
+                                 driDrawPriv);
+         mach64SetSpanFunctions(depthRb, mesaVis);
+         _mesa_add_renderbuffer(fb, BUFFER_DEPTH, &depthRb->Base);
+      }
+
+      _mesa_add_soft_renderbuffers(fb,
+                                   GL_FALSE, /* color */
+                                   GL_FALSE, /* depth */
                                    mesaVis->stencilBits > 0,
                                    mesaVis->accumRedBits > 0,
-                                   mesaVis->alphaBits > 0 );
+                                   GL_FALSE, /* alpha */
+                                   GL_FALSE /* aux */);
+      driDrawPriv->driverPrivate = (void *) fb;
+
       return (driDrawPriv->driverPrivate != NULL);
    }
 }
@@ -406,7 +435,7 @@ mach64CreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 mach64DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
@@ -446,31 +475,6 @@ mach64InitDriver( __DRIscreenPrivate *driScreen )
    return GL_TRUE;
 }
 
-#ifndef _SOLO
-/* This function is called by libGL.so as soon as libGL.so is loaded.
- * This is where we register new extension functions with the dispatcher.
- */
-void __driRegisterExtensions( void )
-{
-#if 0
-   /* KW: This is handled differently in the other drivers, not sure
-    * what to do here.
-    */
-   PFNGLXENABLEEXTENSIONPROC glx_enable_extension;
-
-   if ( driCompareGLXAPIVersion( 20030317 ) >= 0 ) {
-      glx_enable_extension = (PFNGLXENABLEEXTENSIONPROC)
-         glXGetProcAddress( (const GLubyte *) "__glXEnableExtension" );
-
-      if ( glx_enable_extension != NULL ) {
-        glx_enable_extension( "GLX_SGI_swap_control", GL_FALSE );
-        glx_enable_extension( "GLX_SGI_video_sync", GL_FALSE );
-        glx_enable_extension( "GLX_MESA_swap_control", GL_FALSE );
-      }
-   }
-#endif
-}
-#endif
 
 static struct __DriverAPIRec mach64API = {
    .InitDriver      = mach64InitDriver,
@@ -482,8 +486,6 @@ static struct __DriverAPIRec mach64API = {
    .SwapBuffers     = mach64SwapBuffers,
    .MakeCurrent     = mach64MakeCurrent,
    .UnbindContext   = mach64UnbindContext,
-   .OpenFullScreen  = mach64OpenFullScreen,
-   .CloseFullScreen = mach64CloseFullScreen,
    .GetSwapInfo     = NULL,
    .GetMSC          = driGetMSC32,
    .WaitForMSC      = driWaitForMSC32,
@@ -492,29 +494,6 @@ static struct __DriverAPIRec mach64API = {
 };
 
 
-/*
- * This is the bootstrap function for the driver.
- * The __driCreateScreen name is the symbol that libGL.so fetches.
- * Return:  pointer to a __DRIscreenPrivate.
- */
-#ifndef _SOLO 
-void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
-                        int numConfigs, __GLXvisualConfig *config)
-{
-   __DRIscreenPrivate *psp;
-   psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &mach64API);
-   return (void *) psp;
-}
-#else
-void *__driCreateScreen(struct DRIDriverRec *driver,
-                        struct DRIDriverContextRec *driverContext)
-{
-   __DRIscreenPrivate *psp;
-   psp = __driUtilCreateScreen(driver, driverContext, &mach64API);
-   return (void *) psp;
-}
-#endif
-
 /**
  * This is the bootstrap function for the driver.  libGL supplies all of the
  * requisite information about the system, and the driver initializes itself.
@@ -525,8 +504,8 @@ void *__driCreateScreen(struct DRIDriverRec *driver,
  * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on 
  *         failure.
  */
-#ifdef USE_NEW_INTERFACE
-void * __driCreateNewScreenDisplay *dpy, int scrn, __DRIscreen *psc,
+PUBLIC
+void * __driCreateNewScreen_20050727( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
                             const __GLcontextModes * modes,
                             const __DRIversion * ddx_version,
                             const __DRIversion * dri_version,
@@ -534,27 +513,45 @@ void * __driCreateNewScreen( Display *dpy, int scrn, __DRIscreen *psc,
                             const __DRIframebuffer * frame_buffer,
                             drmAddress pSAREA, int fd, 
                             int internal_api_version,
+                            const __DRIinterfaceMethods * interface,
                             __GLcontextModes ** driver_modes )
                             
 {
    __DRIscreenPrivate *psp;
+   static const __DRIversion ddx_expected = { 6, 4, 0 };
+   static const __DRIversion dri_expected = { 4, 0, 0 };
+   static const __DRIversion drm_expected = { 2, 0, 0 };
+
+   dri_interface = interface;
+
+   if ( ! driCheckDriDdxDrmVersions2( "Mach64",
+                                     dri_version, & dri_expected,
+                                     ddx_version, & ddx_expected,
+                                     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, &mach64API);
    if ( psp != NULL ) {
-      create_context_modes = (PFNGLXCREATECONTEXTMODES)
-         glXGetProcAddress( (const GLubyte *) "__glXCreateContextModes" );
-      if ( create_context_modes != NULL ) {
-        ATIDRIPtr dri_priv = (ATIDRIPtr) psp->pDevPriv;
-        *driver_modes = mach64FillInModes( dri_priv->cpp * 8,
-                                           16,
-                                           0,
-                                           1);
-      }
+      ATIDRIPtr dri_priv = (ATIDRIPtr) psp->pDevPriv;
+      *driver_modes = mach64FillInModes( dri_priv->cpp * 8,
+                                        16,
+                                        0,
+                                        1);
+
+      /* 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 );
    }
 
    return (void *) psp;
 }
-#endif /* USE_NEW_INTERFACE */