Merge branch 'dri2'
[mesa.git] / src / mesa / drivers / dri / savage / savage_xmesa.c
index f8d68d7874eae519767766a010fab3072607e97b..013e88216fa70c190eeaead402e34eb2860b91f3 100644 (file)
@@ -40,7 +40,7 @@
 #include "swrast/swrast.h"
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
-#include "array_cache/acache.h"
+#include "vbo/vbo.h"
 
 #include "tnl/t_pipeline.h"
 
@@ -61,6 +61,7 @@
 
 #define need_GL_ARB_multisample
 #define need_GL_ARB_texture_compression
+#define need_GL_ARB_vertex_buffer_object
 #define need_GL_EXT_secondary_color
 #include "extension_helper.h"
 
@@ -135,6 +136,7 @@ static const struct dri_extension card_extensions[] =
     { "GL_ARB_multisample",                GL_ARB_multisample_functions },
     { "GL_ARB_multitexture",               NULL },
     { "GL_ARB_texture_compression",        GL_ARB_texture_compression_functions },
+    { "GL_ARB_vertex_buffer_object",       GL_ARB_vertex_buffer_object_functions },
     { "GL_EXT_stencil_wrap",               NULL },
     { "GL_EXT_texture_lod_bias",           NULL },
     { "GL_EXT_secondary_color",            GL_EXT_secondary_color_functions },
@@ -166,6 +168,10 @@ static const struct tnl_pipeline_stage *savage_pipeline[] = {
 };
 
 
+static const __DRIextension *savageExtensions[] = {
+    &driReadDrawableExtension,
+};
+
 /* this is first function called in dirver*/
 
 static GLboolean
@@ -173,9 +179,6 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
 {
   savageScreenPrivate *savageScreen;
   SAVAGEDRIPtr         gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
-   PFNGLXSCRENABLEEXTENSIONPROC glx_enable_extension =
-     (PFNGLXSCRENABLEEXTENSIONPROC) (*dri_interface->getProcAddress("glxEnableExtension"));
-
 
    if (sPriv->devPrivSize != sizeof(SAVAGEDRIRec)) {
       fprintf(stderr,"\nERROR!  sizeof(SAVAGEDRIRec) does not match passed size from device driver\n");
@@ -263,10 +266,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
    driParseOptionInfo (&savageScreen->optionCache,
                       __driConfigOptions, __driNConfigOptions);
 
-   if (glx_enable_extension != NULL) {
-      (*glx_enable_extension)(sPriv->psc->screenConfigs,
-                             "GLX_SGI_make_current_read");
-   }
+   sPriv->extensions = savageExtensions;
 
 #if 0
    savageDDFastPathInit();
@@ -509,7 +509,7 @@ savageCreateContext( const __GLcontextModes *mesaVis,
    /* Initialize the software rasterizer and helper modules.
     */
    _swrast_CreateContext( ctx );
-   _ac_CreateContext( ctx );
+   _vbo_CreateContext( ctx );
    _tnl_CreateContext( ctx );
    
    _swsetup_CreateContext( ctx );
@@ -523,7 +523,7 @@ savageCreateContext( const __GLcontextModes *mesaVis,
                                            "enable_fastpath");
    /* DRM versions before 2.1.3 would only render triangle lists. ELTS
     * support was added in 2.2.0. */
-   if (imesa->enable_fastpath && sPriv->drmMinor < 2) {
+   if (imesa->enable_fastpath && sPriv->drm_version.minor < 2) {
       fprintf (stderr,
               "*** Disabling fast path because your DRM version is buggy "
               "or doesn't\n*** support ELTS. You need at least Savage DRM "
@@ -599,7 +599,7 @@ savageDestroyContext(__DRIcontextPrivate *driContextPriv)
 
       _swsetup_DestroyContext(imesa->glCtx );
       _tnl_DestroyContext( imesa->glCtx );
-      _ac_DestroyContext( imesa->glCtx );
+      _vbo_DestroyContext( imesa->glCtx );
       _swrast_DestroyContext( imesa->glCtx );
 
       /* free the Mesa context */
@@ -710,7 +710,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 #if 0
@@ -724,34 +724,18 @@ void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
 }
 #endif
 
-void savageXMesaSetFrontClipRects( savageContextPtr imesa )
-{
-   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
 
-   imesa->numClipRects = dPriv->numClipRects;
-   imesa->pClipRects = dPriv->pClipRects;
-   imesa->drawX = dPriv->x;
-   imesa->drawY = dPriv->y;
-
-   savageCalcViewport( imesa->glCtx );
-}
-
-
-void savageXMesaSetBackClipRects( savageContextPtr imesa )
+void savageXMesaSetClipRects(savageContextPtr imesa)
 {
    __DRIdrawablePrivate *dPriv = imesa->driDrawable;
 
-   if (dPriv->numBackClipRects == 0) 
-   {
-
-
+   if ((dPriv->numBackClipRects == 0)
+       || (imesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0] == BUFFER_BIT_FRONT_LEFT)) {
       imesa->numClipRects = dPriv->numClipRects;
       imesa->pClipRects = dPriv->pClipRects;
       imesa->drawX = dPriv->x;
       imesa->drawY = dPriv->y;
    } else {
-
-
       imesa->numClipRects = dPriv->numBackClipRects;
       imesa->pClipRects = dPriv->pBackClipRects;
       imesa->drawX = dPriv->backX;
@@ -770,16 +754,7 @@ static void savageXMesaWindowMoved( savageContextPtr imesa )
    if (0)
       fprintf(stderr, "savageXMesaWindowMoved\n\n");
 
-   switch (imesa->glCtx->DrawBuffer->_ColorDrawBufferMask[0]) {
-   case BUFFER_BIT_FRONT_LEFT:
-      savageXMesaSetFrontClipRects( imesa );
-      break;
-   case BUFFER_BIT_BACK_LEFT:
-      savageXMesaSetBackClipRects( imesa );
-      break;
-   default:
-       break;
-   }
+   savageXMesaSetClipRects(imesa);
 
    driUpdateFramebufferSize(imesa->glCtx, drawable);
    if (drawable != readable) {
@@ -943,7 +918,6 @@ void savageGetLock( savageContextPtr imesa, GLuint flags )
 
 
 static const struct __DriverAPIRec savageAPI = {
-   savageInitDriver,
    savageDestroyScreen,
    savageCreateContext,
    savageDestroyContext,
@@ -1040,63 +1014,44 @@ savageFillInModes( unsigned pixel_bits, unsigned depth_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.
  * 
- * \return A pointer to a \c __DRIscreenPrivate on success, or \c NULL on 
- *         failure.
+ * \todo maybe fold this into intelInitDriver
+ *
+ * \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 )
-                            
+__GLcontextModes *__driDriverInitScreen(__DRIscreenPrivate *psp)
 {
-   __DRIscreenPrivate *psp;
    static const __DRIversion ddx_expected = { 2, 0, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
    static const __DRIversion drm_expected = { 2, 1, 0 };
-
-   dri_interface = interface;
+   SAVAGEDRIPtr dri_priv = (SAVAGEDRIPtr)psp->pDevPriv;
 
    if ( ! driCheckDriDdxDrmVersions2( "Savage",
-                                     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, &savageAPI);
-   if ( psp != NULL ) {
-      SAVAGEDRIPtr dri_priv = (SAVAGEDRIPtr)psp->pDevPriv;
-      *driver_modes = savageFillInModes( dri_priv->cpp*8,
-                                        (dri_priv->cpp == 2) ? 16 : 24,
-                                        (dri_priv->cpp == 2) ? 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 );
-   }
 
-   return (void *) psp;
+   psp->DriverAPI = savageAPI;
+
+   /* 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 );
+
+   if (!savageInitDriver(psp))
+       return NULL;
+
+   return savageFillInModes( dri_priv->cpp*8,
+                            (dri_priv->cpp == 2) ? 16 : 24,
+                            (dri_priv->cpp == 2) ? 0  : 8,
+                            (dri_priv->backOffset != dri_priv->depthOffset) );
 }