#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include "eglstring.h"
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldefines.h"
#include "eglscreen.h"
#include "eglstring.h"
#include "eglsurface.h"
+#include "eglimage.h"
-#if defined(_EGL_PLATFORM_X)
+#if defined(_EGL_OS_UNIX)
#include <dlfcn.h>
-#include "eglx.h"
-#elif defined(_EGL_PLATFORM_WINDOWS)
-/* Use static linking on Windows for now */
-#define WINDOWS_STATIC_LINK
+#include <sys/types.h>
+#include <dirent.h>
+#include <unistd.h>
#endif
+
/**
* Wrappers for dlopen/dlclose()
*/
-#if defined(_EGL_PLATFORM_WINDOWS)
-#ifdef WINDOWS_STATIC_LINK
- static const char *DefaultDriverName = "Windows EGL Static Library";
-#else
- /* XXX Need to decide how to do dynamic name lookup on Windows */
- static const char *DefaultDriverName = "TBD";
-#endif
- static const char *SysFS = NULL;
- typedef HMODULE lib_handle;
-
- static HMODULE
- open_library(const char *filename)
- {
-#ifdef WINDOWS_STATIC_LINK
- return 0;
-#else
- return LoadLibrary(filename);
-#endif
- }
+#if defined(_EGL_OS_WINDOWS)
- static void
- close_library(HMODULE lib)
- {
-#ifdef WINDOWS_STATIC_LINK
-#else
- FreeLibrary(lib);
-#endif
- }
-#elif defined(_EGL_PLATFORM_X)
- static const char *DefaultDriverName = ":0";
- static const char *SysFS = "/sys/class";
+/* XXX Need to decide how to do dynamic name lookup on Windows */
+static const char *DefaultDriverNames[] = {
+ "egl_gdi_swrast"
+};
- typedef void * lib_handle;
+typedef HMODULE lib_handle;
- static void *
- open_library(const char *filename)
- {
- return dlopen(filename, RTLD_LAZY);
- }
+static HMODULE
+open_library(const char *filename)
+{
+ return LoadLibrary(filename);
+}
- static void
- close_library(void *lib)
- {
- dlclose(lib);
- }
-
-#endif
+static void
+close_library(HMODULE lib)
+{
+ FreeLibrary(lib);
+}
-/**
- * Given a card number, use sysfs to determine the DRI driver name.
- */
-const char *
-_eglChooseDRMDriver(int card)
+
+static const char *
+library_suffix(void)
{
-#if 0
- return _eglstrdup("libEGLdri");
-#else
- char path[2000], driverName[2000];
- FILE *f;
- int length;
+ return ".dll";
+}
- snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card);
- f = fopen(path, "r");
- if (!f)
- return NULL;
+#elif defined(_EGL_OS_UNIX)
- fgets(driverName, sizeof(driverName), f);
- fclose(f);
- if ((length = strlen(driverName)) > 1) {
- /* remove the trailing newline from sysfs */
- driverName[length - 1] = '\0';
- strncat(driverName, "_dri", sizeof(driverName));
- return _eglstrdup(driverName);
- }
- else {
- return NULL;
- }
-#endif
-}
+static const char *DefaultDriverNames[] = {
+ "egl_dri2",
+ "egl_glx"
+};
+typedef void * lib_handle;
-/**
- * XXX this function is totally subject change!!!
- *
- *
- * Determine/return the path of the driver to use for the given native display.
- *
- * Try to be clever and determine if nativeDisplay is an Xlib Display
- * ptr or a string (naming a driver or screen number, etc).
- *
- * If the first character is ':' we interpret it as a screen or card index
- * number (i.e. ":0" or ":1", etc)
- * Else if the first character is '!' we interpret it as specific driver name
- * (i.e. "!r200" or "!i830".
- *
- * Whatever follows ':' is interpreted as arguments.
- *
- * The caller may free() the returned strings.
- */
-static char *
-_eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
+static void *
+open_library(const char *filename)
{
- char *path = NULL;
- const char *args = NULL;
-
- path = getenv("EGL_DRIVER");
- if (path)
- path = _eglstrdup(path);
-
-#if defined(_EGL_PLATFORM_X)
- (void) DefaultDriverName;
-
- if (!path && dpy->NativeDisplay) {
- const char *dpyString = (const char *) dpy->NativeDisplay;
- char *p;
- /* parse the display string */
- if (dpyString[0] == '!' || dpyString[0] == ':') {
- if (dpyString[0] == '!') {
- path = _eglstrdup(dpyString);
- p = strchr(path, ':');
- if (p)
- *p++ = '\0';
- } else {
- p = strchr(dpyString, ':');
- if (p)
- p++;
- }
+ return dlopen(filename, RTLD_LAZY);
+}
- if (p) {
- if (!path && p[0] >= '0' && p[0] <= '9' && !p[1]) {
- int card = atoi(p);
- path = (char *) _eglChooseDRMDriver(card);
- }
- args = p;
- }
- }
- else {
- path = (char *) _xeglChooseDriver(dpy);
- }
- }
-#elif defined(_EGL_PLATFORM_WINDOWS)
- if (!path)
- path = _eglstrdup(DefaultDriverName);
-#endif /* _EGL_PLATFORM_X */
+static void
+close_library(void *lib)
+{
+ dlclose(lib);
+}
- if (path && argsRet)
- *argsRet = (args) ? _eglstrdup(args) : NULL;
- return path;
+static const char *
+library_suffix(void)
+{
+ return ".so";
}
+#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().
*/
static _EGLMain_t
-_eglOpenLibrary(const char *driverName, lib_handle *handle)
+_eglOpenLibrary(const char *driverPath, lib_handle *handle)
{
- _EGLMain_t mainFunc;
lib_handle lib;
- char driverFilename[1000];
+ _EGLMain_t mainFunc = NULL;
+ const char *error = "unknown error";
- assert(driverName);
+ assert(driverPath);
-#if defined(_EGL_PLATFORM_WINDOWS)
-/* Use static linking on Windows for now */
-#ifdef WINDOWS_STATIC_LINK
- lib = 0;
- mainFunc = (_EGLMain_t)_eglMain;
-#else
+ _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+ lib = open_library(driverPath);
+
+#if defined(_EGL_OS_WINDOWS)
/* XXX untested */
- sprintf(driverFilename, "%s.dll", driverName);
- _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
- lib = open_library(driverFilename);
- if (!lib) {
- _eglLog(_EGL_WARNING, "Could not open %s",
- driverFilename);
- return NULL;
+ if (lib)
+ mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
+#elif defined(_EGL_OS_UNIX)
+ if (lib) {
+ union {
+ _EGLMain_t func;
+ void *ptr;
+ } tmp = { NULL };
+ /* direct cast gives a warning when compiled with -pedantic */
+ tmp.ptr = dlsym(lib, "_eglMain");
+ mainFunc = tmp.func;
+ if (!mainFunc)
+ error = dlerror();
+ }
+ else {
+ error = dlerror();
}
- mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
#endif
-#elif defined(_EGL_PLATFORM_X)
- /* XXX also prepend a directory path??? */
- sprintf(driverFilename, "%s.so", driverName);
- _eglLog(_EGL_DEBUG, "dlopen(%s)", driverFilename);
- lib = open_library(driverFilename);
+
if (!lib) {
- _eglLog(_EGL_WARNING, "Could not open %s (%s)",
- driverFilename, dlerror());
+ _eglLog(_EGL_WARNING, "Could not open driver %s (%s)",
+ driverPath, error);
+ if (!getenv("EGL_DRIVER"))
+ _eglLog(_EGL_WARNING,
+ "The driver can be overridden by setting EGL_DRIVER");
return NULL;
}
- mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
-#endif
if (!mainFunc) {
- _eglLog(_EGL_WARNING, "_eglMain not found in %s", driverFilename);
+ _eglLog(_EGL_WARNING, "_eglMain not found in %s (%s)",
+ driverPath, error);
if (lib)
close_library(lib);
return NULL;
/**
- * Load the named driver. The path and args passed will be
- * owned by the driver and freed.
+ * Load the named driver.
*/
static _EGLDriver *
-_eglLoadDriver(_EGLDisplay *dpy, char *path, char *args)
+_eglLoadDriver(const char *path, const char *args)
{
_EGLMain_t mainFunc;
lib_handle lib;
if (!mainFunc)
return NULL;
- drv = mainFunc(dpy, args);
+ drv = mainFunc(args);
if (!drv) {
if (lib)
close_library(lib);
drv->Name = "UNNAMED";
}
- drv->Path = path;
- drv->Args = args;
+ drv->Path = _eglstrdup(path);
+ drv->Args = (args) ? _eglstrdup(args) : NULL;
+ if (!drv->Path || (args && !drv->Args)) {
+ if (drv->Path)
+ free((char *) drv->Path);
+ if (drv->Args)
+ free((char *) drv->Args);
+ drv->Unload(drv);
+ if (lib)
+ close_library(lib);
+ return NULL;
+ }
+
drv->LibHandle = lib;
return drv;
/**
* Match a display to a preloaded driver.
+ *
+ * The matching is done by finding the driver with the highest score.
*/
-static _EGLDriver *
+_EGLDriver *
_eglMatchDriver(_EGLDisplay *dpy)
{
- _EGLDriver *defaultDriver = NULL;
- EGLint i;
+ _EGLDriver *best_drv = NULL;
+ EGLint best_score = -1, i;
+ /*
+ * this function is called after preloading and the drivers never change
+ * after preloading.
+ */
for (i = 0; i < _eglGlobal.NumDrivers; i++) {
_EGLDriver *drv = _eglGlobal.Drivers[i];
+ EGLint score;
- /* 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;
+ 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;
}
/**
- * Load a driver and save it.
+ * A loader function for use with _eglPreloadForEach. The loader data is the
+ * filename of the driver. This function stops on the first valid driver.
*/
-const char *
-_eglPreloadDriver(_EGLDisplay *dpy)
+static EGLBoolean
+_eglLoaderFile(const char *dir, size_t len, void *loader_data)
{
- char *path, *args;
_EGLDriver *drv;
- EGLint i;
+ char path[1024];
+ const char *filename = (const char *) loader_data;
+ size_t flen = strlen(filename);
+
+ /* make a full path */
+ if (len + flen + 2 > sizeof(path))
+ return EGL_TRUE;
+ if (len) {
+ memcpy(path, dir, len);
+ path[len++] = '/';
+ }
+ memcpy(path + len, filename, flen);
+ len += flen;
+ path[len] = '\0';
- path = _eglChooseDriver(dpy, &args);
- if (!path)
- return NULL;
+ if (library_suffix() == NULL || strstr(path, library_suffix()))
+ drv = _eglLoadDriver(path, NULL);
+ else {
+ const char *suffix = library_suffix();
+ size_t slen = strlen(suffix);
+ const char *p;
+ EGLBoolean need_suffix;
+
+ p = filename + flen - slen;
+ need_suffix = (p < filename || strcmp(p, suffix) != 0);
+ if (need_suffix && len + slen + 1 <= sizeof(path)) {
+ strcpy(path + len, suffix);
+ drv = _eglLoadDriver(path, NULL);
+ } else {
+ drv = NULL;
+ }
+ }
+ if (!drv)
+ return EGL_TRUE;
- for (i = 0; i < _eglGlobal.NumDrivers; i++) {
- drv = _eglGlobal.Drivers[i];
- if (strcmp(drv->Path, path) == 0) {
- _eglLog(_EGL_DEBUG, "Driver %s is already preloaded",
- drv->Name);
- free(path);
- if (args)
- free(args);
- return drv->Name;
+ /* remember the driver and stop */
+ _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+ return EGL_FALSE;
+}
+
+
+/**
+ * A loader function for use with _eglPreloadForEach. The loader data is the
+ * pattern (prefix) of the files to look for.
+ */
+static EGLBoolean
+_eglLoaderPattern(const char *dir, size_t len, void *loader_data)
+{
+#if defined(_EGL_OS_UNIX)
+ const char *prefix, *suffix;
+ size_t prefix_len, suffix_len;
+ DIR *dirp;
+ struct dirent *dirent;
+ char path[1024];
+
+ if (len + 2 > sizeof(path))
+ return EGL_TRUE;
+ if (len) {
+ memcpy(path, dir, len);
+ path[len++] = '/';
+ }
+ path[len] = '\0';
+
+ dirp = opendir(path);
+ if (!dirp)
+ return EGL_TRUE;
+
+ prefix = (const char *) loader_data;
+ prefix_len = strlen(prefix);
+ suffix = library_suffix();
+ suffix_len = (suffix) ? strlen(suffix) : 0;
+
+ while ((dirent = readdir(dirp))) {
+ _EGLDriver *drv;
+ size_t dirent_len = strlen(dirent->d_name);
+ const char *p;
+
+ /* match the prefix */
+ if (strncmp(dirent->d_name, prefix, prefix_len) != 0)
+ continue;
+ /* match the suffix */
+ if (suffix) {
+ p = dirent->d_name + dirent_len - suffix_len;
+ if (p < dirent->d_name || strcmp(p, suffix) != 0)
+ continue;
+ }
+
+ /* make a full path and load the driver */
+ if (len + dirent_len + 1 <= sizeof(path)) {
+ strcpy(path + len, dirent->d_name);
+ drv = _eglLoadDriver(path, NULL);
+ if (drv)
+ _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
}
}
- drv = _eglLoadDriver(dpy, path, args);
- if (!drv)
- return NULL;
+ closedir(dirp);
+
+ return EGL_TRUE;
+#else /* _EGL_OS_UNIX */
+ /* stop immediately */
+ return EGL_FALSE;
+#endif
+}
- /* update the global notion of supported APIs */
- _eglGlobal.ClientAPIsMask |= drv->ClientAPIsMask;
- _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+/**
+ * Run the preload function on each driver directory and return the number of
+ * drivers loaded.
+ *
+ * The process may end prematurely if the callback function returns false.
+ */
+static EGLint
+_eglPreloadForEach(const char *search_path,
+ EGLBoolean (*loader)(const char *, size_t, void *),
+ void *loader_data)
+{
+ const char *cur, *next;
+ size_t len;
+ EGLint num_drivers = _eglGlobal.NumDrivers;
+
+ cur = search_path;
+ while (cur) {
+ next = strchr(cur, ':');
+ len = (next) ? next - cur : strlen(cur);
+
+ if (!loader(cur, len, loader_data))
+ break;
+
+ cur = (next) ? next + 1 : NULL;
+ }
- return drv->Name;
+ return (_eglGlobal.NumDrivers - num_drivers);
}
/**
- * Open a preloaded driver.
+ * Return a list of colon-separated driver directories.
*/
-_EGLDriver *
-_eglOpenDriver(_EGLDisplay *dpy)
+static const char *
+_eglGetSearchPath(void)
{
- _EGLDriver *drv = _eglMatchDriver(dpy);
- return drv;
+ static const char *search_path;
+
+#if defined(_EGL_OS_UNIX) || defined(_EGL_OS_WINDOWS)
+ if (!search_path) {
+ static char buffer[1024];
+ const char *p;
+ int ret;
+
+ p = getenv("EGL_DRIVERS_PATH");
+#if defined(_EGL_OS_UNIX)
+ if (p && (geteuid() != getuid() || getegid() != getgid())) {
+ _eglLog(_EGL_DEBUG,
+ "ignore EGL_DRIVERS_PATH for setuid/setgid binaries");
+ p = NULL;
+ }
+#endif /* _EGL_OS_UNIX */
+
+ if (p) {
+ ret = _eglsnprintf(buffer, sizeof(buffer),
+ "%s:%s", p, _EGL_DRIVER_SEARCH_DIR);
+ if (ret > 0 && ret < sizeof(buffer))
+ search_path = buffer;
+ }
+ }
+ if (!search_path)
+ search_path = _EGL_DRIVER_SEARCH_DIR;
+#else
+ search_path = "";
+#endif
+
+ return search_path;
}
/**
- * Close a preloaded driver.
+ * Preload a user driver.
+ *
+ * A user driver can be specified by EGL_DRIVER.
*/
-EGLBoolean
-_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy)
+static EGLBoolean
+_eglPreloadUserDriver(void)
{
- _eglReleaseDisplayResources(drv, dpy);
- drv->API.Terminate(drv, dpy);
+ const char *search_path = _eglGetSearchPath();
+ char *env;
+
+ env = getenv("EGL_DRIVER");
+#if defined(_EGL_OS_UNIX)
+ if (env && strchr(env, '/')) {
+ search_path = "";
+ if ((geteuid() != getuid() || getegid() != getgid())) {
+ _eglLog(_EGL_DEBUG,
+ "ignore EGL_DRIVER for setuid/setgid binaries");
+ env = NULL;
+ }
+ }
+#endif /* _EGL_OS_UNIX */
+ if (!env)
+ return EGL_FALSE;
+
+ if (!_eglPreloadForEach(search_path, _eglLoaderFile, (void *) env)) {
+ _eglLog(_EGL_WARNING, "EGL_DRIVER is set to an invalid driver");
+ return EGL_FALSE;
+ }
+
return EGL_TRUE;
}
+/**
+ * Preload platform drivers.
+ *
+ * Platform drivers are a set of drivers that support a certain window system.
+ * The window system may be specified by EGL_PLATFORM.
+ *
+ * FIXME This makes libEGL a memory hog if an user driver is not specified and
+ * there are many platform drivers.
+ */
+static EGLBoolean
+_eglPreloadPlatformDrivers(void)
+{
+ const char *dpy;
+ char prefix[32];
+ int ret;
+
+ dpy = getenv("EGL_PLATFORM");
+ /* try deprecated env variable */
+ if (!dpy || !dpy[0])
+ dpy = getenv("EGL_DISPLAY");
+ if (!dpy || !dpy[0])
+ dpy = _EGL_DEFAULT_PLATFORM;
+ if (!dpy || !dpy[0])
+ return EGL_FALSE;
+
+ ret = _eglsnprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
+ if (ret < 0 || ret >= sizeof(prefix))
+ return EGL_FALSE;
+
+ return (_eglPreloadForEach(_eglGetSearchPath(),
+ _eglLoaderPattern, (void *) prefix) > 0);
+}
+
+
+/**
+ * Preload drivers.
+ *
+ * This function loads the driver modules and creates the corresponding
+ * _EGLDriver objects.
+ */
+EGLBoolean
+_eglPreloadDrivers(void)
+{
+ EGLBoolean loaded;
+
+ /* protect the preloading process */
+ _eglLockMutex(_eglGlobal.Mutex);
+
+ /* already preloaded */
+ if (_eglGlobal.NumDrivers) {
+ _eglUnlockMutex(_eglGlobal.Mutex);
+ return EGL_TRUE;
+ }
+
+ loaded = (_eglPreloadUserDriver() ||
+ _eglPreloadPlatformDrivers());
+
+ _eglUnlockMutex(_eglGlobal.Mutex);
+
+ return loaded;
+}
+
/**
* Unload preloaded drivers.
*/
_eglUnloadDrivers(void)
{
EGLint i;
+
+ /* this is called at atexit time */
for (i = 0; i < _eglGlobal.NumDrivers; i++) {
_EGLDriver *drv = _eglGlobal.Drivers[i];
lib_handle handle = drv->LibHandle;
_eglGlobal.NumDrivers = 0;
}
-
-/**
- * Given a display handle, return the _EGLDriver for that display.
- */
_EGLDriver *
-_eglLookupDriver(EGLDisplay dpy)
+_eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor)
{
- _EGLDisplay *d = _eglLookupDisplay(dpy);
- if (d)
- return d->Driver;
- else
- return NULL;
+ _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 _eglGlobal.NumDrivers > 0 ? drv : NULL;
}
drv->API.CopyBuffers = _eglCopyBuffers;
drv->API.QueryString = _eglQueryString;
- drv->API.WaitGL = _eglWaitGL;
+ drv->API.WaitClient = _eglWaitClient;
drv->API.WaitNative = _eglWaitNative;
#ifdef EGL_MESA_screen_surface
#ifdef EGL_VERSION_1_2
drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer;
#endif /* EGL_VERSION_1_2 */
+
+#ifdef EGL_KHR_image_base
+ drv->API.CreateImageKHR = _eglCreateImageKHR;
+ drv->API.DestroyImageKHR = _eglDestroyImageKHR;
+#endif /* EGL_KHR_image_base */
}
+/**
+ * Invoke a callback function on each EGL search path.
+ *
+ * The first argument of the callback function is the name of the search path.
+ * The second argument is the length of the name.
+ */
+void
+_eglSearchPathForEach(EGLBoolean (*callback)(const char *, size_t, void *),
+ void *callback_data)
+{
+ const char *search_path = _eglGetSearchPath();
+ _eglPreloadForEach(search_path, callback, callback_data);
+}
+
/**
- * Try to determine which EGL APIs (OpenGL, OpenGL ES, OpenVG, etc)
- * are supported on the system by looking for standard library names.
+ * 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.
*/
-EGLint
-_eglFindAPIs(void)
+void
+_eglSetProbeCache(EGLint key, const void *val)
{
- EGLint mask = 0x0;
- lib_handle lib;
-#if defined(_EGL_PLATFORM_WINDOWS)
- /* XXX not sure about these names */
- const char *es1_libname = "libGLESv1_CM.dll";
- const char *es2_libname = "libGLESv2.dll";
- const char *gl_libname = "OpenGL32.dll";
- const char *vg_libname = "libOpenVG.dll";
-#elif defined(_EGL_PLATFORM_X)
- const char *es1_libname = "libGLESv1_CM.so";
- const char *es2_libname = "libGLESv2.so";
- const char *gl_libname = "libGL.so";
- const char *vg_libname = "libOpenVG.so";
-#endif
+ EGLint idx;
- if ((lib = open_library(es1_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_ES_BIT;
+ 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);
- if ((lib = open_library(es2_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_ES2_BIT;
- }
+ _eglProbeCache.keys[idx] = key;
+ _eglProbeCache.values[idx] = val;
+}
- if ((lib = open_library(gl_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_BIT;
- }
- if ((lib = open_library(vg_libname))) {
- close_library(lib);
- mask |= EGL_OPENVG_BIT;
+/**
+ * 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 mask;
+ return (idx < NUM_PROBE_CACHE_SLOTS && _eglProbeCache.keys[idx] == key) ?
+ _eglProbeCache.values[idx] : NULL;
}