/**
* Macros to help return an API entrypoint.
+ *
+ * These macros will unlock the display and record the error code.
*/
#define _EGL_ERROR(disp, err, ret) \
({ \
+ if (disp) \
+ _eglUnlockDisplay(disp); \
/* EGL error codes are non-zero */ \
if (err) \
_eglError(err, __FUNCTION__); \
#endif /* EGL_MESA_screen_surface */
+/**
+ * Lookup and lock a display.
+ */
+static INLINE _EGLDisplay *
+_eglLockDisplay(EGLDisplay display)
+{
+ _EGLDisplay *dpy = _eglLookupDisplay(display);
+ if (dpy)
+ _eglLockMutex(&dpy->Mutex);
+ return dpy;
+}
+
+
+/**
+ * Unlock a display.
+ */
+static INLINE void
+_eglUnlockDisplay(_EGLDisplay *dpy)
+{
+ _eglUnlockMutex(&dpy->Mutex);
+}
+
+
/**
* This is typically the first EGL function that an application calls.
* It associates a private _EGLDisplay object to the native display.
EGLBoolean EGLAPIENTRY
eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
EGLint major_int, minor_int;
if (!disp)
EGLBoolean EGLAPIENTRY
eglTerminate(EGLDisplay dpy)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
if (!disp)
return _EGL_ERROR(NULL, EGL_BAD_DISPLAY, EGL_FALSE);
const char * EGLAPIENTRY
eglQueryString(EGLDisplay dpy, EGLint name)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLDriver *drv;
const char *ret;
eglGetConfigs(EGLDisplay dpy, EGLConfig *configs,
EGLint config_size, EGLint *num_config)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLDriver *drv;
EGLBoolean ret;
eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs,
EGLint config_size, EGLint *num_config)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLDriver *drv;
EGLBoolean ret;
eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
EGLint attribute, EGLint *value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_list,
const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLContext *share = _eglLookupContext(share_list, disp);
_EGLDriver *drv;
EGLBoolean EGLAPIENTRY
eglDestroyContext(EGLDisplay dpy, EGLContext ctx)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *context = _eglLookupContext(ctx, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read,
EGLContext ctx)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *context = _eglLookupContext(ctx, disp);
_EGLSurface *draw_surf = _eglLookupSurface(draw, disp);
_EGLSurface *read_surf = _eglLookupSurface(read, disp);
eglQueryContext(EGLDisplay dpy, EGLContext ctx,
EGLint attribute, EGLint *value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *context = _eglLookupContext(ctx, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config,
EGLNativeWindowType window, const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
_EGLSurface *surf;
eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config,
EGLNativePixmapType pixmap, const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
_EGLSurface *surf;
eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
_EGLSurface *surf;
EGLBoolean EGLAPIENTRY
eglDestroySurface(EGLDisplay dpy, EGLSurface surface)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglQuerySurface(EGLDisplay dpy, EGLSurface surface,
EGLint attribute, EGLint *value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglSurfaceAttrib(EGLDisplay dpy, EGLSurface surface,
EGLint attribute, EGLint value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
EGLBoolean EGLAPIENTRY
eglBindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
EGLBoolean EGLAPIENTRY
eglReleaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
EGLBoolean EGLAPIENTRY
eglSwapInterval(EGLDisplay dpy, EGLint interval)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *ctx = _eglGetCurrentContext();
_EGLSurface *surf;
_EGLDriver *drv;
eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
_EGLContext *ctx = _eglGetCurrentContext();
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
EGLBoolean EGLAPIENTRY
eglCopyBuffers(EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLDriver *drv;
EGLBoolean ret;
if (!ctx)
return _EGL_SUCCESS(NULL, EGL_TRUE);
- /* let bad current context imply bad current surface */
- if (!_eglIsContextLinked(ctx) || !_eglIsSurfaceLinked(ctx->DrawSurface))
- return _EGL_ERROR(NULL, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
disp = ctx->Resource.Display;
+ _eglLockMutex(&disp->Mutex);
+
+ /* let bad current context imply bad current surface */
+ if (!_eglIsContextLinked(ctx) || !_eglIsSurfaceLinked(ctx->DrawSurface))
+ return _EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
/* a valid current context implies an initialized current display */
assert(disp->Initialized);
drv = disp->Driver;
ret = drv->API.WaitClient(drv, disp, ctx);
- return _EGL_EVAL(NULL, ret);
+ return _EGL_EVAL(disp, ret);
}
if (!ctx)
return _EGL_SUCCESS(NULL, EGL_TRUE);
+ disp = ctx->Resource.Display;
+ _eglLockMutex(&disp->Mutex);
+
/* let bad current context imply bad current surface */
if (!_eglIsContextLinked(ctx) || !_eglIsSurfaceLinked(ctx->DrawSurface))
- return _EGL_ERROR(NULL, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
-
- disp = ctx->Resource.Display;
+ return _EGL_ERROR(disp, EGL_BAD_CURRENT_SURFACE, EGL_FALSE);
/* a valid current context implies an initialized current display */
assert(disp->Initialized);
drv = disp->Driver;
ret = drv->API.WaitNative(drv, disp, engine);
- return _EGL_EVAL(NULL, ret);
+ return _EGL_EVAL(disp, ret);
}
const EGLint *attrib_list, EGLModeMESA *modes,
EGLint modes_size, EGLint *num_modes)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen(screen, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglGetModesMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *modes,
EGLint mode_size, EGLint *num_mode)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen(screen, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglGetModeAttribMESA(EGLDisplay dpy, EGLModeMESA mode,
EGLint attribute, EGLint *value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLMode *m = _eglLookupMode(mode, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglCopyContextMESA(EGLDisplay dpy, EGLContext source, EGLContext dest,
EGLint mask)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *source_context = _eglLookupContext(source, disp);
_EGLContext *dest_context = _eglLookupContext(dest, disp);
_EGLDriver *drv;
eglGetScreensMESA(EGLDisplay dpy, EGLScreenMESA *screens,
EGLint max_screens, EGLint *num_screens)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLDriver *drv;
EGLBoolean ret;
eglCreateScreenSurfaceMESA(EGLDisplay dpy, EGLConfig config,
const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
_EGLSurface *surf;
eglShowScreenSurfaceMESA(EGLDisplay dpy, EGLint screen,
EGLSurface surface, EGLModeMESA mode)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp);
_EGLSurface *surf = _eglLookupSurface(surface, disp);
_EGLMode *m = _eglLookupMode(mode, disp);
EGLBoolean
eglScreenPositionMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLint x, EGLint y)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen(screen, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglQueryScreenMESA(EGLDisplay dpy, EGLScreenMESA screen,
EGLint attribute, EGLint *value)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen(screen, disp);
_EGLDriver *drv;
EGLBoolean ret;
eglQueryScreenSurfaceMESA(EGLDisplay dpy, EGLScreenMESA screen,
EGLSurface *surface)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp);
_EGLDriver *drv;
_EGLSurface *surf;
EGLBoolean
eglQueryScreenModeMESA(EGLDisplay dpy, EGLScreenMESA screen, EGLModeMESA *mode)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLScreen *scrn = _eglLookupScreen((EGLScreenMESA) screen, disp);
_EGLDriver *drv;
_EGLMode *m;
const char *
eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLMode *m = _eglLookupMode(mode, disp);
_EGLDriver *drv;
const char *ret;
EGLClientBuffer buffer, EGLConfig config,
const EGLint *attrib_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLConfig *conf = _eglLookupConfig(config, disp);
_EGLDriver *drv;
_EGLSurface *surf;
_EGLContext *ctx = t->CurrentContexts[i];
if (ctx) {
_EGLDisplay *disp = ctx->Resource.Display;
- _EGLDriver *drv = disp->Driver;
+ _EGLDriver *drv;
+
t->CurrentAPIIndex = i;
+
+ _eglLockMutex(&disp->Mutex);
+ drv = disp->Driver;
(void) drv->API.MakeCurrent(drv, disp, NULL, NULL, NULL);
+ _eglUnlockMutex(&disp->Mutex);
}
}
eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
EGLClientBuffer buffer, const EGLint *attr_list)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLContext *context = _eglLookupContext(ctx, disp);
_EGLDriver *drv;
_EGLImage *img;
EGLBoolean
eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR image)
{
- _EGLDisplay *disp = _eglLookupDisplay(dpy);
+ _EGLDisplay *disp = _eglLockDisplay(dpy);
_EGLImage *img = _eglLookupImage(image, disp);
_EGLDriver *drv;
EGLBoolean ret;