summaryrefslogtreecommitdiff
path: root/src/gallium/include/pipe/p_state.h
diff options
context:
space:
mode:
authorMichel Dänzer <daenzer@vmware.com>2009-03-04 11:58:48 +0100
committerMichel Dänzer <daenzer@vmware.com>2009-03-04 11:58:48 +0100
commit5e27cd46c04a9e7b5904cc014bffd0f4daae31fe (patch)
treea57289f14d69f1977dfaee592af908052d726b8c /src/gallium/include/pipe/p_state.h
parent60041203d5847de8ab71842a6ce5d33d96cc4930 (diff)
gallium: Unify reference counting.
The core reference counting code is centralized in p_refcnt.h. This has some consequences related to struct pipe_buffer: * The screen member of struct pipe_buffer must be initialized, or pipe_buffer_reference() will crash trying to destroy a buffer with reference count 0. u_simple_screen takes care of this, but I may have missed some of the drivers not using it. * Except for rare exceptions deep in winsys code, buffers must always be allocated via pipe_buffer_create() or via screen->*buffer_create() rather than via winsys->*buffer_create().
Diffstat (limited to 'src/gallium/include/pipe/p_state.h')
-rw-r--r--src/gallium/include/pipe/p_state.h47
1 files changed, 36 insertions, 11 deletions
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