Mesa (master): glx: Add an optional function call for getting the DRI driver interface.

Eric Anholt anholt at kemper.freedesktop.org
Thu Oct 24 21:48:09 UTC 2013


Module: Mesa
Branch: master
Commit: fcb57a8210e819cc14a39c79f23530eb22296da0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fcb57a8210e819cc14a39c79f23530eb22296da0

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Sep 23 14:44:10 2013 -0700

glx: Add an optional function call for getting the DRI driver interface.

The previous interface relied on a static struct, which meant that the
driver didn't get a chance to edit the struct before the struct got used.
For megadrivers, I want struct specific to the driver being loaded.

v2: Fix the prototype in the docs (caught by Marek).  Since the driver
    name was in the function, we didn't need to also pass it in.
v3: Fix asprintf error checking (caught by Matt's gcc).

Reviewed-by: Matt Turner <mattst88 at gmail.com> (v1)
Reviewed-by: Chad Versace <chad.versace at linux.intel.com>
Reviewed-by: Emil Velikov <emil.l.velikov at gmail.com>

---

 include/GL/internal/dri_interface.h |   13 +++++++++++++
 src/glx/dri2_glx.c                  |    2 +-
 src/glx/dri_common.c                |   17 ++++++++++++++++-
 src/glx/dri_common.h                |    3 ++-
 src/glx/dri_glx.c                   |    2 +-
 src/glx/drisw_glx.c                 |    6 ++----
 6 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 3e54d60..2122ae9 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -488,6 +488,19 @@ struct __DRIuseInvalidateExtensionRec {
 #define __DRI_DRIVER_EXTENSIONS "__driDriverExtensions"
 
 /**
+ * This symbol replaces the __DRI_DRIVER_EXTENSIONS symbol, and will be
+ * suffixed by "_drivername", allowing multiple drivers to be built into one
+ * library, and also giving the driver the chance to return a variable driver
+ * extensions struct depending on the driver name being loaded or any other
+ * system state.
+ *
+ * The function prototype is:
+ *
+ * const __DRIextension **__driDriverGetExtensions_drivername(void);
+ */
+#define __DRI_DRIVER_GET_EXTENSIONS "__driDriverGetExtensions"
+
+/**
  * Tokens for __DRIconfig attribs.  A number of attributes defined by
  * GLX or EGL standards are not in the table, as they must be provided
  * by the loader.  For example, FBConfig ID or visual ID, drawable type.
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 123c87c..7e22906 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -1183,7 +1183,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
       goto handle_error;
    }
 
-   extensions = driGetDriverExtensions(psc->driver);
+   extensions = driGetDriverExtensions(psc->driver, driverName);
    if (extensions == NULL)
       goto handle_error;
 
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index f1d1164..22ba248 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -188,9 +188,24 @@ driOpenDriver(const char *driverName)
 }
 
 _X_HIDDEN const __DRIextension **
-driGetDriverExtensions(void *handle)
+driGetDriverExtensions(void *handle, const char *driver_name)
 {
    const __DRIextension **extensions = NULL;
+   const __DRIextension **(*get_extensions)(void);
+   char *get_extensions_name;
+
+   if (asprintf(&get_extensions_name, "%s_%s",
+                __DRI_DRIVER_GET_EXTENSIONS, driver_name) != -1) {
+      get_extensions = dlsym(handle, get_extensions_name);
+      if (get_extensions) {
+         free(get_extensions_name);
+         return get_extensions();
+      } else {
+         InfoMessageF("driver does not expose %s(): %s\n",
+                      get_extensions_name, dlerror());
+         free(get_extensions_name);
+      }
+   }
 
    extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS);
    if (extensions == NULL) {
diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h
index 2ebcb81..4fe0d3f 100644
--- a/src/glx/dri_common.h
+++ b/src/glx/dri_common.h
@@ -69,7 +69,8 @@ extern void CriticalErrorMessageF(const char *f, ...);
 
 extern void *driOpenDriver(const char *driverName);
 
-extern const __DRIextension **driGetDriverExtensions(void *handle);
+extern const __DRIextension **
+driGetDriverExtensions(void *handle, const char *driver_name);
 
 extern bool
 dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
diff --git a/src/glx/dri_glx.c b/src/glx/dri_glx.c
index a1475b0..0b89e3e 100644
--- a/src/glx/dri_glx.c
+++ b/src/glx/dri_glx.c
@@ -189,7 +189,7 @@ glXGetDriverConfig(const char *driverName)
    if (!handle)
       return NULL;
 
-   extensions = driGetDriverExtensions(handle);
+   extensions = driGetDriverExtensions(handle, driverName);
    if (extensions) {
       for (int i = 0; extensions[i]; i++) {
          if (strcmp(extensions[i]->name, __DRI_CONFIG_OPTIONS) == 0)
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index 393be20..a7d0843 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -664,11 +664,9 @@ driswCreateScreen(int screen, struct glx_display *priv)
    if (psc->driver == NULL)
       goto handle_error;
 
-   extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
-   if (extensions == NULL) {
-      ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
+   extensions = driGetDriverExtensions(psc->driver, SWRAST_DRIVER_NAME);
+   if (extensions == NULL)
       goto handle_error;
-   }
 
    for (i = 0; extensions[i]; i++) {
       if (strcmp(extensions[i]->name, __DRI_CORE) == 0)




More information about the mesa-commit mailing list