Mesa (master): egl: Add a simple cache for driver probe.

Chia-I Wu olv at kemper.freedesktop.org
Wed Jan 20 10:18:04 UTC 2010


Module: Mesa
Branch: master
Commit: c5766c4ae39b4190965abd65eaf67b478a9ad028
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c5766c4ae39b4190965abd65eaf67b478a9ad028

Author: Chia-I Wu <olvaffe at gmail.com>
Date:   Wed Jan 20 14:35:50 2010 +0800

egl: Add a simple cache for driver probe.

In current design, multiple drivers will probe the same display and the
best driver is determined.  The cache can be used by the drivers to
store and share the probed data.

---

 src/egl/main/egldriver.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++
 src/egl/main/egldriver.h |    8 +++++++
 2 files changed, 56 insertions(+), 0 deletions(-)

diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index ef1c366..0574f83 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -113,6 +113,13 @@ library_suffix(void)
 #endif
 
 
+#define NUM_PROBE_CACHE_SLOTS 8
+static struct {
+   EGLint keys[NUM_PROBE_CACHE_SLOTS];
+   const void *values[NUM_PROBE_CACHE_SLOTS];
+} _eglProbeCache;
+
+
 /**
  * Open the named driver and find its bootstrap function: _eglMain().
  */
@@ -569,3 +576,44 @@ _eglFindAPIs(void)
 
    return mask;
 }
+
+
+/**
+ * Set the probe cache at the given key.
+ *
+ * A key, instead of a _EGLDriver, is used to allow the probe cache to be share
+ * by multiple drivers.
+ */
+void
+_eglSetProbeCache(EGLint key, const void *val)
+{
+   EGLint idx;
+
+   for (idx = 0; idx < NUM_PROBE_CACHE_SLOTS; idx++) {
+      if (!_eglProbeCache.keys[idx] || _eglProbeCache.keys[idx] == key)
+         break;
+   }
+   assert(key > 0);
+   assert(idx < NUM_PROBE_CACHE_SLOTS);
+
+   _eglProbeCache.keys[idx] = key;
+   _eglProbeCache.values[idx] = val;
+}
+
+
+/**
+ * Return the probe cache at the given key.
+ */
+const void *
+_eglGetProbeCache(EGLint key)
+{
+   EGLint idx;
+
+   for (idx = 0; idx < NUM_PROBE_CACHE_SLOTS; idx++) {
+      if (!_eglProbeCache.keys[idx] || _eglProbeCache.keys[idx] == key)
+         break;
+   }
+
+   return (idx < NUM_PROBE_CACHE_SLOTS && _eglProbeCache.keys[idx] == key) ?
+      _eglProbeCache.values[idx] : NULL;
+}
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 808b1c3..d9d6129 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -66,4 +66,12 @@ PUBLIC EGLint
 _eglFindAPIs(void);
 
 
+PUBLIC void
+_eglSetProbeCache(EGLint key, const void *val);
+
+
+PUBLIC const void *
+_eglGetProbeCache(EGLint key);
+
+
 #endif /* EGLDRIVER_INCLUDED */




More information about the mesa-commit mailing list