Mesa (master): egl: Improve driver matching.
Chia-I Wu
olv at kemper.freedesktop.org
Wed Jan 20 10:18:04 UTC 2010
Module: Mesa
Branch: master
Commit: cf22fd5e5b13ccdb02ba0368ea722ede3bbc6de0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cf22fd5e5b13ccdb02ba0368ea722ede3bbc6de0
Author: Chia-I Wu <olvaffe at gmail.com>
Date: Tue Jan 19 18:39:59 2010 +0800
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.
---
src/egl/main/egldisplay.h | 1 -
src/egl/main/egldriver.c | 35 +++++++++++++++++++----------------
src/egl/main/egldriver.h | 19 ++++++++++++++++---
3 files changed, 35 insertions(+), 20 deletions(-)
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index ddd9806..a698131 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -26,7 +26,6 @@ struct _egl_display
EGLNativeDisplayType NativeDisplay;
- const char *DriverName;
_EGLDriver *Driver;
void *DriverData; /* private to driver */
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index dd363a1..ef1c366 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -218,32 +218,35 @@ _eglLoadDriver(const char *path, const char *args)
/**
* Match a display to a preloaded driver.
+ *
+ * The matching is done by finding the driver with the highest score.
*/
static _EGLDriver *
_eglMatchDriver(_EGLDisplay *dpy)
{
- _EGLDriver *defaultDriver = NULL;
- EGLint i;
+ _EGLDriver *best_drv = NULL;
+ EGLint best_score = -1, i;
for (i = 0; i < _eglGlobal.NumDrivers; i++) {
_EGLDriver *drv = _eglGlobal.Drivers[i];
-
- /* display specifies a driver */
- if (dpy->DriverName) {
- if (strcmp(dpy->DriverName, drv->Name) == 0)
- return drv;
- }
- else if (drv->Probe) {
- if (drv->Probe(drv, dpy))
- return drv;
- }
- else {
- if (!defaultDriver)
- defaultDriver = drv;
+ EGLint score;
+
+ score = (drv->Probe) ? drv->Probe(drv, dpy) : 0;
+ if (score > best_score) {
+ if (best_drv) {
+ _eglLog(_EGL_DEBUG, "driver %s has higher score than %s",
+ drv->Name, best_drv->Name);
+ }
+
+ best_drv = drv;
+ best_score = score;
+ /* perfect match */
+ if (score >= 100)
+ break;
}
}
- return defaultDriver;
+ return best_drv;
}
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index eca96fc..808b1c3 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -16,9 +16,22 @@ struct _egl_driver
const char *Args; /**< args to load 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);
_EGLAPI API; /**< EGL API dispatch table */
More information about the mesa-commit
mailing list