summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian <[email protected]>2007-09-10 16:52:05 -0600
committerBrian <[email protected]>2007-09-10 16:52:05 -0600
commit6275b40063d7d06e0b05767ebca3963ce7e9c34e (patch)
tree1323c9c266075c70ae186e0f31ca8d09999a088b
parent051a2a3028370da66c15c44fa49fa9474b23d668 (diff)
merge buffer_unreference(), buffer_reference()
-rw-r--r--src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c18
-rw-r--r--src/mesa/drivers/x11/xm_winsys.c42
-rw-r--r--src/mesa/pipe/i915simple/i915_regions.c4
-rw-r--r--src/mesa/pipe/p_winsys.h9
-rw-r--r--src/mesa/pipe/softpipe/sp_region.c4
-rw-r--r--src/mesa/pipe/softpipe/sp_state_fs.c5
-rw-r--r--src/mesa/state_tracker/st_cb_bufferobjects.c2
-rw-r--r--src/mesa/state_tracker/st_cb_rasterpos.c2
-rw-r--r--src/mesa/state_tracker/st_draw.c5
9 files changed, 45 insertions, 46 deletions
diff --git a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c
index 33aacf2a431..668bedcbdab 100644
--- a/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c
+++ b/src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c
@@ -84,22 +84,21 @@ static void intel_buffer_unmap(struct pipe_winsys *sws,
}
-static struct pipe_buffer_handle *
+static void
intel_buffer_reference(struct pipe_winsys *sws,
+ struct pipe_buffer_handle **ptr,
struct pipe_buffer_handle *buf)
{
- return pipe_bo( driBOReference( dri_bo(buf) ) );
-}
-
-static void intel_buffer_unreference(struct pipe_winsys *sws,
- struct pipe_buffer_handle **buf)
-{
- if (*buf) {
- driBOUnReference( dri_bo(*buf) );
+ if (*ptr) {
+ driBOUnReference( dri_bo(*ptr) );
*buf = NULL;
}
+
+ driBOReference( dri_bo(buf) );
+ *ptr = buf;
}
+
/* Grabs the hardware lock!
*/
static void intel_buffer_data(struct pipe_winsys *sws,
@@ -208,7 +207,6 @@ intel_create_pipe_winsys( struct intel_context *intel )
iws->winsys.buffer_map = intel_buffer_map;
iws->winsys.buffer_unmap = intel_buffer_unmap;
iws->winsys.buffer_reference = intel_buffer_reference;
- iws->winsys.buffer_unreference = intel_buffer_unreference;
iws->winsys.buffer_data = intel_buffer_data;
iws->winsys.buffer_subdata = intel_buffer_subdata;
iws->winsys.buffer_get_subdata = intel_buffer_get_subdata;
diff --git a/src/mesa/drivers/x11/xm_winsys.c b/src/mesa/drivers/x11/xm_winsys.c
index f1ecbf531f7..b7b2941490c 100644
--- a/src/mesa/drivers/x11/xm_winsys.c
+++ b/src/mesa/drivers/x11/xm_winsys.c
@@ -108,30 +108,31 @@ xm_buffer_unmap(struct pipe_winsys *pws, struct pipe_buffer_handle *buf)
xm_buf->mapped = NULL;
}
-
-static struct pipe_buffer_handle *
-xm_buffer_reference(struct pipe_winsys *pws, struct pipe_buffer_handle *buf)
-{
- struct xm_buffer *xm_buf = xm_bo(buf);
- xm_buf->refcount++;
- return buf;
-}
-
static void
-xm_buffer_unreference(struct pipe_winsys *pws, struct pipe_buffer_handle **buf)
+xm_buffer_reference(struct pipe_winsys *pws,
+ struct pipe_buffer_handle **ptr,
+ struct pipe_buffer_handle *buf)
{
- if (*buf) {
- struct xm_buffer *xm_buf = xm_bo(*buf);
- xm_buf->refcount--;
- assert(xm_buf->refcount >= 0);
- if (xm_buf->refcount == 0) {
- if (xm_buf->data) {
- free(xm_buf->data);
- xm_buf->data = NULL;
+ if (*ptr) {
+ struct xm_buffer *oldBuf = xm_bo(*ptr);
+ oldBuf->refcount--;
+ assert(oldBuf->refcount >= 0);
+ if (oldBuf->refcount == 0) {
+ if (oldBuf->data) {
+ free(oldBuf->data);
+ oldBuf->data = NULL;
}
- free(xm_buf);
+ free(oldBuf);
}
- *buf = NULL;
+ *ptr = NULL;
+ }
+
+ assert(!(*ptr));
+
+ if (buf) {
+ struct xm_buffer *newBuf = xm_bo(buf);
+ newBuf->refcount++;
+ *ptr = buf;
}
}
@@ -237,7 +238,6 @@ xmesa_create_pipe_winsys( XMesaContext xmesa )
xws->winsys.buffer_map = xm_buffer_map;
xws->winsys.buffer_unmap = xm_buffer_unmap;
xws->winsys.buffer_reference = xm_buffer_reference;
- xws->winsys.buffer_unreference = xm_buffer_unreference;
xws->winsys.buffer_data = xm_buffer_data;
xws->winsys.buffer_subdata = xm_buffer_subdata;
xws->winsys.buffer_get_subdata = xm_buffer_get_subdata;
diff --git a/src/mesa/pipe/i915simple/i915_regions.c b/src/mesa/pipe/i915simple/i915_regions.c
index aad4a6a5375..bab256c7634 100644
--- a/src/mesa/pipe/i915simple/i915_regions.c
+++ b/src/mesa/pipe/i915simple/i915_regions.c
@@ -123,8 +123,8 @@ i915_region_release(struct pipe_context *pipe, struct pipe_region **region)
if ((*region)->refcount == 0) {
assert((*region)->map_refcount == 0);
- i915->pipe.winsys->buffer_unreference( i915->pipe.winsys,
- &((*region)->buffer) );
+ i915->pipe.winsys->buffer_reference( i915->pipe.winsys,
+ &((*region)->buffer), NULL );
free(*region);
}
*region = NULL;
diff --git a/src/mesa/pipe/p_winsys.h b/src/mesa/pipe/p_winsys.h
index 09baef020ea..4d2cc2196f6 100644
--- a/src/mesa/pipe/p_winsys.h
+++ b/src/mesa/pipe/p_winsys.h
@@ -79,11 +79,10 @@ struct pipe_winsys {
void (*buffer_unmap)( struct pipe_winsys *sws,
struct pipe_buffer_handle *buf );
- struct pipe_buffer_handle *(*buffer_reference)( struct pipe_winsys *sws,
- struct pipe_buffer_handle *buf );
-
- void (*buffer_unreference)( struct pipe_winsys *sws,
- struct pipe_buffer_handle **buf );
+ /** Set ptr = buf, with reference counting */
+ void (*buffer_reference)( struct pipe_winsys *sws,
+ struct pipe_buffer_handle **ptr,
+ struct pipe_buffer_handle *buf );
void (*buffer_data)(struct pipe_winsys *sws,
struct pipe_buffer_handle *buf,
diff --git a/src/mesa/pipe/softpipe/sp_region.c b/src/mesa/pipe/softpipe/sp_region.c
index 25d0a419aa3..ae05b1d0dea 100644
--- a/src/mesa/pipe/softpipe/sp_region.c
+++ b/src/mesa/pipe/softpipe/sp_region.c
@@ -121,8 +121,8 @@ sp_region_release(struct pipe_context *pipe, struct pipe_region **region)
if ((*region)->refcount == 0) {
assert((*region)->map_refcount == 0);
- sp->pipe.winsys->buffer_unreference( sp->pipe.winsys,
- &((*region)->buffer) );
+ sp->pipe.winsys->buffer_reference( sp->pipe.winsys,
+ &((*region)->buffer), NULL );
free(*region);
}
*region = NULL;
diff --git a/src/mesa/pipe/softpipe/sp_state_fs.c b/src/mesa/pipe/softpipe/sp_state_fs.c
index 9e3ff6d35c0..5ab246896b9 100644
--- a/src/mesa/pipe/softpipe/sp_state_fs.c
+++ b/src/mesa/pipe/softpipe/sp_state_fs.c
@@ -68,8 +68,9 @@ void softpipe_set_constant_buffer(struct pipe_context *pipe,
assert(index == 0);
/* note: reference counting */
- ws->buffer_unreference(ws, &softpipe->constants[shader].buffer);
- softpipe->constants[shader].buffer = ws->buffer_reference(ws, buf->buffer);
+ ws->buffer_reference(ws,
+ &softpipe->constants[shader].buffer,
+ buf->buffer);
softpipe->constants[shader].size = buf->size;
softpipe->dirty |= SP_NEW_CONSTANTS;
diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c
index f1dc4fbaf49..a593bd74d15 100644
--- a/src/mesa/state_tracker/st_cb_bufferobjects.c
+++ b/src/mesa/state_tracker/st_cb_bufferobjects.c
@@ -81,7 +81,7 @@ st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj)
struct st_buffer_object *st_obj = st_buffer_object(obj);
if (st_obj->buffer)
- pipe->winsys->buffer_unreference(pipe->winsys, &st_obj->buffer);
+ pipe->winsys->buffer_reference(pipe->winsys, &st_obj->buffer, NULL);
free(st_obj);
}
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 5040c21e51c..7bedf3f89f1 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -337,7 +337,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
/* free vertex feedback buffer */
pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer);
- pipe->winsys->buffer_unreference(pipe->winsys, &fb_buf.buffer);
+ pipe->winsys->buffer_reference(pipe->winsys, &fb_buf.buffer, NULL);
/* restore pipe state */
pipe->set_feedback_state(pipe, &ctx->st->state.feedback);
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index afb6f96a260..1facc14ccd4 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -152,7 +152,8 @@ static void
destroy_default_attribs_buffer(struct st_context *st)
{
struct pipe_context *pipe = st->pipe;
- pipe->winsys->buffer_unreference(pipe->winsys, &st->default_attrib_buffer);
+ pipe->winsys->buffer_reference(pipe->winsys,
+ &st->default_attrib_buffer, NULL);
}
@@ -349,7 +350,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim,
pipe->draw_arrays(pipe, prim, 0, numVertex);
/* XXX: do one-time */
- pipe->winsys->buffer_unreference(pipe->winsys, &vbuf);
+ pipe->winsys->buffer_reference(pipe->winsys, &vbuf, NULL);
}