egl: Move context functions in egldisplay.[ch] to eglcontext.[ch].
[mesa.git] / src / egl / main / egldisplay.c
index 000db6c69af495ff959d4bf5297c9efbc7017bb7..e14d0c1b63b94b54924cecb3885cfbd26b7d297c 100644 (file)
@@ -10,7 +10,6 @@
 #include "egldisplay.h"
 #include "egldriver.h"
 #include "eglglobals.h"
-#include "eglhash.h"
 #include "eglstring.h"
 #include "eglmutex.h"
 #include "egllog.h"
@@ -52,15 +51,6 @@ _eglNewDisplay(NativeDisplayType nativeDisplay)
    _EGLDisplay *dpy = (_EGLDisplay *) calloc(1, sizeof(_EGLDisplay));
    if (dpy) {
       dpy->NativeDisplay = nativeDisplay;
-#if defined(_EGL_PLATFORM_X)
-      dpy->Xdpy = (Display *) nativeDisplay;
-#endif
-
-      dpy->DriverName = _eglPreloadDriver(dpy);
-      if (!dpy->DriverName) {
-         free(dpy);
-         return NULL;
-      }
    }
    return dpy;
 }
@@ -113,28 +103,6 @@ _eglUnlinkDisplay(_EGLDisplay *dpy)
 }
 
 
-/**
- * Return the handle of a linked display, or EGL_NO_DISPLAY.
- */
-EGLDisplay
-_eglGetDisplayHandle(_EGLDisplay *dpy)
-{
-   return (EGLDisplay) ((dpy) ? dpy : EGL_NO_DISPLAY);
-}
-
-
-/**
- * Lookup a handle to find the linked display.
- * Return NULL if the handle has no corresponding linked display.
- */
-_EGLDisplay *
-_eglLookupDisplay(EGLDisplay display)
-{
-   _EGLDisplay *dpy = (_EGLDisplay *) display;
-   return dpy;
-}
-
-
 /**
  * Find the display corresponding to the specified native display id in all
  * linked displays.
@@ -214,70 +182,6 @@ _eglCleanupDisplay(_EGLDisplay *disp)
 }
 
 
-/**
- * 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;
-}
-
-
-/**
- * Return the handle of a linked context, or EGL_NO_CONTEXT.
- */
-EGLContext
-_eglGetContextHandle(_EGLContext *ctx)
-{
-   return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
-}
-
-
-/**
- * Lookup a handle to find the linked context.
- * Return NULL if the handle has no corresponding linked context.
- */
-_EGLContext *
-_eglLookupContext(EGLContext ctx, _EGLDisplay *dpy)
-{
-   _EGLContext *context = (_EGLContext *) ctx;
-   return (context && context->Display) ? context : NULL;
-}
-
-
 /**
  * Link a surface to a display and return the handle of the link.
  * The handle can be passed to client directly.
@@ -321,23 +225,48 @@ _eglUnlinkSurface(_EGLSurface *surf)
 }
 
 
+#ifndef _EGL_SKIP_HANDLE_CHECK
+
+
 /**
- * Return the handle of a linked surface, or EGL_NO_SURFACE.
+ * Return EGL_TRUE if the given handle is a valid handle to a display.
  */
-EGLSurface
-_eglGetSurfaceHandle(_EGLSurface *surf)
+EGLBoolean
+_eglCheckDisplayHandle(EGLDisplay dpy)
 {
-   return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
+   _EGLDisplay *cur;
+
+   _eglLockMutex(_eglGlobal.Mutex);
+   cur = _eglGlobal.DisplayList;
+   while (cur) {
+      if (cur == (_EGLDisplay *) dpy)
+         break;
+      cur = cur->Next;
+   }
+   _eglUnlockMutex(_eglGlobal.Mutex);
+   return (cur != NULL);
 }
 
 
 /**
- * Lookup a handle to find the linked surface.
- * Return NULL if the handle has no corresponding linked surface.
+ * Return EGL_TRUE if the given handle is a valid handle to a surface.
  */
-_EGLSurface *
-_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
+EGLBoolean
+_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
 {
-   _EGLSurface *surf = (_EGLSurface *) surface;
-   return (surf && surf->Display) ? surf : NULL;
+   _EGLSurface *cur = NULL;
+
+   if (dpy)
+      cur = dpy->SurfaceList;
+   while (cur) {
+      if (cur == (_EGLSurface *) surf) {
+         assert(cur->Display == dpy);
+         break;
+      }
+      cur = cur->Next;
+   }
+   return (cur != NULL);
 }
+
+
+#endif /* !_EGL_SKIP_HANDLE_CHECK */