diff options
Diffstat (limited to 'src/egl')
-rw-r--r-- | src/egl/Makefile | 2 | ||||
-rw-r--r-- | src/egl/drivers/Makefile.template | 30 | ||||
-rw-r--r-- | src/egl/drivers/dri2/Makefile | 5 | ||||
-rw-r--r-- | src/egl/drivers/dri2/egl_dri2.c | 2 | ||||
-rw-r--r-- | src/egl/drivers/glx/Makefile | 5 | ||||
-rw-r--r-- | src/egl/drivers/glx/egl_glx.c | 2 | ||||
-rw-r--r-- | src/egl/main/Makefile | 16 | ||||
-rw-r--r-- | src/egl/main/egldriver.c | 135 | ||||
-rw-r--r-- | src/egl/main/egldriver.h | 8 |
9 files changed, 106 insertions, 99 deletions
diff --git a/src/egl/Makefile b/src/egl/Makefile index 5b09e178c63..50f227f07da 100644 --- a/src/egl/Makefile +++ b/src/egl/Makefile @@ -3,7 +3,7 @@ TOP = ../.. include $(TOP)/configs/current -SUBDIRS = main drivers +SUBDIRS = drivers main default: subdirs diff --git a/src/egl/drivers/Makefile.template b/src/egl/drivers/Makefile.template index 47709e3c59f..76dbe260c6b 100644 --- a/src/egl/drivers/Makefile.template +++ b/src/egl/drivers/Makefile.template @@ -2,6 +2,7 @@ # # Drivers should define # +# EGL_BUILTIN, the driver is built-in or external # EGL_DRIVER, the driver name # EGL_SOURCES, the driver sources # EGL_INCLUDES, the include pathes @@ -12,32 +13,45 @@ # -EGL_DRIVER_PATH = $(TOP)/$(LIB_DIR)/egl/$(EGL_DRIVER) +EGL_DRIVER_PATH = $(TOP)/$(LIB_DIR)/egl/$(EGL_DRIVER).so EGL_OBJECTS = $(EGL_SOURCES:.c=.o) +# built-in or external +ifeq ($(EGL_BUILTIN),true) +EGL_TARGET = lib$(EGL_DRIVER).a +EGL_INSTALL = +else +EGL_TARGET = $(EGL_DRIVER_PATH) +EGL_INSTALL = install-so +endif -default: depend $(EGL_DRIVER_PATH) +default: depend $(EGL_TARGET) -$(EGL_DRIVER_PATH): $(EGL_DRIVER) +$(EGL_DRIVER_PATH): $(EGL_DRIVER).so @$(INSTALL) -d $(TOP)/$(LIB_DIR)/egl $(INSTALL) $< $(TOP)/$(LIB_DIR)/egl -$(EGL_DRIVER): $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template - @$(MKLIB) -o $(EGL_DRIVER) -noprefix \ +$(EGL_DRIVER).so: $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template + @$(MKLIB) -o $(EGL_DRIVER).so -noprefix \ -linker '$(CC)' -ldflags '-L$(TOP)/$(LIB_DIR) $(LDFLAGS)' \ $(MKLIB_OPTIONS) \ $(EGL_OBJECTS) $(EGL_LIBS) -l$(EGL_LIB) +lib$(EGL_DRIVER).a: $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template + @$(MKLIB) -o $(EGL_DRIVER) -static $(EGL_OBJECTS) + .c.o: $(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@ - -install: $(EGL_DRIVER_PATH) +install-so: $(EGL_DRIVER_PATH) $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) $(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) +install: $(EGL_INSTALL) + clean: - rm -f $(EGL_DRIVER) + rm -f $(EGL_DRIVER).so + rm -f lib$(EGL_DRIVER).a rm -f $(EGL_OBJECTS) rm -f depend depend.bak diff --git a/src/egl/drivers/dri2/Makefile b/src/egl/drivers/dri2/Makefile index ec4d1bcd9be..553ee8771f8 100644 --- a/src/egl/drivers/dri2/Makefile +++ b/src/egl/drivers/dri2/Makefile @@ -3,7 +3,7 @@ TOP = ../../../.. include $(TOP)/configs/current -EGL_DRIVER = egl_dri2.so +EGL_DRIVER = egl_dri2 EGL_SOURCES = egl_dri2.c EGL_INCLUDES = \ @@ -17,4 +17,7 @@ EGL_INCLUDES = \ EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) +EGL_CFLAGS = -D_EGL_MAIN=_eglBuiltInDriverDRI2 +EGL_BUILTIN = true + include ../Makefile.template diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 52232980207..8967969c924 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -2372,7 +2372,7 @@ dri2_load(_EGLDriver *drv) * Create a new _EGLDriver object and init its dispatch table. */ _EGLDriver * -_eglMain(const char *args) +_EGL_MAIN(const char *args) { struct dri2_egl_driver *dri2_drv; diff --git a/src/egl/drivers/glx/Makefile b/src/egl/drivers/glx/Makefile index 89981e6c3a7..a1e6b731fe9 100644 --- a/src/egl/drivers/glx/Makefile +++ b/src/egl/drivers/glx/Makefile @@ -3,7 +3,7 @@ TOP = ../../../.. include $(TOP)/configs/current -EGL_DRIVER = egl_glx.so +EGL_DRIVER = egl_glx EGL_SOURCES = egl_glx.c EGL_INCLUDES = \ @@ -13,4 +13,7 @@ EGL_INCLUDES = \ EGL_CFLAGS = $(X11_CFLAGS) EGL_LIBS = $(X11_LIBS) $(DLOPEN_LIBS) +EGL_CFLAGS += -D_EGL_MAIN=_eglBuiltInDriverGLX +EGL_BUILTIN = true + include ../Makefile.template diff --git a/src/egl/drivers/glx/egl_glx.c b/src/egl/drivers/glx/egl_glx.c index db9109dacc5..5fce06d66df 100644 --- a/src/egl/drivers/glx/egl_glx.c +++ b/src/egl/drivers/glx/egl_glx.c @@ -1115,7 +1115,7 @@ fail: * Create a new _EGLDriver object and init its dispatch table. */ _EGLDriver * -_eglMain(const char *args) +_EGL_MAIN(const char *args) { struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver); diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile index b4ca20c094a..0eb309c1969 100644 --- a/src/egl/main/Makefile +++ b/src/egl/main/Makefile @@ -52,6 +52,19 @@ OBJECTS = $(SOURCES:.c=.o) # use dl*() to load drivers LOCAL_CFLAGS = -D_EGL_OS_UNIX=1 +LOCAL_LIBS = + +# egl_dri2 and egl_glx are built-ins +ifeq ($(filter dri2, $(EGL_DRIVERS_DIRS)),dri2) +LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_DRI2 +LOCAL_LIBS += $(TOP)/src/egl/drivers/dri2/libegl_dri2.a +EGL_LIB_DEPS += $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) +endif +ifeq ($(filter glx, $(EGL_DRIVERS_DIRS)),glx) +LOCAL_CFLAGS += -D_EGL_BUILT_IN_DRIVER_GLX +LOCAL_LIBS += $(TOP)/src/egl/drivers/glx/libegl_glx.a +EGL_LIB_DEPS += $(X11_LIBS) $(DLOPEN_LIBS) +endif # translate --with-egl-platforms to _EGLPlatformType EGL_NATIVE_PLATFORM=_EGL_INVALID_PLATFORM @@ -84,7 +97,8 @@ $(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) + -L$(TOP)/$(LIB_DIR) $(EGL_LIB_DEPS) \ + $(OBJECTS) $(LOCAL_LIBS) install-headers: $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c index e5d8a39a4c8..62c56955134 100644 --- a/src/egl/main/egldriver.c +++ b/src/egl/main/egldriver.c @@ -25,6 +25,7 @@ typedef struct _egl_module { char *Path; + _EGLMain_t BuiltIn; void *Handle; _EGLDriver *Driver; } _EGLModule; @@ -32,6 +33,18 @@ typedef struct _egl_module { static _EGL_DECLARE_MUTEX(_eglModuleMutex); static _EGLArray *_eglModules; +const struct { + const char *name; + _EGLMain_t main; +} _eglBuiltInDrivers[] = { +#ifdef _EGL_BUILT_IN_DRIVER_DRI2 + { "egl_dri2", _eglBuiltInDriverDRI2 }, +#endif +#ifdef _EGL_BUILT_IN_DRIVER_GLX + { "egl_glx", _eglBuiltInDriverGLX }, +#endif + { NULL, NULL } +}; /** * Wrappers for dlopen/dlclose() @@ -157,9 +170,18 @@ _eglLoadModule(_EGLModule *mod) lib_handle lib; _EGLDriver *drv; - mainFunc = _eglOpenLibrary(mod->Path, &lib); - if (!mainFunc) - return EGL_FALSE; + if (mod->Driver) + return EGL_TRUE; + + if (mod->BuiltIn) { + lib = (lib_handle) NULL; + mainFunc = mod->BuiltIn; + } + else { + mainFunc = _eglOpenLibrary(mod->Path, &lib); + if (!mainFunc) + return EGL_FALSE; + } drv = mainFunc(NULL); if (!drv) { @@ -313,68 +335,6 @@ _eglLoaderFile(const char *dir, size_t len, void *loader_data) /** - * 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))) { - 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 add it to the module array */ - if (len + dirent_len + 1 <= sizeof(path)) { - strcpy(path + len, dirent->d_name); - _eglAddModule(path); - } - } - - closedir(dirp); - - return EGL_TRUE; -#else /* _EGL_OS_UNIX */ - /* stop immediately */ - return EGL_FALSE; -#endif -} - - -/** * Run the callback function on each driver directory. * * The process may end prematurely if the callback function returns false. @@ -489,34 +449,37 @@ _eglAddUserDriver(void) } } #endif /* _EGL_OS_UNIX */ - if (env) + if (env) { + _EGLModule *mod; + EGLint i; + + /* env can be a path */ _eglPreloadForEach(search_path, _eglLoaderFile, (void *) env); + /* or the name of a built-in driver */ + for (i = 0; _eglBuiltInDrivers[i].name; i++) { + if (!strcmp(_eglBuiltInDrivers[i].name, env)) { + mod = _eglAddModule(env); + if (mod) + mod->BuiltIn = _eglBuiltInDrivers[i].main; + } + } + } } /** - * Add default drivers to the module array. + * Add built-in drivers to the module array. */ static void -_eglAddDefaultDrivers(void) +_eglAddBuiltInDrivers(void) { - const char *search_path = _eglGetSearchPath(); + _EGLModule *mod; EGLint i; -#if defined(_EGL_OS_WINDOWS) - const char *DefaultDriverNames[] = { - "egl_gallium" - }; -#elif defined(_EGL_OS_UNIX) - const char *DefaultDriverNames[] = { - "egl_gallium", - "egl_dri2", - "egl_glx" - }; -#endif - for (i = 0; i < ARRAY_SIZE(DefaultDriverNames); i++) { - void *name = (void *) DefaultDriverNames[i]; - _eglPreloadForEach(search_path, _eglLoaderFile, name); + for (i = 0; _eglBuiltInDrivers[i].name; i++) { + mod = _eglAddModule(_eglBuiltInDrivers[i].name); + if (mod) + mod->BuiltIn = _eglBuiltInDrivers[i].main; } } @@ -528,13 +491,15 @@ _eglAddDefaultDrivers(void) static EGLBoolean _eglAddDrivers(void) { + void *external = (void *) "egl_gallium"; + if (_eglModules) return EGL_TRUE; /* the order here decides the priorities of the drivers */ _eglAddUserDriver(); - _eglAddDefaultDrivers(); - _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderPattern, (void *) "egl_"); + _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external); + _eglAddBuiltInDrivers(); return (_eglModules != NULL); } diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 1a0aaad1f8c..651788cb7ae 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -64,6 +64,14 @@ struct _egl_driver }; +extern _EGLDriver * +_eglBuiltInDriverDRI2(const char *args); + + +extern _EGLDriver * +_eglBuiltInDriverGLX(const char *args); + + PUBLIC _EGLDriver * _eglMain(const char *args); |