dri: Add DRI entrypoints to create a context for a given API
[mesa.git] / src / mesa / drivers / dri / savage / savage_xmesa.c
index ba4008e6447863d4a71dedba2e2e631968a169c2..cbdc9c87eebb720d91df9fb6bee3f54efd49abb8 100644 (file)
@@ -23,7 +23,6 @@
  */
 
 
-#include <X11/Xlibint.h>
 #include <stdio.h>
 
 #include "main/context.h"
@@ -45,6 +44,7 @@
 #include "tnl/t_pipeline.h"
 
 #include "drivers/common/driverfuncs.h"
+#include "drivers/common/meta.h"
 
 #include "savagedd.h"
 #include "savagestate.h"
@@ -60,7 +60,7 @@
 #include "texmem.h"
 
 #define need_GL_EXT_secondary_color
-#include "extension_helper.h"
+#include "main/remap_helper.h"
 
 #include "xmlpool.h"
 
@@ -169,7 +169,7 @@ PUBLIC const __DRIextension *savageScreenExtensions[] = {
 };
 
 static GLboolean
-savageInitDriver(__DRIscreenPrivate *sPriv)
+savageInitDriver(__DRIscreen *sPriv)
 {
   savageScreenPrivate *savageScreen;
   SAVAGEDRIPtr         gDRIPriv = (SAVAGEDRIPtr)sPriv->pDevPriv;
@@ -180,7 +180,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
    }
 
    /* Allocate the private area */
-   savageScreen = (savageScreenPrivate *)Xmalloc(sizeof(savageScreenPrivate));
+   savageScreen = (savageScreenPrivate *)malloc(sizeof(savageScreenPrivate));
    if (!savageScreen)
       return GL_FALSE;
 
@@ -227,7 +227,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
                  savageScreen->agpTextures.handle,
                  savageScreen->agpTextures.size,
                  (drmAddress *)&(savageScreen->agpTextures.map)) != 0) {
-          Xfree(savageScreen);
+          free(savageScreen);
           sPriv->private = NULL;
           return GL_FALSE;
        }
@@ -247,7 +247,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
              savageScreen->aperture.size, 
              (drmAddress *)&savageScreen->aperture.map) != 0) 
    {
-      Xfree(savageScreen);
+      free(savageScreen);
       sPriv->private = NULL;
       return GL_FALSE;
    }
@@ -273,7 +273,7 @@ savageInitDriver(__DRIscreenPrivate *sPriv)
 /* Accessed by dlsym from dri_mesa_init.c
  */
 static void
-savageDestroyScreen(__DRIscreenPrivate *sPriv)
+savageDestroyScreen(__DRIscreen *sPriv)
 {
    savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
 
@@ -283,25 +283,26 @@ savageDestroyScreen(__DRIscreenPrivate *sPriv)
    /* free all option information */
    driDestroyOptionInfo (&savageScreen->optionCache);
 
-   Xfree(savageScreen);
+   free(savageScreen);
    sPriv->private = NULL;
 }
 
 static GLboolean
-savageCreateContext( const __GLcontextModes *mesaVis,
-                    __DRIcontextPrivate *driContextPriv,
+savageCreateContext( gl_api api,
+                    const __GLcontextModes *mesaVis,
+                    __DRIcontext *driContextPriv,
                     void *sharedContextPrivate )
 {
    GLcontext *ctx, *shareCtx;
    savageContextPtr imesa;
-   __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
+   __DRIscreen *sPriv = driContextPriv->driScreenPriv;
    struct dd_function_table functions;
    savageScreenPrivate *savageScreen = (savageScreenPrivate *)sPriv->private;
    drm_savage_sarea_t *saPriv=(drm_savage_sarea_t *)(((char*)sPriv->pSAREA)+
                                                 savageScreen->sarea_priv_offset);
    int textureSize[SAVAGE_NR_TEX_HEAPS];
    int i;
-   imesa = (savageContextPtr)Xcalloc(sizeof(savageContext), 1);
+   imesa = (savageContextPtr)calloc(1, sizeof(savageContext));
    if (!imesa) {
       return GL_FALSE;
    }
@@ -318,7 +319,7 @@ savageCreateContext( const __GLcontextModes *mesaVis,
       shareCtx = NULL;
    ctx = _mesa_create_context(mesaVis, shareCtx, &functions, imesa);
    if (!ctx) {
-      Xfree(imesa);
+      free(imesa);
       return GL_FALSE;
    }
    driContextPriv->driverPrivate = imesa;
@@ -437,7 +438,7 @@ savageCreateContext( const __GLcontextModes *mesaVis,
    if (ctx->Const.MaxTextureLevels <= 6) { /*spec requires at least 64x64*/
        __driUtilMessage("Not enough texture memory. "
                        "Falling back to indirect rendering.");
-       Xfree(imesa);
+       free(imesa);
        return GL_FALSE;
    }
 
@@ -474,6 +475,8 @@ savageCreateContext( const __GLcontextModes *mesaVis,
    imesa->CurrentTexObj[0] = 0;
    imesa->CurrentTexObj[1] = 0;
 
+   _mesa_meta_init( ctx );
+
    /* Initialize the software rasterizer and helper modules.
     */
    _swrast_CreateContext( ctx );
@@ -547,7 +550,7 @@ savageCreateContext( const __GLcontextModes *mesaVis,
 }
 
 static void
-savageDestroyContext(__DRIcontextPrivate *driContextPriv)
+savageDestroyContext(__DRIcontext *driContextPriv)
 {
    savageContextPtr imesa = (savageContextPtr) driContextPriv->driverPrivate;
    GLuint i;
@@ -565,6 +568,8 @@ savageDestroyContext(__DRIcontextPrivate *driContextPriv)
       free(imesa->cmdBuf.base);
       free(imesa->clientVtxBuf.buf);
 
+      _mesa_meta_free( imesa->glCtx );
+
       _swsetup_DestroyContext(imesa->glCtx );
       _tnl_DestroyContext( imesa->glCtx );
       _vbo_DestroyContext( imesa->glCtx );
@@ -575,14 +580,14 @@ savageDestroyContext(__DRIcontextPrivate *driContextPriv)
       _mesa_destroy_context(imesa->glCtx);
 
       /* no longer use vertex_dma_buf*/
-      Xfree(imesa);
+      free(imesa);
    }
 }
 
 
 static GLboolean
-savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
-                   __DRIdrawablePrivate *driDrawPriv,
+savageCreateBuffer( __DRIscreen *driScrnPriv,
+                   __DRIdrawable *driDrawPriv,
                    const __GLcontextModes *mesaVis,
                    GLboolean isPixmap)
 {
@@ -603,7 +608,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       {
          driRenderbuffer *frontRb
-            = driNewRenderbuffer(GL_RGBA,
+            = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
                                  (GLubyte *) screen->aperture.map
                                  + 0x01000000 * TARGET_FRONT,
                                  screen->cpp,
@@ -616,7 +621,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->doubleBufferMode) {
          driRenderbuffer *backRb
-            = driNewRenderbuffer(GL_RGBA,
+            = driNewRenderbuffer(MESA_FORMAT_ARGB8888,
                                  (GLubyte *) screen->aperture.map
                                  + 0x01000000 * TARGET_BACK,
                                  screen->cpp,
@@ -629,7 +634,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->depthBits == 16) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT16,
+            = driNewRenderbuffer(MESA_FORMAT_Z16,
                                  (GLubyte *) screen->aperture.map
                                  + 0x01000000 * TARGET_DEPTH,
                                  screen->zpp,
@@ -640,7 +645,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
       }
       else if (mesaVis->depthBits == 24) {
          driRenderbuffer *depthRb
-            = driNewRenderbuffer(GL_DEPTH_COMPONENT24,
+            = driNewRenderbuffer(MESA_FORMAT_S8_Z24,
                                  (GLubyte *) screen->aperture.map
                                  + 0x01000000 * TARGET_DEPTH,
                                  screen->zpp,
@@ -652,7 +657,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
       if (mesaVis->stencilBits > 0 && !swStencil) {
          driRenderbuffer *stencilRb
-            = driNewRenderbuffer(GL_STENCIL_INDEX8_EXT,
+            = driNewRenderbuffer(MESA_FORMAT_S8,
                                  (GLubyte *) screen->aperture.map
                                  + 0x01000000 * TARGET_DEPTH,
                                  screen->zpp,
@@ -676,13 +681,13 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 }
 
 static void
-savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
+savageDestroyBuffer(__DRIdrawable *driDrawPriv)
 {
-   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+   _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
 }
 
 #if 0
-void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
+void XMesaSwapBuffers(__DRIdrawable *driDrawPriv)
 {
    /* XXX should do swap according to the buffer, not the context! */
    savageContextPtr imesa = savageCtx; 
@@ -695,7 +700,7 @@ void XMesaSwapBuffers(__DRIdrawablePrivate *driDrawPriv)
 
 void savageXMesaSetClipRects(savageContextPtr imesa)
 {
-   __DRIdrawablePrivate *dPriv = imesa->driDrawable;
+   __DRIdrawable *dPriv = imesa->driDrawable;
 
    if ((dPriv->numBackClipRects == 0)
        || (imesa->glCtx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT)) {
@@ -716,8 +721,8 @@ void savageXMesaSetClipRects(savageContextPtr imesa)
 
 static void savageXMesaWindowMoved( savageContextPtr imesa ) 
 {
-   __DRIdrawablePrivate *const drawable = imesa->driDrawable;
-   __DRIdrawablePrivate *const readable = imesa->driReadable;
+   __DRIdrawable *const drawable = imesa->driDrawable;
+   __DRIdrawable *const readable = imesa->driReadable;
 
    if (0)
       fprintf(stderr, "savageXMesaWindowMoved\n\n");
@@ -732,7 +737,7 @@ static void savageXMesaWindowMoved( savageContextPtr imesa )
 
 
 static GLboolean
-savageUnbindContext(__DRIcontextPrivate *driContextPriv)
+savageUnbindContext(__DRIcontext *driContextPriv)
 {
    savageContextPtr savage = (savageContextPtr) driContextPriv->driverPrivate;
    if (savage)
@@ -743,7 +748,7 @@ savageUnbindContext(__DRIcontextPrivate *driContextPriv)
 
 #if 0
 static GLboolean
-savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
+savageOpenFullScreen(__DRIcontext *driContextPriv)
 {
     
   
@@ -762,7 +767,7 @@ savageOpenFullScreen(__DRIcontextPrivate *driContextPriv)
 }
 
 static GLboolean
-savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
+savageCloseFullScreen(__DRIcontext *driContextPriv)
 {
     
     if (driContextPriv) {
@@ -778,9 +783,9 @@ savageCloseFullScreen(__DRIcontextPrivate *driContextPriv)
 #endif
 
 static GLboolean
-savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
-                 __DRIdrawablePrivate *driDrawPriv,
-                 __DRIdrawablePrivate *driReadPriv)
+savageMakeCurrent(__DRIcontext *driContextPriv,
+                 __DRIdrawable *driDrawPriv,
+                 __DRIdrawable *driReadPriv)
 {
    if (driContextPriv) {
       savageContextPtr imesa
@@ -817,9 +822,9 @@ savageMakeCurrent(__DRIcontextPrivate *driContextPriv,
 
 void savageGetLock( savageContextPtr imesa, GLuint flags ) 
 {
-   __DRIdrawablePrivate *const drawable = imesa->driDrawable;
-   __DRIdrawablePrivate *const readable = imesa->driReadable;
-   __DRIscreenPrivate *sPriv = imesa->driScreen;
+   __DRIdrawable *const drawable = imesa->driDrawable;
+   __DRIdrawable *const readable = imesa->driReadable;
+   __DRIscreen *sPriv = imesa->driScreen;
    drm_savage_sarea_t *sarea = imesa->sarea;
    int me = imesa->hHWContext;
    int stamp = drawable->lastStamp; 
@@ -884,7 +889,7 @@ void savageGetLock( savageContextPtr imesa, GLuint flags )
 }
 
 static const  __DRIconfig **
-savageFillInModes( __DRIscreenPrivate *psp,
+savageFillInModes( __DRIscreen *psp,
                   unsigned pixel_bits, unsigned depth_bits,
                   unsigned stencil_bits, GLboolean have_back_buffer )
 {
@@ -922,6 +927,8 @@ savageFillInModes( __DRIscreenPrivate *psp,
     stencil_bits_array[0] = 0;
     stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
 
+    msaa_samples_array[0] = 0;
+
     depth_buffer_factor = ((depth_bits != 0) || (stencil_bits != 0)) ? 2 : 1;
     back_buffer_factor  = (have_back_buffer) ? 2 : 1;
 
@@ -938,7 +945,7 @@ savageFillInModes( __DRIscreenPrivate *psp,
                               depth_bits_array, stencil_bits_array,
                               depth_buffer_factor,
                               back_buffer_modes, back_buffer_factor,
-                               msaa_samples_array, 1);
+                               msaa_samples_array, 1, GL_TRUE);
     if (configs == NULL) {
        fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
                 __func__, __LINE__ );
@@ -966,7 +973,7 @@ savageFillInModes( __DRIscreenPrivate *psp,
  * \return the __GLcontextModes supported by this driver
  */
 static const __DRIconfig **
-savageInitScreen(__DRIscreenPrivate *psp)
+savageInitScreen(__DRIscreen *psp)
 {
    static const __DRIversion ddx_expected = { 2, 0, 0 };
    static const __DRIversion dri_expected = { 4, 0, 0 };
@@ -979,18 +986,6 @@ savageInitScreen(__DRIscreenPrivate *psp)
                                      &psp->drm_version, & drm_expected ) )
       return NULL;
 
-   /* 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;
 
@@ -1012,3 +1007,10 @@ const struct __DriverAPIRec driDriverAPI = {
    savageMakeCurrent,
    savageUnbindContext
 };
+
+/* This is the table of extensions that the loader will dlsym() for. */
+PUBLIC const __DRIextension *__driDriverExtensions[] = {
+    &driCoreExtension.base,
+    &driLegacyExtension.base,
+    NULL
+};