merge buffer_unreference(), buffer_reference()
authorBrian <brian.paul@tungstengraphics.com>
Mon, 10 Sep 2007 22:52:05 +0000 (16:52 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Mon, 10 Sep 2007 22:52:05 +0000 (16:52 -0600)
src/mesa/drivers/dri/intel_winsys/intel_winsys_pipe.c
src/mesa/drivers/x11/xm_winsys.c
src/mesa/pipe/i915simple/i915_regions.c
src/mesa/pipe/p_winsys.h
src/mesa/pipe/softpipe/sp_region.c
src/mesa/pipe/softpipe/sp_state_fs.c
src/mesa/state_tracker/st_cb_bufferobjects.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_draw.c

index 33aacf2a431915406ffc4b9c72198550637bae50..668bedcbdab0e2257a3dd74ca93519228ada9be2 100644 (file)
@@ -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;
index f1ecbf531f7a358de3a9a13d895ebbfad4517206..b7b2941490c93b9ee3d20bb1be6ef5d2c47fb475 100644 (file)
@@ -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;
index aad4a6a5375f8a9fa7cdc2e8eb486e4a16006708..bab256c7634a4b9a949b72a22e51106427ea07f2 100644 (file)
@@ -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;
index 09baef020ea5043834378504bc718d986eda5b42..4d2cc2196f6a8dd5852ad7cfaab72e1e7ee2034e 100644 (file)
@@ -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,
index 25d0a419aa3e7283ed2dc6b11cf4601adc3d729f..ae05b1d0dea53c5e24f7a1c461b9fa2d46d839c9 100644 (file)
@@ -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;
index 9e3ff6d35c0549b5f74270363fcac6a730b9acaa..5ab246896b98015be2075ca9c36ca1ac769f1ea2 100644 (file)
@@ -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;
index f1dc4fbaf4991e1ea52c3815ee312731ac329bb8..a593bd74d15ab9a44b62d1634f104246b453a62c 100644 (file)
@@ -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);
 }
index 5040c21e51cf9aa832ef2d89c44323211b4b0640..7bedf3f89f10f346ecae364f65ed206fcb458f99 100644 (file)
@@ -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);
index afb6f96a2607cd2c305e4d844d0641500c9de749..1facc14ccd41ea33d4ce383b259013cf2fd549d8 100644 (file)
@@ -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);
 }