[Mesa-dev] [PATCH 2/5] glx: Move DRI extensions pointer loading to driOpenDriver().

Eric Anholt eric at anholt.net
Thu Nov 15 23:05:24 UTC 2018


The only thing you do with a dri driver handle is get the extensions
pointer, so just fold it in to simplify the callers.
---
 src/glx/dri2_glx.c   |  8 +-------
 src/glx/dri3_glx.c   |  8 +-------
 src/glx/dri_common.c | 20 +++++++++++++++-----
 src/glx/dri_common.h |  6 ++----
 src/glx/dri_glx.c    | 16 +++-------------
 src/glx/drisw_glx.c  | 17 +----------------
 6 files changed, 23 insertions(+), 52 deletions(-)

diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index 91afc3375058..d8c5ba25f04e 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -1252,13 +1252,7 @@ dri2CreateScreen(int screen, struct glx_display * priv)
       driverName = loader_driverName;
    }
 
-   psc->driver = driOpenDriver(driverName);
-   if (psc->driver == NULL) {
-      ErrorMessageF("driver pointer missing\n");
-      goto handle_error;
-   }
-
-   extensions = driGetDriverExtensions(psc->driver, driverName);
+   extensions = driOpenDriver(driverName, &psc->driver);
    if (extensions == NULL)
       goto handle_error;
 
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index ce60b95c71e3..298adc80ef16 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -861,13 +861,7 @@ dri3_create_screen(int screen, struct glx_display * priv)
       goto handle_error;
    }
 
-   psc->driver = driOpenDriver(driverName);
-   if (psc->driver == NULL) {
-      ErrorMessageF("driver pointer missing\n");
-      goto handle_error;
-   }
-
-   extensions = driGetDriverExtensions(psc->driver, driverName);
+   extensions = driOpenDriver(driverName, &psc->driver);
    if (extensions == NULL)
       goto handle_error;
 
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 08923d7efd55..75a5e5025761 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -85,12 +85,14 @@ dri_message(int level, const char *f, ...)
  * order to find the driver.
  *
  * \param driverName - a name like "i965", "radeon", "nouveau", etc.
+ * \param out_driver_handle - Address to return the resulting dlopen() handle.
  *
  * \returns
- * A handle from \c dlopen, or \c NULL if driver file not found.
+ * The __DRIextension entrypoint table for the driver, or \c NULL if driver
+ * file not found.
  */
-_X_HIDDEN void *
-driOpenDriver(const char *driverName)
+_X_HIDDEN const __DRIextension **
+driOpenDriver(const char *driverName, void **out_driver_handle)
 {
    void *glhandle, *handle;
    const char *libPaths, *p, *next;
@@ -148,10 +150,18 @@ driOpenDriver(const char *driverName)
    if (glhandle)
       dlclose(glhandle);
 
-   return handle;
+   const __DRIextension **extensions = driGetDriverExtensions(handle,
+                                                              driverName);
+   if (!extensions) {
+      dlclose(handle);
+      handle = NULL;
+   }
+
+   *out_driver_handle = handle;
+   return extensions;
 }
 
-_X_HIDDEN const __DRIextension **
+static const __DRIextension **
 driGetDriverExtensions(void *handle, const char *driver_name)
 {
    const __DRIextension **extensions = NULL;
diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h
index 4d97ff82b4d1..363f15bf9bb2 100644
--- a/src/glx/dri_common.h
+++ b/src/glx/dri_common.h
@@ -69,10 +69,8 @@ extern void dri_message(int level, const char *f, ...) PRINTFLIKE(2, 3);
 #define ErrorMessageF(...) dri_message(_LOADER_WARNING, __VA_ARGS__)
 #define CriticalErrorMessageF(...) dri_message(_LOADER_FATAL, __VA_ARGS__)
 
-extern void *driOpenDriver(const char *driverName);
-
-extern const __DRIextension **
-driGetDriverExtensions(void *handle, const char *driver_name);
+extern const __DRIextension **driOpenDriver(const char *driverName,
+                                            void **out_driver_handle);
 
 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 5c4346cec0d8..6e9412d3fb17 100644
--- a/src/glx/dri_glx.c
+++ b/src/glx/dri_glx.c
@@ -199,15 +199,9 @@ clear_driver_config_cache()
 static char *
 get_driver_config(const char *driverName)
 {
-   void *handle = driOpenDriver(driverName);
-   const __DRIextension **extensions;
-
-   if (!handle)
-      return NULL;
-
+   void *handle;
    char *config = NULL;
-
-   extensions = driGetDriverExtensions(handle, driverName);
+   const __DRIextension **extensions = driOpenDriver(driverName, &handle);
    if (extensions) {
       for (int i = 0; extensions[i]; i++) {
          if (strcmp(extensions[i]->name, __DRI_CONFIG_OPTIONS) != 0)
@@ -918,11 +912,7 @@ driCreateScreen(int screen, struct glx_display *priv)
       goto cleanup;
    }
 
-   psc->driver = driOpenDriver(driverName);
-   if (psc->driver == NULL)
-      goto cleanup;
-
-   extensions = dlsym(psc->driver, __DRI_DRIVER_EXTENSIONS);
+   extensions = driOpenDriver(driverName, &psc->driver);
    if (extensions == NULL) {
       ErrorMessageF("driver exports no extensions (%s)\n", dlerror());
       goto cleanup;
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index a2777100a321..7b99e49f000f 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -748,17 +748,6 @@ driswDestroyScreen(struct glx_screen *base)
 
 #define SWRAST_DRIVER_NAME "swrast"
 
-static void *
-driOpenSwrast(void)
-{
-   void *driver = NULL;
-
-   if (driver == NULL)
-      driver = driOpenDriver(SWRAST_DRIVER_NAME);
-
-   return driver;
-}
-
 static const struct glx_screen_vtable drisw_screen_vtable = {
    .create_context         = drisw_create_context,
    .create_context_attribs = drisw_create_context_attribs,
@@ -837,11 +826,7 @@ driswCreateScreen(int screen, struct glx_display *priv)
       return NULL;
    }
 
-   psc->driver = driOpenSwrast();
-   if (psc->driver == NULL)
-      goto handle_error;
-
-   extensions = driGetDriverExtensions(psc->driver, SWRAST_DRIVER_NAME);
+   extensions = driOpenDriver(SWRAST_DRIVER_NAME, &psc->driver);
    if (extensions == NULL)
       goto handle_error;
 
-- 
2.19.1



More information about the mesa-dev mailing list