egl: Improve driver matching.

Make drv->Probe return a score so that the matching can be done by
finding the driver with the highest score.
This commit is contained in:
Chia-I Wu
2010-01-19 18:39:59 +08:00
parent 925f8113be
commit cf22fd5e5b
3 changed files with 34 additions and 19 deletions

View File

@@ -26,7 +26,6 @@ struct _egl_display
EGLNativeDisplayType NativeDisplay; EGLNativeDisplayType NativeDisplay;
const char *DriverName;
_EGLDriver *Driver; _EGLDriver *Driver;
void *DriverData; /* private to driver */ void *DriverData; /* private to driver */

View File

@@ -218,32 +218,35 @@ _eglLoadDriver(const char *path, const char *args)
/** /**
* Match a display to a preloaded driver. * Match a display to a preloaded driver.
*
* The matching is done by finding the driver with the highest score.
*/ */
static _EGLDriver * static _EGLDriver *
_eglMatchDriver(_EGLDisplay *dpy) _eglMatchDriver(_EGLDisplay *dpy)
{ {
_EGLDriver *defaultDriver = NULL; _EGLDriver *best_drv = NULL;
EGLint i; EGLint best_score = -1, i;
for (i = 0; i < _eglGlobal.NumDrivers; i++) { for (i = 0; i < _eglGlobal.NumDrivers; i++) {
_EGLDriver *drv = _eglGlobal.Drivers[i]; _EGLDriver *drv = _eglGlobal.Drivers[i];
EGLint score;
/* display specifies a driver */ score = (drv->Probe) ? drv->Probe(drv, dpy) : 0;
if (dpy->DriverName) { if (score > best_score) {
if (strcmp(dpy->DriverName, drv->Name) == 0) if (best_drv) {
return drv; _eglLog(_EGL_DEBUG, "driver %s has higher score than %s",
} drv->Name, best_drv->Name);
else if (drv->Probe) { }
if (drv->Probe(drv, dpy))
return drv; best_drv = drv;
} best_score = score;
else { /* perfect match */
if (!defaultDriver) if (score >= 100)
defaultDriver = drv; break;
} }
} }
return defaultDriver; return best_drv;
} }

View File

@@ -16,9 +16,22 @@ struct _egl_driver
const char *Args; /**< args to load this driver */ const char *Args; /**< args to load this driver */
const char *Name; /**< name of this driver */ const char *Name; /**< name of this driver */
/**< probe a display to see if it is supported */
EGLBoolean (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy); /**
/**< called before dlclose to release this driver */ * Probe a display and return a score.
*
* Roughly,
* 50 means the driver supports the display;
* 90 means the driver can accelerate the display;
* 100 means a perfect match.
*/
EGLint (*Probe)(_EGLDriver *drv, _EGLDisplay *dpy);
/**
* Release the driver resource.
*
* It is called before dlclose().
*/
void (*Unload)(_EGLDriver *drv); void (*Unload)(_EGLDriver *drv);
_EGLAPI API; /**< EGL API dispatch table */ _EGLAPI API; /**< EGL API dispatch table */