egl_dri2: Look up _glapi_get_proc_address dynamically.
[mesa.git] / src / egl / main / eglcurrent.c
index 4431f964f69bce0e851b3bbb7d99d0a5ac261f3e..4221a9be3e1307d95027b040e12f154b686e4dff 100644 (file)
@@ -1,47 +1,20 @@
 #include <stdlib.h>
 #include <string.h>
-#include "eglcurrent.h"
-#include "eglcontext.h"
 #include "egllog.h"
 #include "eglmutex.h"
+#include "eglcurrent.h"
 #include "eglglobals.h"
 
 
 /* This should be kept in sync with _eglInitThreadInfo() */
 #define _EGL_THREAD_INFO_INITIALIZER \
-   { EGL_SUCCESS, { NULL }, 1 }
+   { EGL_SUCCESS, { NULL }, 0 }
 
 /* a fallback thread info to guarantee that every thread always has one */
 static _EGLThreadInfo dummy_thread = _EGL_THREAD_INFO_INITIALIZER;
 
 
-#ifdef GLX_USE_TLS
-static __thread const _EGLThreadInfo *_egl_TSD;
-   __attribute__ ((tls_model("initial-exec")));
-
-static INLINE void _eglSetTSD(const _EGLThreadInfo *t)
-{
-   _egl_TSD = t;
-}
-
-static INLINE _EGLThreadInfo *_eglGetTSD(void)
-{
-   return (_EGLThreadInfo *) _egl_TSD;
-}
-
-static INLINE void _eglFiniTSD(void)
-{
-}
-
-static INLINE EGLBoolean _eglInitTSD(void (*dtor)(_EGLThreadInfo *))
-{
-   /* TODO destroy TSD */
-   (void) dtor;
-   (void) _eglFiniTSD;
-   return EGL_TRUE;
-}
-
-#elif PTHREADS
+#if PTHREADS
 #include <pthread.h>
 
 static _EGL_DECLARE_MUTEX(_egl_TSDMutex);
@@ -49,14 +22,26 @@ static EGLBoolean _egl_TSDInitialized;
 static pthread_key_t _egl_TSD;
 static void (*_egl_FreeTSD)(_EGLThreadInfo *);
 
+#ifdef GLX_USE_TLS
+static __thread const _EGLThreadInfo *_egl_TLS
+   __attribute__ ((tls_model("initial-exec")));
+#endif
+
 static INLINE void _eglSetTSD(const _EGLThreadInfo *t)
 {
    pthread_setspecific(_egl_TSD, (const void *) t);
+#ifdef GLX_USE_TLS
+   _egl_TLS = t;
+#endif
 }
 
 static INLINE _EGLThreadInfo *_eglGetTSD(void)
 {
+#ifdef GLX_USE_TLS
+   return (_EGLThreadInfo *) _egl_TLS;
+#else
    return (_EGLThreadInfo *) pthread_getspecific(_egl_TSD);
+#endif
 }
 
 static INLINE void _eglFiniTSD(void)
@@ -227,67 +212,42 @@ _eglIsCurrentThreadDummy(void)
 
 
 /**
- * Return the currently bound context, or NULL.
- */
-_EGLContext *
-_eglGetCurrentContext(void)
-{
-   _EGLThreadInfo *t = _eglGetCurrentThread();
-   return t->CurrentContexts[t->CurrentAPIIndex];
-}
-
-
-/**
- * Return the display of the currently bound context, or NULL.
+ * Return the currently bound context of the given API, 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];
 }
 
 
 /**
- * Record EGL error code.
+ * Record EGL error code and return EGL_FALSE.
  */
 EGLBoolean
 _eglError(EGLint errCode, const char *msg)
 {
    _EGLThreadInfo *t = _eglGetCurrentThread();
-   const char *s;
 
    if (t == &dummy_thread)
       return EGL_FALSE;
 
-   if (t->LastError == EGL_SUCCESS) {
-      t->LastError = errCode;
+   t->LastError = errCode;
+
+   if (errCode != EGL_SUCCESS) {
+      const char *s;
 
       switch (errCode) {
       case EGL_BAD_ACCESS:
@@ -326,14 +286,19 @@ _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";
          break;
       case EGL_BAD_MODE_MESA:
          s = "EGL_BAD_MODE_MESA";
          break;
+#endif
       default:
-         s = "other";
+         s = "other EGL error";
       }
       _eglLog(_EGL_DEBUG, "EGL user error 0x%x (%s) in %s\n", errCode, s, msg);
    }