summaryrefslogtreecommitdiff
path: root/src/gallium/include/pipe
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/include/pipe')
-rw-r--r--src/gallium/include/pipe/internal/p_winsys_screen.h3
-rw-r--r--src/gallium/include/pipe/p_inlines.h113
-rw-r--r--src/gallium/include/pipe/p_refcnt.h84
-rw-r--r--src/gallium/include/pipe/p_screen.h16
-rw-r--r--src/gallium/include/pipe/p_state.h47
5 files changed, 125 insertions, 138 deletions
diff --git a/src/gallium/include/pipe/internal/p_winsys_screen.h b/src/gallium/include/pipe/internal/p_winsys_screen.h
index 8d3bab0caa..f4a29e63c7 100644
--- a/src/gallium/include/pipe/internal/p_winsys_screen.h
+++ b/src/gallium/include/pipe/internal/p_winsys_screen.h
@@ -154,8 +154,7 @@ struct pipe_winsys
void (*buffer_unmap)( struct pipe_winsys *ws,
struct pipe_buffer *buf );
- void (*buffer_destroy)( struct pipe_winsys *ws,
- struct pipe_buffer *buf );
+ void (*buffer_destroy)( struct pipe_buffer *buf );
/** Set ptr = fence, with reference counting */
diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h
index 4eb928d882..a68b521429 100644
--- a/src/gallium/include/pipe/p_inlines.h
+++ b/src/gallium/include/pipe/p_inlines.h
@@ -39,97 +39,6 @@ extern "C" {
/**
- * Set 'ptr' to point to 'surf' and update reference counting.
- * The old thing pointed to, if any, will be unreferenced first.
- * 'surf' may be NULL.
- */
-static INLINE void
-pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
-{
- /* bump the refcount first */
- if (surf) {
- assert(surf->refcount);
- surf->refcount++;
- }
-
- if (*ptr) {
- struct pipe_screen *screen;
- assert((*ptr)->refcount);
- assert((*ptr)->texture);
- screen = (*ptr)->texture->screen;
- screen->tex_surface_release( screen, ptr );
- assert(!*ptr);
- }
-
- *ptr = surf;
-}
-
-
-/**
- * \sa pipe_surface_reference
- */
-static INLINE void
-pipe_transfer_reference(struct pipe_transfer **ptr, struct pipe_transfer *trans)
-{
- /* bump the refcount first */
- if (trans) {
- assert(trans->refcount);
- trans->refcount++;
- }
-
- if (*ptr) {
- struct pipe_screen *screen;
- assert((*ptr)->refcount);
- assert((*ptr)->texture);
- screen = (*ptr)->texture->screen;
- screen->tex_transfer_release( screen, ptr );
- assert(!*ptr);
- }
-
- *ptr = trans;
-}
-
-
-/**
- * \sa pipe_surface_reference
- */
-static INLINE void
-pipe_texture_reference(struct pipe_texture **ptr,
- struct pipe_texture *pt)
-{
- assert(ptr);
-
- if (pt) {
- assert(pt->refcount);
- pt->refcount++;
- }
-
- if (*ptr) {
- struct pipe_screen *screen = (*ptr)->screen;
- assert(screen);
- assert((*ptr)->refcount);
- screen->texture_release(screen, ptr);
-
- assert(!*ptr);
- }
-
- *ptr = pt;
-}
-
-
-static INLINE void
-pipe_texture_release(struct pipe_texture **ptr)
-{
- struct pipe_screen *screen;
- assert(ptr);
- screen = (*ptr)->screen;
- assert((*ptr)->refcount);
- screen->texture_release(screen, ptr);
- *ptr = NULL;
-}
-
-
-/**
* Convenience wrappers for screen buffer functions.
*/
@@ -199,28 +108,6 @@ pipe_buffer_read(struct pipe_screen *screen,
}
}
-/* XXX: thread safety issues!
- */
-static INLINE void
-pipe_buffer_reference(struct pipe_screen *screen,
- struct pipe_buffer **ptr,
- struct pipe_buffer *buf)
-{
- if (buf) {
- assert(buf->refcount);
- buf->refcount++;
- }
-
- if (*ptr) {
- assert((*ptr)->refcount);
- if(--(*ptr)->refcount == 0) {
- screen->buffer_destroy( screen, *ptr );
- }
- }
-
- *ptr = buf;
-}
-
#ifdef __cplusplus
}
diff --git a/src/gallium/include/pipe/p_refcnt.h b/src/gallium/include/pipe/p_refcnt.h
new file mode 100644
index 0000000000..50b7aa90ef
--- /dev/null
+++ b/src/gallium/include/pipe/p_refcnt.h
@@ -0,0 +1,84 @@
+/**************************************************************************
+ *
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+#ifndef P_REFCNT_H
+#define P_REFCNT_H
+
+
+#include "p_defines.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+struct pipe_reference
+{
+ unsigned count;
+};
+
+
+static INLINE void
+pipe_reference_init(struct pipe_reference *reference, unsigned count)
+{
+ reference->count = count;
+}
+
+
+/**
+ * Set 'ptr' to point to 'reference' and update reference counting.
+ * The old thing pointed to, if any, will be unreferenced first.
+ * 'reference' may be NULL.
+ *
+ * XXX: thread safety issues!
+ */
+static INLINE bool
+pipe_reference(struct pipe_reference **ptr, struct pipe_reference *reference)
+{
+ bool destroy = FALSE;
+
+ /* bump the reference.count first */
+ if (reference) {
+ assert(reference->count);
+ reference->count++;
+ }
+
+ if (*ptr) {
+ assert((*ptr)->count);
+ if (--(*ptr)->count == 0) {
+ destroy = TRUE;
+ }
+ }
+
+ *ptr = reference;
+
+ return destroy;
+}
+
+
+#endif /* P_REFCNT_H */
diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
index 341d1caea0..3688d58118 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -113,8 +113,7 @@ struct pipe_screen {
const unsigned *stride,
struct pipe_buffer *buffer);
- void (*texture_release)(struct pipe_screen *,
- struct pipe_texture **pt);
+ void (*texture_destroy)(struct pipe_texture *pt);
/** Get a surface which is a "view" into a texture */
struct pipe_surface *(*get_tex_surface)(struct pipe_screen *,
@@ -123,10 +122,7 @@ struct pipe_screen {
unsigned zslice,
unsigned usage );
- /* Surfaces allocated by the above must be released here:
- */
- void (*tex_surface_release)( struct pipe_screen *,
- struct pipe_surface ** );
+ void (*tex_surface_destroy)(struct pipe_surface *);
/** Get a transfer object for transferring data to/from a texture */
@@ -138,10 +134,7 @@ struct pipe_screen {
unsigned x, unsigned y,
unsigned w, unsigned h);
- /* Transfer objects allocated by the above must be released here:
- */
- void (*tex_transfer_release)( struct pipe_screen *,
- struct pipe_transfer ** );
+ void (*tex_transfer_destroy)(struct pipe_transfer *);
void *(*transfer_map)( struct pipe_screen *,
struct pipe_transfer *transfer );
@@ -213,8 +206,7 @@ struct pipe_screen {
void (*buffer_unmap)( struct pipe_screen *screen,
struct pipe_buffer *buf );
- void (*buffer_destroy)( struct pipe_screen *screen,
- struct pipe_buffer *buf );
+ void (*buffer_destroy)( struct pipe_buffer *buf );
/**
diff --git a/src/gallium/include/pipe/p_state.h b/src/gallium/include/pipe/p_state.h
index a2e839da5c..57a7672d6c 100644
--- a/src/gallium/include/pipe/p_state.h
+++ b/src/gallium/include/pipe/p_state.h
@@ -43,6 +43,8 @@
#include "p_compiler.h"
#include "p_defines.h"
#include "p_format.h"
+#include "p_refcnt.h"
+#include "p_screen.h"
#ifdef __cplusplus
@@ -64,23 +66,20 @@ extern "C" {
/* fwd decls */
-struct pipe_screen;
struct pipe_surface;
-
/**
* The driver will certainly subclass this to include actual memory
* management information.
*/
struct pipe_buffer
{
+ struct pipe_reference reference;
+ struct pipe_screen *screen;
unsigned alignment;
unsigned usage;
unsigned size;
-
- /** Reference count */
- unsigned refcount;
};
@@ -275,6 +274,7 @@ struct pipe_sampler_state
*/
struct pipe_surface
{
+ struct pipe_reference reference;
enum pipe_format format; /**< PIPE_FORMAT_x */
unsigned status; /**< PIPE_SURFACE_STATUS_x */
unsigned clear_value; /**< XXX may be temporary */
@@ -282,7 +282,6 @@ struct pipe_surface
unsigned height; /**< logical height in pixels */
unsigned layout; /**< PIPE_SURFACE_LAYOUT_x */
unsigned offset; /**< offset from start of buffer, in bytes */
- unsigned refcount;
unsigned usage; /**< PIPE_BUFFER_USAGE_* */
struct pipe_texture *texture; /**< texture into which this is a view */
@@ -306,7 +305,6 @@ struct pipe_transfer
unsigned nblocksx; /**< allocated width in blocks */
unsigned nblocksy; /**< allocated height in blocks */
unsigned stride; /**< stride in bytes between rows of blocks */
- unsigned refcount;
unsigned usage; /**< PIPE_TRANSFER_* */
struct pipe_texture *texture; /**< texture to transfer to/from */
@@ -321,6 +319,8 @@ struct pipe_transfer
*/
struct pipe_texture
{
+ struct pipe_reference reference;
+
enum pipe_texture_target target; /**< PIPE_TEXTURE_x */
enum pipe_format format; /**< PIPE_FORMAT_x */
@@ -339,10 +339,6 @@ struct pipe_texture
unsigned tex_usage; /* PIPE_TEXTURE_USAGE_* */
- /* These are also refcounted:
- */
- unsigned refcount;
-
struct pipe_screen *screen; /**< screen that this texture belongs to */
};
@@ -379,6 +375,35 @@ struct pipe_vertex_element
};
+/* Reference counting helper functions */
+static INLINE void
+pipe_buffer_reference(struct pipe_buffer **ptr, struct pipe_buffer *buf)
+{
+ struct pipe_buffer *old_buf = *ptr;
+
+ if (pipe_reference((struct pipe_reference **)ptr, &buf->reference))
+ old_buf->screen->buffer_destroy(old_buf);
+}
+
+static INLINE void
+pipe_surface_reference(struct pipe_surface **ptr, struct pipe_surface *surf)
+{
+ struct pipe_surface *old_surf = *ptr;
+
+ if (pipe_reference((struct pipe_reference **)ptr, &surf->reference))
+ old_surf->texture->screen->tex_surface_destroy(old_surf);
+}
+
+static INLINE void
+pipe_texture_reference(struct pipe_texture **ptr, struct pipe_texture *tex)
+{
+ struct pipe_texture *old_tex = *ptr;
+
+ if (pipe_reference((struct pipe_reference **)ptr, &tex->reference))
+ old_tex->screen->texture_destroy(old_tex);
+}
+
+
#ifdef __cplusplus
}
#endif