}
+/**
+ * Return EGL_TRUE if the given resource is valid. That is, the display does
+ * own the resource.
+ */
+EGLBoolean
+_eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
+{
+ _EGLResource *list = dpy->ResourceLists[type];
+
+ while (list) {
+ if (res == list) {
+ assert(list->Display == dpy);
+ break;
+ }
+ list = list->Next;
+ }
+
+ return (list != NULL);
+}
+
+
#endif /* !_EGL_SKIP_HANDLE_CHECK */
+
+
+/**
+ * Link a resource to a display.
+ */
+void
+_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
+{
+ res->Display = dpy;
+ res->Next = dpy->ResourceLists[type];
+ dpy->ResourceLists[type] = res;
+}
+
+
+/**
+ * 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;
+ res->Display = NULL;
+}
#include "egldefines.h"
+enum _egl_resource_type {
+ _EGL_RESOURCE_CONTEXT,
+ _EGL_RESOURCE_SURFACE,
+
+ _EGL_NUM_RESOURCES
+};
+
+
+/**
+ * A resource of a display.
+ */
+struct _egl_resource
+{
+ _EGLDisplay *Display;
+ _EGLResource *Next;
+};
+
+
/**
* Optional EGL extensions info.
*/
/* lists of linked contexts and surface */
_EGLContext *ContextList;
_EGLSurface *SurfaceList;
+
+ _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];
};
_eglCheckDisplayHandle(EGLDisplay dpy);
+extern EGLBoolean
+_eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
+
+
#else /* !_EGL_SKIP_HANDLE_CHECK */
/* Only do a quick check. This is NOT standard compliant. */
}
+static INLINE EGLBoolean
+_eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy)
+{
+ return (res->Display == dpy);
+}
+
+
#endif /* _EGL_SKIP_HANDLE_CHECK */
}
+extern void
+_eglLinkResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy);
+
+
+extern void
+_eglUnlinkResource(_EGLResource *res, _EGLResourceType type);
+
+
+/**
+ * Return true if the resource is linked.
+ */
+static INLINE EGLBoolean
+_eglIsResourceLinked(_EGLResource *res)
+{
+ return (res->Display != NULL);
+}
+
+
/**
* Cast an unsigned int to a pointer.
*/
#include "eglcompiler.h"
+typedef enum _egl_resource_type _EGLResourceType;
+
typedef struct _egl_api _EGLAPI;
typedef struct _egl_config _EGLConfig;
typedef struct _egl_mode _EGLMode;
+typedef struct _egl_resource _EGLResource;
+
typedef struct _egl_screen _EGLScreen;
typedef struct _egl_surface _EGLSurface;