}
-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,
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;
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;
}
}
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;
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;
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,
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;
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;
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);
}
/* 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);
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);
}
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);
}