Commit c2b51537 authored by Eric Anholt's avatar Eric Anholt

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 <eric.engestrom@intel.com> (v1)
Reviewed-by: Emil Velikov <emil.velikov@collabora.com> (v1)
parent 7076e9f1
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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,
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment