summaryrefslogtreecommitdiff
path: root/src/egl/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/egl/main')
-rw-r--r--src/egl/main/Makefile44
-rw-r--r--src/egl/main/eglapi.c110
-rw-r--r--src/egl/main/eglapi.h21
-rw-r--r--src/egl/main/eglcompiler.h29
-rw-r--r--src/egl/main/eglconfig.c6
-rw-r--r--src/egl/main/eglconfig.h14
-rw-r--r--src/egl/main/eglconfigutil.c207
-rw-r--r--src/egl/main/eglconfigutil.h14
-rw-r--r--src/egl/main/eglcontext.c236
-rw-r--r--src/egl/main/eglcontext.h70
-rw-r--r--src/egl/main/eglcurrent.c42
-rw-r--r--src/egl/main/eglcurrent.h16
-rw-r--r--src/egl/main/egldisplay.c237
-rw-r--r--src/egl/main/egldisplay.h167
-rw-r--r--src/egl/main/egldriver.c421
-rw-r--r--src/egl/main/egldriver.h44
-rw-r--r--src/egl/main/eglimage.c51
-rw-r--r--src/egl/main/eglimage.h94
-rw-r--r--src/egl/main/egllog.h6
-rw-r--r--src/egl/main/eglmisc.c8
-rw-r--r--src/egl/main/eglmode.h2
-rw-r--r--src/egl/main/eglscreen.h6
-rw-r--r--src/egl/main/eglsurface.c6
-rw-r--r--src/egl/main/eglsurface.h74
-rw-r--r--src/egl/main/egltypedefs.h6
25 files changed, 1045 insertions, 886 deletions
diff --git a/src/egl/main/Makefile b/src/egl/main/Makefile
index c951b070f1..31f214cf6f 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 \
@@ -16,6 +19,7 @@ HEADERS = \
egldisplay.h \
egldriver.h \
eglglobals.h \
+ eglimage.h \
egllog.h \
eglmisc.h \
eglmode.h \
@@ -33,6 +37,7 @@ SOURCES = \
egldisplay.c \
egldriver.c \
eglglobals.c \
+ eglimage.c \
egllog.c \
eglmisc.c \
eglmode.c \
@@ -43,9 +48,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=\"$(EGL_DRIVER_INSTALL_DIR)\"
.c.o:
$(CC) -c $(INCLUDE_DIRS) $(CFLAGS) $(LOCAL_CFLAGS) $< -o $@
@@ -56,21 +66,29 @@ 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-headers:
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/KHR
+ $(INSTALL) -m 644 $(TOP)/include/KHR/*.h \
+ $(DESTDIR)$(INSTALL_INC_DIR)/KHR
+ $(INSTALL) -d $(DESTDIR)$(INSTALL_INC_DIR)/EGL
+ $(INSTALL) -m 644 $(TOP)/include/EGL/*.h \
+ $(DESTDIR)$(INSTALL_INC_DIR)/EGL
+
+install: default install-headers
$(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 +100,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..90828bd3e9 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -65,6 +65,7 @@
#include "eglconfig.h"
#include "eglscreen.h"
#include "eglmode.h"
+#include "eglimage.h"
/**
@@ -72,7 +73,7 @@
* We initialize our global vars and create a private _EGLDisplay object.
*/
EGLDisplay EGLAPIENTRY
-eglGetDisplay(NativeDisplayType nativeDisplay)
+eglGetDisplay(EGLNativeDisplayType nativeDisplay)
{
_EGLDisplay *dpy;
dpy = _eglFindDisplay(nativeDisplay);
@@ -101,15 +102,15 @@ eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
drv = disp->Driver;
if (!drv) {
- drv = _eglOpenDriver(disp);
+ _eglPreloadDrivers();
+
+ drv = _eglMatchDriver(disp);
if (!drv)
return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__);
/* Initialize the particular display now */
- if (!drv->API.Initialize(drv, disp, &major_int, &minor_int)) {
- _eglCloseDriver(drv, disp);
+ if (!drv->API.Initialize(drv, disp, &major_int, &minor_int))
return _eglError(EGL_NOT_INITIALIZED, __FUNCTION__);
- }
disp->APImajor = major_int;
disp->APIminor = minor_int;
@@ -147,7 +148,6 @@ eglTerminate(EGLDisplay dpy)
drv = disp->Driver;
if (drv) {
drv->API.Terminate(drv, disp);
- _eglCloseDriver(drv, disp);
disp->Driver = NULL;
}
@@ -415,7 +415,7 @@ eglQueryContext(EGLDisplay dpy, EGLContext ctx,
EGLSurface EGLAPIENTRY
eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
- NativeWindowType window, const EGLint *attrib_list)
+ EGLNativeWindowType window, const EGLint *attrib_list)
{
_EGLDisplay *disp = _eglLookupDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
@@ -436,7 +436,7 @@ eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
EGLSurface EGLAPIENTRY
eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
- NativePixmapType pixmap, const EGLint *attrib_list)
+ EGLNativePixmapType pixmap, const EGLint *attrib_list)
{
_EGLDisplay *disp = _eglLookupDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
@@ -524,7 +524,7 @@ eglSwapInterval(EGLDisplay dpy, EGLint interval)
_EGLSurface *surf;
_EGL_DECLARE_DD(dpy);
- if (!ctx || !_eglIsContextLinked(ctx) || ctx->Display != disp)
+ if (!ctx || !_eglIsContextLinked(ctx) || ctx->Resource.Display != disp)
return _eglError(EGL_BAD_CONTEXT, __FUNCTION__);
surf = ctx->DrawSurface;
@@ -550,7 +550,7 @@ eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
EGLBoolean EGLAPIENTRY
-eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, NativePixmapType target)
+eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
{
_EGL_DECLARE_DD_AND_SURFACE(dpy, surface);
return drv->API.CopyBuffers(drv, disp, surf, target);
@@ -571,7 +571,7 @@ eglWaitClient(void)
return _eglError(EGL_BAD_CURRENT_SURFACE, __FUNCTION__);
/* a valid current context implies an initialized current display */
- disp = ctx->Display;
+ disp = ctx->Resource.Display;
drv = disp->Driver;
assert(drv);
@@ -615,7 +615,7 @@ eglWaitNative(EGLint engine)
return _eglError(EGL_BAD_CURRENT_SURFACE, __FUNCTION__);
/* a valid current context implies an initialized current display */
- disp = ctx->Display;
+ disp = ctx->Resource.Display;
drv = disp->Driver;
assert(drv);
@@ -626,8 +626,8 @@ eglWaitNative(EGLint engine)
EGLDisplay EGLAPIENTRY
eglGetCurrentDisplay(void)
{
- _EGLDisplay *dpy = _eglGetCurrentDisplay();
- return _eglGetDisplayHandle(dpy);
+ _EGLContext *ctx = _eglGetCurrentContext();
+ return (ctx) ? _eglGetDisplayHandle(ctx->Resource.Display) : EGL_NO_DISPLAY;
}
@@ -676,7 +676,8 @@ eglGetError(void)
}
-void (* EGLAPIENTRY eglGetProcAddress(const char *procname))()
+__eglMustCastToProperFunctionPointerType EGLAPIENTRY
+eglGetProcAddress(const char *procname)
{
static const struct {
const char *name;
@@ -697,6 +698,10 @@ void (* EGLAPIENTRY eglGetProcAddress(const char *procname))()
{ "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA },
{ "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA },
#endif /* EGL_MESA_screen_surface */
+#ifdef EGL_KHR_image_base
+ { "eglCreateImageKHR", (_EGLProc) eglCreateImageKHR },
+ { "eglDestroyImageKHR", (_EGLProc) eglDestroyImageKHR },
+#endif /* EGL_KHR_image_base */
{ NULL, NULL }
};
EGLint i;
@@ -710,13 +715,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;
}
@@ -977,13 +981,20 @@ eglCreatePbufferFromClientBuffer(EGLDisplay dpy, EGLenum buftype,
EGLBoolean
eglReleaseThread(void)
{
- /* unbind current context */
+ /* unbind current contexts */
if (!_eglIsCurrentThreadDummy()) {
- _EGLDisplay *disp = _eglGetCurrentDisplay();
- _EGLDriver *drv;
- if (disp) {
- drv = disp->Driver;
- (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
+ _EGLThreadInfo *t = _eglGetCurrentThread();
+ EGLint i;
+
+ for (i = 0; i < _EGL_API_NUM_APIS; i++) {
+ _EGLContext *ctx = t->CurrentContexts[i];
+ if (ctx) {
+ _EGLDisplay *disp = ctx->Resource.Display;
+ _EGLDriver *drv = disp->Driver;
+ /* what if drv is not avaialbe? */
+ if (drv)
+ (void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
+ }
}
}
@@ -993,3 +1004,52 @@ eglReleaseThread(void)
#endif /* EGL_VERSION_1_2 */
+
+
+#ifdef EGL_KHR_image_base
+
+
+EGLImageKHR
+eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
+ EGLClientBuffer buffer, const EGLint *attr_list)
+{
+ _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLContext *context = _eglLookupContext(ctx, disp);
+ _EGLDriver *drv;
+ _EGLImage *img;
+
+ drv = _eglCheckDisplay(disp, __FUNCTION__);
+ if (!drv)
+ return EGL_NO_IMAGE_KHR;
+ if (!context && ctx != EGL_NO_CONTEXT) {
+ _eglError(EGL_BAD_CONTEXT, __FUNCTION__);
+ return EGL_NO_IMAGE_KHR;
+ }
+
+ img = drv->API.CreateImageKHR(drv,
+ disp, context, target, buffer, attr_list);
+ if (img)
+ return _eglLinkImage(img, disp);
+ else
+ return EGL_NO_IMAGE_KHR;
+}
+
+
+EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
+{
+ _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLImage *img = _eglLookupImage(image, disp);
+ _EGLDriver *drv;
+
+ drv = _eglCheckDisplay(disp, __FUNCTION__);
+ if (!drv)
+ return EGL_FALSE;
+ if (!img)
+ return _eglError(EGL_BAD_PARAMETER, __FUNCTION__);
+
+ _eglUnlinkImage(img);
+ return drv->API.DestroyImageKHR(drv, disp, img);
+}
+
+
+#endif /* EGL_KHR_image_base */
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index aa0abe3eb6..db31c7cf93 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -27,8 +27,8 @@ typedef EGLBoolean (*MakeCurrent_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurfa
typedef EGLBoolean (*QueryContext_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLint attribute, EGLint *value);
/* surface funcs */
-typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativeWindowType window, const EGLint *attrib_list);
-typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, NativePixmapType pixmap, const EGLint *attrib_list);
+typedef _EGLSurface *(*CreateWindowSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativeWindowType window, const EGLint *attrib_list);
+typedef _EGLSurface *(*CreatePixmapSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
typedef _EGLSurface *(*CreatePbufferSurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *config, const EGLint *attrib_list);
typedef EGLBoolean (*DestroySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface);
typedef EGLBoolean (*QuerySurface_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint attribute, EGLint *value);
@@ -37,14 +37,14 @@ typedef EGLBoolean (*BindTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurf
typedef EGLBoolean (*ReleaseTexImage_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLint buffer);
typedef EGLBoolean (*SwapInterval_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint interval);
typedef EGLBoolean (*SwapBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw);
-typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, NativePixmapType target);
+typedef EGLBoolean (*CopyBuffers_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface, EGLNativePixmapType target);
/* misc funcs */
typedef const char *(*QueryString_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLint name);
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);
@@ -69,6 +69,11 @@ typedef _EGLSurface *(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDis
#endif /* EGL_VERSION_1_2 */
+#ifdef EGL_KHR_image_base
+typedef _EGLImage *(*CreateImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list);
+typedef EGLBoolean (*DestroyImageKHR_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image);
+#endif /* EGL_KHR_image_base */
+
/**
* The API dispatcher jumps through these functions
@@ -104,7 +109,7 @@ struct _egl_api
WaitNative_t WaitNative;
GetProcAddress_t GetProcAddress;
- /* EGL_MESA_screen extension */
+#ifdef EGL_MESA_screen_surface
ChooseModeMESA_t ChooseModeMESA;
GetModesMESA_t GetModesMESA;
GetModeAttribMESA_t GetModeAttribMESA;
@@ -117,10 +122,16 @@ struct _egl_api
QueryScreenSurfaceMESA_t QueryScreenSurfaceMESA;
QueryScreenModeMESA_t QueryScreenModeMESA;
QueryModeStringMESA_t QueryModeStringMESA;
+#endif /* EGL_MESA_screen_surface */
#ifdef EGL_VERSION_1_2
CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer;
#endif
+
+#ifdef EGL_KHR_image_base
+ CreateImageKHR_t CreateImageKHR;
+ DestroyImageKHR_t DestroyImageKHR;
+#endif /* EGL_KHR_image_base */
};
#endif /* EGLAPI_INCLUDED */
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..a57aa33352 100644
--- a/src/egl/main/eglconfig.c
+++ b/src/egl/main/eglconfig.c
@@ -224,7 +224,8 @@ static const struct {
{ EGL_MATCH_NATIVE_PIXMAP, ATTRIB_TYPE_PSEUDO,
ATTRIB_CRITERION_SPECIAL,
EGL_NONE },
- { EGL_PRESERVED_RESOURCES, ATTRIB_TYPE_PSEUDO,
+ /* there is a gap before EGL_SAMPLES */
+ { 0x3030, ATTRIB_TYPE_PSEUDO,
ATTRIB_CRITERION_IGNORE,
0 },
{ EGL_NONE, ATTRIB_TYPE_PSEUDO,
@@ -324,6 +325,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 |
@@ -772,7 +774,7 @@ _eglIsConfigAttribValid(_EGLConfig *conf, EGLint attr)
/* there are some holes in the range */
switch (attr) {
- case EGL_PRESERVED_RESOURCES:
+ case 0x3030 /* a gap before EGL_SAMPLES */:
case EGL_NONE:
#ifdef EGL_VERSION_1_4
case EGL_MATCH_NATIVE_PIXMAP:
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.c b/src/egl/main/eglconfigutil.c
index 36e94f0d2d..9cf94b3c4a 100644
--- a/src/egl/main/eglconfigutil.c
+++ b/src/egl/main/eglconfigutil.c
@@ -128,210 +128,3 @@ _eglConfigFromContextModesRec(_EGLConfig *conf, const __GLcontextModes *m,
return EGL_TRUE;
}
-
-
-/**
- * Creates a set of \c _EGLConfigs that a driver will expose.
- *
- * A set of \c __GLcontextModes will be created based on the supplied
- * parameters. The number of modes processed will be 2 *
- * \c num_depth_stencil_bits * \c num_db_modes.
- *
- * For the most part, data is just copied from \c depth_bits, \c stencil_bits,
- * \c db_modes, and \c visType into each \c __GLcontextModes element.
- * However, the meanings of \c fb_format and \c fb_type require further
- * explanation. The \c fb_format specifies which color components are in
- * each pixel and what the default order is. For example, \c GL_RGB specifies
- * that red, green, blue are available and red is in the "most significant"
- * position and blue is in the "least significant". The \c fb_type specifies
- * the bit sizes of each component and the actual ordering. For example, if
- * \c GL_UNSIGNED_SHORT_5_6_5_REV is specified with \c GL_RGB, bits [15:11]
- * are the blue value, bits [10:5] are the green value, and bits [4:0] are
- * the red value.
- *
- * One sublte issue is the combination of \c GL_RGB or \c GL_BGR and either
- * of the \c GL_UNSIGNED_INT_8_8_8_8 modes. The resulting mask values in the
- * \c __GLcontextModes structure is \b identical to the \c GL_RGBA or
- * \c GL_BGRA case, except the \c alphaMask is zero. This means that, as
- * far as this routine is concerned, \c GL_RGB with \c GL_UNSIGNED_INT_8_8_8_8
- * still uses 32-bits.
- *
- * If in doubt, look at the tables used in the function.
- *
- * \param configs the array of configs generated
- * \param fb_format Format of the framebuffer. Currently only \c GL_RGB,
- * \c GL_RGBA, \c GL_BGR, and \c GL_BGRA are supported.
- * \param fb_type Type of the pixels in the framebuffer. Currently only
- * \c GL_UNSIGNED_SHORT_5_6_5,
- * \c GL_UNSIGNED_SHORT_5_6_5_REV,
- * \c GL_UNSIGNED_INT_8_8_8_8, and
- * \c GL_UNSIGNED_INT_8_8_8_8_REV are supported.
- * \param depth_bits Array of depth buffer sizes to be exposed.
- * \param stencil_bits Array of stencil buffer sizes to be exposed.
- * \param num_depth_stencil_bits Number of entries in both \c depth_bits and
- * \c stencil_bits.
- * \param db_modes Array of buffer swap modes. If an element has a
- * value of \c GLX_NONE, then it represents a
- * single-buffered mode. Other valid values are
- * \c GLX_SWAP_EXCHANGE_OML, \c GLX_SWAP_COPY_OML, and
- * \c GLX_SWAP_UNDEFINED_OML. See the
- * GLX_OML_swap_method extension spec for more details.
- * \param num_db_modes Number of entries in \c db_modes.
- * \param visType GLX visual type. Usually either \c GLX_TRUE_COLOR or
- * \c GLX_DIRECT_COLOR.
- *
- * \returns
- * \c GL_TRUE on success or \c GL_FALSE on failure. Currently the only
- * cause of failure is a bad parameter (i.e., unsupported \c fb_format or
- * \c fb_type).
- *
- * \todo
- * There is currently no way to support packed RGB modes (i.e., modes with
- * exactly 3 bytes per pixel) or floating-point modes. This could probably
- * be done by creating some new, private enums with clever names likes
- * \c GL_UNSIGNED_3BYTE_8_8_8, \c GL_4FLOAT_32_32_32_32,
- * \c GL_4HALF_16_16_16_16, etc. We can cross that bridge when we come to it.
- */
-EGLBoolean
-_eglFillInConfigs(_EGLConfig * configs,
- GLenum fb_format, GLenum fb_type,
- const uint8_t * depth_bits, const uint8_t * stencil_bits,
- unsigned num_depth_stencil_bits,
- const GLenum * db_modes, unsigned num_db_modes,
- int visType)
-{
- static const uint8_t bits_table[3][4] = {
- /* R G B A */
- { 5, 6, 5, 0 }, /* Any GL_UNSIGNED_SHORT_5_6_5 */
- { 8, 8, 8, 0 }, /* Any RGB with any GL_UNSIGNED_INT_8_8_8_8 */
- { 8, 8, 8, 8 } /* Any RGBA with any GL_UNSIGNED_INT_8_8_8_8 */
- };
-
- /* The following arrays are all indexed by the fb_type masked with 0x07.
- * Given the four supported fb_type values, this results in valid array
- * indices of 3, 4, 5, and 7.
- */
- static const uint32_t masks_table_rgb[8][4] = {
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
- {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
- {0xFF000000, 0x00FF0000, 0x0000FF00, 0x00000000}, /* 8_8_8_8 */
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000} /* 8_8_8_8_REV */
- };
-
- static const uint32_t masks_table_rgba[8][4] = {
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5 */
- {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5_REV */
- {0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF}, /* 8_8_8_8 */
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, /* 8_8_8_8_REV */
- };
-
-#if 0
- static const uint32_t masks_table_bgr[8][4] = {
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
- {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
- {0x0000FF00, 0x00FF0000, 0xFF000000, 0x00000000}, /* 8_8_8_8 */
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000}, /* 8_8_8_8_REV */
- };
-
- static const uint32_t masks_table_bgra[8][4] = {
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x0000001F, 0x000007E0, 0x0000F800, 0x00000000}, /* 5_6_5 */
- {0x0000F800, 0x000007E0, 0x0000001F, 0x00000000}, /* 5_6_5_REV */
- {0x0000FF00, 0x00FF0000, 0xFF000000, 0x000000FF}, /* 8_8_8_8 */
- {0x00000000, 0x00000000, 0x00000000, 0x00000000},
- {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, /* 8_8_8_8_REV */
- };
-#endif
-
- static const uint8_t bytes_per_pixel[8] = {
- 0, 0, 0, 2, 2, 4, 0, 4
- };
-
- const uint8_t * bits;
- const uint32_t * masks;
- const int index = fb_type & 0x07;
- _EGLConfig *config;
- unsigned i;
- unsigned j;
- unsigned k;
-
- if ( bytes_per_pixel[index] == 0 ) {
- _eglLog(_EGL_INFO,
- "[_eglFillInConfigs:%u] Framebuffer type 0x%04x has 0 bytes per pixel.",
- __LINE__, fb_type);
- return GL_FALSE;
- }
-
- /* Valid types are GL_UNSIGNED_SHORT_5_6_5 and GL_UNSIGNED_INT_8_8_8_8 and
- * the _REV versions.
- *
- * Valid formats are GL_RGBA, GL_RGB, and GL_BGRA.
- */
- switch ( fb_format ) {
- case GL_RGB:
- bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
- masks = masks_table_rgb[index];
- break;
-
- case GL_RGBA:
- bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
- masks = masks_table_rgba[index];
- break;
-
-#if 0
- case GL_BGR:
- bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[1];
- masks = masks_table_bgr[index];
- break;
-
- case GL_BGRA:
- bits = (bytes_per_pixel[index] == 2) ? bits_table[0] : bits_table[2];
- masks = masks_table_bgra[index];
- break;
-#endif
-
- default:
- _eglLog(_EGL_WARNING,
- "[_eglFillInConfigs:%u] Framebuffer format 0x%04x is not GL_RGB, GL_RGBA, GL_BGR, or GL_BGRA.",
- __LINE__, fb_format);
- return GL_FALSE;
- }
-
- config = configs;
- for (k = 0; k < num_depth_stencil_bits; k++) {
- for (i = 0; i < num_db_modes; i++) {
- for (j = 0; j < 2; j++) {
- _eglSetConfigAttrib(config, EGL_RED_SIZE, bits[0]);
- _eglSetConfigAttrib(config, EGL_GREEN_SIZE, bits[1]);
- _eglSetConfigAttrib(config, EGL_BLUE_SIZE, bits[2]);
- _eglSetConfigAttrib(config, EGL_ALPHA_SIZE, bits[3]);
- _eglSetConfigAttrib(config, EGL_BUFFER_SIZE,
- bits[0] + bits[1] + bits[2] + bits[3]);
-
- _eglSetConfigAttrib(config, EGL_STENCIL_SIZE, stencil_bits[k]);
- _eglSetConfigAttrib(config, EGL_DEPTH_SIZE, depth_bits[i]);
-
- _eglSetConfigAttrib(config, EGL_SURFACE_TYPE, EGL_SCREEN_BIT_MESA |
- EGL_PBUFFER_BIT | EGL_PIXMAP_BIT | EGL_WINDOW_BIT);
-
- config++;
- }
- }
- }
- return GL_TRUE;
-}
-
diff --git a/src/egl/main/eglconfigutil.h b/src/egl/main/eglconfigutil.h
index 8c923ee206..c6f4819960 100644
--- a/src/egl/main/eglconfigutil.h
+++ b/src/egl/main/eglconfigutil.h
@@ -7,23 +7,13 @@
#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
-_eglFillInConfigs( _EGLConfig *configs,
- EGLenum fb_format, EGLenum fb_type,
- const uint8_t * depth_bits, const uint8_t * stencil_bits,
- unsigned num_depth_stencil_bits,
- const EGLenum * db_modes, unsigned num_db_modes,
- int visType );
-
-
-
#endif /* EGLCONFIGUTIL_INCLUDED */
diff --git a/src/egl/main/eglcontext.c b/src/egl/main/eglcontext.c
index ee4b1b59f5..deaa8d3f41 100644
--- a/src/egl/main/eglcontext.c
+++ b/src/egl/main/eglcontext.c
@@ -140,101 +140,181 @@ _eglQueryContext(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *c,
/**
- * Drivers will typically call this to do the error checking and
- * update the various flags.
- * Then, the driver will do its device-dependent Make-Current stuff.
+ * Bind the context to the surface as the draw or read surface. Return the
+ * previous surface that the context is bound to.
+ *
+ * Note that the context may be NULL.
*/
-EGLBoolean
-_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw,
- _EGLSurface *read, _EGLContext *ctx)
+static _EGLSurface *
+_eglBindContextToSurface(_EGLContext *ctx, _EGLSurface *surf, EGLint readdraw)
+{
+ _EGLSurface **attachment, *oldSurf;
+
+ if (!ctx) {
+ surf->Binding = NULL;
+ return NULL;
+ }
+
+ attachment = (readdraw == EGL_DRAW) ?
+ &ctx->DrawSurface : &ctx->ReadSurface;
+ oldSurf = *attachment;
+
+ if (oldSurf == surf)
+ return NULL;
+
+ if (oldSurf)
+ oldSurf->Binding = NULL;
+ surf->Binding = ctx;
+ *attachment = surf;
+
+ return oldSurf;
+}
+
+
+/**
+ * Bind the context to the thread and return the previous context.
+ *
+ * Note that the context may be NULL.
+ */
+static _EGLContext *
+_eglBindContextToThread(_EGLContext *ctx, _EGLThreadInfo *t)
{
- _EGLThreadInfo *t = _eglGetCurrentThread();
- _EGLContext *oldContext = NULL;
- _EGLSurface *oldDrawSurface = NULL;
- _EGLSurface *oldReadSurface = NULL;
EGLint apiIndex;
+ _EGLContext *oldCtx;
+
+ apiIndex = (ctx) ?
+ _eglConvertApiToIndex(ctx->ClientAPI) : t->CurrentAPIIndex;
+
+ oldCtx = t->CurrentContexts[apiIndex];
+ if (ctx == oldCtx)
+ return NULL;
+
+ if (oldCtx)
+ oldCtx->Binding = NULL;
+ if (ctx)
+ ctx->Binding = t;
+
+ t->CurrentContexts[apiIndex] = ctx;
+
+ return oldCtx;
+}
+
+
+/**
+ * Return true if the given context and surfaces can be made current.
+ */
+static EGLBoolean
+_eglCheckMakeCurrent(_EGLContext *ctx, _EGLSurface *draw, _EGLSurface *read)
+{
+ _EGLThreadInfo *t = _eglGetCurrentThread();
+ EGLint conflict_api;
if (_eglIsCurrentThreadDummy())
return _eglError(EGL_BAD_ALLOC, "eglMakeCurrent");
- if (ctx) {
- /* error checking */
- if (ctx->Binding && ctx->Binding != t)
- return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
- if (draw == NULL || read == NULL)
- return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
- if (draw->Config != ctx->Config || read->Config != ctx->Config)
+ /* this is easy */
+ if (!ctx) {
+ if (draw || read)
return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
- if ((draw->Binding && draw->Binding->Binding != t) ||
- (read->Binding && read->Binding->Binding != t))
- return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
+ return EGL_TRUE;
+ }
+
+ /* ctx/draw/read must be all given */
+ if (draw == NULL || read == NULL)
+ return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
+
+ /* context stealing from another thread is not allowed */
+ if (ctx->Binding && ctx->Binding != t)
+ return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
+
+ /*
+ * The spec says
+ *
+ * "If ctx is current to some other thread, or if either draw or read are
+ * bound to contexts in another thread, an EGL_BAD_ACCESS error is
+ * generated."
+ *
+ * But it also says
+ *
+ * "at most one context may be bound to a particular surface at a given
+ * time"
+ *
+ * The latter is more restrictive so we can check only the latter case.
+ */
+ if ((draw->Binding && draw->Binding != ctx) ||
+ (read->Binding && read->Binding != ctx))
+ return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
+
+ /* simply require the configs to be equal */
+ if (draw->Config != ctx->Config || read->Config != ctx->Config)
+ return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
+ switch (ctx->ClientAPI) {
#ifdef EGL_VERSION_1_4
- /* OpenGL and OpenGL ES are conflicting */
- switch (ctx->ClientAPI) {
- case EGL_OPENGL_ES_API:
- if (t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_API)])
- return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
- break;
- case EGL_OPENGL_API:
- if (t->CurrentContexts[_eglConvertApiToIndex(EGL_OPENGL_ES_API)])
- return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
- break;
- default:
- break;
- }
+ /* OpenGL and OpenGL ES are conflicting */
+ case EGL_OPENGL_ES_API:
+ conflict_api = EGL_OPENGL_API;
+ break;
+ case EGL_OPENGL_API:
+ conflict_api = EGL_OPENGL_ES_API;
+ break;
#endif
- apiIndex = _eglConvertApiToIndex(ctx->ClientAPI);
- }
- else {
- if (draw != NULL || read != NULL)
- return _eglError(EGL_BAD_MATCH, "eglMakeCurrent");
- apiIndex = t->CurrentAPIIndex;
+ default:
+ conflict_api = -1;
+ break;
}
- oldContext = t->CurrentContexts[apiIndex];
- if (oldContext) {
- oldDrawSurface = oldContext->DrawSurface;
- oldReadSurface = oldContext->ReadSurface;
- assert(oldDrawSurface);
- assert(oldReadSurface);
-
- /* break old bindings */
- t->CurrentContexts[apiIndex] = NULL;
- oldContext->Binding = NULL;
- oldContext->DrawSurface = NULL;
- oldContext->ReadSurface = NULL;
- oldDrawSurface->Binding = NULL;
- oldReadSurface->Binding = NULL;
-
- /*
- * check if the old context or surfaces need to be deleted
- */
- if (!_eglIsSurfaceLinked(oldDrawSurface)) {
- assert(draw != oldDrawSurface && read != oldDrawSurface);
- drv->API.DestroySurface(drv, dpy, oldDrawSurface);
- }
- if (oldReadSurface != oldDrawSurface &&
- !_eglIsSurfaceLinked(oldReadSurface)) {
- assert(draw != oldReadSurface && read != oldReadSurface);
- drv->API.DestroySurface(drv, dpy, oldReadSurface);
- }
- if (!_eglIsContextLinked(oldContext)) {
- assert(ctx != oldContext);
- drv->API.DestroyContext(drv, dpy, oldContext);
- }
- }
+ if (conflict_api >= 0 && _eglGetAPIContext(conflict_api))
+ return _eglError(EGL_BAD_ACCESS, "eglMakeCurrent");
+
+ return EGL_TRUE;
+}
+
+
+/**
+ * Drivers will typically call this to do the error checking and
+ * update the various flags.
+ * Then, the driver will do its device-dependent Make-Current stuff.
+ */
+EGLBoolean
+_eglMakeCurrent(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *draw,
+ _EGLSurface *read, _EGLContext *ctx)
+{
+ _EGLThreadInfo *t = _eglGetCurrentThread();
+ _EGLSurface *oldDraw = NULL, *oldRead = NULL;
+ _EGLContext *oldCtx;
+
+ if (!_eglCheckMakeCurrent(ctx, draw, read))
+ return EGL_FALSE;
+
+ oldCtx = _eglBindContextToThread(ctx, t);
- /* build new bindings */
if (ctx) {
- t->CurrentContexts[apiIndex] = ctx;
- ctx->Binding = t;
- ctx->DrawSurface = draw;
- ctx->ReadSurface = read;
- draw->Binding = ctx;
- read->Binding = ctx;
+ oldDraw = _eglBindContextToSurface(ctx, draw, EGL_DRAW);
+ oldRead = _eglBindContextToSurface(ctx, read, EGL_READ);
+ }
+ else if (oldCtx) {
+ /* unbind the old context from its binding surfaces */
+ oldDraw = oldCtx->DrawSurface;
+ oldRead = oldCtx->ReadSurface;
+
+ if (oldDraw)
+ _eglBindContextToSurface(NULL, oldDraw, EGL_DRAW);
+ if (oldRead && oldRead != oldDraw)
+ _eglBindContextToSurface(NULL, oldRead, EGL_READ);
}
+ /* avoid double destroy */
+ if (oldRead && oldRead == oldDraw)
+ oldRead = NULL;
+
+ if (oldCtx && !_eglIsContextLinked(oldCtx))
+ drv->API.DestroyContext(drv, dpy, oldCtx);
+ if (oldDraw && !_eglIsSurfaceLinked(oldDraw))
+ drv->API.DestroySurface(drv, dpy, oldDraw);
+ if (oldRead && !_eglIsSurfaceLinked(oldRead))
+ drv->API.DestroySurface(drv, dpy, oldRead);
+
return EGL_TRUE;
}
diff --git a/src/egl/main/eglcontext.h b/src/egl/main/eglcontext.h
index 45c7b4717b..be00642d13 100644
--- a/src/egl/main/eglcontext.h
+++ b/src/egl/main/eglcontext.h
@@ -4,6 +4,7 @@
#include "egltypedefs.h"
+#include "egldisplay.h"
/**
@@ -11,9 +12,8 @@
*/
struct _egl_context
{
- /* Managed by EGLDisplay for linking */
- _EGLDisplay *Display;
- _EGLContext *Next;
+ /* A context is a display resource */
+ _EGLResource Resource;
/* The bound status of the context */
_EGLThreadInfo *Binding;
@@ -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);
@@ -65,4 +65,64 @@ _eglIsContextBound(_EGLContext *ctx)
}
+/**
+ * Link a context to a display and return the handle of the link.
+ * The handle can be passed to client directly.
+ */
+static INLINE EGLContext
+_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy)
+{
+ _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy);
+ return (EGLContext) ctx;
+}
+
+
+/**
+ * Unlink a linked context from its display.
+ * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
+ */
+static INLINE void
+_eglUnlinkContext(_EGLContext *ctx)
+{
+ _eglUnlinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT);
+}
+
+
+/**
+ * Lookup a handle to find the linked context.
+ * Return NULL if the handle has no corresponding linked context.
+ */
+static INLINE _EGLContext *
+_eglLookupContext(EGLContext context, _EGLDisplay *dpy)
+{
+ _EGLContext *ctx = (_EGLContext *) context;
+ if (!dpy || !_eglCheckResource((void *) ctx, _EGL_RESOURCE_CONTEXT, dpy))
+ ctx = NULL;
+ return ctx;
+}
+
+
+/**
+ * Return the handle of a linked context, or EGL_NO_CONTEXT.
+ */
+static INLINE EGLContext
+_eglGetContextHandle(_EGLContext *ctx)
+{
+ _EGLResource *res = (_EGLResource *) ctx;
+ return (res && _eglIsResourceLinked(res)) ?
+ (EGLContext) ctx : EGL_NO_CONTEXT;
+}
+
+
+/**
+ * Return true if the context is linked to a display.
+ */
+static INLINE EGLBoolean
+_eglIsContextLinked(_EGLContext *ctx)
+{
+ _EGLResource *res = (_EGLResource *) ctx;
+ return (res && _eglIsResourceLinked(res));
+}
+
+
#endif /* EGLCONTEXT_INCLUDED */
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index df506151b5..696d04e8ba 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -227,50 +227,24 @@ _eglIsCurrentThreadDummy(void)
/**
- * Return the currently bound context, or NULL.
+ * Return the currently bound context of the given API, or NULL.
*/
-_EGLContext *
-_eglGetCurrentContext(void)
-{
- _EGLThreadInfo *t = _eglGetCurrentThread();
- return t->CurrentContexts[t->CurrentAPIIndex];
-}
-
-
-/**
- * Return the display of the currently bound context, or NULL.
- */
-_EGLDisplay *
-_eglGetCurrentDisplay(void)
+PUBLIC _EGLContext *
+_eglGetAPIContext(EGLenum api)
{
_EGLThreadInfo *t = _eglGetCurrentThread();
- _EGLContext *ctx = t->CurrentContexts[t->CurrentAPIIndex];
- if (ctx)
- return ctx->Display;
- else
- return NULL;
+ return t->CurrentContexts[_eglConvertApiToIndex(api)];
}
/**
- * Return the read or write surface of the currently bound context, or NULL.
+ * Return the currently bound context of the current API, or NULL.
*/
-_EGLSurface *
-_eglGetCurrentSurface(EGLint readdraw)
+_EGLContext *
+_eglGetCurrentContext(void)
{
_EGLThreadInfo *t = _eglGetCurrentThread();
- _EGLContext *ctx = t->CurrentContexts[t->CurrentAPIIndex];
- if (ctx) {
- switch (readdraw) {
- case EGL_DRAW:
- return ctx->DrawSurface;
- case EGL_READ:
- return ctx->ReadSurface;
- default:
- return NULL;
- }
- }
- return NULL;
+ return t->CurrentContexts[t->CurrentAPIIndex];
}
diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h
index 9503e0aba0..c169c93e94 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,15 @@ extern EGLBoolean
_eglIsCurrentThreadDummy(void);
-extern _EGLContext *
-_eglGetCurrentContext(void);
-
-
-extern _EGLDisplay *
-_eglGetCurrentDisplay(void);
+PUBLIC _EGLContext *
+_eglGetAPIContext(EGLenum api);
-extern _EGLSurface *
-_eglGetCurrentSurface(EGLint readdraw);
+PUBLIC _EGLContext *
+_eglGetCurrentContext(void);
-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..b53cc59713 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -26,12 +26,18 @@ _eglFiniDisplay(void)
/* atexit function is called with global mutex locked */
dpyList = _eglGlobal.DisplayList;
while (dpyList) {
+ EGLint i;
+
/* pop list head */
dpy = dpyList;
dpyList = dpyList->Next;
- if (dpy->ContextList || dpy->SurfaceList)
- _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy);
+ for (i = 0; i < _EGL_NUM_RESOURCES; i++) {
+ if (dpy->ResourceLists[i]) {
+ _eglLog(_EGL_DEBUG, "Display %p is destroyed with resources", dpy);
+ break;
+ }
+ }
free(dpy);
}
@@ -40,53 +46,17 @@ _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.
*
* Note that nativeDisplay may be an X Display ptr, or a string.
*/
_EGLDisplay *
-_eglNewDisplay(NativeDisplayType nativeDisplay)
+_eglNewDisplay(EGLNativeDisplayType 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;
}
@@ -144,7 +114,7 @@ _eglUnlinkDisplay(_EGLDisplay *dpy)
* linked displays.
*/
_EGLDisplay *
-_eglFindDisplay(NativeDisplayType nativeDisplay)
+_eglFindDisplay(EGLNativeDisplayType nativeDisplay)
{
_EGLDisplay *dpy;
@@ -171,29 +141,27 @@ _eglFindDisplay(NativeDisplayType nativeDisplay)
void
_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *display)
{
- _EGLContext *contexts;
- _EGLSurface *surfaces;
-
- contexts = display->ContextList;
- surfaces = display->SurfaceList;
+ _EGLResource *list;
- while (contexts) {
- _EGLContext *ctx = contexts;
- contexts = contexts->Next;
+ list = display->ResourceLists[_EGL_RESOURCE_CONTEXT];
+ while (list) {
+ _EGLContext *ctx = (_EGLContext *) list;
+ list = list->Next;
_eglUnlinkContext(ctx);
drv->API.DestroyContext(drv, display, ctx);
}
- assert(!display->ContextList);
+ assert(!display->ResourceLists[_EGL_RESOURCE_CONTEXT]);
- while (surfaces) {
- _EGLSurface *surf = surfaces;
- surfaces = surfaces->Next;
+ list = display->ResourceLists[_EGL_RESOURCE_SURFACE];
+ while (list) {
+ _EGLSurface *surf = (_EGLSurface *) list;
+ list = list->Next;
_eglUnlinkSurface(surf);
drv->API.DestroySurface(drv, display, surf);
}
- assert(!display->SurfaceList);
+ assert(!display->ResourceLists[_EGL_RESOURCE_SURFACE]);
}
@@ -212,97 +180,13 @@ _eglCleanupDisplay(_EGLDisplay *disp)
free(disp->Configs);
disp->Configs = NULL;
disp->NumConfigs = 0;
+ disp->MaxConfigs = 0;
}
/* XXX incomplete */
}
-/**
- * Link a context to a display and return the handle of the link.
- * The handle can be passed to client directly.
- */
-EGLContext
-_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy)
-{
- ctx->Display = dpy;
- ctx->Next = dpy->ContextList;
- dpy->ContextList = ctx;
- return (EGLContext) ctx;
-}
-
-
-/**
- * Unlink a linked context from its display.
- * Accessing an unlinked context should generate EGL_BAD_CONTEXT error.
- */
-void
-_eglUnlinkContext(_EGLContext *ctx)
-{
- _EGLContext *prev;
-
- prev = ctx->Display->ContextList;
- if (prev != ctx) {
- while (prev) {
- if (prev->Next == ctx)
- break;
- prev = prev->Next;
- }
- assert(prev);
- prev->Next = ctx->Next;
- }
- else {
- ctx->Display->ContextList = ctx->Next;
- }
-
- ctx->Next = NULL;
- ctx->Display = NULL;
-}
-
-
-/**
- * Link a surface to a display and return the handle of the link.
- * The handle can be passed to client directly.
- */
-EGLSurface
-_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy)
-{
- surf->Display = dpy;
- surf->Next = dpy->SurfaceList;
- dpy->SurfaceList = surf;
- return (EGLSurface) surf;
-}
-
-
-/**
- * Unlink a linked surface from its display.
- * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
- */
-void
-_eglUnlinkSurface(_EGLSurface *surf)
-{
- _EGLSurface *prev;
-
- prev = surf->Display->SurfaceList;
- if (prev != surf) {
- while (prev) {
- if (prev->Next == surf)
- break;
- prev = prev->Next;
- }
- assert(prev);
- prev->Next = surf->Next;
- }
- else {
- prev = NULL;
- surf->Display->SurfaceList = surf->Next;
- }
-
- surf->Next = NULL;
- surf->Display = NULL;
-}
-
-
#ifndef _EGL_SKIP_HANDLE_CHECK
@@ -327,45 +211,70 @@ _eglCheckDisplayHandle(EGLDisplay dpy)
/**
- * Return EGL_TRUE if the given handle is a valid handle to a context.
+ * Return EGL_TRUE if the given resource is valid. That is, the display does
+ * own the resource.
*/
EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
+_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy)
{
- _EGLContext *cur = NULL;
-
- if (dpy)
- cur = dpy->ContextList;
- while (cur) {
- if (cur == (_EGLContext *) ctx) {
- assert(cur->Display == dpy);
+ _EGLResource *list = dpy->ResourceLists[type];
+
+ if (!res)
+ return EGL_FALSE;
+
+ while (list) {
+ if (res == (void *) list) {
+ assert(list->Display == dpy);
break;
}
- cur = cur->Next;
+ list = list->Next;
}
- return (cur != NULL);
+
+ return (list != NULL);
}
+#endif /* !_EGL_SKIP_HANDLE_CHECK */
+
+
/**
- * Return EGL_TRUE if the given handle is a valid handle to a surface.
+ * Link a resource to a display.
*/
-EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
+void
+_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
{
- _EGLSurface *cur = NULL;
+ assert(!res->Display || res->Display == dpy);
- if (dpy)
- cur = dpy->SurfaceList;
- while (cur) {
- if (cur == (_EGLSurface *) surf) {
- assert(cur->Display == dpy);
- break;
- }
- cur = cur->Next;
- }
- return (cur != NULL);
+ res->Display = dpy;
+ res->IsLinked = EGL_TRUE;
+ res->Next = dpy->ResourceLists[type];
+ dpy->ResourceLists[type] = res;
}
-#endif /* !_EGL_SKIP_HANDLE_CHECK */
+/**
+ * Unlink a linked resource from its display.
+ */
+void
+_eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
+{
+ _EGLResource *prev;
+
+ prev = res->Display->ResourceLists[type];
+ if (prev != res) {
+ while (prev) {
+ if (prev->Next == res)
+ break;
+ prev = prev->Next;
+ }
+ assert(prev);
+ prev->Next = res->Next;
+ }
+ else {
+ res->Display->ResourceLists[type] = res->Next;
+ }
+
+ res->Next = NULL;
+ /* do not reset res->Display */
+ res->IsLinked = EGL_FALSE;
+}
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index ea4e35a8b3..8f74ad23a8 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -3,8 +3,29 @@
#include "egltypedefs.h"
#include "egldefines.h"
-#include "eglcontext.h"
-#include "eglsurface.h"
+
+
+enum _egl_resource_type {
+ _EGL_RESOURCE_CONTEXT,
+ _EGL_RESOURCE_SURFACE,
+ _EGL_RESOURCE_IMAGE,
+
+ _EGL_NUM_RESOURCES
+};
+
+
+/**
+ * A resource of a display.
+ */
+struct _egl_resource
+{
+ /* which display the resource belongs to */
+ _EGLDisplay *Display;
+ EGLBoolean IsLinked;
+
+ /* used to link resources of the same type */
+ _EGLResource *Next;
+};
/**
@@ -14,6 +35,8 @@ struct _egl_extensions
{
EGLBoolean MESA_screen_surface;
EGLBoolean MESA_copy_context;
+ EGLBoolean KHR_image_base;
+ EGLBoolean KHR_image_pixmap;
char String[_EGL_MAX_EXTENSIONS_LEN];
};
@@ -26,7 +49,6 @@ struct _egl_display
EGLNativeDisplayType NativeDisplay;
- const char *DriverName;
_EGLDriver *Driver;
void *DriverData; /* private to driver */
@@ -48,9 +70,8 @@ struct _egl_display
EGLint NumConfigs;
_EGLConfig **Configs; /* array [NumConfigs] of ptr to _EGLConfig */
- /* lists of linked contexts and surface */
- _EGLContext *ContextList;
- _EGLSurface *SurfaceList;
+ /* lists of resources */
+ _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
};
@@ -58,12 +79,8 @@ extern void
_eglFiniDisplay(void);
-extern char *
-_eglSplitDisplayString(const char *dpyString, const char **args);
-
-
extern _EGLDisplay *
-_eglNewDisplay(NativeDisplayType displayName);
+_eglNewDisplay(EGLNativeDisplayType displayName);
extern EGLDisplay
@@ -75,33 +92,17 @@ _eglUnlinkDisplay(_EGLDisplay *dpy);
extern _EGLDisplay *
-_eglFindDisplay(NativeDisplayType nativeDisplay);
+_eglFindDisplay(EGLNativeDisplayType nativeDisplay);
-extern void
+PUBLIC void
_eglReleaseDisplayResources(_EGLDriver *drv, _EGLDisplay *dpy);
-extern void
+PUBLIC void
_eglCleanupDisplay(_EGLDisplay *disp);
-extern EGLContext
-_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy);
-
-
-extern void
-_eglUnlinkContext(_EGLContext *ctx);
-
-
-extern EGLSurface
-_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
-
-
-extern void
-_eglUnlinkSurface(_EGLSurface *surf);
-
-
#ifndef _EGL_SKIP_HANDLE_CHECK
@@ -109,12 +110,8 @@ extern EGLBoolean
_eglCheckDisplayHandle(EGLDisplay dpy);
-extern EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy);
-
-
-extern EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
+PUBLIC EGLBoolean
+_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy);
#else /* !_EGL_SKIP_HANDLE_CHECK */
@@ -129,18 +126,9 @@ _eglCheckDisplayHandle(EGLDisplay dpy)
static INLINE EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
+_eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy);
{
- _EGLContext *c = (_EGLContext *) ctx;
- return (dpy && c && c->Display == dpy);
-}
-
-
-static INLINE EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
-{
- _EGLSurface *s = (_EGLSurface *) surf;
- return (dpy && s && s->Display == dpy);
+ return (((_EGLResource *) res)->Display == dpy);
}
@@ -181,92 +169,21 @@ _eglIsDisplayLinked(_EGLDisplay *dpy)
}
-/**
- * Lookup a handle to find the linked context.
- * Return NULL if the handle has no corresponding linked context.
- */
-static INLINE _EGLContext *
-_eglLookupContext(EGLContext context, _EGLDisplay *dpy)
-{
- _EGLContext *ctx = (_EGLContext *) context;
- if (!_eglCheckContextHandle(context, dpy))
- ctx = NULL;
- return ctx;
-}
-
-
-/**
- * Return the handle of a linked context, or EGL_NO_CONTEXT.
- */
-static INLINE EGLContext
-_eglGetContextHandle(_EGLContext *ctx)
-{
- return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
-}
-
-
-/**
- * Return true if the context is linked to a display.
- */
-static INLINE EGLBoolean
-_eglIsContextLinked(_EGLContext *ctx)
-{
- return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
-}
-
-
-/**
- * Lookup a handle to find the linked surface.
- * Return NULL if the handle has no corresponding linked surface.
- */
-static INLINE _EGLSurface *
-_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
-{
- _EGLSurface *surf = (_EGLSurface *) surface;
- if (!_eglCheckSurfaceHandle(surf, dpy))
- surf = NULL;
- return surf;
-}
+extern void
+_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
-/**
- * Return the handle of a linked surface, or EGL_NO_SURFACE.
- */
-static INLINE EGLSurface
-_eglGetSurfaceHandle(_EGLSurface *surf)
-{
- return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
-}
+extern void
+_eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
/**
- * Return true if the surface is linked to a display.
+ * Return true if the resource is linked.
*/
static INLINE EGLBoolean
-_eglIsSurfaceLinked(_EGLSurface *surf)
-{
- return (EGLBoolean) (_eglGetSurfaceHandle(surf) != EGL_NO_SURFACE);
-}
-
-
-/**
- * Cast an unsigned int to a pointer.
- */
-static INLINE void *
-_eglUIntToPointer(unsigned int v)
-{
- return (void *) ((uintptr_t) v);
-}
-
-
-/**
- * Cast a pointer to an unsigned int. The pointer must be one that is
- * returned by _eglUIntToPointer.
- */
-static INLINE unsigned int
-_eglPointerToUInt(const void *p)
+_eglIsResourceLinked(_EGLResource *res)
{
- return (unsigned int) ((uintptr_t) p);
+ return res->IsLinked;
}
diff --git a/src/egl/main/egldriver.c b/src/egl/main/egldriver.c
index 018b06d3be..1dadbf783b 100644
--- a/src/egl/main/egldriver.c
+++ b/src/egl/main/egldriver.c
@@ -19,9 +19,12 @@
#include "eglscreen.h"
#include "eglstring.h"
#include "eglsurface.h"
+#include "eglimage.h"
-#if defined(_EGL_PLATFORM_X)
+#if defined(_EGL_PLATFORM_POSIX)
#include <dlfcn.h>
+#include <sys/types.h>
+#include <dirent.h>
#endif
@@ -49,10 +52,31 @@ close_library(HMODULE lib)
}
-#elif defined(_EGL_PLATFORM_X)
+static const char *
+library_suffix(void)
+{
+ return "dll";
+}
+
+
+static EGLBoolean
+make_library_path(char *buf, unsigned int size, const char *name)
+{
+ EGLBoolean need_suffix;
+ const char *suffix = ".dll";
+ int ret;
+
+ need_suffix = (strchr(name, '.') == NULL);
+ ret = snprintf(buf, size, "%s%s", name, (need_suffix) ? suffix : "");
+
+ return ((unsigned int) ret < size);
+}
+
+#elif defined(_EGL_PLATFORM_POSIX)
-static const char DefaultDriverName[] = "egl_softpipe";
+
+static const char DefaultDriverName[] = "egl_glx";
typedef void * lib_handle;
@@ -68,6 +92,32 @@ close_library(void *lib)
dlclose(lib);
}
+
+static const char *
+library_suffix(void)
+{
+ return "so";
+}
+
+
+static EGLBoolean
+make_library_path(char *buf, unsigned int size, const char *name)
+{
+ EGLBoolean need_dir, need_suffix;
+ const char *suffix = ".so";
+ int ret;
+
+ need_dir = (strchr(name, '/') == NULL);
+ need_suffix = (strchr(name, '.') == NULL);
+
+ ret = snprintf(buf, size, "%s%s%s",
+ (need_dir) ? _EGL_DRIVER_SEARCH_DIR"/" : "", name,
+ (need_suffix) ? suffix : "");
+
+ return ((unsigned int) ret < size);
+}
+
+
#else /* _EGL_PLATFORM_NO_OS */
static const char DefaultDriverName[] = "builtin";
@@ -86,67 +136,29 @@ close_library(void *lib)
}
-#endif
+static const char *
+library_suffix(void)
+{
+ return NULL;
+}
-/**
- * Choose a driver for a given display.
- * The caller may free() the returned strings.
- */
-static char *
-_eglChooseDriver(_EGLDisplay *dpy, char **argsRet)
+static EGLBoolean
+make_library_path(char *buf, unsigned int size, const char *name)
{
- 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
+ int ret = snprintf(buf, size, name);
+ return ((unsigned int) ret < size);
+}
- if (!path)
- path = _eglstrdup(DefaultDriverName);
-
- /* append suffix if there isn't */
- p = strrchr(path, '.');
- if (!p && suffix) {
- size_t len = strlen(path);
- char *tmp = malloc(len + strlen(suffix) + 2);
- if (tmp) {
- memcpy(tmp, path, len);
- tmp[len++] = '.';
- tmp[len] = '\0';
- strcat(tmp + len, suffix);
-
- free(path);
- path = tmp;
- }
- }
- if (argsRet)
- *argsRet = (args) ? _eglstrdup(args) : NULL;
+#endif
+
- 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 +180,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 +220,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 +245,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 +266,182 @@ _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 *
+_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.
+ * Preload a user driver.
+ *
+ * A user driver can be specified by EGL_DRIVER.
*/
-const char *
-_eglPreloadDriver(_EGLDisplay *dpy)
+static EGLBoolean
+_eglPreloadUserDriver(void)
{
- char *path, *args;
+#if defined(_EGL_PLATFORM_POSIX) || defined(_EGL_PLATFORM_WINDOWS)
_EGLDriver *drv;
- EGLint i;
+ char path[1024];
+ char *env;
- 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;
- }
- }
+ if (!make_library_path(path, sizeof(path), env))
+ return EGL_FALSE;
- drv = _eglLoadDriver(path, args);
- if (!drv)
- return NULL;
+ drv = _eglLoadDriver(path, NULL);
+ if (!drv) {
+ _eglLog(_EGL_WARNING, "EGL_DRIVER is set to an invalid driver");
+ 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];
+
+ if (!make_library_path(path, sizeof(path), DefaultDriverName))
+ return EGL_FALSE;
+
+ 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 +471,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.
*/
@@ -428,56 +525,50 @@ _eglInitDriverFallbacks(_EGLDriver *drv)
#ifdef EGL_VERSION_1_2
drv->API.CreatePbufferFromClientBuffer = _eglCreatePbufferFromClientBuffer;
#endif /* EGL_VERSION_1_2 */
-}
+#ifdef EGL_KHR_image_base
+ drv->API.CreateImageKHR = _eglCreateImageKHR;
+ drv->API.DestroyImageKHR = _eglDestroyImageKHR;
+#endif /* EGL_KHR_image_base */
+}
/**
- * Try to determine which EGL APIs (OpenGL, OpenGL ES, OpenVG, etc)
- * are supported on the system by looking for standard library names.
+ * 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.
*/
-EGLint
-_eglFindAPIs(void)
+void
+_eglSetProbeCache(EGLint key, const void *val)
{
- EGLint mask = 0x0;
- lib_handle lib;
-#if defined(_EGL_PLATFORM_WINDOWS)
- /* XXX not sure about these names */
- const char *es1_libname = "libGLESv1_CM.dll";
- const char *es2_libname = "libGLESv2.dll";
- const char *gl_libname = "OpenGL32.dll";
- const char *vg_libname = "libOpenVG.dll";
-#elif defined(_EGL_PLATFORM_X)
- const char *es1_libname = "libGLESv1_CM.so";
- const char *es2_libname = "libGLESv2.so";
- const char *gl_libname = "libGL.so";
- const char *vg_libname = "libOpenVG.so";
-#else /* _EGL_PLATFORM_NO_OS */
- const char *es1_libname = NULL;
- const char *es2_libname = NULL;
- const char *gl_libname = NULL;
- const char *vg_libname = NULL;
-#endif
+ EGLint idx;
- if ((lib = open_library(es1_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_ES_BIT;
+ 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);
- if ((lib = open_library(es2_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_ES2_BIT;
- }
+ _eglProbeCache.keys[idx] = key;
+ _eglProbeCache.values[idx] = val;
+}
- if ((lib = open_library(gl_libname))) {
- close_library(lib);
- mask |= EGL_OPENGL_BIT;
- }
- if ((lib = open_library(vg_libname))) {
- close_library(lib);
- mask |= EGL_OPENVG_BIT;
+/**
+ * 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 mask;
+ 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..6ebb60a8f1 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -16,44 +16,54 @@ 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 *
-_eglOpenDriver(_EGLDisplay *dpy);
+_eglMatchDriver(_EGLDisplay *dpy);
extern EGLBoolean
-_eglCloseDriver(_EGLDriver *drv, _EGLDisplay *dpy);
+_eglPreloadDrivers(void);
-void
+extern void
_eglUnloadDrivers(void);
-extern _EGLDriver *
-_eglLookupDriver(EGLDisplay d);
+PUBLIC void
+_eglInitDriverFallbacks(_EGLDriver *drv);
-extern void
-_eglInitDriverFallbacks(_EGLDriver *drv);
+PUBLIC void
+_eglSetProbeCache(EGLint key, const void *val);
-extern EGLint
-_eglFindAPIs(void);
+PUBLIC const void *
+_eglGetProbeCache(EGLint key);
#endif /* EGLDRIVER_INCLUDED */
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
new file mode 100644
index 0000000000..5044112fa8
--- /dev/null
+++ b/src/egl/main/eglimage.c
@@ -0,0 +1,51 @@
+#include <assert.h>
+
+#include "eglimage.h"
+#include "egldisplay.h"
+
+
+#ifdef EGL_KHR_image_base
+
+
+EGLBoolean
+_eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list)
+{
+ EGLint i;
+
+ img->Preserved = EGL_FALSE;
+
+ for (i = 0; attrib_list && attrib_list[i] != EGL_NONE; i++) {
+ switch (attrib_list[i]) {
+ case EGL_IMAGE_PRESERVED_KHR:
+ i++;
+ img->Preserved = attrib_list[i];
+ break;
+ default:
+ /* not an error */
+ break;
+ }
+ }
+
+ return EGL_TRUE;
+}
+
+
+_EGLImage *
+_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
+ EGLenum target, EGLClientBuffer buffer,
+ const EGLint *attr_list)
+{
+ /* driver should override this function */
+ return NULL;
+}
+
+
+EGLBoolean
+_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image)
+{
+ /* driver should override this function */
+ return EGL_FALSE;
+}
+
+
+#endif /* EGL_KHR_image_base */
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
new file mode 100644
index 0000000000..43107c23e9
--- /dev/null
+++ b/src/egl/main/eglimage.h
@@ -0,0 +1,94 @@
+#ifndef EGLIMAGE_INCLUDED
+#define EGLIMAGE_INCLUDED
+
+
+#include "egltypedefs.h"
+#include "egldisplay.h"
+
+
+/**
+ * "Base" class for device driver images.
+ */
+struct _egl_image
+{
+ /* An image is a display resource */
+ _EGLResource Resource;
+
+ EGLBoolean Preserved;
+};
+
+
+PUBLIC EGLBoolean
+_eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list);
+
+
+extern _EGLImage *
+_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
+ EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list);
+
+
+extern EGLBoolean
+_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image);
+
+
+/**
+ * Link an image to a display and return the handle of the link.
+ * The handle can be passed to client directly.
+ */
+static INLINE EGLImageKHR
+_eglLinkImage(_EGLImage *img, _EGLDisplay *dpy)
+{
+ _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE, dpy);
+ return (EGLImageKHR) img;
+}
+
+
+/**
+ * Unlink a linked image from its display.
+ * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
+ */
+static INLINE void
+_eglUnlinkImage(_EGLImage *img)
+{
+ _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
+}
+
+
+/**
+ * Lookup a handle to find the linked image.
+ * Return NULL if the handle has no corresponding linked image.
+ */
+static INLINE _EGLImage *
+_eglLookupImage(EGLImageKHR image, _EGLDisplay *dpy)
+{
+ _EGLImage *img = (_EGLImage *) image;
+ if (!dpy || !_eglCheckResource((void *) img, _EGL_RESOURCE_IMAGE, dpy))
+ img = NULL;
+ return img;
+}
+
+
+/**
+ * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
+ */
+static INLINE EGLImageKHR
+_eglGetImageHandle(_EGLImage *img)
+{
+ _EGLResource *res = (_EGLResource *) img;
+ return (res && _eglIsResourceLinked(res)) ?
+ (EGLImageKHR) img : EGL_NO_IMAGE_KHR;
+}
+
+
+/**
+ * Return true if the image is linked to a display.
+ */
+static INLINE EGLBoolean
+_eglIsImageLinked(_EGLImage *img)
+{
+ _EGLResource *res = (_EGLResource *) img;
+ return (res && _eglIsResourceLinked(res));
+}
+
+
+#endif /* EGLIMAGE_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/eglmisc.c b/src/egl/main/eglmisc.c
index e66913320b..5726f5bca8 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -54,6 +54,14 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
strcat(exts, "EGL_MESA_screen_surface ");
if (dpy->Extensions.MESA_copy_context)
strcat(exts, "EGL_MESA_copy_context ");
+
+ if (dpy->Extensions.KHR_image_base)
+ strcat(exts, "EGL_KHR_image_base ");
+ if (dpy->Extensions.KHR_image_pixmap)
+ strcat(exts, "EGL_KHR_image_pixmap ");
+ if (dpy->Extensions.KHR_image_base && dpy->Extensions.KHR_image_pixmap)
+ strcat(exts, "EGL_KHR_image ");
+
assert(strlen(exts) < _EGL_MAX_EXTENSIONS_LEN);
}
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.c b/src/egl/main/eglsurface.c
index 940a1b760c..89eb93d808 100644
--- a/src/egl/main/eglsurface.c
+++ b/src/egl/main/eglsurface.c
@@ -237,7 +237,7 @@ _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf)
EGLBoolean
_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf,
- NativePixmapType target)
+ EGLNativePixmapType target)
{
/* copy surface to native pixmap */
/* All implementation burdon for this is in the device driver */
@@ -319,7 +319,7 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surface,
*/
_EGLSurface *
_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- NativeWindowType window, const EGLint *attrib_list)
+ EGLNativeWindowType window, const EGLint *attrib_list)
{
#if 0 /* THIS IS JUST EXAMPLE CODE */
_EGLSurface *surf;
@@ -344,7 +344,7 @@ _eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
*/
_EGLSurface *
_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
- NativePixmapType pixmap, const EGLint *attrib_list)
+ EGLNativePixmapType pixmap, const EGLint *attrib_list)
{
#if 0 /* THIS IS JUST EXAMPLE CODE */
_EGLSurface *surf;
diff --git a/src/egl/main/eglsurface.h b/src/egl/main/eglsurface.h
index b75fa9c368..4062b990fa 100644
--- a/src/egl/main/eglsurface.h
+++ b/src/egl/main/eglsurface.h
@@ -3,6 +3,7 @@
#include "egltypedefs.h"
+#include "egldisplay.h"
/**
@@ -10,9 +11,8 @@
*/
struct _egl_surface
{
- /* Managed by EGLDisplay for linking */
- _EGLDisplay *Display;
- _EGLSurface *Next;
+ /* A surface is a display resource */
+ _EGLResource Resource;
/* The bound status of the surface */
_EGLContext *Binding;
@@ -40,7 +40,7 @@ struct _egl_surface
};
-extern EGLBoolean
+PUBLIC EGLBoolean
_eglInitSurface(_EGLDriver *drv, _EGLSurface *surf, EGLint type,
_EGLConfig *config, const EGLint *attrib_list);
@@ -50,7 +50,7 @@ _eglSwapBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf);
extern EGLBoolean
-_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, NativePixmapType target);
+_eglCopyBuffers(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLNativePixmapType target);
extern EGLBoolean
@@ -58,11 +58,11 @@ _eglQuerySurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSurface *surf, EGLint at
extern _EGLSurface *
-_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativeWindowType window, const EGLint *attrib_list);
+_eglCreateWindowSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativeWindowType window, const EGLint *attrib_list);
extern _EGLSurface *
-_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, NativePixmapType pixmap, const EGLint *attrib_list);
+_eglCreatePixmapSurface(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf, EGLNativePixmapType pixmap, const EGLint *attrib_list);
extern _EGLSurface *
@@ -111,4 +111,64 @@ _eglIsSurfaceBound(_EGLSurface *surf)
}
+/**
+ * Link a surface to a display and return the handle of the link.
+ * The handle can be passed to client directly.
+ */
+static INLINE EGLSurface
+_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy)
+{
+ _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE, dpy);
+ return (EGLSurface) surf;
+}
+
+
+/**
+ * Unlink a linked surface from its display.
+ * Accessing an unlinked surface should generate EGL_BAD_SURFACE error.
+ */
+static INLINE void
+_eglUnlinkSurface(_EGLSurface *surf)
+{
+ _eglUnlinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE);
+}
+
+
+/**
+ * Lookup a handle to find the linked surface.
+ * Return NULL if the handle has no corresponding linked surface.
+ */
+static INLINE _EGLSurface *
+_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
+{
+ _EGLSurface *surf = (_EGLSurface *) surface;
+ if (!dpy || !_eglCheckResource((void *) surf, _EGL_RESOURCE_SURFACE, dpy))
+ surf = NULL;
+ return surf;
+}
+
+
+/**
+ * Return the handle of a linked surface, or EGL_NO_SURFACE.
+ */
+static INLINE EGLSurface
+_eglGetSurfaceHandle(_EGLSurface *surf)
+{
+ _EGLResource *res = (_EGLResource *) surf;
+ return (res && _eglIsResourceLinked(res)) ?
+ (EGLSurface) surf : EGL_NO_SURFACE;
+}
+
+
+/**
+ * Return true if the surface is linked to a display.
+ */
+static INLINE EGLBoolean
+_eglIsSurfaceLinked(_EGLSurface *surf)
+{
+ _EGLResource *res = (_EGLResource *) surf;
+ return (res && _eglIsResourceLinked(res));
+}
+
+
#endif /* EGLSURFACE_INCLUDED */
diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h
index 4461440b9b..e6b19b35d0 100644
--- a/src/egl/main/egltypedefs.h
+++ b/src/egl/main/egltypedefs.h
@@ -8,6 +8,8 @@
#include "eglcompiler.h"
+typedef enum _egl_resource_type _EGLResourceType;
+
typedef struct _egl_api _EGLAPI;
typedef struct _egl_config _EGLConfig;
@@ -20,8 +22,12 @@ typedef struct _egl_driver _EGLDriver;
typedef struct _egl_extensions _EGLExtensions;
+typedef struct _egl_image _EGLImage;
+
typedef struct _egl_mode _EGLMode;
+typedef struct _egl_resource _EGLResource;
+
typedef struct _egl_screen _EGLScreen;
typedef struct _egl_surface _EGLSurface;