summaryrefslogtreecommitdiffstats
path: root/src/egl/main/egldriver.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2011-01-13 00:27:45 +0800
committerChia-I Wu <[email protected]>2011-01-13 18:10:38 +0800
commit655e4598927728a663f4cfcd6babdf7e5ad83f77 (patch)
treefa937088bf0e27f51311c86dfbc016c103331f00 /src/egl/main/egldriver.c
parenta4a38dcf61f141297a083ccac217200947d57b0d (diff)
egl: Simplify driver matching.
Add initialization options that drv->API.Initialize should support. Replace drv->Probe by TestOnly initialization option and simplify _eglMatchDriver.
Diffstat (limited to 'src/egl/main/egldriver.c')
-rw-r--r--src/egl/main/egldriver.c121
1 files changed, 48 insertions, 73 deletions
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 1ae030db448..7baa24fbf86 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -525,100 +525,75 @@ _eglAddDrivers(void)
/**
- * Match a display to a driver. The display is initialized unless use_probe is
- * true.
- *
- * The matching is done by finding the first driver that can initialize the
- * display, or when use_probe is true, the driver with highest score.
+ * A helper function for _eglMatchDriver. It finds the first driver that can
+ * initialize the display and return.
*/
-_EGLDriver *
-_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe)
+static _EGLDriver *
+_eglMatchAndInitialize(_EGLDisplay *dpy)
{
- _EGLModule *mod;
- _EGLDriver *best_drv = NULL;
- EGLint best_score = 0;
- EGLint i;
-
- _eglLockMutex(&_eglModuleMutex);
+ _EGLDriver *drv = NULL;
+ EGLint i = 0;
if (!_eglAddDrivers()) {
- _eglUnlockMutex(&_eglModuleMutex);
_eglLog(_EGL_WARNING, "failed to find any driver");
- return EGL_FALSE;
+ return NULL;
}
- /* match the loaded modules */
- for (i = 0; i < _eglModules->Size; i++) {
- mod = (_EGLModule *) _eglModules->Elements[i];
- if (!mod->Driver)
- break;
+ if (dpy->Driver) {
+ drv = dpy->Driver;
+ /* no re-matching? */
+ if (!drv->API.Initialize(drv, dpy))
+ drv = NULL;
+ return drv;
+ }
- if (use_probe) {
- EGLint score = (mod->Driver->Probe) ?
- mod->Driver->Probe(mod->Driver, dpy) : 1;
- if (score > best_score) {
- best_drv = mod->Driver;
- best_score = score;
- }
+ while (i < _eglModules->Size) {
+ _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i];
+
+ if (!_eglLoadModule(mod)) {
+ /* remove invalid modules */
+ _eglEraseArray(_eglModules, i, _eglFreeModule);
+ continue;
+ }
+
+ if (mod->Driver->API.Initialize(mod->Driver, dpy)) {
+ drv = mod->Driver;
+ break;
}
else {
- if (mod->Driver->API.Initialize(mod->Driver, dpy)) {
- best_drv = mod->Driver;
- best_score = 100;
- }
+ i++;
}
- /* perfect match */
- if (best_score >= 100)
- break;
}
- /* load more modules */
- if (!best_drv) {
- EGLint first_unloaded = i;
+ return drv;
+}
- while (i < _eglModules->Size) {
- mod = (_EGLModule *) _eglModules->Elements[i];
- assert(!mod->Driver);
- if (!_eglLoadModule(mod)) {
- /* remove invalid modules */
- _eglEraseArray(_eglModules, i, _eglFreeModule);
- continue;
- }
+/**
+ * Match a display to a driver. The display is initialized unless test_only is
+ * true. The matching is done by finding the first driver that can initialize
+ * the display.
+ */
+_EGLDriver *
+_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
+{
+ _EGLDriver *best_drv;
- if (use_probe) {
- best_score = (mod->Driver->Probe) ?
- mod->Driver->Probe(mod->Driver, dpy) : 1;
- }
- else {
- if (mod->Driver->API.Initialize(mod->Driver, dpy))
- best_score = 100;
- }
+ assert(!dpy->Initialized);
- if (best_score > 0) {
- best_drv = mod->Driver;
- /* loaded modules come before unloaded ones */
- if (first_unloaded != i) {
- void *tmp = _eglModules->Elements[i];
- _eglModules->Elements[i] =
- _eglModules->Elements[first_unloaded];
- _eglModules->Elements[first_unloaded] = tmp;
- }
- break;
- }
- else {
- _eglUnloadModule(mod);
- i++;
- }
- }
- }
+ _eglLockMutex(&_eglModuleMutex);
+
+ /* set options */
+ dpy->Options.TestOnly = test_only;
+
+ best_drv = _eglMatchAndInitialize(dpy);
_eglUnlockMutex(&_eglModuleMutex);
if (best_drv) {
- _eglLog(_EGL_DEBUG, "the best driver is %s (score %d)",
- best_drv->Name, best_score);
- if (!use_probe) {
+ _eglLog(_EGL_DEBUG, "the best driver is %s%s",
+ best_drv->Name, (test_only) ? " (test only) " : "");
+ if (!test_only) {
dpy->Driver = best_drv;
dpy->Initialized = EGL_TRUE;
}