summaryrefslogtreecommitdiffstats
path: root/src/egl/drivers
diff options
context:
space:
mode:
authorEric Anholt <[email protected]>2018-11-15 13:54:49 -0800
committerEric Anholt <[email protected]>2018-11-16 17:49:17 -0800
commitd971a4230d54069c996bca78b6ed6a6a23377821 (patch)
tree2d9c29c0c0df5405a0bad5b2c7860bcc614069a2 /src/egl/drivers
parentcc198157382a988590b0288d287281139c5f73e6 (diff)
loader: Factor out the common driver opening logic from each loader.
I copied the code from egl_dri2.c, but the functionality was equivalent between all the loaders other than their particular environment variables. v2: Drop the logging function equivalent to loader_default_logger() (requested by Eric, Emil). Move the SCons workaround across. Drop the now-unused driGetDriverExtensions() declaration that was lost in a rebase. Reviewed-by: Eric Engestrom <[email protected]> (v1) Reviewed-by: Emil Velikov <[email protected]> (v1)
Diffstat (limited to 'src/egl/drivers')
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c75
1 files changed, 7 insertions, 68 deletions
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index af2b3a6fa8f..0be9235835d 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -483,75 +483,14 @@ static const __DRIextension **
dri2_open_driver(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- const __DRIextension **extensions = NULL;
- char path[PATH_MAX], *search_paths, *next, *end;
- char *get_extensions_name;
- const __DRIextension **(*get_extensions)(void);
-
- search_paths = NULL;
- if (geteuid() == getuid()) {
- /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
- search_paths = getenv("LIBGL_DRIVERS_PATH");
- }
- if (search_paths == NULL)
- search_paths = DEFAULT_DRIVER_DIR;
-
- dri2_dpy->driver = NULL;
- end = search_paths + strlen(search_paths);
- for (char *p = search_paths; p < end; p = next + 1) {
- int len;
- next = strchr(p, ':');
- if (next == NULL)
- next = end;
-
- len = next - p;
-#if GLX_USE_TLS
- snprintf(path, sizeof path,
- "%.*s/tls/%s_dri.so", len, p, dri2_dpy->driver_name);
- dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
-#endif
- if (dri2_dpy->driver == NULL) {
- snprintf(path, sizeof path,
- "%.*s/%s_dri.so", len, p, dri2_dpy->driver_name);
- dri2_dpy->driver = dlopen(path, RTLD_NOW | RTLD_GLOBAL);
- if (dri2_dpy->driver == NULL)
- _eglLog(_EGL_DEBUG, "failed to open %s: %s\n", path, dlerror());
- }
- /* not need continue to loop all paths once the driver is found */
- if (dri2_dpy->driver != NULL)
- break;
- }
-
- if (dri2_dpy->driver == NULL) {
- _eglLog(_EGL_WARNING,
- "DRI2: failed to open %s (search paths %s)",
- dri2_dpy->driver_name, search_paths);
- return NULL;
- }
-
- _eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
-
- get_extensions_name = loader_get_extensions_name(dri2_dpy->driver_name);
- if (get_extensions_name) {
- get_extensions = dlsym(dri2_dpy->driver, get_extensions_name);
- if (get_extensions) {
- extensions = get_extensions();
- } else {
- _eglLog(_EGL_DEBUG, "driver does not expose %s(): %s\n",
- get_extensions_name, dlerror());
- }
- free(get_extensions_name);
- }
-
- if (!extensions)
- extensions = dlsym(dri2_dpy->driver, __DRI_DRIVER_EXTENSIONS);
- if (extensions == NULL) {
- _eglLog(_EGL_WARNING,
- "DRI2: driver exports no extensions (%s)", dlerror());
- dlclose(dri2_dpy->driver);
- }
+ static const char *search_path_vars[] = {
+ "LIBGL_DRIVERS_PATH",
+ NULL,
+ };
- return extensions;
+ return loader_open_driver(dri2_dpy->driver_name,
+ &dri2_dpy->driver,
+ search_path_vars);
}
EGLBoolean