summaryrefslogtreecommitdiff
path: root/src/egl
diff options
context:
space:
mode:
Diffstat (limited to 'src/egl')
-rw-r--r--src/egl/Makefile2
-rw-r--r--src/egl/drivers/Makefile.template30
-rw-r--r--src/egl/drivers/dri2/Makefile7
-rw-r--r--src/egl/drivers/dri2/egl_dri2.c139
-rw-r--r--src/egl/drivers/glx/Makefile7
-rw-r--r--src/egl/drivers/glx/egl_glx.c359
-rw-r--r--src/egl/main/Makefile18
-rw-r--r--src/egl/main/SConscript30
-rw-r--r--src/egl/main/eglapi.c9
-rw-r--r--src/egl/main/eglapi.h2
-rw-r--r--src/egl/main/eglarray.c39
-rw-r--r--src/egl/main/eglarray.h4
-rw-r--r--src/egl/main/eglconfig.c13
-rw-r--r--src/egl/main/eglcurrent.c5
-rw-r--r--src/egl/main/egldisplay.h40
-rw-r--r--src/egl/main/egldriver.c309
-rw-r--r--src/egl/main/egldriver.h24
-rw-r--r--src/egl/main/eglmisc.c33
-rw-r--r--src/egl/main/eglstring.h1
19 files changed, 650 insertions, 421 deletions
diff --git a/src/egl/Makefile b/src/egl/Makefile
index 5b09e178c6..50f227f07d 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 47709e3c59..76dbe260c6 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 8a3c9b6a0a..553ee8771f 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 = \
@@ -15,6 +15,9 @@ EGL_INCLUDES = \
$(LIBUDEV_CFLAGS) \
$(LIBDRM_CFLAGS)
-EGL_LIBS = $(XCB_DRI2_LIBS) $(LIBUDEV_LIBS) $(LIBDRM_LIBS)
+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 a83f32b0d1..6fc1e49e77 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -47,7 +47,6 @@
#include <libudev.h>
#endif
-#include <glapi/glapi.h>
#include "eglconfig.h"
#include "eglcontext.h"
#include "egldisplay.h"
@@ -63,6 +62,7 @@ struct dri2_egl_driver
{
_EGLDriver base;
+ _EGLProc (*get_proc_address)(const char *procname);
void (*glFlush)(void);
};
@@ -260,8 +260,8 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
base.BindToTextureRGBA = bind_to_texture_rgba;
}
- base.RenderableType = disp->ClientAPIsMask;
- base.Conformant = disp->ClientAPIsMask;
+ base.RenderableType = disp->ClientAPIs;
+ base.Conformant = disp->ClientAPIs;
if (!_eglValidateConfig(&base, EGL_FALSE)) {
_eglLog(_EGL_DEBUG, "DRI2: failed to validate config %d", id);
@@ -752,13 +752,13 @@ dri2_create_screen(_EGLDisplay *disp)
else
api_mask = 1 << __DRI_API_OPENGL;
- disp->ClientAPIsMask = 0;
+ disp->ClientAPIs = 0;
if (api_mask & (1 <<__DRI_API_OPENGL))
- disp->ClientAPIsMask |= EGL_OPENGL_BIT;
+ disp->ClientAPIs |= EGL_OPENGL_BIT;
if (api_mask & (1 <<__DRI_API_GLES))
- disp->ClientAPIsMask |= EGL_OPENGL_ES_BIT;
+ disp->ClientAPIs |= EGL_OPENGL_ES_BIT;
if (api_mask & (1 << __DRI_API_GLES2))
- disp->ClientAPIsMask |= EGL_OPENGL_ES2_BIT;
+ disp->ClientAPIs |= EGL_OPENGL_ES2_BIT;
if (dri2_dpy->dri2->base.version >= 2) {
disp->Extensions.KHR_surfaceless_gles1 = EGL_TRUE;
@@ -775,8 +775,7 @@ dri2_create_screen(_EGLDisplay *disp)
}
static EGLBoolean
-dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp,
- EGLint *major, EGLint *minor)
+dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy;
@@ -855,8 +854,8 @@ dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp,
disp->Extensions.NOK_texture_from_pixmap = EGL_TRUE;
/* we're supporting EGL 1.4 */
- *major = 1;
- *minor = 4;
+ disp->VersionMajor = 1;
+ disp->VersionMinor = 4;
return EGL_TRUE;
@@ -1415,8 +1414,7 @@ dri2_get_driver_for_fd(int fd)
}
static EGLBoolean
-dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp,
- EGLint *major, EGLint *minor)
+dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy;
int i;
@@ -1451,8 +1449,8 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp,
disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE;
/* we're supporting EGL 1.4 */
- *major = 1;
- *minor = 4;
+ disp->VersionMajor = 1;
+ disp->VersionMinor = 4;
return EGL_TRUE;
@@ -1470,16 +1468,23 @@ dri2_initialize_drm(_EGLDriver *drv, _EGLDisplay *disp,
* Called via eglInitialize(), GLX_drv->API.Initialize().
*/
static EGLBoolean
-dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp,
- EGLint *major, EGLint *minor)
+dri2_initialize(_EGLDriver *drv, _EGLDisplay *disp)
{
+ /* not until swrast_dri is supported */
+ if (disp->Options.UseFallback)
+ return EGL_FALSE;
+
switch (disp->Platform) {
case _EGL_PLATFORM_X11:
- return dri2_initialize_x11(drv, disp, major, minor);
+ if (disp->Options.TestOnly)
+ return EGL_TRUE;
+ return dri2_initialize_x11(drv, disp);
#ifdef HAVE_LIBUDEV
case _EGL_PLATFORM_DRM:
- return dri2_initialize_drm(drv, disp, major, minor);
+ if (disp->Options.TestOnly)
+ return EGL_TRUE;
+ return dri2_initialize_drm(drv, disp);
#endif
default:
@@ -1648,7 +1653,11 @@ dri2_make_current(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
dri2_destroy_surface(drv, disp, old_dsurf);
dri2_destroy_surface(drv, disp, old_rsurf);
if (old_ctx) {
- dri2_dpy->core->unbindContext(dri2_egl_context(old_ctx)->dri_context);
+ /* unbind the old context only when there is no new context bound */
+ if (!ctx) {
+ __DRIcontext *old_cctx = dri2_egl_context(old_ctx)->dri_context;
+ dri2_dpy->core->unbindContext(old_cctx);
+ }
/* no destroy? */
_eglPutContext(old_ctx);
}
@@ -1863,11 +1872,9 @@ dri2_swap_buffers_region(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw,
static _EGLProc
dri2_get_proc_address(_EGLDriver *drv, const char *procname)
{
- (void) drv;
-
- /* FIXME: Do we need to support lookup of EGL symbols too? */
+ struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
- return (_EGLProc) _glapi_get_proc_address(procname);
+ return dri2_drv->get_proc_address(procname);
}
static EGLBoolean
@@ -1899,13 +1906,6 @@ dri2_wait_native(_EGLDriver *drv, _EGLDisplay *disp, EGLint engine)
return EGL_TRUE;
}
-static void
-dri2_unload(_EGLDriver *drv)
-{
- struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
- free(dri2_drv);
-}
-
static EGLBoolean
dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
EGLNativePixmapType target)
@@ -1979,10 +1979,31 @@ static EGLBoolean
dri2_release_tex_image(_EGLDriver *drv,
_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
{
- (void) drv;
- (void) disp;
- (void) surf;
- (void) buffer;
+#if __DRI_TEX_BUFFER_VERSION >= 3
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
+ struct dri2_egl_context *dri2_ctx;
+ _EGLContext *ctx;
+ GLint target;
+
+ ctx = _eglGetCurrentContext();
+ dri2_ctx = dri2_egl_context(ctx);
+
+ if (!_eglReleaseTexImage(drv, disp, surf, buffer))
+ return EGL_FALSE;
+
+ switch (dri2_surf->base.TextureTarget) {
+ case EGL_TEXTURE_2D:
+ target = GL_TEXTURE_2D;
+ break;
+ default:
+ assert(0);
+ }
+ if (dri2_dpy->tex_buffer->releaseTexBuffer!=NULL)
+ (*dri2_dpy->tex_buffer->releaseTexBuffer)(dri2_ctx->dri_context,
+ target,
+ dri2_surf->dri_drawable);
+#endif
return EGL_TRUE;
}
@@ -2312,12 +2333,51 @@ dri2_export_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *img,
return EGL_TRUE;
}
+static void
+dri2_unload(_EGLDriver *drv)
+{
+ struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
+ free(dri2_drv);
+}
+
+static EGLBoolean
+dri2_load(_EGLDriver *drv)
+{
+ struct dri2_egl_driver *dri2_drv = dri2_egl_driver(drv);
+ void *handle;
+
+ handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
+ if (handle) {
+ dri2_drv->get_proc_address = (_EGLProc (*)(const char *))
+ dlsym(handle, "_glapi_get_proc_address");
+ /* no need to keep a reference */
+ dlclose(handle);
+ }
+
+ /*
+ * If glapi is not available, loading DRI drivers will fail. Ideally, we
+ * should load one of libGL, libGLESv1_CM, or libGLESv2 and go on. But if
+ * the app has loaded another one of them with RTLD_LOCAL, there may be
+ * unexpected behaviors later because there will be two copies of glapi
+ * (with global variables of the same names!) in the memory.
+ */
+ if (!dri2_drv->get_proc_address) {
+ _eglLog(_EGL_WARNING, "DRI2: failed to find _glapi_get_proc_address");
+ return EGL_FALSE;
+ }
+
+ dri2_drv->glFlush = (void (*)(void))
+ dri2_drv->get_proc_address("glFlush");
+
+ return EGL_TRUE;
+}
+
/**
* This is the main entrypoint into the driver, called by libEGL.
* 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;
@@ -2328,6 +2388,10 @@ _eglMain(const char *args)
return NULL;
memset(dri2_drv, 0, sizeof *dri2_drv);
+
+ if (!dri2_load(&dri2_drv->base))
+ return NULL;
+
_eglInitDriverFallbacks(&dri2_drv->base);
dri2_drv->base.API.Initialize = dri2_initialize;
dri2_drv->base.API.Terminate = dri2_terminate;
@@ -2353,8 +2417,5 @@ _eglMain(const char *args)
dri2_drv->base.Name = "DRI2";
dri2_drv->base.Unload = dri2_unload;
- dri2_drv->glFlush =
- (void (*)(void)) dri2_get_proc_address(&dri2_drv->base, "glFlush");
-
return &dri2_drv->base;
}
diff --git a/src/egl/drivers/glx/Makefile b/src/egl/drivers/glx/Makefile
index d976b91a74..a1e6b731fe 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 = \
@@ -11,6 +11,9 @@ EGL_INCLUDES = \
-I$(TOP)/src/egl/main
EGL_CFLAGS = $(X11_CFLAGS)
-EGL_LIBS = $(X11_LIBS) -lGL
+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 8ec7c48c50..c3c11c7b6e 100644
--- a/src/egl/drivers/glx/egl_glx.c
+++ b/src/egl/drivers/glx/egl_glx.c
@@ -36,8 +36,8 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
-#include <GL/glx.h>
-#include <EGL/egl.h>
+#include <dlfcn.h>
+#include "GL/glx.h"
#include "eglconfig.h"
#include "eglcontext.h"
@@ -54,10 +54,66 @@
#error "GL/glx.h must be equal to or greater than GLX 1.4"
#endif
+/* GLX 1.0 */
+typedef GLXContext (*GLXCREATECONTEXTPROC)( Display *dpy, XVisualInfo *vis, GLXContext shareList, Bool direct );
+typedef void (*GLXDESTROYCONTEXTPROC)( Display *dpy, GLXContext ctx );
+typedef Bool (*GLXMAKECURRENTPROC)( Display *dpy, GLXDrawable drawable, GLXContext ctx);
+typedef void (*GLXSWAPBUFFERSPROC)( Display *dpy, GLXDrawable drawable );
+typedef GLXPixmap (*GLXCREATEGLXPIXMAPPROC)( Display *dpy, XVisualInfo *visual, Pixmap pixmap );
+typedef void (*GLXDESTROYGLXPIXMAPPROC)( Display *dpy, GLXPixmap pixmap );
+typedef Bool (*GLXQUERYVERSIONPROC)( Display *dpy, int *maj, int *min );
+typedef int (*GLXGETCONFIGPROC)( Display *dpy, XVisualInfo *visual, int attrib, int *value );
+typedef void (*GLXWAITGLPROC)( void );
+typedef void (*GLXWAITXPROC)( void );
+
+/* GLX 1.1 */
+typedef const char *(*GLXQUERYEXTENSIONSSTRINGPROC)( Display *dpy, int screen );
+typedef const char *(*GLXQUERYSERVERSTRINGPROC)( Display *dpy, int screen, int name );
+typedef const char *(*GLXGETCLIENTSTRINGPROC)( Display *dpy, int name );
+
/** subclass of _EGLDriver */
struct GLX_egl_driver
{
_EGLDriver Base; /**< base class */
+
+ void *handle;
+
+ /* GLX 1.0 */
+ GLXCREATECONTEXTPROC glXCreateContext;
+ GLXDESTROYCONTEXTPROC glXDestroyContext;
+ GLXMAKECURRENTPROC glXMakeCurrent;
+ GLXSWAPBUFFERSPROC glXSwapBuffers;
+ GLXCREATEGLXPIXMAPPROC glXCreateGLXPixmap;
+ GLXDESTROYGLXPIXMAPPROC glXDestroyGLXPixmap;
+ GLXQUERYVERSIONPROC glXQueryVersion;
+ GLXGETCONFIGPROC glXGetConfig;
+ GLXWAITGLPROC glXWaitGL;
+ GLXWAITXPROC glXWaitX;
+
+ /* GLX 1.1 */
+ GLXQUERYEXTENSIONSSTRINGPROC glXQueryExtensionsString;
+ GLXQUERYSERVERSTRINGPROC glXQueryServerString;
+ GLXGETCLIENTSTRINGPROC glXGetClientString;
+
+ /* GLX 1.3 or (GLX_SGI_make_current_read and GLX_SGIX_fbconfig) */
+ PFNGLXGETFBCONFIGSPROC glXGetFBConfigs;
+ PFNGLXGETFBCONFIGATTRIBPROC glXGetFBConfigAttrib;
+ PFNGLXGETVISUALFROMFBCONFIGPROC glXGetVisualFromFBConfig;
+ PFNGLXCREATEWINDOWPROC glXCreateWindow;
+ PFNGLXDESTROYWINDOWPROC glXDestroyWindow;
+ PFNGLXCREATEPIXMAPPROC glXCreatePixmap;
+ PFNGLXDESTROYPIXMAPPROC glXDestroyPixmap;
+ PFNGLXCREATEPBUFFERPROC glXCreatePbuffer;
+ PFNGLXDESTROYPBUFFERPROC glXDestroyPbuffer;
+ PFNGLXCREATENEWCONTEXTPROC glXCreateNewContext;
+ PFNGLXMAKECONTEXTCURRENTPROC glXMakeContextCurrent;
+
+ /* GLX 1.4 or GLX_ARB_get_proc_address */
+ PFNGLXGETPROCADDRESSPROC glXGetProcAddress;
+
+ /* GLX_SGIX_pbuffer */
+ PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX;
+ PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX;
};
@@ -76,14 +132,9 @@ struct GLX_egl_display
EGLBoolean have_fbconfig;
EGLBoolean have_pbuffer;
- /* GLX_SGIX_pbuffer */
- PFNGLXCREATEGLXPBUFFERSGIXPROC glXCreateGLXPbufferSGIX;
- PFNGLXDESTROYGLXPBUFFERSGIXPROC glXDestroyGLXPbufferSGIX;
-
/* workaround quirks of different GLX implementations */
EGLBoolean single_buffered_quirk;
EGLBoolean glx_window_quirk;
-
};
@@ -168,19 +219,21 @@ static const struct {
static EGLBoolean
-convert_fbconfig(Display *dpy, GLXFBConfig fbconfig,
+convert_fbconfig(struct GLX_egl_driver *GLX_drv,
+ struct GLX_egl_display *GLX_dpy, GLXFBConfig fbconfig,
struct GLX_egl_config *GLX_conf)
{
+ Display *dpy = GLX_dpy->dpy;
int err, attr, val;
unsigned i;
/* must have rgba bit */
- err = glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val);
+ err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &val);
if (err || !(val & GLX_RGBA_BIT))
return EGL_FALSE;
/* must know whether it is double-buffered */
- err = glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val);
+ err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &val);
if (err)
return EGL_FALSE;
GLX_conf->double_buffered = val;
@@ -196,7 +249,7 @@ convert_fbconfig(Display *dpy, GLXFBConfig fbconfig,
if (!egl_attr)
continue;
- err = glXGetFBConfigAttrib(dpy, fbconfig, attr, &val);
+ err = GLX_drv->glXGetFBConfigAttrib(dpy, fbconfig, attr, &val);
if (err) {
if (err == GLX_BAD_ATTRIBUTE) {
err = 0;
@@ -303,21 +356,23 @@ static const struct {
};
static EGLBoolean
-convert_visual(Display *dpy, XVisualInfo *vinfo,
+convert_visual(struct GLX_egl_driver *GLX_drv,
+ struct GLX_egl_display *GLX_dpy, XVisualInfo *vinfo,
struct GLX_egl_config *GLX_conf)
{
+ Display *dpy = GLX_dpy->dpy;
int err, attr, val;
unsigned i;
/* the visual must support OpenGL and RGBA buffer */
- err = glXGetConfig(dpy, vinfo, GLX_USE_GL, &val);
+ err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_USE_GL, &val);
if (!err && val)
- err = glXGetConfig(dpy, vinfo, GLX_RGBA, &val);
+ err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_RGBA, &val);
if (err || !val)
return EGL_FALSE;
/* must know whether it is double-buffered */
- err = glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val);
+ err = GLX_drv->glXGetConfig(dpy, vinfo, GLX_DOUBLEBUFFER, &val);
if (err)
return EGL_FALSE;
GLX_conf->double_buffered = val;
@@ -341,7 +396,7 @@ convert_visual(Display *dpy, XVisualInfo *vinfo,
if (!egl_attr)
continue;
- err = glXGetConfig(dpy, vinfo, attr, &val);
+ err = GLX_drv->glXGetConfig(dpy, vinfo, attr, &val);
if (err) {
if (err == GLX_BAD_ATTRIBUTE) {
err = 0;
@@ -406,14 +461,16 @@ fix_config(struct GLX_egl_display *GLX_dpy, struct GLX_egl_config *GLX_conf)
static EGLBoolean
-create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy,
- EGLint screen)
+create_configs(_EGLDriver *drv, _EGLDisplay *dpy, EGLint screen)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ struct GLX_egl_display *GLX_dpy = GLX_egl_display(dpy);
EGLint num_configs = 0, i;
EGLint id = 1;
if (GLX_dpy->have_fbconfig) {
- GLX_dpy->fbconfigs = glXGetFBConfigs(GLX_dpy->dpy, screen, &num_configs);
+ GLX_dpy->fbconfigs =
+ GLX_drv->glXGetFBConfigs(GLX_dpy->dpy, screen, &num_configs);
}
else {
XVisualInfo vinfo_template;
@@ -434,10 +491,14 @@ create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy,
memset(&template, 0, sizeof(template));
_eglInitConfig(&template.Base, dpy, id);
- if (GLX_dpy->have_fbconfig)
- ok = convert_fbconfig(GLX_dpy->dpy, GLX_dpy->fbconfigs[i], &template);
- else
- ok = convert_visual(GLX_dpy->dpy, &GLX_dpy->visuals[i], &template);
+ if (GLX_dpy->have_fbconfig) {
+ ok = convert_fbconfig(GLX_drv, GLX_dpy,
+ GLX_dpy->fbconfigs[i], &template);
+ }
+ else {
+ ok = convert_visual(GLX_drv, GLX_dpy,
+ &GLX_dpy->visuals[i], &template);
+ }
if (!ok)
continue;
@@ -462,13 +523,12 @@ create_configs(_EGLDisplay *dpy, struct GLX_egl_display *GLX_dpy,
static void
-check_extensions(struct GLX_egl_display *GLX_dpy, EGLint screen)
+check_extensions(struct GLX_egl_driver *GLX_drv,
+ struct GLX_egl_display *GLX_dpy, EGLint screen)
{
GLX_dpy->extensions =
- glXQueryExtensionsString(GLX_dpy->dpy, screen);
+ GLX_drv->glXQueryExtensionsString(GLX_dpy->dpy, screen);
if (GLX_dpy->extensions) {
- /* glXGetProcAddress is assumed */
-
if (strstr(GLX_dpy->extensions, "GLX_SGI_make_current_read")) {
/* GLX 1.3 entry points are used */
GLX_dpy->have_make_current_read = EGL_TRUE;
@@ -480,13 +540,8 @@ check_extensions(struct GLX_egl_display *GLX_dpy, EGLint screen)
}
if (strstr(GLX_dpy->extensions, "GLX_SGIX_pbuffer")) {
- GLX_dpy->glXCreateGLXPbufferSGIX = (PFNGLXCREATEGLXPBUFFERSGIXPROC)
- glXGetProcAddress((const GLubyte *) "glXCreateGLXPbufferSGIX");
- GLX_dpy->glXDestroyGLXPbufferSGIX = (PFNGLXDESTROYGLXPBUFFERSGIXPROC)
- glXGetProcAddress((const GLubyte *) "glXDestroyGLXPbufferSGIX");
-
- if (GLX_dpy->glXCreateGLXPbufferSGIX &&
- GLX_dpy->glXDestroyGLXPbufferSGIX &&
+ if (GLX_drv->glXCreateGLXPbufferSGIX &&
+ GLX_drv->glXDestroyGLXPbufferSGIX &&
GLX_dpy->have_fbconfig)
GLX_dpy->have_pbuffer = EGL_TRUE;
}
@@ -502,16 +557,17 @@ check_extensions(struct GLX_egl_display *GLX_dpy, EGLint screen)
static void
-check_quirks(struct GLX_egl_display *GLX_dpy, EGLint screen)
+check_quirks(struct GLX_egl_driver *GLX_drv,
+ struct GLX_egl_display *GLX_dpy, EGLint screen)
{
const char *vendor;
GLX_dpy->single_buffered_quirk = EGL_TRUE;
GLX_dpy->glx_window_quirk = EGL_TRUE;
- vendor = glXGetClientString(GLX_dpy->dpy, GLX_VENDOR);
+ vendor = GLX_drv->glXGetClientString(GLX_dpy->dpy, GLX_VENDOR);
if (vendor && strstr(vendor, "NVIDIA")) {
- vendor = glXQueryServerString(GLX_dpy->dpy, screen, GLX_VENDOR);
+ vendor = GLX_drv->glXQueryServerString(GLX_dpy->dpy, screen, GLX_VENDOR);
if (vendor && strstr(vendor, "NVIDIA")) {
_eglLog(_EGL_DEBUG, "disable quirks");
GLX_dpy->single_buffered_quirk = EGL_FALSE;
@@ -525,16 +581,21 @@ check_quirks(struct GLX_egl_display *GLX_dpy, EGLint screen)
* Called via eglInitialize(), GLX_drv->API.Initialize().
*/
static EGLBoolean
-GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
- EGLint *major, EGLint *minor)
+GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy;
- (void) drv;
-
if (disp->Platform != _EGL_PLATFORM_X11)
return EGL_FALSE;
+ /* this is a fallback driver */
+ if (!disp->Options.UseFallback)
+ return EGL_FALSE;
+
+ if (disp->Options.TestOnly)
+ return EGL_TRUE;
+
GLX_dpy = CALLOC_STRUCT(GLX_egl_display);
if (!GLX_dpy)
return _eglError(EGL_BAD_ALLOC, "eglInitialize");
@@ -549,7 +610,8 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
}
}
- if (!glXQueryVersion(GLX_dpy->dpy, &GLX_dpy->glx_maj, &GLX_dpy->glx_min)) {
+ if (!GLX_drv->glXQueryVersion(GLX_dpy->dpy,
+ &GLX_dpy->glx_maj, &GLX_dpy->glx_min)) {
_eglLog(_EGL_WARNING, "GLX: glXQueryVersion failed");
if (!disp->PlatformDisplay)
XCloseDisplay(GLX_dpy->dpy);
@@ -557,10 +619,13 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
return EGL_FALSE;
}
- check_extensions(GLX_dpy, DefaultScreen(GLX_dpy->dpy));
- check_quirks(GLX_dpy, DefaultScreen(GLX_dpy->dpy));
+ disp->DriverData = (void *) GLX_dpy;
+ disp->ClientAPIs = EGL_OPENGL_BIT;
+
+ check_extensions(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
+ check_quirks(GLX_drv, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
- create_configs(disp, GLX_dpy, DefaultScreen(GLX_dpy->dpy));
+ create_configs(drv, disp, DefaultScreen(GLX_dpy->dpy));
if (!_eglGetArraySize(disp->Configs)) {
_eglLog(_EGL_WARNING, "GLX: failed to create any config");
if (!disp->PlatformDisplay)
@@ -569,16 +634,14 @@ GLX_eglInitialize(_EGLDriver *drv, _EGLDisplay *disp,
return EGL_FALSE;
}
- disp->DriverData = (void *) GLX_dpy;
- disp->ClientAPIsMask = EGL_OPENGL_BIT;
-
/* we're supporting EGL 1.4 */
- *major = 1;
- *minor = 4;
+ disp->VersionMajor = 1;
+ disp->VersionMinor = 4;
return EGL_TRUE;
}
+
/**
* Called via eglTerminate(), drv->API.Terminate().
*/
@@ -612,12 +675,11 @@ static _EGLContext *
GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
_EGLContext *share_list, const EGLint *attrib_list)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_context *GLX_ctx = CALLOC_STRUCT(GLX_egl_context);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_context *GLX_ctx_shared = GLX_egl_context(share_list);
- (void) drv;
-
if (!GLX_ctx) {
_eglError(EGL_BAD_ALLOC, "eglCreateContext");
return NULL;
@@ -628,19 +690,19 @@ GLX_eglCreateContext(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
return NULL;
}
- if (GLX_dpy->have_fbconfig)
- GLX_ctx->context =
- glXCreateNewContext(GLX_dpy->dpy,
- GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
- GLX_RGBA_TYPE,
- GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
- GL_TRUE);
- else
- GLX_ctx->context =
- glXCreateContext(GLX_dpy->dpy,
- &GLX_dpy->visuals[GLX_egl_config_index(conf)],
- GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
- GL_TRUE);
+ if (GLX_dpy->have_fbconfig) {
+ GLX_ctx->context = GLX_drv->glXCreateNewContext(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
+ GLX_RGBA_TYPE,
+ GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
+ GL_TRUE);
+ }
+ else {
+ GLX_ctx->context = GLX_drv->glXCreateContext(GLX_dpy->dpy,
+ &GLX_dpy->visuals[GLX_egl_config_index(conf)],
+ GLX_ctx_shared ? GLX_ctx_shared->context : NULL,
+ GL_TRUE);
+ }
if (!GLX_ctx->context) {
free(GLX_ctx);
return NULL;
@@ -673,6 +735,7 @@ static EGLBoolean
GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
_EGLSurface *rsurf, _EGLContext *ctx)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_dsurf = GLX_egl_surface(dsurf);
struct GLX_egl_surface *GLX_rsurf = GLX_egl_surface(rsurf);
@@ -683,8 +746,6 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
GLXContext cctx;
EGLBoolean ret = EGL_FALSE;
- (void) drv;
-
/* make new bindings */
if (!_eglBindContext(ctx, dsurf, rsurf, &old_ctx, &old_dsurf, &old_rsurf))
return EGL_FALSE;
@@ -694,9 +755,9 @@ GLX_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *dsurf,
cctx = (GLX_ctx) ? GLX_ctx->context : NULL;
if (GLX_dpy->have_make_current_read)
- ret = glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx);
+ ret = GLX_drv->glXMakeContextCurrent(GLX_dpy->dpy, ddraw, rdraw, cctx);
else if (ddraw == rdraw)
- ret = glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
+ ret = GLX_drv->glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
if (ret) {
if (_eglPutSurface(old_dsurf))
@@ -747,12 +808,11 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, EGLNativeWindowType window,
const EGLint *attrib_list)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
uint width, height;
- (void) drv;
-
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
if (!GLX_surf) {
_eglError(EGL_BAD_ALLOC, "eglCreateWindowSurface");
@@ -767,13 +827,14 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp,
GLX_surf->drawable = window;
- if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk)
- GLX_surf->glx_drawable =
- glXCreateWindow(GLX_dpy->dpy,
- GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
- GLX_surf->drawable, NULL);
- else
+ if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk) {
+ GLX_surf->glx_drawable = GLX_drv->glXCreateWindow(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
+ GLX_surf->drawable, NULL);
+ }
+ else {
GLX_surf->glx_drawable = GLX_surf->drawable;
+ }
if (!GLX_surf->glx_drawable) {
free(GLX_surf);
@@ -781,7 +842,7 @@ GLX_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *disp,
}
if (GLX_dpy->have_1_3 && !GLX_dpy->glx_window_quirk)
- GLX_surf->destroy = glXDestroyWindow;
+ GLX_surf->destroy = GLX_drv->glXDestroyWindow;
get_drawable_size(GLX_dpy->dpy, window, &width, &height);
GLX_surf->Base.Width = width;
@@ -795,12 +856,11 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, EGLNativePixmapType pixmap,
const EGLint *attrib_list)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
uint width, height;
- (void) drv;
-
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
if (!GLX_surf) {
_eglError(EGL_BAD_ALLOC, "eglCreatePixmapSurface");
@@ -816,25 +876,25 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
GLX_surf->drawable = pixmap;
if (GLX_dpy->have_1_3) {
- GLX_surf->glx_drawable =
- glXCreatePixmap(GLX_dpy->dpy,
- GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
- GLX_surf->drawable, NULL);
+ GLX_surf->glx_drawable = GLX_drv->glXCreatePixmap(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
+ GLX_surf->drawable, NULL);
}
else if (GLX_dpy->have_fbconfig) {
GLXFBConfig fbconfig = GLX_dpy->fbconfigs[GLX_egl_config_index(conf)];
- XVisualInfo *vinfo = glXGetVisualFromFBConfig(GLX_dpy->dpy, fbconfig);
+ XVisualInfo *vinfo;
+
+ vinfo = GLX_drv->glXGetVisualFromFBConfig(GLX_dpy->dpy, fbconfig);
if (vinfo) {
- GLX_surf->glx_drawable =
- glXCreateGLXPixmap(GLX_dpy->dpy, vinfo, GLX_surf->drawable);
+ GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPixmap(GLX_dpy->dpy,
+ vinfo, GLX_surf->drawable);
XFree(vinfo);
}
}
else {
- GLX_surf->glx_drawable =
- glXCreateGLXPixmap(GLX_dpy->dpy,
- &GLX_dpy->visuals[GLX_egl_config_index(conf)],
- GLX_surf->drawable);
+ GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPixmap(GLX_dpy->dpy,
+ &GLX_dpy->visuals[GLX_egl_config_index(conf)],
+ GLX_surf->drawable);
}
if (!GLX_surf->glx_drawable) {
@@ -843,7 +903,7 @@ GLX_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *disp,
}
GLX_surf->destroy = (GLX_dpy->have_1_3) ?
- glXDestroyPixmap : glXDestroyGLXPixmap;
+ GLX_drv->glXDestroyPixmap : GLX_drv->glXDestroyGLXPixmap;
get_drawable_size(GLX_dpy->dpy, pixmap, &width, &height);
GLX_surf->Base.Width = width;
@@ -856,13 +916,12 @@ static _EGLSurface *
GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
_EGLConfig *conf, const EGLint *attrib_list)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf;
int attribs[5];
int i;
- (void) drv;
-
GLX_surf = CALLOC_STRUCT(GLX_egl_surface);
if (!GLX_surf) {
_eglError(EGL_BAD_ALLOC, "eglCreatePbufferSurface");
@@ -892,14 +951,11 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
}
attribs[i] = None;
- GLX_surf->glx_drawable =
- glXCreatePbuffer(GLX_dpy->dpy,
- GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
- attribs);
+ GLX_surf->glx_drawable = GLX_drv->glXCreatePbuffer(GLX_dpy->dpy,
+ GLX_dpy->fbconfigs[GLX_egl_config_index(conf)], attribs);
}
else if (GLX_dpy->have_pbuffer) {
- GLX_surf->glx_drawable = GLX_dpy->glXCreateGLXPbufferSGIX(
- GLX_dpy->dpy,
+ GLX_surf->glx_drawable = GLX_drv->glXCreateGLXPbufferSGIX(GLX_dpy->dpy,
GLX_dpy->fbconfigs[GLX_egl_config_index(conf)],
GLX_surf->Base.Width,
GLX_surf->Base.Height,
@@ -912,7 +968,7 @@ GLX_eglCreatePbufferSurface(_EGLDriver *drv, _EGLDisplay *disp,
}
GLX_surf->destroy = (GLX_dpy->have_1_3) ?
- glXDestroyPbuffer : GLX_dpy->glXDestroyGLXPbufferSGIX;
+ GLX_drv->glXDestroyPbuffer : GLX_drv->glXDestroyGLXPbufferSGIX;
return &GLX_surf->Base;
}
@@ -933,12 +989,11 @@ GLX_eglDestroySurface(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
static EGLBoolean
GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
struct GLX_egl_display *GLX_dpy = GLX_egl_display(disp);
struct GLX_egl_surface *GLX_surf = GLX_egl_surface(draw);
- (void) drv;
-
- glXSwapBuffers(GLX_dpy->dpy, GLX_surf->glx_drawable);
+ GLX_drv->glXSwapBuffers(GLX_dpy->dpy, GLX_surf->glx_drawable);
return EGL_TRUE;
}
@@ -949,31 +1004,33 @@ GLX_eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
static _EGLProc
GLX_eglGetProcAddress(_EGLDriver *drv, const char *procname)
{
- (void) drv;
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
- return (_EGLProc) glXGetProcAddress((const GLubyte *) procname);
+ return (_EGLProc) GLX_drv->glXGetProcAddress((const GLubyte *) procname);
}
static EGLBoolean
GLX_eglWaitClient(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx)
{
- (void) drv;
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+
(void) dpy;
(void) ctx;
- glXWaitGL();
+ GLX_drv->glXWaitGL();
return EGL_TRUE;
}
static EGLBoolean
GLX_eglWaitNative(_EGLDriver *drv, _EGLDisplay *dpy, EGLint engine)
{
- (void) drv;
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+
(void) dpy;
if (engine != EGL_CORE_NATIVE_ENGINE)
return _eglError(EGL_BAD_PARAMETER, "eglWaitNative");
- glXWaitX();
+ GLX_drv->glXWaitX();
return EGL_TRUE;
}
@@ -981,16 +1038,90 @@ static void
GLX_Unload(_EGLDriver *drv)
{
struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+
+ if (GLX_drv->handle)
+ dlclose(GLX_drv->handle);
free(GLX_drv);
}
+static EGLBoolean
+GLX_Load(_EGLDriver *drv)
+{
+ struct GLX_egl_driver *GLX_drv = GLX_egl_driver(drv);
+ void *handle;
+
+ handle = dlopen("libGL.so", RTLD_LAZY | RTLD_LOCAL);
+ if (!handle)
+ goto fail;
+
+ GLX_drv->glXGetProcAddress = dlsym(handle, "glXGetProcAddress");
+ if (!GLX_drv->glXGetProcAddress)
+ GLX_drv->glXGetProcAddress = dlsym(handle, "glXGetProcAddressARB");
+ if (!GLX_drv->glXGetProcAddress)
+ goto fail;
+
+#define GET_PROC(proc_type, proc_name, check) \
+ do { \
+ GLX_drv->proc_name = (proc_type) \
+ GLX_drv->glXGetProcAddress((const GLubyte *) #proc_name); \
+ if (check && !GLX_drv->proc_name) goto fail; \
+ } while (0)
+
+ /* GLX 1.0 */
+ GET_PROC(GLXCREATECONTEXTPROC, glXCreateContext, EGL_TRUE);
+ GET_PROC(GLXDESTROYCONTEXTPROC, glXDestroyContext, EGL_TRUE);
+ GET_PROC(GLXMAKECURRENTPROC, glXMakeCurrent, EGL_TRUE);
+ GET_PROC(GLXSWAPBUFFERSPROC, glXSwapBuffers, EGL_TRUE);
+ GET_PROC(GLXCREATEGLXPIXMAPPROC, glXCreateGLXPixmap, EGL_TRUE);
+ GET_PROC(GLXDESTROYGLXPIXMAPPROC, glXDestroyGLXPixmap, EGL_TRUE);
+ GET_PROC(GLXQUERYVERSIONPROC, glXQueryVersion, EGL_TRUE);
+ GET_PROC(GLXGETCONFIGPROC, glXGetConfig, EGL_TRUE);
+ GET_PROC(GLXWAITGLPROC, glXWaitGL, EGL_TRUE);
+ GET_PROC(GLXWAITXPROC, glXWaitX, EGL_TRUE);
+
+ /* GLX 1.1 */
+ GET_PROC(GLXQUERYEXTENSIONSSTRINGPROC, glXQueryExtensionsString, EGL_TRUE);
+ GET_PROC(GLXQUERYSERVERSTRINGPROC, glXQueryServerString, EGL_TRUE);
+ GET_PROC(GLXGETCLIENTSTRINGPROC, glXGetClientString, EGL_TRUE);
+
+ /* GLX 1.3 */
+ GET_PROC(PFNGLXGETFBCONFIGSPROC, glXGetFBConfigs, EGL_FALSE);
+ GET_PROC(PFNGLXGETFBCONFIGATTRIBPROC, glXGetFBConfigAttrib, EGL_FALSE);
+ GET_PROC(PFNGLXGETVISUALFROMFBCONFIGPROC, glXGetVisualFromFBConfig, EGL_FALSE);
+ GET_PROC(PFNGLXCREATEWINDOWPROC, glXCreateWindow, EGL_FALSE);
+ GET_PROC(PFNGLXDESTROYWINDOWPROC, glXDestroyWindow, EGL_FALSE);
+ GET_PROC(PFNGLXCREATEPIXMAPPROC, glXCreatePixmap, EGL_FALSE);
+ GET_PROC(PFNGLXDESTROYPIXMAPPROC, glXDestroyPixmap, EGL_FALSE);
+ GET_PROC(PFNGLXCREATEPBUFFERPROC, glXCreatePbuffer, EGL_FALSE);
+ GET_PROC(PFNGLXDESTROYPBUFFERPROC, glXDestroyPbuffer, EGL_FALSE);
+ GET_PROC(PFNGLXCREATENEWCONTEXTPROC, glXCreateNewContext, EGL_FALSE);
+ GET_PROC(PFNGLXMAKECONTEXTCURRENTPROC, glXMakeContextCurrent, EGL_FALSE);
+
+ /* GLX_SGIX_pbuffer */
+ GET_PROC(PFNGLXCREATEGLXPBUFFERSGIXPROC,
+ glXCreateGLXPbufferSGIX, EGL_FALSE);
+ GET_PROC(PFNGLXDESTROYGLXPBUFFERSGIXPROC,
+ glXDestroyGLXPbufferSGIX, EGL_FALSE);
+#undef GET_PROC
+
+ GLX_drv->handle = handle;
+
+ return EGL_TRUE;
+
+fail:
+ if (handle)
+ dlclose(handle);
+ return EGL_FALSE;
+}
+
+
/**
* This is the main entrypoint into the driver, called by libEGL.
* 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);
@@ -999,6 +1130,12 @@ _eglMain(const char *args)
if (!GLX_drv)
return NULL;
+ if (!GLX_Load(&GLX_drv->Base)) {
+ _eglLog(_EGL_WARNING, "GLX: failed to load GLX");
+ free(GLX_drv);
+ return NULL;
+ }
+
_eglInitDriverFallbacks(&GLX_drv->Base);
GLX_drv->Base.API.Initialize = GLX_eglInitialize;
GLX_drv->Base.API.Terminate = GLX_eglTerminate;
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index b4ca20c094..c710631688 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
@@ -80,11 +93,12 @@ default: depend library
# EGL Library
library: $(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME)
-$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS)
+$(TOP)/$(LIB_DIR)/$(EGL_LIB_NAME): $(OBJECTS) $(LOCAL_LIBS)
$(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/SConscript b/src/egl/main/SConscript
index f001b81600..8c57ceaf20 100644
--- a/src/egl/main/SConscript
+++ b/src/egl/main/SConscript
@@ -7,13 +7,23 @@ Import('*')
env = env.Clone()
env.Append(CPPDEFINES = [
- '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_WINDOWS',
+ '_EGL_BUILT_IN_DRIVER_GALLIUM',
'_EGL_DRIVER_SEARCH_DIR=\\"\\"',
- '_EGL_OS_WINDOWS',
- '_EGL_GET_CORE_ADDRESSES',
- 'KHRONOS_DLL_EXPORTS',
])
+if env['platform'] == 'windows':
+ env.Append(CPPDEFINES = [
+ '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_WINDOWS',
+ '_EGL_OS_WINDOWS',
+ '_EGL_GET_CORE_ADDRESSES',
+ 'KHRONOS_DLL_EXPORTS',
+ ])
+else:
+ env.Append(CPPDEFINES = [
+ '_EGL_NATIVE_PLATFORM=_EGL_PLATFORM_X11',
+ '_EGL_OS_UNIX',
+ ])
+
env.Append(CPPPATH = [
'#/include',
])
@@ -38,15 +48,9 @@ egl_sources = [
'eglsync.c',
]
-egl = env.SharedLibrary(
- target = 'libEGL',
- source = egl_sources + ['egl.def'],
+egl = env.ConvenienceLibrary(
+ target = 'egl',
+ source = egl_sources,
)
-installed_egl = env.InstallSharedLibrary(egl, version=(1, 4, 0))
-
-env.Alias('egl', installed_egl)
-
-egl = [env.FindIxes(egl, 'LIBPREFIX', 'LIBSUFFIX')]
-
Export('egl')
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index efa9e97346..4e64ce6f71 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -57,7 +57,6 @@
#include <stdlib.h>
#include <string.h>
-#include "eglstring.h"
#include "eglcontext.h"
#include "egldisplay.h"
#include "egltypedefs.h"
@@ -294,16 +293,14 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
if (!_eglMatchDriver(disp, EGL_FALSE))
RETURN_EGL_ERROR(disp, EGL_NOT_INITIALIZED, EGL_FALSE);
- _eglsnprintf(disp->Version, sizeof(disp->Version), "%d.%d (%s)",
- disp->APImajor, disp->APIminor, disp->Driver->Name);
/* limit to APIs supported by core */
- disp->ClientAPIsMask &= _EGL_API_ALL_BITS;
+ disp->ClientAPIs &= _EGL_API_ALL_BITS;
}
/* Update applications version of major and minor if not NULL */
if ((major != NULL) && (minor != NULL)) {
- *major = disp->APImajor;
- *minor = disp->APIminor;
+ *major = disp->VersionMajor;
+ *minor = disp->VersionMinor;
}
RETURN_EGL_SUCCESS(disp, EGL_TRUE);
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index 127becc9ac..01492082f6 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -12,7 +12,7 @@ typedef void (*_EGLProc)(void);
*/
/* driver funcs */
-typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy, EGLint *major, EGLint *minor);
+typedef EGLBoolean (*Initialize_t)(_EGLDriver *, _EGLDisplay *dpy);
typedef EGLBoolean (*Terminate_t)(_EGLDriver *, _EGLDisplay *dpy);
/* config funcs */
diff --git a/src/egl/main/eglarray.c b/src/egl/main/eglarray.c
index d686fa162d..fe2f1a7f32 100644
--- a/src/egl/main/eglarray.c
+++ b/src/egl/main/eglarray.c
@@ -118,38 +118,39 @@ _eglFindArray(_EGLArray *array, void *elem)
/**
- * Filter an array and return the filtered data. The returned data pointer
- * should be freed.
+ * Filter an array and return the number of filtered elements.
*/
-void **
-_eglFilterArray(_EGLArray *array, EGLint *size,
+EGLint
+_eglFilterArray(_EGLArray *array, void **data, EGLint size,
_EGLArrayForEach filter, void *filter_data)
{
- void **data;
EGLint count = 0, i;
- if (!array) {
- *size = 0;
- return malloc(0);
- }
-
- data = malloc(array->Size * sizeof(array->Elements[0]));
- if (!data)
- return NULL;
+ if (!array)
+ return 0;
if (filter) {
for (i = 0; i < array->Size; i++) {
- if (filter(array->Elements[i], filter_data))
- data[count++] = array->Elements[i];
+ if (filter(array->Elements[i], filter_data)) {
+ if (data && count < size)
+ data[count] = array->Elements[i];
+ count++;
+ }
+ if (data && count >= size)
+ break;
}
}
else {
- memcpy(data, array->Elements, array->Size * sizeof(array->Elements[0]));
+ if (data) {
+ count = (size < array->Size) ? size : array->Size;
+ memcpy(data, array->Elements, count * sizeof(array->Elements[0]));
+ }
+ else {
+ count = array->Size;
+ }
}
- *size = count;
-
- return data;
+ return count;
}
diff --git a/src/egl/main/eglarray.h b/src/egl/main/eglarray.h
index c8309fb066..a88189a625 100644
--- a/src/egl/main/eglarray.h
+++ b/src/egl/main/eglarray.h
@@ -37,8 +37,8 @@ void *
_eglFindArray(_EGLArray *array, void *elem);
-PUBLIC void **
-_eglFilterArray(_EGLArray *array, EGLint *size,
+PUBLIC EGLint
+_eglFilterArray(_EGLArray *array, void **data, EGLint size,
_EGLArrayForEach filter, void *filter_data);
diff --git a/src/egl/main/eglconfig.c b/src/egl/main/eglconfig.c
index fec94fb20c..5b377b7f61 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -697,11 +697,22 @@ _eglChooseConfig(_EGLDriver *drv, _EGLDisplay *disp, const EGLint *attrib_list,
if (!_eglParseConfigAttribList(&criteria, disp, attrib_list))
return _eglError(EGL_BAD_ATTRIBUTE, "eglChooseConfig");
- configList = (_EGLConfig **) _eglFilterArray(disp->Configs, &count,
+ /* get the number of matched configs */
+ count = _eglFilterArray(disp->Configs, NULL, 0,
(_EGLArrayForEach) _eglMatchConfig, (void *) &criteria);
+ if (!count) {
+ *num_configs = count;
+ return EGL_TRUE;
+ }
+
+ configList = malloc(sizeof(*configList) * count);
if (!configList)
return _eglError(EGL_BAD_ALLOC, "eglChooseConfig(out of memory)");
+ /* get the matched configs */
+ _eglFilterArray(disp->Configs, (void **) configList, count,
+ (_EGLArrayForEach) _eglMatchConfig, (void *) &criteria);
+
/* perform sorting of configs */
if (configs && count) {
_eglSortConfigs((const _EGLConfig **) configList, count,
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index cbca9ff2c2..4221a9be3e 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -286,6 +286,9 @@ _eglError(EGLint errCode, const char *msg)
case EGL_BAD_SURFACE:
s = "EGL_BAD_SURFACE";
break;
+ case EGL_NOT_INITIALIZED:
+ s = "EGL_NOT_INITIALIZED";
+ break;
#ifdef EGL_MESA_screen_surface
case EGL_BAD_SCREEN_MESA:
s = "EGL_BAD_SCREEN_MESA";
@@ -295,7 +298,7 @@ _eglError(EGLint errCode, const char *msg)
break;
#endif
default:
- s = "other";
+ s = "other EGL error";
}
_eglLog(_EGL_DEBUG, "EGL user error 0x%x (%s) in %s\n", errCode, s, msg);
}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index bcba05480a..dbc5d32d91 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -74,8 +74,6 @@ struct _egl_extensions
EGLBoolean NOK_swap_region;
EGLBoolean NOK_texture_from_pixmap;
-
- char String[_EGL_MAX_EXTENSIONS_LEN];
};
@@ -86,21 +84,29 @@ struct _egl_display
_EGLMutex Mutex;
- _EGLPlatformType Platform;
- void *PlatformDisplay;
-
- EGLBoolean Initialized; /**< True if the display is initialized */
- _EGLDriver *Driver;
- void *DriverData; /* private to driver */
-
- int APImajor, APIminor; /**< as returned by eglInitialize() */
- char Version[1000]; /**< initialized from APImajor/minor, DriverName */
-
- /** Bitmask of supported APIs (EGL_xx_BIT) set by the driver during init */
- EGLint ClientAPIsMask;
- char ClientAPIs[1000]; /**< updated by eglQueryString */
-
- _EGLExtensions Extensions;
+ _EGLPlatformType Platform; /**< The type of the platform display */
+ void *PlatformDisplay; /**< A pointer to the platform display */
+
+ _EGLDriver *Driver; /**< Matched driver of the display */
+ EGLBoolean Initialized; /**< True if the display is initialized */
+
+ /* options that affect how the driver initializes the display */
+ struct {
+ EGLBoolean TestOnly; /**< Driver should not set fields when true */
+ EGLBoolean UseFallback; /**< Use fallback driver (sw or less features) */
+ } Options;
+
+ /* these fields are set by the driver during init */
+ void *DriverData; /**< Driver private data */
+ EGLint VersionMajor; /**< EGL major version */
+ EGLint VersionMinor; /**< EGL minor version */
+ EGLint ClientAPIs; /**< Bitmask of APIs supported (EGL_xxx_BIT) */
+ _EGLExtensions Extensions; /**< Extensions supported */
+
+ /* these fields are derived from above */
+ char VersionString[1000]; /**< EGL_VERSION */
+ char ClientAPIsString[1000]; /**< EGL_CLIENT_APIS */
+ char ExtensionsString[_EGL_MAX_EXTENSIONS_LEN]; /**< EGL_EXTENSIONS */
_EGLArray *Screens;
_EGLArray *Configs;
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index ff0011c4b1..e133c220f5 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,21 @@ 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_GALLIUM
+ { "egl_gallium", _eglBuiltInDriverGALLIUM },
+#endif
+#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()
@@ -128,9 +144,6 @@ _eglOpenLibrary(const char *driverPath, lib_handle *handle)
if (!lib) {
_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;
}
@@ -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) {
@@ -186,11 +208,22 @@ _eglLoadModule(_EGLModule *mod)
static void
_eglUnloadModule(_EGLModule *mod)
{
+#if defined(_EGL_OS_UNIX)
/* destroy the driver */
if (mod->Driver && mod->Driver->Unload)
mod->Driver->Unload(mod->Driver);
+
+ /*
+ * XXX At this point (atexit), the module might be the last reference to
+ * libEGL. Closing the module might unmap libEGL and give problems.
+ */
+#if 0
if (mod->Handle)
close_library(mod->Handle);
+#endif
+#elif defined(_EGL_OS_WINDOWS)
+ /* XXX Windows unloads DLLs before atexit */
+#endif
mod->Driver = NULL;
mod->Handle = NULL;
@@ -302,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.
@@ -461,7 +432,7 @@ _eglGetSearchPath(void)
*
* The user driver is specified by EGL_DRIVER.
*/
-static void
+static EGLBoolean
_eglAddUserDriver(void)
{
const char *search_path = _eglGetSearchPath();
@@ -478,34 +449,54 @@ _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;
+ }
+ }
+
+ return EGL_TRUE;
+ }
+
+ return EGL_FALSE;
}
/**
- * Add default drivers to the module array.
+ * Add egl_gallium to the module array.
*/
static void
-_eglAddDefaultDrivers(void)
+_eglAddGalliumDriver(void)
{
- const char *search_path = _eglGetSearchPath();
- 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"
- };
+#ifndef _EGL_BUILT_IN_DRIVER_GALLIUM
+ void *external = (void *) "egl_gallium";
+ _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderFile, external);
#endif
+}
+
+
+/**
+ * Add built-in drivers to the module array.
+ */
+static void
+_eglAddBuiltInDrivers(void)
+{
+ _EGLModule *mod;
+ EGLint i;
- 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;
}
}
@@ -520,113 +511,96 @@ _eglAddDrivers(void)
if (_eglModules)
return EGL_TRUE;
- /* the order here decides the priorities of the drivers */
- _eglAddUserDriver();
- _eglAddDefaultDrivers();
- _eglPreloadForEach(_eglGetSearchPath(), _eglLoaderPattern, (void *) "egl_");
+ if (!_eglAddUserDriver()) {
+ /*
+ * Add other drivers only when EGL_DRIVER is not set. The order here
+ * decides the priorities.
+ */
+ _eglAddGalliumDriver();
+ _eglAddBuiltInDrivers();
+ }
return (_eglModules != NULL);
}
/**
- * Match a display to a driver. The display is initialized unless use_probe is
- * true.
- *
- * The matching is done by finding the first driver that can initialize the
- * display, or when use_probe is true, the driver with highest score.
+ * A helper function for _eglMatchDriver. It finds the first driver that can
+ * initialize the display and return.
*/
-_EGLDriver *
-_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean use_probe)
+static _EGLDriver *
+_eglMatchAndInitialize(_EGLDisplay *dpy)
{
- _EGLModule *mod;
- _EGLDriver *best_drv = NULL;
- EGLint best_score = 0;
- EGLint major, minor, i;
-
- _eglLockMutex(&_eglModuleMutex);
+ _EGLDriver *drv = NULL;
+ EGLint i = 0;
if (!_eglAddDrivers()) {
- _eglUnlockMutex(&_eglModuleMutex);
- return EGL_FALSE;
+ _eglLog(_EGL_WARNING, "failed to find any driver");
+ return NULL;
}
- /* match the loaded modules */
- for (i = 0; i < _eglModules->Size; i++) {
- mod = (_EGLModule *) _eglModules->Elements[i];
- if (!mod->Driver)
- break;
+ if (dpy->Driver) {
+ drv = dpy->Driver;
+ /* no re-matching? */
+ if (!drv->API.Initialize(drv, dpy))
+ drv = NULL;
+ return drv;
+ }
- if (use_probe) {
- EGLint score = (mod->Driver->Probe) ?
- mod->Driver->Probe(mod->Driver, dpy) : 1;
- if (score > best_score) {
- best_drv = mod->Driver;
- best_score = score;
- }
+ while (i < _eglModules->Size) {
+ _EGLModule *mod = (_EGLModule *) _eglModules->Elements[i];
+
+ if (!_eglLoadModule(mod)) {
+ /* remove invalid modules */
+ _eglEraseArray(_eglModules, i, _eglFreeModule);
+ continue;
+ }
+
+ if (mod->Driver->API.Initialize(mod->Driver, dpy)) {
+ drv = mod->Driver;
+ break;
}
else {
- if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor)) {
- best_drv = mod->Driver;
- best_score = 100;
- }
+ i++;
}
- /* perfect match */
- if (best_score >= 100)
- break;
}
- /* load more modules */
- if (!best_drv) {
- EGLint first_unloaded = i;
+ return drv;
+}
- while (i < _eglModules->Size) {
- mod = (_EGLModule *) _eglModules->Elements[i];
- assert(!mod->Driver);
- if (!_eglLoadModule(mod)) {
- /* remove invalid modules */
- _eglEraseArray(_eglModules, i, _eglFreeModule);
- continue;
- }
+/**
+ * Match a display to a driver. The display is initialized unless test_only is
+ * true. The matching is done by finding the first driver that can initialize
+ * the display.
+ */
+_EGLDriver *
+_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only)
+{
+ _EGLDriver *best_drv;
- if (use_probe) {
- best_score = (mod->Driver->Probe) ?
- mod->Driver->Probe(mod->Driver, dpy) : 1;
- }
- else {
- if (mod->Driver->API.Initialize(mod->Driver, dpy, &major, &minor))
- best_score = 100;
- }
+ assert(!dpy->Initialized);
- if (best_score > 0) {
- best_drv = mod->Driver;
- /* loaded modules come before unloaded ones */
- if (first_unloaded != i) {
- void *tmp = _eglModules->Elements[i];
- _eglModules->Elements[i] =
- _eglModules->Elements[first_unloaded];
- _eglModules->Elements[first_unloaded] = tmp;
- }
- break;
- }
- else {
- _eglUnloadModule(mod);
- i++;
- }
- }
+ _eglLockMutex(&_eglModuleMutex);
+
+ /* set options */
+ dpy->Options.TestOnly = test_only;
+ dpy->Options.UseFallback = EGL_FALSE;
+
+ best_drv = _eglMatchAndInitialize(dpy);
+ if (!best_drv) {
+ dpy->Options.UseFallback = EGL_TRUE;
+ best_drv = _eglMatchAndInitialize(dpy);
}
_eglUnlockMutex(&_eglModuleMutex);
if (best_drv) {
- _eglLog(_EGL_DEBUG, "the best driver is %s (score %d)",
- best_drv->Name, best_score);
- if (!use_probe) {
+ _eglLog(_EGL_DEBUG, "the best driver is %s%s",
+ best_drv->Name, (test_only) ? " (test only) " : "");
+ if (!test_only) {
dpy->Driver = best_drv;
dpy->Initialized = EGL_TRUE;
- dpy->APImajor = major;
- dpy->APIminor = minor;
}
}
@@ -670,12 +644,7 @@ _eglUnloadDrivers(void)
{
/* this is called at atexit time */
if (_eglModules) {
-#if defined(_EGL_OS_UNIX)
_eglDestroyArray(_eglModules, _eglFreeModule);
-#elif defined(_EGL_OS_WINDOWS)
- /* XXX Windows unloads DLLs before atexit */
- _eglDestroyArray(_eglModules, NULL);
-#endif
_eglModules = NULL;
}
}
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index 1a0aaad1f8..3cde102d12 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -44,16 +44,6 @@ struct _egl_driver
const char *Name; /**< name of 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().
@@ -64,12 +54,24 @@ struct _egl_driver
};
+extern _EGLDriver *
+_eglBuiltInDriverGALLIUM(const char *args);
+
+
+extern _EGLDriver *
+_eglBuiltInDriverDRI2(const char *args);
+
+
+extern _EGLDriver *
+_eglBuiltInDriverGLX(const char *args);
+
+
PUBLIC _EGLDriver *
_eglMain(const char *args);
extern _EGLDriver *
-_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean probe_only);
+_eglMatchDriver(_EGLDisplay *dpy, EGLBoolean test_only);
extern __eglMustCastToProperFunctionPointerType
diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
index bbb96a908e..f8ba5f33eb 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -36,6 +36,8 @@
#include "eglcurrent.h"
#include "eglmisc.h"
#include "egldisplay.h"
+#include "egldriver.h"
+#include "eglstring.h"
/**
@@ -73,11 +75,11 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
do { \
if (dpy->Extensions.ext) { \
_eglAppendExtension(&exts, "EGL_" #ext); \
- assert(exts <= dpy->Extensions.String + _EGL_MAX_EXTENSIONS_LEN); \
+ assert(exts <= dpy->ExtensionsString + _EGL_MAX_EXTENSIONS_LEN); \
} \
} while (0)
- char *exts = dpy->Extensions.String;
+ char *exts = dpy->ExtensionsString;
if (exts[0])
return;
@@ -114,24 +116,24 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
static void
_eglUpdateAPIsString(_EGLDisplay *dpy)
{
- char *apis = dpy->ClientAPIs;
+ char *apis = dpy->ClientAPIsString;
- if (apis[0] || !dpy->ClientAPIsMask)
+ if (apis[0] || !dpy->ClientAPIs)
return;
- if (dpy->ClientAPIsMask & EGL_OPENGL_BIT)
+ if (dpy->ClientAPIs & EGL_OPENGL_BIT)
strcat(apis, "OpenGL ");
- if (dpy->ClientAPIsMask & EGL_OPENGL_ES_BIT)
+ if (dpy->ClientAPIs & EGL_OPENGL_ES_BIT)
strcat(apis, "OpenGL_ES ");
- if (dpy->ClientAPIsMask & EGL_OPENGL_ES2_BIT)
+ if (dpy->ClientAPIs & EGL_OPENGL_ES2_BIT)
strcat(apis, "OpenGL_ES2 ");
- if (dpy->ClientAPIsMask & EGL_OPENVG_BIT)
+ if (dpy->ClientAPIs & EGL_OPENVG_BIT)
strcat(apis, "OpenVG ");
- assert(strlen(apis) < sizeof(dpy->ClientAPIs));
+ assert(strlen(apis) < sizeof(dpy->ClientAPIsString));
}
@@ -139,20 +141,21 @@ const char *
_eglQueryString(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name)
{
(void) drv;
- (void) dpy;
+
switch (name) {
case EGL_VENDOR:
return _EGL_VENDOR_STRING;
case EGL_VERSION:
- return dpy->Version;
+ _eglsnprintf(dpy->VersionString, sizeof(dpy->VersionString),
+ "%d.%d (%s)", dpy->VersionMajor, dpy->VersionMinor,
+ dpy->Driver->Name);
+ return dpy->VersionString;
case EGL_EXTENSIONS:
_eglUpdateExtensionsString(dpy);
- return dpy->Extensions.String;
-#ifdef EGL_VERSION_1_2
+ return dpy->ExtensionsString;
case EGL_CLIENT_APIS:
_eglUpdateAPIsString(dpy);
- return dpy->ClientAPIs;
-#endif
+ return dpy->ClientAPIsString;
default:
_eglError(EGL_BAD_PARAMETER, "eglQueryString");
return NULL;
diff --git a/src/egl/main/eglstring.h b/src/egl/main/eglstring.h
index f1d559b24a..d4c8954136 100644
--- a/src/egl/main/eglstring.h
+++ b/src/egl/main/eglstring.h
@@ -2,6 +2,7 @@
#define EGLSTRING_INCLUDED
#include <string.h>
+#include <stdio.h>
#ifdef _EGL_OS_WINDOWS
#define _eglstrcasecmp _stricmp