summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/p_inlines.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe/p_inlines.h')
-rw-r--r--src/mesa/pipe/p_inlines.h43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/mesa/pipe/p_inlines.h b/src/mesa/pipe/p_inlines.h
index 8ee0820f92..ebf6ed86bc 100644
--- a/src/mesa/pipe/p_inlines.h
+++ b/src/mesa/pipe/p_inlines.h
@@ -56,20 +56,38 @@ pipe_surface_unmap(struct pipe_surface *surface)
static INLINE void
pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
{
- assert(ptr);
- if (*ptr) {
+ /* bump the refcount first */
+ if (surf)
+ surf->refcount++;
+
+ if (*ptr /* && --(*ptr)->refcount == 0 */) {
struct pipe_winsys *winsys = (*ptr)->winsys;
winsys->surface_release(winsys, ptr);
assert(!*ptr);
}
- if (surf) {
- /* reference the new thing */
- surf->refcount++;
- *ptr = surf;
- }
+
+ *ptr = surf;
+}
+
+
+/* XXX: thread safety issues!
+ */
+static INLINE void
+pipe_buffer_reference(struct pipe_winsys *winsys,
+ struct pipe_buffer **ptr,
+ struct pipe_buffer *buf)
+{
+ if (buf)
+ buf->refcount++;
+
+ if (*ptr && --(*ptr)->refcount == 0)
+ winsys->buffer_destroy( winsys, *ptr );
+
+ *ptr = buf;
}
+
/**
* \sa pipe_surface_reference
*/
@@ -78,15 +96,16 @@ pipe_texture_reference(struct pipe_context *pipe, struct pipe_texture **ptr,
struct pipe_texture *pt)
{
assert(ptr);
+
+ if (pt)
+ pt->refcount++;
+
if (*ptr) {
pipe->texture_release(pipe, ptr);
assert(!*ptr);
}
- if (pt) {
- /* reference the new thing */
- pt->refcount++;
- *ptr = pt;
- }
+
+ *ptr = pt;
}