_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;
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);
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);
*/
return EGL_FALSE;
}
-
-
-/**
- * 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;
-}
-
-
-#ifndef _EGL_SKIP_HANDLE_CHECK
-
-
-/**
- * Return EGL_TRUE if the given handle is a valid handle to a context.
- */
-EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
-{
- _EGLContext *cur = NULL;
-
- if (dpy)
- cur = dpy->ContextList;
- while (cur) {
- if (cur == (_EGLContext *) ctx) {
- assert(cur->Display == dpy);
- break;
- }
- cur = cur->Next;
- }
- return (cur != NULL);
-}
-
-
-#endif /* !_EGL_SKIP_HANDLE_CHECK */
#include "egltypedefs.h"
+#include "egldisplay.h"
/**
*/
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;
}
-extern EGLContext
-_eglLinkContext(_EGLContext *ctx, _EGLDisplay *dpy);
-
-
-extern void
-_eglUnlinkContext(_EGLContext *ctx);
-
-
-#ifndef _EGL_SKIP_HANDLE_CHECK
-
-
-extern EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy);
-
-
-#else /* !_EGL_SKIP_HANDLE_CHECK */
-
-
-static INLINE EGLBoolean
-_eglCheckContextHandle(EGLContext ctx, _EGLDisplay *dpy)
+/**
+ * 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)
{
- _EGLContext *c = (_EGLContext *) ctx;
- return (dpy && c && c->Display == dpy);
+ _eglLinkResource(&ctx->Resource, _EGL_RESOURCE_CONTEXT, dpy);
+ return (EGLContext) ctx;
}
-#endif /* _EGL_SKIP_HANDLE_CHECK */
+/**
+ * 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);
+}
/**
static INLINE _EGLContext *
_eglLookupContext(EGLContext context, _EGLDisplay *dpy)
{
+ _EGLResource *res = (_EGLResource *) context;
_EGLContext *ctx = (_EGLContext *) context;
- if (!_eglCheckContextHandle(context, dpy))
+ if (!res || !dpy || !_eglCheckResource(res, _EGL_RESOURCE_CONTEXT, dpy))
ctx = NULL;
return ctx;
}
static INLINE EGLContext
_eglGetContextHandle(_EGLContext *ctx)
{
- return (EGLContext) ((ctx && ctx->Display) ? ctx : EGL_NO_CONTEXT);
+ _EGLResource *res = (_EGLResource *) ctx;
+ return (res && _eglIsResourceLinked(res)) ?
+ (EGLContext) ctx : EGL_NO_CONTEXT;
}
static INLINE EGLBoolean
_eglIsContextLinked(_EGLContext *ctx)
{
- return (EGLBoolean) (_eglGetContextHandle(ctx) != EGL_NO_CONTEXT);
+ _EGLResource *res = (_EGLResource *) ctx;
+ return (res && _eglIsResourceLinked(res));
}
_EGLThreadInfo *t = _eglGetCurrentThread();
_EGLContext *ctx = t->CurrentContexts[t->CurrentAPIIndex];
if (ctx)
- return ctx->Display;
+ return ctx->Resource.Display;
else
return NULL;
}
/* 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);
}
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]);
}
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];
};
}
#endif /* EGL_VERSION_1_2 */
-
-
-/**
- * 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
-
-
-/**
- * Return EGL_TRUE if the given handle is a valid handle to a surface.
- */
-EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
-{
- _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 */
#include "egltypedefs.h"
+#include "egldisplay.h"
/**
*/
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;
}
-extern EGLSurface
-_eglLinkSurface(_EGLSurface *surf, _EGLDisplay *dpy);
-
-
-extern void
-_eglUnlinkSurface(_EGLSurface *surf);
-
-
-#ifndef _EGL_SKIP_HANDLE_CHECK
-
-
-extern EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy);
-
-
-#else /* !_EGL_SKIP_HANDLE_CHECK */
-
-
-static INLINE EGLBoolean
-_eglCheckSurfaceHandle(EGLSurface surf, _EGLDisplay *dpy)
+/**
+ * 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)
{
- _EGLSurface *s = (_EGLSurface *) surf;
- return (dpy && s && s->Display == dpy);
+ _eglLinkResource(&surf->Resource, _EGL_RESOURCE_SURFACE, dpy);
+ return (EGLSurface) surf;
}
-#endif /* _EGL_SKIP_HANDLE_CHECK */
+/**
+ * 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);
+}
/**
static INLINE _EGLSurface *
_eglLookupSurface(EGLSurface surface, _EGLDisplay *dpy)
{
+ _EGLResource *res = (_EGLResource *) surface;
_EGLSurface *surf = (_EGLSurface *) surface;
- if (!_eglCheckSurfaceHandle(surf, dpy))
+ if (!res || !dpy || !_eglCheckResource(res, _EGL_RESOURCE_SURFACE, dpy))
surf = NULL;
return surf;
}
static INLINE EGLSurface
_eglGetSurfaceHandle(_EGLSurface *surf)
{
- return (EGLSurface) ((surf && surf->Display) ? surf : EGL_NO_SURFACE);
+ _EGLResource *res = (_EGLResource *) surf;
+ return (res && _eglIsResourceLinked(res)) ?
+ (EGLSurface) surf : EGL_NO_SURFACE;
}
static INLINE EGLBoolean
_eglIsSurfaceLinked(_EGLSurface *surf)
{
- return (EGLBoolean) (_eglGetSurfaceHandle(surf) != EGL_NO_SURFACE);
+ _EGLResource *res = (_EGLResource *) surf;
+ return (res && _eglIsResourceLinked(res));
}
* Set force_validate to skip an unnecessary check.
*/
gctx->force_validate = EGL_TRUE;
- egl_g3d_validate_context(gctx->base.Display, &gctx->base);
+ egl_g3d_validate_context(gctx->base.Resource.Display, &gctx->base);
}
static EGLBoolean