uint*t -> u_int*t changes
[mesa.git] / src / mesa / drivers / dri / mga / mga_xmesa.c
index 4c5babf7bf52a399495a77bedd206b7f4161fbf8..476756dba31097f94314bf226973003692170a7b 100644 (file)
@@ -26,7 +26,9 @@
  *    Keith Whitwell <keith@tungstengraphics.com>
  */
 
-#include "mga_common.h"
+#include <stdlib.h>
+#include "drm.h"
+#include "mga_drm.h"
 #include "mga_xmesa.h"
 #include "context.h"
 #include "matrix.h"
@@ -57,9 +59,9 @@
 #include "utils.h"
 #include "vblank.h"
 
-#ifndef _SOLO
-#include "glxextensions.h"
-#endif
+#include "extensions.h"
+
+#include "GL/internal/dri_interface.h"
 
 /* MGA configuration
  */
@@ -74,8 +76,12 @@ DRI_CONF_BEGIN
         DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
         DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
     DRI_CONF_SECTION_END
+    DRI_CONF_SECTION_SOFTWARE
+        DRI_CONF_ARB_VERTEX_PROGRAM(true)
+        DRI_CONF_NV_VERTEX_PROGRAM(true)
+    DRI_CONF_SECTION_END
 DRI_CONF_END;
-static const GLuint __driNConfigOptions = 3;
+static const GLuint __driNConfigOptions = 5;
 
 #ifdef USE_NEW_INTERFACE
 static PFNGLXCREATECONTEXTMODES create_context_modes = NULL;
@@ -87,74 +93,6 @@ int MGA_DEBUG = 0;
 
 static int getSwapInfo( __DRIdrawablePrivate *dPriv, __DRIswapInfo * sInfo );
 
-#ifdef USE_NEW_INTERFACE
-static __GLcontextModes * fill_in_modes( __GLcontextModes * modes,
-                                        unsigned pixel_bits, 
-                                        unsigned depth_bits,
-                                        unsigned stencil_bits,
-                                        const GLenum * db_modes,
-                                        unsigned num_db_modes,
-                                        int visType )
-{
-    static const uint8_t bits[2][4] = {
-       {          5,          6,          5,          0 },
-       {          8,          8,          8,          0 }
-    };
-
-    static const uint32_t masks[2][4] = {
-       { 0x0000F800, 0x000007E0, 0x0000001F, 0x00000000 },
-       { 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000 }
-    };
-
-    unsigned   i;
-    unsigned   j;
-    const unsigned index = ((pixel_bits + 15) / 16) - 1;
-
-    for ( i = 0 ; i < num_db_modes ; i++ ) {
-       for ( j = 0 ; j < 2 ; j++ ) {
-
-           modes->redBits   = bits[index][0];
-           modes->greenBits = bits[index][1];
-           modes->blueBits  = bits[index][2];
-           modes->alphaBits = bits[index][3];
-           modes->redMask   = masks[index][0];
-           modes->greenMask = masks[index][1];
-           modes->blueMask  = masks[index][2];
-           modes->alphaMask = masks[index][3];
-           modes->rgbBits   = modes->redBits + modes->greenBits
-               + modes->blueBits;
-
-           modes->accumRedBits   = 16 * j;
-           modes->accumGreenBits = 16 * j;
-           modes->accumBlueBits  = 16 * j;
-           modes->accumAlphaBits = (masks[index][3] != 0) ? 16 * j : 0;
-           modes->visualRating = (j == 0) ? GLX_NONE : GLX_SLOW_CONFIG;
-
-           modes->stencilBits = stencil_bits;
-           modes->depthBits = depth_bits;
-
-           modes->visualType = visType;
-           modes->renderType = GLX_RGBA_BIT;
-           modes->drawableType = GLX_WINDOW_BIT;
-           modes->rgbMode = GL_TRUE;
-
-           if ( db_modes[i] == GLX_NONE ) {
-               modes->doubleBufferMode = GL_FALSE;
-           }
-           else {
-               modes->doubleBufferMode = GL_TRUE;
-               modes->swapMethod = db_modes[i];
-           }
-
-           modes = modes->next;
-       }
-    }
-    
-    return modes;
-}
-#endif /* USE_NEW_INTERFACE */
-
-
 #ifdef USE_NEW_INTERFACE
 static __GLcontextModes *
 mgaFillInModes( unsigned pixel_bits, unsigned depth_bits,
@@ -165,7 +103,8 @@ mgaFillInModes( unsigned pixel_bits, unsigned depth_bits,
     unsigned num_modes;
     unsigned depth_buffer_factor;
     unsigned back_buffer_factor;
-    unsigned i;
+    GLenum fb_format;
+    GLenum fb_type;
 
     /* GLX_SWAP_COPY_OML is only supported because the MGA driver doesn't
      * support pageflipping at all.
@@ -174,38 +113,54 @@ mgaFillInModes( unsigned pixel_bits, unsigned depth_bits,
        GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML
     };
 
-    int depth_buffer_modes[2][2];
-
+    u_int8_t depth_bits_array[3];
+    u_int8_t stencil_bits_array[3];
 
-    depth_buffer_modes[0][0] = depth_bits;
-    depth_buffer_modes[1][0] = depth_bits;
 
+    depth_bits_array[0] = 0;
+    depth_bits_array[1] = depth_bits;
+    depth_bits_array[2] = depth_bits;
+    
     /* Just like with the accumulation buffer, always provide some modes
      * with a stencil buffer.  It will be a sw fallback, but some apps won't
      * care about that.
      */
-    depth_buffer_modes[0][1] = 0;
-    depth_buffer_modes[1][1] = (stencil_bits == 0) ? 8 : stencil_bits;
+    stencil_bits_array[0] = 0;
+    stencil_bits_array[1] = 0;
+    stencil_bits_array[2] = (stencil_bits == 0) ? 8 : stencil_bits;
 
-    depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
+    depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 3 : 1;
     back_buffer_factor  = (have_back_buffer) ? 2 : 1;
 
     num_modes = depth_buffer_factor * back_buffer_factor * 4;
 
+    if ( pixel_bits == 16 ) {
+        fb_format = GL_RGB;
+        fb_type = GL_UNSIGNED_SHORT_5_6_5;
+    }
+    else {
+        fb_format = GL_BGR;
+        fb_type = GL_UNSIGNED_INT_8_8_8_8_REV;
+    }
+
     modes = (*create_context_modes)( num_modes, sizeof( __GLcontextModes ) );
     m = modes;
-    for ( i = 0 ; i < depth_buffer_factor ; i++ ) {
-       m = fill_in_modes( m, pixel_bits, 
-                          depth_buffer_modes[i][0], depth_buffer_modes[i][1],
+    if ( ! driFillInModes( & m, fb_format, fb_type,
+                          depth_bits_array, stencil_bits_array, depth_buffer_factor,
                           back_buffer_modes, back_buffer_factor,
-                          GLX_TRUE_COLOR );
+                          GLX_TRUE_COLOR ) ) {
+       fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
+                __func__, __LINE__ );
+       return NULL;
     }
 
-    for ( i = 0 ; i < depth_buffer_factor ; i++ ) {
-       m = fill_in_modes( m, pixel_bits, 
-                          depth_buffer_modes[i][0], depth_buffer_modes[i][1],
+    if ( ! driFillInModes( & m, fb_format, fb_type,
+                          depth_bits_array, stencil_bits_array, depth_buffer_factor,
                           back_buffer_modes, back_buffer_factor,
-                          GLX_DIRECT_COLOR );
+                          GLX_DIRECT_COLOR ) ) {
+       fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
+                __func__, __LINE__ );
+       return NULL;
     }
 
     /* Mark the visual as slow if there are "fake" stencil bits.
@@ -227,8 +182,6 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
    mgaScreenPrivate *mgaScreen;
    MGADRIPtr         serverInfo = (MGADRIPtr)sPriv->pDevPriv;
 
-   if ( ! driCheckDriDdxDrmVersions( sPriv, "MGA", 4, 0, 1, 0, 3, 0 ) )
-      return GL_FALSE;
 
    /* Allocate the private area */
    mgaScreen = (mgaScreenPrivate *)MALLOC(sizeof(mgaScreenPrivate));
@@ -242,10 +195,11 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
 
    if (sPriv->drmMinor >= 1) {
       int ret;
-      drmMGAGetParam gp;
+      drm_mga_getparam_t gp;
 
       gp.param = MGA_PARAM_IRQ_NR;
       gp.value = &mgaScreen->irq;
+      mgaScreen->irq = 0;
 
       ret = drmCommandWriteRead( sPriv->fd, DRM_MGA_GETPARAM,
                                    &gp, sizeof(gp));
@@ -259,7 +213,7 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
    
    mgaScreen->linecomp_sane = (sPriv->ddxMajor > 1) || (sPriv->ddxMinor > 1)
        || ((sPriv->ddxMinor == 1) && (sPriv->ddxPatch > 0));
-#ifndef _SOLO       
+
    if ( driCompareGLXAPIVersion( 20030813 ) >= 0 ) {
       PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
           (PFNGLXSCRENABLEEXTENSIONPROC) glXGetProcAddress( (const GLubyte *) "__glXScrEnableExtension" );
@@ -281,7 +235,6 @@ mgaInitDriver(__DRIscreenPrivate *sPriv)
         }
       }
    }
-#endif
 
    if (serverInfo->chipset != MGA_CARD_TYPE_G200 &&
        serverInfo->chipset != MGA_CARD_TYPE_G400) {
@@ -401,6 +354,8 @@ mgaDestroyScreen(__DRIscreenPrivate *sPriv)
    if (MGA_DEBUG&DEBUG_VERBOSE_DRI)
       fprintf(stderr, "mgaDestroyScreen\n");
 
+   drmUnmapBufs(mgaScreen->bufs);
+
    /*drmUnmap(mgaScreen->agp_tex.map, mgaScreen->agp_tex.size);*/
 
    /* free all option information */
@@ -420,6 +375,8 @@ static const struct tnl_pipeline_stage *mga_pipeline[] = {
    &_tnl_fog_coordinate_stage,
    &_tnl_texgen_stage, 
    &_tnl_texture_transform_stage, 
+   &_tnl_vertex_program_stage,
+
                                /* REMOVE: point attenuation stage */
 #if 0
    &_mga_render_stage,         /* ADD: unclipped rastersetup-to-dma */
@@ -449,8 +406,10 @@ static const char * const card_extensions[] =
 {
    "GL_ARB_multisample",
    "GL_ARB_texture_compression",
+   "GL_ARB_texture_rectangle",
    "GL_EXT_blend_logic_op",
    "GL_EXT_fog_coord",
+   "GL_EXT_multi_draw_arrays",
    /* paletted_textures currently doesn't work, but we could fix them later */
 #if 0
    "GL_EXT_shared_texture_palette",
@@ -458,10 +417,8 @@ static const char * const card_extensions[] =
 #endif
    "GL_EXT_secondary_color",
    "GL_EXT_stencil_wrap",
-   "GL_EXT_texture_rectangle",
    "GL_MESA_ycbcr_texture",
    "GL_SGIS_generate_mipmap",
-   "GL_SGIS_texture_lod",
    NULL
 };
 
@@ -495,7 +452,7 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
    mgaContextPtr mmesa;
    __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
    mgaScreenPrivate *mgaScreen = (mgaScreenPrivate *)sPriv->private;
-   MGASAREAPrivPtr saPriv=(MGASAREAPrivPtr)(((char*)sPriv->pSAREA)+
+   drm_mga_sarea_t *saPriv = (drm_mga_sarea_t *)(((char*)sPriv->pSAREA)+
                                              mgaScreen->sarea_priv_offset);
    struct dd_function_table functions;
 
@@ -551,9 +508,9 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
            mgaScreen->textureSize[i],
            6,
            MGA_NR_TEX_REGIONS,
-           mmesa->sarea->texList[i],
-           & mmesa->sarea->texAge[i],
-           & mmesa->swapped,
+           (drmTextureRegionPtr)mmesa->sarea->texList[i],
+           &mmesa->sarea->texAge[i],
+           &mmesa->swapped,
            sizeof( mgaTextureObject_t ),
            (destroy_texture_object_t *) mgaDestroyTexObj );
    }
@@ -666,6 +623,16 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
       driInitExtensions( ctx, g400_extensions, GL_FALSE );
    }
 
+   if ( driQueryOptionb( &mmesa->optionCache, "arb_vertex_program" ) ) {
+      _mesa_enable_extension( ctx, "GL_ARB_vertex_program" );
+   }
+   
+   if ( driQueryOptionb( &mmesa->optionCache, "nv_vertex_program" ) ) {
+      _mesa_enable_extension( ctx, "GL_NV_vertex_program" );
+      _mesa_enable_extension( ctx, "GL_NV_vertex_program1_1" );
+   }
+
+       
    /* XXX these should really go right after _mesa_init_driver_functions() */
    mgaDDInitStateFuncs( ctx );
    mgaDDInitSpanFuncs( ctx );
@@ -685,14 +652,11 @@ mgaCreateContext( const __GLcontextModes *mesaVis,
    mmesa->vblank_flags = ((mmesa->mgaScreen->irq == 0) 
                          || !mmesa->mgaScreen->linecomp_sane)
        ? VBLANK_FLAG_NO_IRQ : driGetDefaultVBlankFlags(&mmesa->optionCache);
-#ifndef _SOLO
+
    mmesa->get_ust = (PFNGLXGETUSTPROC) glXGetProcAddress( (const GLubyte *) "__glXGetUST" );
    if ( mmesa->get_ust == NULL ) {
       mmesa->get_ust = get_ust_nop;
    }
-#else
-   mmesa->get_ust = get_ust_nop;
-#endif   
 
    (*mmesa->get_ust)( & mmesa->swap_ust );
 
@@ -811,13 +775,6 @@ mgaUnbindContext(__DRIcontextPrivate *driContextPriv)
    return GL_TRUE;
 }
 
-static GLboolean
-mgaOpenCloseFullScreen(__DRIcontextPrivate *driContextPriv)
-{
-    return GL_TRUE;
-}
-
-
 /* This looks buggy to me - the 'b' variable isn't used anywhere...
  * Hmm - It seems that the drawable is already hooked in to
  * driDrawablePriv.
@@ -845,11 +802,6 @@ mgaMakeCurrent(__DRIcontextPrivate *driContextPriv,
       _mesa_make_current2(mmesa->glCtx,
                           (GLframebuffer *) driDrawPriv->driverPrivate,
                           (GLframebuffer *) driReadPriv->driverPrivate);
-
-      if (!mmesa->glCtx->Viewport.Width)
-        _mesa_set_viewport(mmesa->glCtx, 0, 0,
-                            driDrawPriv->w, driDrawPriv->h);
-
    }
    else {
       _mesa_make_current(NULL, NULL);
@@ -862,7 +814,7 @@ mgaMakeCurrent(__DRIcontextPrivate *driContextPriv,
 void mgaGetLock( mgaContextPtr mmesa, GLuint flags )
 {
    __DRIdrawablePrivate *dPriv = mmesa->driDrawable;
-   MGASAREAPrivPtr sarea = mmesa->sarea;
+   drm_mga_sarea_t *sarea = mmesa->sarea;
    int me = mmesa->hHWContext;
    int i;
 
@@ -903,8 +855,6 @@ static const struct __DriverAPIRec mgaAPI = {
    .SwapBuffers     = mgaSwapBuffers,
    .MakeCurrent     = mgaMakeCurrent,
    .UnbindContext   = mgaUnbindContext,
-   .OpenFullScreen  = mgaOpenCloseFullScreen,
-   .CloseFullScreen = mgaOpenCloseFullScreen,
    .GetSwapInfo     = getSwapInfo,
    .GetMSC          = driGetMSC32,
    .WaitForMSC      = driWaitForMSC32,
@@ -918,7 +868,7 @@ static const struct __DriverAPIRec mgaAPI = {
  * The __driCreateScreen name is the symbol that libGL.so fetches.
  * Return:  pointer to a __DRIscreenPrivate.
  */
-#ifndef _SOLO 
+#if !defined(DRI_NEW_INTERFACE_ONLY)
 void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
                         int numConfigs, __GLXvisualConfig *config)
 {
@@ -926,15 +876,7 @@ void *__driCreateScreen(Display *dpy, int scrn, __DRIscreen *psc,
    psp = __driUtilCreateScreen(dpy, scrn, psc, numConfigs, config, &mgaAPI);
    return (void *) psp;
 }
-#else
-void *__driCreateScreen(struct DRIDriverRec *driver,
-                        struct DRIDriverContextRec *driverContext)
-{
-   __DRIscreenPrivate *psp;
-   psp = __driUtilCreateScreen(driver, driverContext, &mgaAPI);
-   return (void *) psp;
-}
-#endif
+#endif /* !defined(DRI_NEW_INTERFACE_ONLY) */
 
 
 /**
@@ -948,7 +890,7 @@ void *__driCreateScreen(struct DRIDriverRec *driver,
  *         failure.
  */
 #ifdef USE_NEW_INTERFACE
-void * __driCreateNewScreen( Display *dpy, int scrn, __DRIscreen *psc,
+void * __driCreateNewScreen( __DRInativeDisplay *dpy, int scrn, __DRIscreen *psc,
                             const __GLcontextModes * modes,
                             const __DRIversion * ddx_version,
                             const __DRIversion * dri_version,
@@ -960,21 +902,31 @@ void * __driCreateNewScreen( Display *dpy, int scrn, __DRIscreen *psc,
                             
 {
    __DRIscreenPrivate *psp;
+   static const __DRIversion ddx_expected = { 1, 0, 0 };
+   static const __DRIversion dri_expected = { 4, 0, 0 };
+   static const __DRIversion drm_expected = { 3, 0, 0 };
+
+   if ( ! driCheckDriDdxDrmVersions2( "MGA",
+                                     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, &mgaAPI);
-
-
-   create_context_modes = 
-       (PFNGLXCREATECONTEXTMODES) glXGetProcAddress( (const GLubyte *) "__glXCreateContextModes" );
-   if ( create_context_modes != NULL ) {
-      MGADRIPtr dri_priv = (MGADRIPtr) psp->pDevPriv;
-      *driver_modes = mgaFillInModes( dri_priv->cpp * 8,
-                                     (dri_priv->cpp == 2) ? 16 : 24,
-                                     (dri_priv->cpp == 2) ? 0  : 8,
-                                     (dri_priv->backOffset != dri_priv->depthOffset) );
+   if ( psp != NULL ) {
+      create_context_modes = (PFNGLXCREATECONTEXTMODES)
+         glXGetProcAddress( (const GLubyte *) "__glXCreateContextModes" );
+      if ( create_context_modes != NULL ) {
+        MGADRIPtr dri_priv = (MGADRIPtr) psp->pDevPriv;
+        *driver_modes = mgaFillInModes( dri_priv->cpp * 8,
+                                        (dri_priv->cpp == 2) ? 16 : 24,
+                                        (dri_priv->cpp == 2) ? 0  : 8,
+                                        (dri_priv->backOffset != dri_priv->depthOffset) );
+      }
    }
 
    return (void *) psp;