#include "eglscreen.h"
#include "eglstring.h"
#include "eglsurface.h"
+#include "eglimage.h"
#if defined(_EGL_PLATFORM_X)
#include <dlfcn.h>
-#include "eglx.h"
-#elif defined(_EGL_PLATFORM_WINDOWS)
-/* Use static linking on Windows for now */
-#define WINDOWS_STATIC_LINK
#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
- }
- static void
- close_library(HMODULE lib)
- {
-#ifdef WINDOWS_STATIC_LINK
-#else
- FreeLibrary(lib);
-#endif
- }
+
+/* XXX Need to decide how to do dynamic name lookup on Windows */
+static const char DefaultDriverName[] = "TBD";
+
+typedef HMODULE lib_handle;
+
+static HMODULE
+open_library(const char *filename)
+{
+ return LoadLibrary(filename);
+}
+
+static void
+close_library(HMODULE lib)
+{
+ FreeLibrary(lib);
+}
+
#elif defined(_EGL_PLATFORM_X)
- static const char *DefaultDriverName = ":0";
- static const char *SysFS = "/sys/class";
- typedef void * lib_handle;
- static void *
- open_library(const char *filename)
- {
- return dlopen(filename, RTLD_LAZY);
- }
+static const char DefaultDriverName[] = "egl_softpipe";
- static void
- close_library(void *lib)
- {
- dlclose(lib);
- }
-
-#endif
+typedef void * lib_handle;
-/**
- * Given a card number, use sysfs to determine the DRI driver name.
- */
-const char *
-_eglChooseDRMDriver(int card)
+static void *
+open_library(const char *filename)
{
-#if 0
- return _eglstrdup("libEGLdri");
-#else
- char path[2000], driverName[2000];
- FILE *f;
- int length;
+ return dlopen(filename, RTLD_LAZY);
+}
- snprintf(path, sizeof(path), "%s/drm/card%d/dri_library_name", SysFS, card);
+static void
+close_library(void *lib)
+{
+ dlclose(lib);
+}
- f = fopen(path, "r");
- if (!f)
- return NULL;
+#else /* _EGL_PLATFORM_NO_OS */
- fgets(driverName, sizeof(driverName), f);
- fclose(f);
+static const char DefaultDriverName[] = "builtin";
- 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
+typedef void *lib_handle;
+
+static INLINE void *
+open_library(const char *filename)
+{
+ return (void *) filename;
+}
+
+static INLINE void
+close_library(void *lib)
+{
}
+#endif
+
+
/**
- * 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.
- *
+ * Choose a driver for a given display.
* The caller may free() the returned strings.
*/
static char *
{
char *path = NULL;
const char *args = NULL;
+ const char *suffix = NULL;
+ const char *p;
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++;
- }
-
- 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);
- }
+ if (!path && dpy && dpy->NativeDisplay) {
+ /* assume (wrongly!) that the native display is a display string */
+ path = _eglSplitDisplayString((const char *) dpy->NativeDisplay, &args);
}
+ suffix = "so";
#elif defined(_EGL_PLATFORM_WINDOWS)
+ suffix = "dll";
+#else /* _EGL_PLATFORM_NO_OS */
+ if (path) {
+ /* force the use of the default driver */
+ _eglLog(_EGL_DEBUG, "ignore EGL_DRIVER");
+ free(path);
+ path = NULL;
+ }
+ suffix = NULL;
+#endif
+
if (!path)
path = _eglstrdup(DefaultDriverName);
-#endif /* _EGL_PLATFORM_X */
- if (path && argsRet)
+ /* append suffix if there isn't */
+ p = strrchr(path, '.');
+ if (!p && suffix) {
+ size_t len = strlen(path);
+ char *tmp = malloc(len + strlen(suffix) + 2);
+ if (tmp) {
+ memcpy(tmp, path, len);
+ tmp[len++] = '.';
+ tmp[len] = '\0';
+ strcat(tmp + len, suffix);
+
+ free(path);
+ path = tmp;
+ }
+ }
+
+ if (argsRet)
*argsRet = (args) ? _eglstrdup(args) : NULL;
return path;
* 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(driverPath);
- assert(driverName);
+ _eglLog(_EGL_DEBUG, "dlopen(%s)", driverPath);
+ lib = open_library(driverPath);
#if defined(_EGL_PLATFORM_WINDOWS)
-/* Use static linking on Windows for now */
-#ifdef WINDOWS_STATIC_LINK
- lib = 0;
- mainFunc = (_EGLMain_t)_eglMain;
-#else
/* 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_PLATFORM_X)
+ if (lib) {
+ mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
+ if (!mainFunc)
+ error = dlerror();
}
- mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
+ 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
-#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;
* owned by the driver and freed.
*/
static _EGLDriver *
-_eglLoadDriver(_EGLDisplay *dpy, char *path, char *args)
+_eglLoadDriver(char *path, 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 = _eglLoadDriver(dpy, path, args);
+ drv = _eglLoadDriver(path, args);
if (!drv)
return NULL;
- /* update the global notion of supported APIs */
- _eglGlobal.ClientAPIsMask |= drv->ClientAPIsMask;
-
_eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
return drv->Name;
EGLBoolean
_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy)
{
- _eglReleaseDisplayResources(drv, dpy);
- drv->API.Terminate(drv, dpy);
return EGL_TRUE;
}
#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 */
}
const char *es2_libname = "libGLESv2.so";
const char *gl_libname = "libGL.so";
const char *vg_libname = "libOpenVG.so";
+#else /* _EGL_PLATFORM_NO_OS */
+ const char *es1_libname = NULL;
+ const char *es2_libname = NULL;
+ const char *gl_libname = NULL;
+ const char *vg_libname = NULL;
#endif
if ((lib = open_library(es1_libname))) {