From 681fd73f1e95d43425b946a250b241bfdb0ce1c8 Mon Sep 17 00:00:00 2001 From: Kristian Høgsberg Date: Thu, 13 May 2010 16:06:29 -0400 Subject: egl: Allow a prioritized list of default drivers When there is no user driver or any matching display drivers we fall back to the default driver. This patch lets us have a list of default drivers instead of just one. The drivers are loaded in turn and we attempt to initialize the display. If it fails we unload the driver and move on to the next one. Compared to the display driver mechanism, this avoids loading a number of drivers and then only using one. Also, we call Initialize to see if the driver will work instead of relying on Probe. To know for sure that a driver will work, Probe really have to do a full Initialize, so we will just use Initialize directly. --- src/egl/main/eglapi.c | 14 ++++++++------ src/egl/main/eglconfig.c | 1 - src/egl/main/egldefines.h | 1 + src/egl/main/egldriver.c | 48 +++++++++++++++++++++++++++++++---------------- src/egl/main/egldriver.h | 4 ++++ src/egl/main/eglglobals.c | 3 --- 6 files changed, 45 insertions(+), 26 deletions(-) (limited to 'src/egl') diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index 647be65220..f57dda8883 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -272,13 +272,15 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor) if (!drv) { _eglPreloadDrivers(); drv = _eglMatchDriver(disp); - if (!drv) - RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); + /* Initialize the particular display now */ + if (drv && !drv->API.Initialize(drv, disp, &major_int, &minor_int)) + RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); } - - /* Initialize the particular display now */ - if (!drv->API.Initialize(drv, disp, &major_int, &minor_int)) - RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); + if (!drv) + /* Load and initialize the first default driver that works */ + drv = _eglLoadDefaultDriver(disp, &major_int, &minor_int); + if (!drv) + RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE); disp->APImajor = major_int; disp->APIminor = minor_int; diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c index 21d13cba90..47513a4edb 100644 --- a/src/egl/main/eglconfig.c +++ b/src/egl/main/eglconfig.c @@ -13,7 +13,6 @@ #define MIN2(A, B) (((A) < (B)) ? (A) : (B)) -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) /** diff --git a/src/egl/main/egldefines.h b/src/egl/main/egldefines.h index 8fc2301b79..4ecd4c1420 100644 --- a/src/egl/main/egldefines.h +++ b/src/egl/main/egldefines.h @@ -40,6 +40,7 @@ #define _EGL_VENDOR_STRING "Mesa Project" +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #endif /* EGLDEFINES_INCLUDED */ diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index 2913ce2ece..566554d51d 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -36,7 +36,9 @@ /* XXX Need to decide how to do dynamic name lookup on Windows */ -static const char DefaultDriverName[] = "TBD"; +static const char DefaultDriverNames[] = { + "TBD", +}; typedef HMODULE lib_handle; @@ -63,7 +65,10 @@ library_suffix(void) #elif defined(_EGL_PLATFORM_POSIX) -static const char DefaultDriverName[] = "egl_glx"; +static const char *DefaultDriverNames[] = { + "egl_dri2", + "egl_glx" +}; typedef void * lib_handle; @@ -487,17 +492,6 @@ _eglPreloadDisplayDrivers(void) } -/** - * Preload the default driver. - */ -static EGLBoolean -_eglPreloadDefaultDriver(void) -{ - return (_eglPreloadForEach(_eglGetSearchPath(), - _eglLoaderFile, (void *) DefaultDriverName) > 0); -} - - /** * Preload drivers. * @@ -519,15 +513,13 @@ _eglPreloadDrivers(void) } loaded = (_eglPreloadUserDriver() || - _eglPreloadDisplayDrivers() || - _eglPreloadDefaultDriver()); + _eglPreloadDisplayDrivers()); _eglUnlockMutex(_eglGlobal.Mutex); return loaded; } - /** * Unload preloaded drivers. */ @@ -558,6 +550,30 @@ _eglUnloadDrivers(void) _eglGlobal.NumDrivers = 0; } +_EGLDriver * +_eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor) +{ + _EGLDriver *drv = NULL; + int i; + + _eglLockMutex(_eglGlobal.Mutex); + + for (i = 0; i < ARRAY_SIZE(DefaultDriverNames); i++) { + _eglPreloadForEach(_eglGetSearchPath(), + _eglLoaderFile, (void *) DefaultDriverNames[i]); + if (_eglGlobal.NumDrivers == 0) + continue; + drv = _eglGlobal.Drivers[0]; + if (drv->API.Initialize(drv, dpy, major, minor)) + break; + _eglUnloadDrivers(); + } + + _eglUnlockMutex(_eglGlobal.Mutex); + + return drv; +} + /** * Plug all the available fallback routines into the given driver's diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 28b79562f8..8b34c43b92 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -84,6 +84,10 @@ extern void _eglUnloadDrivers(void); +extern _EGLDriver * +_eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor); + + PUBLIC void _eglInitDriverFallbacks(_EGLDriver *drv); diff --git a/src/egl/main/eglglobals.c b/src/egl/main/eglglobals.c index 5182b18e22..e63819e08a 100644 --- a/src/egl/main/eglglobals.c +++ b/src/egl/main/eglglobals.c @@ -6,9 +6,6 @@ #include "eglmutex.h" -#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) - - static _EGL_DECLARE_MUTEX(_eglGlobalMutex); struct _egl_global _eglGlobal = { -- cgit v1.2.3