#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+
+#include "eglstring.h"
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldefines.h"
#include "eglsurface.h"
#include "eglimage.h"
-#if defined(_EGL_PLATFORM_POSIX)
+#if defined(_EGL_OS_UNIX)
#include <dlfcn.h>
#include <sys/types.h>
#include <dirent.h>
/**
* Wrappers for dlopen/dlclose()
*/
-#if defined(_EGL_PLATFORM_WINDOWS)
+#if defined(_EGL_OS_WINDOWS)
/* XXX Need to decide how to do dynamic name lookup on Windows */
-static const char DefaultDriverName[] = "TBD";
+static const char *DefaultDriverNames[] = {
+ "egl_gdi_swrast"
+};
typedef HMODULE lib_handle;
}
-#elif defined(_EGL_PLATFORM_POSIX)
+#elif defined(_EGL_OS_UNIX)
-static const char DefaultDriverName[] = "egl_glx";
+static const char *DefaultDriverNames[] = {
+ "egl_dri2",
+ "egl_glx"
+};
typedef void * lib_handle;
}
-#else /* _EGL_PLATFORM_NO_OS */
-
-
-static const char DefaultDriverName[] = "builtin";
-
-typedef void *lib_handle;
-
-static INLINE void *
-open_library(const char *filename)
-{
- return (void *) filename;
-}
-
-static INLINE void
-close_library(void *lib)
-{
-}
-
-
-static const char *
-library_suffix(void)
-{
- return NULL;
-}
-
-
#endif
_eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
lib = open_library(driverPath);
-#if defined(_EGL_PLATFORM_WINDOWS)
+#if defined(_EGL_OS_WINDOWS)
/* XXX untested */
if (lib)
mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
-#elif defined(_EGL_PLATFORM_POSIX)
+#elif defined(_EGL_OS_UNIX)
if (lib) {
union {
_EGLMain_t func;
else {
error = dlerror();
}
-#else /* _EGL_PLATFORM_NO_OS */
- /* must be the default driver name */
- if (strcmp(driverPath, DefaultDriverName) == 0)
- mainFunc = (_EGLMain_t) _eglMain;
- else
- error = "not builtin driver";
#endif
if (!lib) {
static EGLBoolean
_eglLoaderPattern(const char *dir, size_t len, void *loader_data)
{
-#if defined(_EGL_PLATFORM_POSIX)
+#if defined(_EGL_OS_UNIX)
const char *prefix, *suffix;
size_t prefix_len, suffix_len;
DIR *dirp;
closedir(dirp);
return EGL_TRUE;
-#else /* _EGL_PLATFORM_POSIX */
+#else /* _EGL_OS_UNIX */
/* stop immediately */
return EGL_FALSE;
#endif
{
static const char *search_path;
-#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS)
+#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_PLATFORM_POSIX)
+#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_PLATFORM_POSIX */
+#endif /* _EGL_OS_UNIX */
if (p) {
- ret = snprintf(buffer, sizeof(buffer),
+ ret = _eglsnprintf(buffer, sizeof(buffer),
"%s:%s", p, _EGL_DRIVER_SEARCH_DIR);
if (ret > 0 && ret < sizeof(buffer))
search_path = buffer;
char *env;
env = getenv("EGL_DRIVER");
-#if defined(_EGL_PLATFORM_POSIX)
+#if defined(_EGL_OS_UNIX)
if (env && strchr(env, '/')) {
search_path = "";
if ((geteuid() != getuid() || getegid() != getgid())) {
env = NULL;
}
}
-#endif /* _EGL_PLATFORM_POSIX */
+#endif /* _EGL_OS_UNIX */
if (!env)
return EGL_FALSE;
/**
- * Preload display drivers.
+ * Preload platform drivers.
*
- * Display drivers are a set of drivers that support a certain display system.
- * The display system may be specified by EGL_DISPLAY.
+ * 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 display drivers.
+ * there are many platform drivers.
*/
static EGLBoolean
-_eglPreloadDisplayDrivers(void)
+_eglPreloadPlatformDrivers(void)
{
const char *dpy;
char prefix[32];
int ret;
- dpy = getenv("EGL_DISPLAY");
+ dpy = getenv("EGL_PLATFORM");
+ /* try deprecated env variable */
if (!dpy || !dpy[0])
- dpy = _EGL_DEFAULT_DISPLAY;
+ dpy = getenv("EGL_DISPLAY");
+ if (!dpy || !dpy[0])
+ dpy = _EGL_DEFAULT_PLATFORM;
if (!dpy || !dpy[0])
return EGL_FALSE;
- ret = snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
+ ret = _eglsnprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
if (ret < 0 || ret >= sizeof(prefix))
return EGL_FALSE;
}
-/**
- * Preload the default driver.
- */
-static EGLBoolean
-_eglPreloadDefaultDriver(void)
-{
- return (_eglPreloadForEach(_eglGetSearchPath(),
- _eglLoaderFile, (void *) DefaultDriverName) > 0);
-}
-
-
/**
* Preload drivers.
*
}
loaded = (_eglPreloadUserDriver() ||
- _eglPreloadDisplayDrivers() ||
- _eglPreloadDefaultDriver());
+ _eglPreloadPlatformDrivers());
_eglUnlockMutex(_eglGlobal.Mutex);
return loaded;
}
-
/**
* Unload preloaded drivers.
*/
_eglGlobal.NumDrivers = 0;
}
+_EGLDriver *
+_eglLoadDefaultDriver(EGLDisplay dpy, EGLint *major, EGLint *minor)
+{
+ _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;
+}
+
+
+/**
+ * Return the native platform. It is the platform of the EGL native types.
+ */
+_EGLPlatformType
+_eglGetNativePlatform(void)
+{
+ return _EGL_NATIVE_PLATFORM;
+}
+
/**
* Plug all the available fallback routines into the given driver's