diff options
| author | Chia-I Wu <olvaffe@gmail.com> | 2010-01-24 20:30:04 +0800 | 
|---|---|---|
| committer | Chia-I Wu <olvaffe@gmail.com> | 2010-01-24 20:38:15 +0800 | 
| commit | 7abf42626fe8552cf898652134f3767e591614ab (patch) | |
| tree | 3789e1b655e73cdc7cec84ba1954844e49af5ab3 | |
| parent | b4d2c97a2d2cce92fa638ff74bef7dedf593fd1f (diff) | |
egl: Add _EGLResource and _EGLResourceType.
Resources are objects managed by a display.  They can be linked to or
unlinked from a display.  It is also possible to check if a resource is
valid.
| -rw-r--r-- | src/egl/main/egldisplay.c | 60 | ||||
| -rw-r--r-- | src/egl/main/egldisplay.h | 49 | ||||
| -rw-r--r-- | src/egl/main/egltypedefs.h | 4 | 
3 files changed, 113 insertions, 0 deletions
| diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c index 79efa8477e..ef144f7f07 100644 --- a/src/egl/main/egldisplay.c +++ b/src/egl/main/egldisplay.c @@ -205,4 +205,64 @@ _eglCheckDisplayHandle(EGLDisplay dpy)  } +/** + * 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; +} diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h index 77458cb38d..c1069d7c59 100644 --- a/src/egl/main/egldisplay.h +++ b/src/egl/main/egldisplay.h @@ -5,6 +5,24 @@  #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.   */ @@ -48,6 +66,8 @@ struct _egl_display     /* lists of linked contexts and surface */     _EGLContext *ContextList;     _EGLSurface *SurfaceList; + +   _EGLResource *ResourceLists[_EGL_NUM_RESOURCES];  }; @@ -86,6 +106,10 @@ extern EGLBoolean  _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. */ @@ -97,6 +121,13 @@ _eglCheckDisplayHandle(EGLDisplay dpy)  } +static INLINE EGLBoolean +_eglCheckResource(_EGLResource *res, _EGLResourceType type, _EGLDisplay *dpy) +{ +   return (res->Display == dpy); +} + +  #endif /* _EGL_SKIP_HANDLE_CHECK */ @@ -134,6 +165,24 @@ _eglIsDisplayLinked(_EGLDisplay *dpy)  } +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.   */ diff --git a/src/egl/main/egltypedefs.h b/src/egl/main/egltypedefs.h index 4461440b9b..a49ffbb0cd 100644 --- a/src/egl/main/egltypedefs.h +++ b/src/egl/main/egltypedefs.h @@ -8,6 +8,8 @@  #include "eglcompiler.h" +typedef enum _egl_resource_type _EGLResourceType; +  typedef struct _egl_api _EGLAPI;  typedef struct _egl_config _EGLConfig; @@ -22,6 +24,8 @@ typedef struct _egl_extensions _EGLExtensions;  typedef struct _egl_mode _EGLMode; +typedef struct _egl_resource _EGLResource; +  typedef struct _egl_screen _EGLScreen;  typedef struct _egl_surface _EGLSurface; | 
