From: Eric Anholt Date: Thu, 15 Nov 2018 22:22:16 +0000 (-0800) Subject: glx: Move DRI extensions pointer loading to driOpenDriver(). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c2b515379bfc669660133bb2d25e50bb04ac0d66;p=mesa.git glx: Move DRI extensions pointer loading to driOpenDriver(). The only thing you do with a dri driver handle is get the extensions pointer, so just fold it in to simplify the callers. v2: Add the declaration of driGetDriverExtensions() that got lost in a rebase. Reviewed-by: Eric Engestrom (v1) Reviewed-by: Emil Velikov (v1) --- diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c index 91afc337505..d8c5ba25f04 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 ce60b95c71e..298adc80ef1 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 08923d7efd5..b4712a6038b 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -77,6 +77,9 @@ dri_message(int level, const char *f, ...) #define GL_LIB_NAME "libGL.so.1" #endif +static const __DRIextension ** +driGetDriverExtensions(void *handle, const char *driver_name); + /** * Try to \c dlopen the named driver. * @@ -85,12 +88,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 +153,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 4d97ff82b4d..363f15bf9bb 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 5c4346cec0d..6e9412d3fb1 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 a2777100a32..7b99e49f000 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;