dri: cosmetic
[mesa.git] / src / mesa / drivers / dri / common / drisw_util.c
index 141ca302d088b9647bd4b00fe8c1d349de523e4f..614339eeb422a7347eae8346fed77be01a60b633 100644 (file)
@@ -27,7 +27,7 @@
  * DRISW utility functions, i.e. dri_util.c stripped from drm-specific bits.
  */
 
-#include "drisw_util.h"
+#include "dri_util.h"
 #include "utils.h"
 
 
@@ -54,19 +54,19 @@ driCreateNewScreen(int scrn, const __DRIextension **extensions,
     static const __DRIextension *emptyExtensionList[] = { NULL };
     __DRIscreen *psp;
 
-    (void) data;
-
     psp = CALLOC_STRUCT(__DRIscreenRec);
     if (!psp)
        return NULL;
 
     setupLoaderExtensions(psp, extensions);
 
+    psp->loaderPrivate = data;
+
     psp->extensions = emptyExtensionList;
+    psp->fd = -1;
     psp->myNum = scrn;
 
     *driver_configs = driDriverAPI.InitScreen(psp);
-
     if (*driver_configs == NULL) {
        FREE(psp);
        return NULL;
@@ -79,7 +79,6 @@ static void driDestroyScreen(__DRIscreen *psp)
 {
     if (psp) {
        driDriverAPI.DestroyScreen(psp);
-
        FREE(psp);
     }
 }
@@ -95,15 +94,32 @@ static const __DRIextension **driGetExtensions(__DRIscreen *psp)
  */
 
 static __DRIcontext *
-driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
-                   __DRIcontext *shared, void *data)
+driCreateNewContextForAPI(__DRIscreen *psp, int api,
+                          const __DRIconfig *config,
+                          __DRIcontext *shared, void *data)
 {
     __DRIcontext *pcp;
+    const struct gl_config *modes = (config != NULL) ? &config->modes : NULL;
     void * const shareCtx = (shared != NULL) ? shared->driverPrivate : NULL;
+    gl_api mesa_api;
+
+    switch (api) {
+    case __DRI_API_OPENGL:
+            mesa_api = API_OPENGL;
+            break;
+    case __DRI_API_GLES:
+            mesa_api = API_OPENGLES;
+            break;
+    case __DRI_API_GLES2:
+            mesa_api = API_OPENGLES2;
+            break;
+    default:
+            return NULL;
+    }
 
     pcp = CALLOC_STRUCT(__DRIcontextRec);
     if (!pcp)
-       return NULL;
+        return NULL;
 
     pcp->loaderPrivate = data;
 
@@ -111,14 +127,22 @@ driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
     pcp->driDrawablePriv = NULL;
     pcp->driReadablePriv = NULL;
 
-    if (!driDriverAPI.CreateContext(&config->modes, pcp, shareCtx)) {
-       FREE(pcp);
-       return NULL;
+    if (!driDriverAPI.CreateContext(mesa_api, modes, pcp, shareCtx)) {
+        FREE(pcp);
+        return NULL;
     }
 
     return pcp;
 }
 
+static __DRIcontext *
+driCreateNewContext(__DRIscreen *psp, const __DRIconfig *config,
+                   __DRIcontext *shared, void *data)
+{
+    return driCreateNewContextForAPI(psp, __DRI_API_OPENGL,
+                                    config, shared, data);
+}
+
 static void
 driDestroyContext(__DRIcontext *pcp)
 {
@@ -146,9 +170,10 @@ static int driBindContext(__DRIcontext *pcp,
        pcp->driDrawablePriv = pdp;
        pcp->driReadablePriv = prp;
        if (pdp) {
+           pdp->driContextPriv = pcp;
            dri_get_drawable(pdp);
        }
-       if ( prp && pdp != prp ) {
+       if (prp && pdp != prp) {
            dri_get_drawable(prp);
        }
     }
@@ -203,7 +228,6 @@ static void dri_put_drawable(__DRIdrawable *pdp)
            return;
 
        driDriverAPI.DestroyBuffer(pdp);
-
        FREE(pdp);
     }
 }
@@ -221,6 +245,7 @@ driCreateNewDrawable(__DRIscreen *psp,
     pdp->loaderPrivate = data;
 
     pdp->driScreenPriv = psp;
+    pdp->driContextPriv = NULL;
 
     dri_get_drawable(pdp);
 
@@ -229,6 +254,8 @@ driCreateNewDrawable(__DRIscreen *psp,
        return NULL;
     }
 
+    pdp->lastStamp = 1; /* const */
+
     return pdp;
 }
 
@@ -263,5 +290,6 @@ const __DRIcoreExtension driCoreExtension = {
 const __DRIswrastExtension driSWRastExtension = {
     { __DRI_SWRAST, __DRI_SWRAST_VERSION },
     driCreateNewScreen,
-    driCreateNewDrawable
+    driCreateNewDrawable,
+    driCreateNewContextForAPI
 };