summaryrefslogtreecommitdiffstats
path: root/src/egl/main/egldisplay.c
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-10-23 11:59:03 +0800
committerChia-I Wu <[email protected]>2010-10-23 15:19:34 +0800
commitdc4f845c37a8446de19036e24fd397a0aa864c02 (patch)
tree7b1d125da53a1a6f932eae5cdbbdbcf489474601 /src/egl/main/egldisplay.c
parent662e098b560c6983f5ac320cc5ff7a82ecdc5f8a (diff)
egl: Add reference count for resources.
This is a really simple mechanism. There is no atomicity and the caller is expected to hold the display lock.
Diffstat (limited to 'src/egl/main/egldisplay.c')
-rw-r--r--src/egl/main/egldisplay.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/egl/main/egldisplay.c b/src/egl/main/egldisplay.c
index 47dcc3e05a5..565e44d2d23 100644
--- a/src/egl/main/egldisplay.c
+++ b/src/egl/main/egldisplay.c
@@ -233,6 +233,42 @@ _eglCheckResource(void *res, _EGLResourceType type, _EGLDisplay *dpy)
/**
+ * Initialize a display resource.
+ */
+void
+_eglInitResource(_EGLResource *res, EGLint size, _EGLDisplay *dpy)
+{
+ memset(res, 0, size);
+ res->Display = dpy;
+ res->RefCount = 1;
+}
+
+
+/**
+ * Increment reference count for the resource.
+ */
+void
+_eglGetResource(_EGLResource *res)
+{
+ assert(res && res->RefCount > 0);
+ /* hopefully a resource is always manipulated with its display locked */
+ res->RefCount++;
+}
+
+
+/**
+ * Decrement reference count for the resource.
+ */
+EGLBoolean
+_eglPutResource(_EGLResource *res)
+{
+ assert(res && res->RefCount > 0);
+ res->RefCount--;
+ return (!res->RefCount);
+}
+
+
+/**
* Link a resource to its display.
*/
void
@@ -243,6 +279,7 @@ _eglLinkResource(_EGLResource *res, _EGLResourceType type)
res->IsLinked = EGL_TRUE;
res->Next = res->Display->ResourceLists[type];
res->Display->ResourceLists[type] = res;
+ _eglGetResource(res);
}
@@ -269,6 +306,9 @@ _eglUnlinkResource(_EGLResource *res, _EGLResourceType type)
}
res->Next = NULL;
- /* do not reset res->Display */
res->IsLinked = EGL_FALSE;
+ _eglPutResource(res);
+
+ /* We always unlink before destroy. The driver still owns a reference */
+ assert(res->RefCount);
}