dri: Reference the global driver vtable once at screen init..
authorEric Anholt <eric@anholt.net>
Thu, 26 Sep 2013 17:51:29 +0000 (10:51 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 10 Oct 2013 23:34:30 +0000 (16:34 -0700)
This is part of the prep for megadrivers, which won't allow using a single
global symbol due to the fact that there will be multiple drivers built
into the same dri.so file.  For that, we'll need screen init to take a
reference to the driver to set up this vtable.

v2: Fix two missed references to driDriverAPI.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
src/mesa/drivers/dri/common/dri_util.c
src/mesa/drivers/dri/common/dri_util.h

index 70448c2df4d2845c15cd35fd48afc7b17a552900..32f0e33009f594dfd6ccdffd037fd4dd8527f380 100644 (file)
@@ -99,6 +99,8 @@ dri2CreateNewScreen(int scrn, int fd,
     if (!psp)
        return NULL;
 
+    psp->driver = &driDriverAPI;
+
     setupLoaderExtensions(psp, extensions);
 
 #ifndef __NOT_HAVE_DRM_H
@@ -119,7 +121,7 @@ dri2CreateNewScreen(int scrn, int fd,
     psp->fd = fd;
     psp->myNum = scrn;
 
-    *driver_configs = driDriverAPI.InitScreen(psp);
+    *driver_configs = psp->driver->InitScreen(psp);
     if (*driver_configs == NULL) {
        free(psp);
        return NULL;
@@ -176,7 +178,7 @@ static void driDestroyScreen(__DRIscreen *psp)
 
        _mesa_destroy_shader_compiler();
 
-       driDriverAPI.DestroyScreen(psp);
+       psp->driver->DestroyScreen(psp);
 
        driDestroyOptionCache(&psp->optionCache);
        driDestroyOptionInfo(&psp->optionInfo);
@@ -369,9 +371,9 @@ dri2CreateContextAttribs(__DRIscreen *screen, int api,
     context->driDrawablePriv = NULL;
     context->driReadablePriv = NULL;
 
-    if (!driDriverAPI.CreateContext(mesa_api, modes, context,
-                                   major_version, minor_version,
-                                   flags, error, shareCtx) ) {
+    if (!screen->driver->CreateContext(mesa_api, modes, context,
+                                       major_version, minor_version,
+                                       flags, error, shareCtx) ) {
         free(context);
         return NULL;
     }
@@ -410,7 +412,7 @@ static void
 driDestroyContext(__DRIcontext *pcp)
 {
     if (pcp) {
-       driDriverAPI.DestroyContext(pcp);
+       pcp->driScreenPriv->driver->DestroyContext(pcp);
        free(pcp);
     }
 }
@@ -463,7 +465,7 @@ static int driBindContext(__DRIcontext *pcp,
        dri_get_drawable(prp);
     }
 
-    return driDriverAPI.MakeCurrent(pcp, pdp, prp);
+    return pcp->driScreenPriv->driver->MakeCurrent(pcp, pdp, prp);
 }
 
 /**
@@ -502,7 +504,7 @@ static int driUnbindContext(__DRIcontext *pcp)
     if (!pdp && !prp)
        return GL_TRUE;
 
-    driDriverAPI.UnbindContext(pcp);
+    pcp->driScreenPriv->driver->UnbindContext(pcp);
 
     assert(pdp);
     if (pdp->refcount == 0) {
@@ -542,7 +544,7 @@ static void dri_put_drawable(__DRIdrawable *pdp)
        if (pdp->refcount)
            return;
 
-       driDriverAPI.DestroyBuffer(pdp);
+       pdp->driScreenPriv->driver->DestroyBuffer(pdp);
        free(pdp);
     }
 }
@@ -569,7 +571,8 @@ dri2CreateNewDrawable(__DRIscreen *screen,
 
     dri_get_drawable(pdraw);
 
-    if (!driDriverAPI.CreateBuffer(screen, pdraw, &config->modes, GL_FALSE)) {
+    if (!screen->driver->CreateBuffer(screen, pdraw, &config->modes,
+                                      GL_FALSE)) {
        free(pdraw);
        return NULL;
     }
@@ -590,14 +593,14 @@ dri2AllocateBuffer(__DRIscreen *screen,
                   unsigned int attachment, unsigned int format,
                   int width, int height)
 {
-    return driDriverAPI.AllocateBuffer(screen, attachment, format,
-                                      width, height);
+    return screen->driver->AllocateBuffer(screen, attachment, format,
+                                          width, height);
 }
 
 static void
 dri2ReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 {
-    driDriverAPI.ReleaseBuffer(screen, buffer);
+    screen->driver->ReleaseBuffer(screen, buffer);
 }
 
 
@@ -652,7 +655,7 @@ driSwapBuffers(__DRIdrawable *pdp)
 {
     assert(pdp->driScreenPriv->swrast_loader);
 
-    driDriverAPI.SwapBuffers(pdp);
+    pdp->driScreenPriv->driver->SwapBuffers(pdp);
 }
 
 /** Core interface */
index 92edccbb02e925db18e8571712cecd0ed37f221f..61c80bc4541dead01ded3e875193ad32177b73c2 100644 (file)
@@ -122,6 +122,12 @@ extern const struct __DriverAPIRec driDriverAPI;
  * Per-screen private driver information.
  */
 struct __DRIscreenRec {
+    /**
+     * Driver-specific entrypoints provided by the driver's
+     * __DRIDriverVtableExtensionRec.
+     */
+    const struct __DriverAPIRec *driver;
+
     /**
      * Current screen's number
      */