egl: Make egl_dri2 and egl_glx built-in drivers.

These two drivers are small in size.  Making them built-in should
simplify packaging.
This commit is contained in:
Chia-I Wu 2011-01-07 16:30:08 +08:00
parent 15f0223931
commit c98ea26e16
11 changed files with 111 additions and 103 deletions

View File

@ -1783,7 +1783,7 @@ if test "$enable_egl" = yes; then
egl_drivers="" egl_drivers=""
for d in $EGL_DRIVERS_DIRS; do for d in $EGL_DRIVERS_DIRS; do
egl_drivers="$egl_drivers egl_$d" egl_drivers="$egl_drivers builtin:egl_$d"
done done
if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then if test "$enable_gallium" = yes -a "$HAVE_ST_EGL" = yes; then

View File

@ -148,9 +148,10 @@ may set</p>
<li><code>EGL_DRIVER</code> <li><code>EGL_DRIVER</code>
<p>This variable specifies a full path to an EGL driver and it forces the <p>This variable specifies a full path to or the name of an EGL driver. It
specified EGL driver to be loaded. It comes in handy when one wants to test a forces the specified EGL driver to be loaded. It comes in handy when one wants
specific driver. This variable is ignored for setuid/setgid binaries.</p> to test a specific driver. This variable is ignored for setuid/setgid
binaries.</p>
</li> </li>

View File

@ -3,7 +3,7 @@
TOP = ../.. TOP = ../..
include $(TOP)/configs/current include $(TOP)/configs/current
SUBDIRS = main drivers SUBDIRS = drivers main
default: subdirs default: subdirs

View File

@ -2,6 +2,7 @@
# #
# Drivers should define # Drivers should define
# #
# EGL_BUILTIN, the driver is built-in or external
# EGL_DRIVER, the driver name # EGL_DRIVER, the driver name
# EGL_SOURCES, the driver sources # EGL_SOURCES, the driver sources
# EGL_INCLUDES, the include pathes # 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) 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) -d $(TOP)/$(LIB_DIR)/egl
$(INSTALL) $< $(TOP)/$(LIB_DIR)/egl $(INSTALL) $< $(TOP)/$(LIB_DIR)/egl
$(EGL_DRIVER): $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template $(EGL_DRIVER).so: $(EGL_OBJECTS) Makefile $(TOP)/src/egl/drivers/Makefile.template
@$(MKLIB) -o $(EGL_DRIVER) -noprefix \ @$(MKLIB) -o $(EGL_DRIVER).so -noprefix \
-linker '$(CC)' -ldflags '-L$(TOP)/$(LIB_DIR) $(LDFLAGS)' \ -linker '$(CC)' -ldflags '-L$(TOP)/$(LIB_DIR) $(LDFLAGS)' \
$(MKLIB_OPTIONS) \ $(MKLIB_OPTIONS) \
$(EGL_OBJECTS) $(EGL_LIBS) -l$(EGL_LIB) $(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: .c.o:
$(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@ $(CC) -c $(EGL_INCLUDES) $(CFLAGS) $(EGL_CFLAGS) $< -o $@
install-so: $(EGL_DRIVER_PATH)
install: $(EGL_DRIVER_PATH)
$(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) $(INSTALL) -d $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR)
$(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR) $(MINSTALL) $(EGL_DRIVER_PATH) $(DESTDIR)$(EGL_DRIVER_INSTALL_DIR)
install: $(EGL_INSTALL)
clean: clean:
rm -f $(EGL_DRIVER) rm -f $(EGL_DRIVER).so
rm -f lib$(EGL_DRIVER).a
rm -f $(EGL_OBJECTS) rm -f $(EGL_OBJECTS)
rm -f depend depend.bak rm -f depend depend.bak

View File

@ -3,7 +3,7 @@
TOP = ../../../.. TOP = ../../../..
include $(TOP)/configs/current include $(TOP)/configs/current
EGL_DRIVER = egl_dri2.so EGL_DRIVER = egl_dri2
EGL_SOURCES = egl_dri2.c EGL_SOURCES = egl_dri2.c
EGL_INCLUDES = \ EGL_INCLUDES = \
@ -17,4 +17,7 @@ EGL_INCLUDES = \
EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB) EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(DLOPEN_LIBS) $(LIBDRM_LIB)
EGL_CFLAGS = -D_EGL_MAIN=_eglBuiltInDriverDRI2
EGL_BUILTIN = true
include ../Makefile.template include ../Makefile.template

View File

@ -2372,7 +2372,7 @@ dri2_load(_EGLDriver *drv)
* Create a new _EGLDriver object and init its dispatch table. * Create a new _EGLDriver object and init its dispatch table.
*/ */
_EGLDriver * _EGLDriver *
_eglMain(const char *args) _EGL_MAIN(const char *args)
{ {
struct dri2_egl_driver *dri2_drv; struct dri2_egl_driver *dri2_drv;

View File

@ -3,7 +3,7 @@
TOP = ../../../.. TOP = ../../../..
include $(TOP)/configs/current include $(TOP)/configs/current
EGL_DRIVER = egl_glx.so EGL_DRIVER = egl_glx
EGL_SOURCES = egl_glx.c EGL_SOURCES = egl_glx.c
EGL_INCLUDES = \ EGL_INCLUDES = \
@ -13,4 +13,7 @@ EGL_INCLUDES = \
EGL_CFLAGS = $(X11_CFLAGS) EGL_CFLAGS = $(X11_CFLAGS)
EGL_LIBS = $(X11_LIBS) $(DLOPEN_LIBS) EGL_LIBS = $(X11_LIBS) $(DLOPEN_LIBS)
EGL_CFLAGS += -D_EGL_MAIN=_eglBuiltInDriverGLX
EGL_BUILTIN = true
include ../Makefile.template include ../Makefile.template

View File

@ -1115,7 +1115,7 @@ fail:
* Create a new _EGLDriver object and init its dispatch table. * Create a new _EGLDriver object and init its dispatch table.
*/ */
_EGLDriver * _EGLDriver *
_eglMain(const char *args) _EGL_MAIN(const char *args)
{ {
struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver); struct GLX_egl_driver *GLX_drv = CALLOC_STRUCT(GLX_egl_driver);

View File

@ -52,6 +52,19 @@ OBJECTS = $(SOURCES:.c=.o)
# use dl*() to load drivers # use dl*() to load drivers
LOCAL_CFLAGS = -D_EGL_OS_UNIX=1 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 # translate --with-egl-platforms to _EGLPlatformType
EGL_NATIVE_PLATFORM=_EGL_INVALID_PLATFORM 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)' \ $(MKLIB) -o $(EGL_LIB) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
-major $(EGL_MAJOR) -minor $(EGL_MINOR) \ -major $(EGL_MAJOR) -minor $(EGL_MINOR) \
-install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \ -install $(TOP)/$(LIB_DIR) $(MKLIB_OPTIONS) \
$(EGL_LIB_DEPS) $(OBJECTS) -L$(TOP)/$(LIB_DIR) $(EGL_LIB_DEPS) \
$(OBJECTS) $(LOCAL_LIBS)
install-headers: install-headers:
$(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR

View File

@ -25,6 +25,7 @@
typedef struct _egl_module { typedef struct _egl_module {
char *Path; char *Path;
_EGLMain_t BuiltIn;
void *Handle; void *Handle;
_EGLDriver *Driver; _EGLDriver *Driver;
} _EGLModule; } _EGLModule;
@ -32,6 +33,18 @@ typedef struct _egl_module {
static _EGL_DECLARE_MUTEX(_eglModuleMutex); static _EGL_DECLARE_MUTEX(_eglModuleMutex);
static _EGLArray *_eglModules; 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() * Wrappers for dlopen/dlclose()
@ -157,9 +170,18 @@ _eglLoadModule(_EGLModule *mod)
lib_handle lib; lib_handle lib;
_EGLDriver *drv; _EGLDriver *drv;
mainFunc = _eglOpenLibrary(mod->Path, &lib); if (mod->Driver)
if (!mainFunc) return EGL_TRUE;
return EGL_FALSE;
if (mod->BuiltIn) {
lib = (lib_handle) NULL;
mainFunc = mod->BuiltIn;
}
else {
mainFunc = _eglOpenLibrary(mod->Path, &lib);
if (!mainFunc)
return EGL_FALSE;
}
drv = mainFunc(NULL); drv = mainFunc(NULL);
if (!drv) { if (!drv) {
@ -312,68 +334,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. * Run the callback function on each driver directory.
* *
@ -489,34 +449,37 @@ _eglAddUserDriver(void)
} }
} }
#endif /* _EGL_OS_UNIX */ #endif /* _EGL_OS_UNIX */
if (env) if (env) {
_EGLModule *mod;
EGLint i;
/* env can be a path */
_eglPreloadForEach(search_path, _eglLoaderFile, (void *) env); _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 static void
_eglAddDefaultDrivers(void) _eglAddBuiltInDrivers(void)
{ {
const char *search_path = _eglGetSearchPath(); _EGLModule *mod;
EGLint i; 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++) { for (i = 0; _eglBuiltInDrivers[i].name; i++) {
void *name = (void *) DefaultDriverNames[i]; mod = _eglAddModule(_eglBuiltInDrivers[i].name);
_eglPreloadForEach(search_path, _eglLoaderFile, name); if (mod)
mod->BuiltIn = _eglBuiltInDrivers[i].main;
} }
} }
@ -528,13 +491,15 @@ _eglAddDefaultDrivers(void)
static EGLBoolean static EGLBoolean
_eglAddDrivers(void) _eglAddDrivers(void)
{ {
void *external = (void *) "egl_gallium";
if (_eglModules) if (_eglModules)
return EGL_TRUE; return EGL_TRUE;
/* the order here decides the priorities of the drivers */ /* the order here decides the priorities of the drivers */
_eglAddUserDriver(); _eglAddUserDriver();
_eglAddDefaultDrivers(); _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external);
_eglPreloadForEach(_eglGetSearchPath(), _eglLoaderPattern, (void *) "egl_"); _eglAddBuiltInDrivers();
return (_eglModules != NULL); return (_eglModules != NULL);
} }

View File

@ -64,6 +64,14 @@ struct _egl_driver
}; };
extern _EGLDriver *
_eglBuiltInDriverDRI2(const char *args);
extern _EGLDriver *
_eglBuiltInDriverGLX(const char *args);
PUBLIC _EGLDriver * PUBLIC _EGLDriver *
_eglMain(const char *args); _eglMain(const char *args);