summaryrefslogtreecommitdiff
path: root/src/egl/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/egl/main')
-rw-r--r--src/egl/main/Makefile32
-rw-r--r--src/egl/main/eglapi.c9
-rw-r--r--src/egl/main/eglapi.h2
-rw-r--r--src/egl/main/eglcompiler.h29
-rw-r--r--src/egl/main/eglconfig.c1
-rw-r--r--src/egl/main/eglconfig.h14
-rw-r--r--src/egl/main/eglconfigutil.h6
-rw-r--r--src/egl/main/eglcontext.h4
-rw-r--r--src/egl/main/eglcurrent.h10
-rw-r--r--src/egl/main/egldisplay.c36
-rw-r--r--src/egl/main/egldisplay.h9
-rw-r--r--src/egl/main/egldriver.c384
-rw-r--r--src/egl/main/egldriver.h46
-rw-r--r--src/egl/main/egllog.h6
-rw-r--r--src/egl/main/eglmode.h2
-rw-r--r--src/egl/main/eglscreen.h6
-rw-r--r--src/egl/main/eglsurface.h2
17 files changed, 375 insertions, 223 deletions
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index c951b070f1..66f8f01b8e 100644
--- a/src/egl/main/Makefile
+++ b/src/egl/main/Makefile
@@ -4,7 +4,10 @@ TOP = ../../..
include $(TOP)/configs/current
-INCLUDE_DIRS = -I$(TOP)/include -I$(TOP)/src/mesa/glapi $(X11_INCLUDES)
+EGL_MAJOR = 1
+EGL_MINOR = 0
+
+INCLUDE_DIRS = -I$(TOP)/include
HEADERS = \
eglcompiler.h \
@@ -43,9 +46,14 @@ SOURCES = \
OBJECTS = $(SOURCES:.c=.o)
-# Undefined for now
-LOCAL_CFLAGS = -D_EGL_PLATFORM_X=1
+# use dl*() to load drivers
+LOCAL_CFLAGS = -D_EGL_PLATFORM_POSIX=1
+
+EGL_DEFAULT_DISPLAY = $(word 1, $(EGL_DISPLAYS))
+LOCAL_CFLAGS += \
+ -D_EGL_DEFAULT_DISPLAY=\"$(EGL_DEFAULT_DISPLAY)\" \
+ -D_EGL_DRIVER_SEARCH_DIR=\"$(DRI_DRIVER_SEARCH_DIR)\"
.c.o:
$(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@
@@ -56,21 +64,21 @@ default: depend library
# EGL Library
-library: $(TOP)/$(LIB_DIR)/libEGL.so
+library: $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME)
-$(TOP)/$(LIB_DIR)/libEGL.so: $(OBJECTS)
- $(MKLIB) -o EGL -linker '$(CC)' -ldflags '$(LDFLAGS)' \
- -major 1 -minor 0 \
- -install $(TOP)/$(LIB_DIR) \
+$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS)
+ $(MKLIB) -o $(EGL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+ -major $(EGL_MAJOR) -minor $(EGL_MINOR) \
+ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
$(EGL_LIB_DEPS) $(OBJECTS)
install: default
$(INSTALL) -d $(DESTDIR)$(INSTALL_LIB_DIR)
- $(MINSTALL) $(TOP)/$(LIB_DIR)/libEGL.so* $(DESTDIR)$(INSTALL_LIB_DIR)
+ $(MINSTALL) $(TOP)/$(LIB_DIR)/$(EGL_LIB_GLOB) \
+ $(DESTDIR)$(INSTALL_LIB_DIR)
clean:
- -rm -f *.o *.so*
- -rm -f core.*
+ -rm -f *.o
-rm -f depend depend.bak
@@ -82,5 +90,5 @@ depend: $(SOURCES) $(HEADERS)
$(SOURCES) $(HEADERS) > /dev/null 2>/dev/null
-include depend
+-include depend
# DO NOT DELETE
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 14cc5fa613..6e8f444d7f 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -101,6 +101,8 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
drv = disp->Driver;
if (!drv) {
+ _eglPreloadDrivers();
+
drv = _eglOpenDriver(disp);
if (!drv)
return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__);
@@ -710,13 +712,12 @@ void (* EGLAPIENTRY eglGetProcAddress(const char *procname))()
}
}
- /* preload a driver if there isn't one */
- if (!_eglGlobal.NumDrivers)
- _eglPreloadDriver(NULL);
+ _eglPreloadDrivers();
/* now loop over drivers to query their procs */
for (i = 0; i < _eglGlobal.NumDrivers; i++) {
- _EGLProc p = _eglGlobal.Drivers[i]->API.GetProcAddress(procname);
+ _EGLDriver *drv = _eglGlobal.Drivers[i];
+ _EGLProc p = drv->API.GetProcAddress(drv, procname);
if (p)
return p;
}
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index aa0abe3eb6..080f2155e3 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -44,7 +44,7 @@ typedef const char *(*QueryString_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint n
typedef EGLBoolean (*WaitClient_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx);
typedef EGLBoolean (*WaitNative_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine);
-typedef _EGLProc (*GetProcAddress_t)(const char *procname);
+typedef _EGLProc (*GetProcAddress_t)(_EGLDriver *drv, const char *procname);
diff --git a/src/egl/main/eglcompiler.h b/src/egl/main/eglcompiler.h
index 6b639b75c6..d844fbb0ef 100644
--- a/src/egl/main/eglcompiler.h
+++ b/src/egl/main/eglcompiler.h
@@ -61,4 +61,33 @@
#endif
+/**
+ * Function visibility
+ */
+#if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 303) \
+ || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590))
+# define PUBLIC __attribute__((visibility("default")))
+#else
+# define PUBLIC
+#endif
+
+/**
+ * The __FUNCTION__ gcc variable is generally only used for debugging.
+ * If we're not using gcc, define __FUNCTION__ as a cpp symbol here.
+ * Don't define it if using a newer Windows compiler.
+ */
+#ifndef __FUNCTION__
+# if defined(__VMS)
+# define __FUNCTION__ "VMS$NL:"
+# elif ((!defined __GNUC__) || (__GNUC__ < 2)) && (!defined __xlC__) && \
+ (!defined(_MSC_VER) || _MSC_VER < 1300)
+# if (__STDC_VERSION__ >= 199901L) /* C99 */ || \
+ (defined(__SUNPRO_C) && defined(__C99FEATURES__))
+# define __FUNCTION__ __func__
+# else
+# define __FUNCTION__ "<unknown>"
+# endif
+# endif
+#endif
+
#endif /* EGLCOMPILER_INCLUDED */
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index 31d69a7708..4d149603ae 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -324,6 +324,7 @@ _eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching)
mask = EGL_PBUFFER_BIT |
EGL_PIXMAP_BIT |
EGL_WINDOW_BIT |
+ EGL_SCREEN_BIT_MESA | /* XXX should check the extension */
EGL_VG_COLORSPACE_LINEAR_BIT |
EGL_VG_ALPHA_FORMAT_PRE_BIT |
EGL_MULTISAMPLE_RESOLVE_BOX_BIT |
diff --git a/src/egl/main/eglconfig.h b/src/egl/main/eglconfig.h
index 6b8a259984..799bf4ee24 100644
--- a/src/egl/main/eglconfig.h
+++ b/src/egl/main/eglconfig.h
@@ -91,11 +91,11 @@ _eglSetConfigAttrib(_EGLConfig *conf, EGLint attr, EGLint val)
}
-extern void
+PUBLIC void
_eglInitConfig(_EGLConfig *config, EGLint id);
-extern EGLConfig
+PUBLIC EGLConfig
_eglAddConfig(_EGLDisplay *dpy, _EGLConfig *conf);
@@ -144,24 +144,24 @@ _eglGetConfigHandle(_EGLConfig *conf)
}
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglValidateConfig(const _EGLConfig *conf, EGLBoolean for_matching);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglMatchConfig(const _EGLConfig *conf, const _EGLConfig *criteria);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglParseConfigAttribList(_EGLConfig *conf, const EGLint *attrib_list);
-extern EGLint
+PUBLIC EGLint
_eglCompareConfigs(const _EGLConfig *conf1, const _EGLConfig *conf2,
const _EGLConfig *criteria, EGLBoolean compare_id);
-extern void
+PUBLIC void
_eglSortConfigs(const _EGLConfig **configs, EGLint count,
EGLint (*compare)(const _EGLConfig *, const _EGLConfig *,
void *),
diff --git a/src/egl/main/eglconfigutil.h b/src/egl/main/eglconfigutil.h
index 8c923ee206..9f8906dedb 100644
--- a/src/egl/main/eglconfigutil.h
+++ b/src/egl/main/eglconfigutil.h
@@ -7,16 +7,16 @@
#include "eglconfig.h"
-extern void
+PUBLIC void
_eglConfigToContextModesRec(const _EGLConfig *config, __GLcontextModes *mode);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m,
EGLint conformant, EGLint renderable_type);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglFillInConfigs( _EGLConfig *configs,
EGLenum fb_format, EGLenum fb_type,
const uint8_t * depth_bits, const uint8_t * stencil_bits,
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 45c7b4717b..cb9e3f4a89 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -30,7 +30,7 @@ struct _egl_context
};
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglInitContext(_EGLDriver *drv, _EGLContext *ctx,
_EGLConfig *config, const EGLint *attrib_list);
@@ -47,7 +47,7 @@ extern EGLBoolean
_eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw, _EGLSurface *read, _EGLContext *ctx);
diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h
index 9503e0aba0..c4478b3891 100644
--- a/src/egl/main/eglcurrent.h
+++ b/src/egl/main/eglcurrent.h
@@ -60,7 +60,7 @@ _eglConvertApiFromIndex(EGLint idx)
}
-extern _EGLThreadInfo *
+PUBLIC _EGLThreadInfo *
_eglGetCurrentThread(void);
@@ -72,19 +72,19 @@ extern EGLBoolean
_eglIsCurrentThreadDummy(void);
-extern _EGLContext *
+PUBLIC _EGLContext *
_eglGetCurrentContext(void);
-extern _EGLDisplay *
+PUBLIC _EGLDisplay *
_eglGetCurrentDisplay(void);
-extern _EGLSurface *
+PUBLIC _EGLSurface *
_eglGetCurrentSurface(EGLint readdraw);
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglError(EGLint errCode, const char *msg);
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 896d60dbe1..eb82af4884 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -40,36 +40,6 @@ _eglFiniDisplay(void)
/**
- * 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 driver name.
- */
-char *
-_eglSplitDisplayString(const char *dpyString, const char **args)
-{
- char *drv, *p;
-
- if (!dpyString || dpyString[0] != '!')
- return NULL;
- drv = _eglstrdup(dpyString + 1);
- if (!drv)
- return NULL;
-
- p = strchr(dpyString, ':');
- if (p) {
- drv[p - dpyString] = '\0';
- p++;
- }
- if (args)
- *args = p;
-
- return drv;
-}
-
-
-/**
* Allocate a new _EGLDisplay object for the given nativeDisplay handle.
* We'll also try to determine the device driver name at this time.
*
@@ -81,12 +51,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay)
_EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
if (dpy) {
dpy->NativeDisplay = nativeDisplay;
-
- dpy->DriverName = _eglPreloadDriver(dpy);
- if (!dpy->DriverName) {
- free(dpy);
- return NULL;
- }
}
return dpy;
}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index ea4e35a8b3..a69813196f 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 */
@@ -58,10 +57,6 @@ extern void
_eglFiniDisplay(void);
-extern char *
-_eglSplitDisplayString(const char *dpyString, const char **args);
-
-
extern _EGLDisplay *
_eglNewDisplay(NativeDisplayType displayName);
@@ -78,11 +73,11 @@ extern _EGLDisplay *
_eglFindDisplay(NativeDisplayType nativeDisplay);
-extern void
+PUBLIC void
_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
-extern void
+PUBLIC void
_eglCleanupDisplay(_EGLDisplay *disp);
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 018b06d3be..f890df1bb1 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -20,8 +20,10 @@
#include "eglstring.h"
#include "eglsurface.h"
-#if defined(_EGL_PLATFORM_X)
+#if defined(_EGL_PLATFORM_POSIX)
#include <dlfcn.h>
+#include <sys/types.h>
+#include <dirent.h>
#endif
@@ -49,10 +51,17 @@ close_library(HMODULE lib)
}
-#elif defined(_EGL_PLATFORM_X)
+static const char *
+library_suffix(void)
+{
+ return "dll";
+}
+
+#elif defined(_EGL_PLATFORM_POSIX)
-static const char DefaultDriverName[] = "egl_softpipe";
+
+static const char DefaultDriverName[] = "egl_glx";
typedef void * lib_handle;
@@ -68,6 +77,14 @@ close_library(void *lib)
dlclose(lib);
}
+
+static const char *
+library_suffix(void)
+{
+ return "so";
+}
+
+
#else /* _EGL_PLATFORM_NO_OS */
static const char DefaultDriverName[] = "builtin";
@@ -86,67 +103,21 @@ close_library(void *lib)
}
-#endif
-
-
-/**
- * Choose a driver for a given display.
- * The caller may free() the returned strings.
- */
-static char *
-_eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
+static const char *
+library_suffix(void)
{
- 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)
- 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);
+ return NULL;
+}
- /* 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;
- }
- }
+#endif
- if (argsRet)
- *argsRet = (args) ? _eglstrdup(args) : NULL;
- return path;
-}
+#define NUM_PROBE_CACHE_SLOTS 8
+static struct {
+ EGLint keys[NUM_PROBE_CACHE_SLOTS];
+ const void *values[NUM_PROBE_CACHE_SLOTS];
+} _eglProbeCache;
/**
@@ -168,7 +139,7 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
/* XXX untested */
if (lib)
mainFunc = (_EGLMain_t) GetProcAddress(lib, "_eglMain");
-#elif defined(_EGL_PLATFORM_X)
+#elif defined(_EGL_PLATFORM_POSIX)
if (lib) {
mainFunc = (_EGLMain_t) dlsym(lib, "_eglMain");
if (!mainFunc)
@@ -208,11 +179,10 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
/**
- * Load the named driver. The path and args passed will be
- * owned by the driver and freed.
+ * Load the named driver.
*/
static _EGLDriver *
-_eglLoadDriver(char *path, char *args)
+_eglLoadDriver(const char *path, const char *args)
{
_EGLMain_t mainFunc;
lib_handle lib;
@@ -234,8 +204,19 @@ _eglLoadDriver(char *path, char *args)
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;
@@ -244,93 +225,221 @@ _eglLoadDriver(char *path, 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;
}
/**
- * Load a driver and save it.
+ * Open a preloaded driver.
*/
-const char *
-_eglPreloadDriver(_EGLDisplay *dpy)
+_EGLDriver *
+_eglOpenDriver(_EGLDisplay *dpy)
{
- char *path, *args;
+ _EGLDriver *drv = _eglMatchDriver(dpy);
+ return drv;
+}
+
+
+/**
+ * Close a preloaded driver.
+ */
+EGLBoolean
+_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy)
+{
+ return EGL_TRUE;
+}
+
+
+/**
+ * Preload a user driver.
+ *
+ * A user driver can be specified by EGL_DRIVER.
+ */
+static EGLBoolean
+_eglPreloadUserDriver(void)
+{
+#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS)
_EGLDriver *drv;
- EGLint i;
+ char *env, *path;
+ const char *suffix, *p;
- path = _eglChooseDriver(dpy, &args);
- if (!path)
- return NULL;
+ env = getenv("EGL_DRIVER");
+ if (!env)
+ return EGL_FALSE;
- 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;
+ path = env;
+ suffix = library_suffix();
+
+ /* 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);
+
+ path = tmp;
}
}
- drv = _eglLoadDriver(path, args);
+ drv = _eglLoadDriver(path, NULL);
+ if (path != env)
+ free(path);
if (!drv)
- return NULL;
+ return EGL_FALSE;
_eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
- return drv->Name;
+ return EGL_TRUE;
+#else /* _EGL_PLATFORM_POSIX || _EGL_PLATFORM_WINDOWS */
+ return EGL_FALSE;
+#endif
}
/**
- * Open a preloaded driver.
+ * Preload display drivers.
+ *
+ * Display drivers are a set of drivers that support a certain display system.
+ * The display system may be specified by EGL_DISPLAY.
+ *
+ * FIXME This makes libEGL a memory hog if an user driver is not specified and
+ * there are many display drivers.
*/
-_EGLDriver *
-_eglOpenDriver(_EGLDisplay *dpy)
+static EGLBoolean
+_eglPreloadDisplayDrivers(void)
{
- _EGLDriver *drv = _eglMatchDriver(dpy);
- return drv;
+#if defined(_EGL_PLATFORM_POSIX)
+ const char *dpy, *suffix;
+ char path[1024], prefix[32];
+ DIR *dirp;
+ struct dirent *dirent;
+
+ dpy = getenv("EGL_DISPLAY");
+ if (!dpy || !dpy[0])
+ dpy = _EGL_DEFAULT_DISPLAY;
+ if (!dpy || !dpy[0])
+ return EGL_FALSE;
+
+ snprintf(prefix, sizeof(prefix), "egl_%s_", dpy);
+ suffix = library_suffix();
+
+ dirp = opendir(_EGL_DRIVER_SEARCH_DIR);
+ if (!dirp)
+ return EGL_FALSE;
+
+ while ((dirent = readdir(dirp))) {
+ _EGLDriver *drv;
+ const char *p;
+
+ /* match the prefix */
+ if (strncmp(dirent->d_name, prefix, strlen(prefix)) != 0)
+ continue;
+
+ /* match the suffix */
+ p = strrchr(dirent->d_name, '.');
+ if ((p && !suffix) || (!p && suffix))
+ continue;
+ else if (p && suffix && strcmp(p + 1, suffix) != 0)
+ continue;
+
+ snprintf(path, sizeof(path),
+ _EGL_DRIVER_SEARCH_DIR"/%s", dirent->d_name);
+
+ drv = _eglLoadDriver(path, NULL);
+ if (drv)
+ _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+ }
+
+ closedir(dirp);
+
+ return (_eglGlobal.NumDrivers > 0);
+#else /* _EGL_PLATFORM_POSIX */
+ return EGL_FALSE;
+#endif
}
/**
- * Close a preloaded driver.
+ * Preload the default driver.
*/
-EGLBoolean
-_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy)
+static EGLBoolean
+_eglPreloadDefaultDriver(void)
{
+ _EGLDriver *drv;
+ char path[1024];
+ const char *suffix = library_suffix();
+
+ if (suffix)
+ snprintf(path, sizeof(path), "%s.%s", DefaultDriverName, suffix);
+ else
+ snprintf(path, sizeof(path), DefaultDriverName);
+
+ drv = _eglLoadDriver(path, NULL);
+ if (!drv)
+ return EGL_FALSE;
+
+ _eglGlobal.Drivers[_eglGlobal.NumDrivers++] = drv;
+
return EGL_TRUE;
}
/**
+ * Preload drivers.
+ *
+ * This function loads the driver modules and creates the corresponding
+ * _EGLDriver objects.
+ */
+EGLBoolean
+_eglPreloadDrivers(void)
+{
+ EGLBoolean loaded;
+
+ /* already preloaded */
+ if (_eglGlobal.NumDrivers)
+ return EGL_TRUE;
+
+ loaded = (_eglPreloadUserDriver() ||
+ _eglPreloadDisplayDrivers() ||
+ _eglPreloadDefaultDriver());
+
+ return loaded;
+}
+
+
+/**
* Unload preloaded drivers.
*/
void
@@ -360,20 +469,6 @@ _eglUnloadDrivers(void)
/**
- * Given a display handle, return the _EGLDriver for that display.
- */
-_EGLDriver *
-_eglLookupDriver(EGLDisplay dpy)
-{
- _EGLDisplay *d = _eglLookupDisplay(dpy);
- if (d)
- return d->Driver;
- else
- return NULL;
-}
-
-
-/**
* Plug all the available fallback routines into the given driver's
* dispatch table.
*/
@@ -447,7 +542,7 @@ _eglFindAPIs(void)
const char *es2_libname = "libGLESv2.dll";
const char *gl_libname = "OpenGL32.dll";
const char *vg_libname = "libOpenVG.dll";
-#elif defined(_EGL_PLATFORM_X)
+#elif defined(_EGL_PLATFORM_POSIX)
const char *es1_libname = "libGLESv1_CM.so";
const char *es2_libname = "libGLESv2.so";
const char *gl_libname = "libGL.so";
@@ -481,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 6c848eb35e..d9d61297c1 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -16,20 +16,30 @@ 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 */
};
-extern _EGLDriver *_eglMain(const char *args);
-
-
-extern const char *
-_eglPreloadDriver(_EGLDisplay *dpy);
+PUBLIC _EGLDriver *
+_eglMain(const char *args);
extern _EGLDriver *
@@ -40,20 +50,28 @@ extern EGLBoolean
_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy);
-void
-_eglUnloadDrivers(void);
+extern EGLBoolean
+_eglPreloadDrivers(void);
-extern _EGLDriver *
-_eglLookupDriver(EGLDisplay d);
+extern void
+_eglUnloadDrivers(void);
-extern void
+PUBLIC void
_eglInitDriverFallbacks(_EGLDriver *drv);
-extern EGLint
+PUBLIC EGLint
_eglFindAPIs(void);
+PUBLIC void
+_eglSetProbeCache(EGLint key, const void *val);
+
+
+PUBLIC const void *
+_eglGetProbeCache(EGLint key);
+
+
#endif /* EGLDRIVER_INCLUDED */
diff --git a/src/egl/main/egllog.h b/src/egl/main/egllog.h
index 83c8bb72a6..3a99bfea4b 100644
--- a/src/egl/main/egllog.h
+++ b/src/egl/main/egllog.h
@@ -12,15 +12,15 @@
typedef void (*_EGLLogProc)(EGLint level, const char *msg);
-extern void
+PUBLIC void
_eglSetLogProc(_EGLLogProc logger);
-extern void
+PUBLIC void
_eglSetLogLevel(EGLint level);
-extern void
+PUBLIC void
_eglLog(EGLint level, const char *fmtStr, ...);
diff --git a/src/egl/main/eglmode.h b/src/egl/main/eglmode.h
index af7c2c56d3..a089a5e194 100644
--- a/src/egl/main/eglmode.h
+++ b/src/egl/main/eglmode.h
@@ -29,7 +29,7 @@ extern _EGLMode *
_eglLookupMode(EGLModeMESA mode, _EGLDisplay *dpy);
-extern _EGLMode *
+PUBLIC _EGLMode *
_eglAddNewMode(_EGLScreen *screen, EGLint width, EGLint height,
EGLint refreshRate, const char *name);
diff --git a/src/egl/main/eglscreen.h b/src/egl/main/eglscreen.h
index 8860a2aa7f..d52e5388c3 100644
--- a/src/egl/main/eglscreen.h
+++ b/src/egl/main/eglscreen.h
@@ -30,7 +30,7 @@ extern EGLScreenMESA
_eglAllocScreenHandle(void);
-extern void
+PUBLIC void
_eglInitScreen(_EGLScreen *screen);
@@ -38,7 +38,7 @@ extern _EGLScreen *
_eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *dpy);
-extern void
+PUBLIC void
_eglAddScreen(_EGLDisplay *display, _EGLScreen *screen);
@@ -83,7 +83,7 @@ extern void
_eglDestroyScreenModes(_EGLScreen *scrn);
-extern void
+PUBLIC void
_eglDestroyScreen(_EGLScreen *scrn);
diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h
index b75fa9c368..dacdf7e63c 100644
--- a/src/egl/main/eglsurface.h
+++ b/src/egl/main/eglsurface.h
@@ -40,7 +40,7 @@ struct _egl_surface
};
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
_EGLConfig *config, const EGLint *attrib_list);