Fix/improve framebuffer object reference counting.
authorBrian <brian@yutani.localnet.net>
Tue, 6 Mar 2007 17:07:59 +0000 (10:07 -0700)
committerBrian <brian@yutani.localnet.net>
Tue, 6 Mar 2007 17:07:59 +0000 (10:07 -0700)
Use _mesa_reference_framebuffer() and _mesa_unreference_framebuffer() functions
to be sure reference counting is done correctly.  Additional assertions are
done too.  Note _mesa_dereference_framebuffer() renamed to "unreference" as
that's more accurate.

30 files changed:
src/mesa/drivers/allegro/amesa.c
src/mesa/drivers/dri/fb/fb_dri.c
src/mesa/drivers/dri/ffb/ffb_xmesa.c
src/mesa/drivers/dri/gamma/gamma_xmesa.c
src/mesa/drivers/dri/i810/i810screen.c
src/mesa/drivers/dri/i915/intel_screen.c
src/mesa/drivers/dri/i915tex/intel_screen.c
src/mesa/drivers/dri/i965/intel_screen.c
src/mesa/drivers/dri/mach64/mach64_screen.c
src/mesa/drivers/dri/mga/mga_xmesa.c
src/mesa/drivers/dri/nouveau/nouveau_screen.c
src/mesa/drivers/dri/r128/r128_screen.c
src/mesa/drivers/dri/radeon/radeon_screen.c
src/mesa/drivers/dri/s3v/s3v_xmesa.c
src/mesa/drivers/dri/savage/savage_xmesa.c
src/mesa/drivers/dri/sis/sis_screen.c
src/mesa/drivers/dri/tdfx/tdfx_screen.c
src/mesa/drivers/dri/trident/trident_context.c
src/mesa/drivers/dri/unichrome/via_screen.c
src/mesa/drivers/glide/fxapi.c
src/mesa/drivers/osmesa/osmesa.c
src/mesa/drivers/svga/svgamesa.c
src/mesa/drivers/x11/xm_api.c
src/mesa/main/context.c
src/mesa/main/fbobject.c
src/mesa/main/framebuffer.c
src/mesa/main/framebuffer.h
src/mesa/main/rbadaptors.c
src/mesa/main/renderbuffer.c
src/mesa/main/renderbuffer.h

index 594668affda0f46fecdd8c5130fb70543d52f88a..518211ccf467431bae4131ea82e39f926436b660 100644 (file)
@@ -338,7 +338,7 @@ void AMesaDestroyBuffer(AMesaBuffer buffer)
 {\r
    if (buffer->Screen)     destroy_bitmap(buffer->Screen);\r
    if (buffer->Background) destroy_bitmap(buffer->Background);\r
-   _mesa_destroy_framebuffer(buffer->GLBuffer);\r
+   _mesa_unreference_framebuffer(&buffer->GLBuffer);\r
    free(buffer);\r
 }\r
 \r
index 08b52b4d8f717691bda4ff185c6022496af23aad..a6d7590eff7ec4a82016a26b98d992c21aa2553f 100644 (file)
@@ -480,11 +480,7 @@ fbCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 fbDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   struct gl_framebuffer *mesa_framebuffer = (struct gl_framebuffer *)driDrawPriv->driverPrivate;
-   
-   _mesa_free(mesa_framebuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer->Data);
-   _mesa_destroy_framebuffer(mesa_framebuffer);
-   driDrawPriv->driverPrivate = NULL;
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index 215aaf8ffbaff0b72075afec3972b345934263f4..4c5323d230ee3d33d84b3a824b0999fc46dfc11d 100644 (file)
@@ -392,7 +392,7 @@ ffbCreateBuffer(__DRIscreenPrivate *driScrnPriv,
 static void
 ffbDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index e8922b15036456d412dc9a5dbaf7331c7c677da6..f41682cea71ad014cad71e149f589bb81a952cfd 100644 (file)
@@ -97,7 +97,7 @@ gammaCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 gammaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void
index ebe2615fe874b54b2f37fdf1b9a06bfedf64f150..f64c10a9ae099110e5476f9dd417140b27fbfad3 100644 (file)
@@ -398,8 +398,7 @@ i810CreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 i810DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-    /* _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); */
-    _mesa_dereference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+    _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index 942e1e9c226cc511f038ec04e282412a078d1d4c..67e176a1c6ff56d2dfd9273b4633d7d4affcb556 100644 (file)
@@ -449,8 +449,7 @@ static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
 static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-    /* _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); */
-    _mesa_dereference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index bc538902b4cf9310396c298e30d28ca8aad778b0..ac83254593bc979498e715de560481754151e978 100644 (file)
@@ -609,8 +609,7 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
 static void
 intelDestroyBuffer(__DRIdrawablePrivate * driDrawPriv)
 {
-    /* _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); */
-    _mesa_dereference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index 06e5d0c5bd751cedef8590ce569efa0a54f13895..5dac50df32c324c1986d0d5dba7b84d319b2d8f3 100644 (file)
@@ -457,8 +457,7 @@ static GLboolean intelCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 
 static void intelDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-    /* _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate)); */
-    _mesa_dereference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index 1014b8acd525fc1442a3779da9d7f9a42049b524..4e9e216e7dbd4acb7c83a8c9790947e68e2be3ff 100644 (file)
@@ -435,7 +435,7 @@ mach64CreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 mach64DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index f024f73eb6af30429c9472d12ee3f994e47fed8e..67a6f8bdf09767453ba9793a66ef98b81df6c42c 100644 (file)
@@ -831,7 +831,7 @@ mgaCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 mgaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void
index 24e77750f937f74eb074c700906b92d63ec7c84b..e00080fce1e03e8a25e19bd7fd61e01885e729d5 100644 (file)
@@ -202,7 +202,7 @@ nouveauCreateBuffer(__DRIscreenPrivate *driScrnPriv,
 static void
 nouveauDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-       _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+       _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static int
index 4f1b20aadd7fb32710e0e4fee3f66647166fa3c7..880dee85c25b4d7fd86a151108f533fa3dce6096 100644 (file)
@@ -357,7 +357,7 @@ r128CreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 r128DestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index fc5aa11462109fd6f4c920e24815dd8f4d9dacd3..abb14faaa130f996176396f59252144f4f3e40ad 100644 (file)
@@ -901,7 +901,7 @@ radeonCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 radeonDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R300)
index c451f7452bf63c3896c1c1cfa54b5e92e713a323..c66fd6dac311e3e2dd16b7430544b8bca5840996 100644 (file)
@@ -131,7 +131,7 @@ s3vCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 s3vDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void
index ad79b9235c116788662ed7fcdd9383a4aa5b8fed..f859217069cedd05902cb6cacd8d05f1a66fb7fc 100644 (file)
@@ -710,7 +710,7 @@ savageCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 savageDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 #if 0
index 8f52cfe098e28d5561bc4836cceeb25d98255f61..89d734ba786f6e3ce99a249909df4109829dc1e3 100644 (file)
@@ -233,7 +233,7 @@ sisCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 sisDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void sisCopyBuffer( __DRIdrawablePrivate *dPriv )
index 646f5126eb01d635c523360a6fb31639eb565e8e..1f9ff4e30cabde97069ff7bd19a35e05e2fe0a33 100644 (file)
@@ -233,7 +233,7 @@ tdfxCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 tdfxDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index dbbd1ac0c69a2cff07cf6ac62fabc6dd42ad6db8..8dc7f0dc781e837011241f71c4f63db2bd461c25 100644 (file)
@@ -279,7 +279,7 @@ tridentCreateBuffer( __DRIscreenPrivate *driScrnPriv,
 static void
 tridentDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-   _mesa_destroy_framebuffer((GLframebuffer *) (driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 static void
index 28e1f9451e65d53ff81af6e59a2a5bcabd1f9147..90f76be44d4b85c2f6b0eab52d0515e1ed38e4e6 100644 (file)
@@ -320,7 +320,7 @@ viaCreateBuffer(__DRIscreenPrivate *driScrnPriv,
 static void
 viaDestroyBuffer(__DRIdrawablePrivate *driDrawPriv)
 {
-    _mesa_destroy_framebuffer((GLframebuffer *)(driDrawPriv->driverPrivate));
+   _mesa_unreference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)));
 }
 
 
index e535e739b31229857dea7cb7eb54464dabfc2abb..00b9d29fac148af2fecfb1b135db22d1c226f4c3 100644 (file)
@@ -728,7 +728,7 @@ errorhandler:
        FREE(fxMesa->fogTable);
     }
     if (fxMesa->glBuffer) {
-       _mesa_destroy_framebuffer(fxMesa->glBuffer);
+       _mesa_unreference_framebuffer(&fxMesa->glBuffer);
     }
     if (fxMesa->glVis) {
        _mesa_destroy_visual(fxMesa->glVis);
@@ -828,7 +828,7 @@ fxMesaDestroyContext(fxMesaContext fxMesa)
    fxDDDestroyFxMesaContext(fxMesa); /* must be before _mesa_destroy_context */
    _mesa_destroy_visual(fxMesa->glVis);
    _mesa_destroy_context(fxMesa->glCtx);
-   _mesa_destroy_framebuffer(fxMesa->glBuffer);
+   _mesa_unreference_framebuffer(&fxMesa->glBuffer);
    fxTMClose(fxMesa); /* must be after _mesa_destroy_context */
 
    FREE(fxMesa);
index c4fc8821e505950311744dab3b77058be7b22f89..96b9b5c1741eef814291fbef34a311bb06f2af10 100644 (file)
@@ -1303,7 +1303,8 @@ OSMesaDestroyContext( OSMesaContext osmesa )
       _swrast_DestroyContext( &osmesa->mesa );
 
       _mesa_destroy_visual( osmesa->gl_visual );
-      _mesa_destroy_framebuffer( osmesa->gl_buffer );
+      _mesa_unreference_framebuffer( &osmesa->gl_buffer );
+
       _mesa_free_context_data( &osmesa->mesa );
       _mesa_free( osmesa );
    }
index 0dd9a144fe8b8ea660212c07d1b669fcd381d40c..d13858756905f91b965c7561013f2d459492ebbe 100644 (file)
@@ -433,7 +433,6 @@ void SVGAMesaDestroyContext( SVGAMesaContext ctx )
    if (ctx) {
       _mesa_destroy_visual( ctx->gl_vis );
       _mesa_destroy_context( ctx->gl_ctx );
-      _mesa_destroy_framebuffer( ctx->gl_buffer );
       free( ctx );
       if (ctx==SVGAMesa) {
          SVGAMesa = NULL;
index 2cd7d8a6ca1832528b6d5634520b07525ed070dd..a42de72827fe8bc5d1f8cacae4a4748c3ceb77b8 100644 (file)
@@ -485,8 +485,8 @@ xmesa_free_buffer(XMesaBuffer buffer)
 
          /* mark as delete pending */
          fb->DeletePending = GL_TRUE;
-         /* Dereference.  If count = zero we'll really delete the buffer */
-         _mesa_dereference_framebuffer(&fb);
+         /* Unreference.  If count = zero we'll really delete the buffer */
+         _mesa_unreference_framebuffer(&fb);
 
          return;
       }
index 1245c10cc2c32f67d1424a539fce891a72e4e053..135c814c0a6ac4a083b022dd6b5a6c3bec1d3a20 100644 (file)
@@ -1408,6 +1408,13 @@ _mesa_free_context_data( GLcontext *ctx )
    if (ctx == _mesa_get_current_context()) {
       _mesa_make_current(NULL, NULL, NULL);
    }
+   else {
+      /* unreference WinSysDraw/Read buffers */
+      _mesa_unreference_framebuffer(&ctx->WinSysDrawBuffer);
+      _mesa_unreference_framebuffer(&ctx->WinSysReadBuffer);
+      _mesa_unreference_framebuffer(&ctx->DrawBuffer);
+      _mesa_unreference_framebuffer(&ctx->ReadBuffer);
+   }
 
    _mesa_free_lighting_data( ctx );
    _mesa_free_eval_data( ctx );
@@ -1694,12 +1701,8 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
    ASSERT(_mesa_get_current_context() == newCtx);
 
    if (oldCtx) {
-      if (oldCtx->WinSysDrawBuffer) {
-         _mesa_dereference_framebuffer(&oldCtx->WinSysDrawBuffer);
-      }
-      if (oldCtx->WinSysReadBuffer) {
-         _mesa_dereference_framebuffer(&oldCtx->WinSysReadBuffer);
-      }
+      _mesa_unreference_framebuffer(&oldCtx->WinSysDrawBuffer);
+      _mesa_unreference_framebuffer(&oldCtx->WinSysReadBuffer);
    }
          
    if (!newCtx) {
@@ -1713,20 +1716,18 @@ _mesa_make_current( GLcontext *newCtx, GLframebuffer *drawBuffer,
 
          ASSERT(drawBuffer->Name == 0);
          ASSERT(readBuffer->Name == 0);
-         newCtx->WinSysDrawBuffer = drawBuffer;
-         newCtx->WinSysReadBuffer = readBuffer;
-         drawBuffer->RefCount++;
-         readBuffer->RefCount++;
+         _mesa_reference_framebuffer(&newCtx->WinSysDrawBuffer, drawBuffer);
+         _mesa_reference_framebuffer(&newCtx->WinSysReadBuffer, readBuffer);
 
          /*
           * Only set the context's Draw/ReadBuffer fields if they're NULL
           * or not bound to a user-created FBO.
           */
          if (!newCtx->DrawBuffer || newCtx->DrawBuffer->Name == 0) {
-            newCtx->DrawBuffer = drawBuffer;
+            _mesa_reference_framebuffer(&newCtx->DrawBuffer, drawBuffer);
          }
          if (!newCtx->ReadBuffer || newCtx->ReadBuffer->Name == 0) {
-            newCtx->ReadBuffer = readBuffer;
+            _mesa_reference_framebuffer(&newCtx->ReadBuffer, readBuffer);
          }
 
         newCtx->NewState |= _NEW_BUFFERS;
index a99ff9dc97ec297e75e64b2ef1fad1446c98b0c2..6608eefc6c0e0f293b17b9bf3d53837fb027203e 100644 (file)
@@ -602,7 +602,7 @@ _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer)
 
    oldRb = ctx->CurrentRenderbuffer;
    if (oldRb) {
-      _mesa_dereference_renderbuffer(&oldRb);
+      _mesa_unreference_renderbuffer(&oldRb);
    }
 
    ASSERT(newRb != &DummyRenderbuffer);
@@ -639,7 +639,7 @@ _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers)
                /* But the object will not be freed until it's no longer
                 * bound in any context.
                 */
-               _mesa_dereference_renderbuffer(&rb);
+               _mesa_unreference_renderbuffer(&rb);
            }
         }
       }
@@ -998,12 +998,6 @@ _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
         }
          _mesa_HashInsert(ctx->Shared->FrameBuffers, framebuffer, newFb);
       }
-      _glthread_LOCK_MUTEX(newFb->Mutex);
-      if (bindReadBuf)
-         newFb->RefCount++;
-      if (bindDrawBuf)
-         newFb->RefCount++;
-      _glthread_UNLOCK_MUTEX(newFb->Mutex);
    }
    else {
       /* Binding the window system framebuffer (which was originally set
@@ -1020,22 +1014,16 @@ _mesa_BindFramebufferEXT(GLenum target, GLuint framebuffer)
     */
 
    if (bindReadBuf) {
-      struct gl_framebuffer *oldFb = ctx->ReadBuffer;
-      if (oldFb && oldFb->Name != 0) {
-         _mesa_dereference_framebuffer(&oldFb);
-      }
-      ctx->ReadBuffer = newFb;
+      _mesa_unreference_framebuffer(&ctx->ReadBuffer);
+      _mesa_reference_framebuffer(&ctx->ReadBuffer, newFb);
    }
 
    if (bindDrawBuf) {
-      struct gl_framebuffer *oldFb = ctx->DrawBuffer;
-      if (oldFb && oldFb->Name != 0) {
-         /* check if old FB had any texture attachments */
-         check_end_texture_render(ctx, oldFb);
-         /* check if time to delete this framebuffer */
-         _mesa_dereference_framebuffer(&oldFb);
-      }
-      ctx->DrawBuffer = newFb;
+      /* check if old FB had any texture attachments */
+      check_end_texture_render(ctx, ctx->DrawBuffer);
+      /* check if time to delete this framebuffer */
+      _mesa_unreference_framebuffer(&ctx->DrawBuffer);
+      _mesa_reference_framebuffer(&ctx->DrawBuffer, newFb);
       if (newFb->Name != 0) {
          /* check if newly bound framebuffer has any texture attachments */
          check_begin_texture_render(ctx, newFb);
@@ -1083,7 +1071,7 @@ _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers)
                /* But the object will not be freed until it's no longer
                 * bound in any context.
                 */
-               _mesa_dereference_framebuffer(&fb);
+               _mesa_unreference_framebuffer(&fb);
            }
         }
       }
index dabc96d91d921bfdc71a00278664144802e23cf1..c97d2f0077bfc8ef001b927705ce91ef9d8e09fd 100644 (file)
@@ -78,7 +78,7 @@ set_depth_renderbuffer(struct gl_framebuffer *fb,
                        struct gl_renderbuffer *rb)
 {
    if (fb->_DepthBuffer) {
-      _mesa_dereference_renderbuffer(&fb->_DepthBuffer);
+      _mesa_unreference_renderbuffer(&fb->_DepthBuffer);
    }
    fb->_DepthBuffer = rb;
    if (rb) {
@@ -96,7 +96,7 @@ set_stencil_renderbuffer(struct gl_framebuffer *fb,
                          struct gl_renderbuffer *rb)
 {
    if (fb->_StencilBuffer) {
-      _mesa_dereference_renderbuffer(&fb->_StencilBuffer);
+      _mesa_unreference_renderbuffer(&fb->_StencilBuffer);
    }
    fb->_StencilBuffer = rb;
    if (rb) {
@@ -223,7 +223,7 @@ _mesa_free_framebuffer_data(struct gl_framebuffer *fb)
    for (i = 0; i < BUFFER_COUNT; i++) {
       struct gl_renderbuffer_attachment *att = &fb->Attachment[i];
       if (att->Renderbuffer) {
-         _mesa_dereference_renderbuffer(&att->Renderbuffer);
+         _mesa_unreference_renderbuffer(&att->Renderbuffer);
       }
       if (att->Texture) {
          /* render to texture */
@@ -236,7 +236,6 @@ _mesa_free_framebuffer_data(struct gl_framebuffer *fb)
          }
       }
       att->Type = GL_NONE;
-      att->Renderbuffer = NULL;
       att->Texture = NULL;
    }
 
@@ -247,25 +246,44 @@ _mesa_free_framebuffer_data(struct gl_framebuffer *fb)
 
 
 /**
- * Decrement the reference count on a framebuffer and delete it when
+ * Set *ptr to point to fb, with refcounting and locking.
+ */
+void
+_mesa_reference_framebuffer(struct gl_framebuffer **ptr,
+                            struct gl_framebuffer *fb)
+{
+   assert(ptr);
+   assert(!*ptr);
+   assert(fb);
+   _glthread_LOCK_MUTEX(fb->Mutex);
+   fb->RefCount++;
+   _glthread_UNLOCK_MUTEX(fb->Mutex);
+   *ptr = fb;
+}
+
+
+/**
+ * Undo/remove a reference to a framebuffer object.
+ * Decrement the framebuffer object's reference count and delete it when
  * the refcount hits zero.
- * Note: we pass the address of a pointer and set it to NULL if we delete it.
+ * Note: we pass the address of a pointer and set it to NULL.
  */
 void
-_mesa_dereference_framebuffer(struct gl_framebuffer **fb)
+_mesa_unreference_framebuffer(struct gl_framebuffer **fb)
 {
-   GLboolean deleteFlag = GL_FALSE;
+   assert(fb);
+   if (*fb) {
+      GLboolean deleteFlag = GL_FALSE;
 
-   _glthread_LOCK_MUTEX((*fb)->Mutex);
-   {
+      _glthread_LOCK_MUTEX((*fb)->Mutex);
       ASSERT((*fb)->RefCount > 0);
       (*fb)->RefCount--;
       deleteFlag = ((*fb)->RefCount == 0);
-   }
-   _glthread_UNLOCK_MUTEX((*fb)->Mutex);
+      _glthread_UNLOCK_MUTEX((*fb)->Mutex);
+      
+      if (deleteFlag)
+         (*fb)->Delete(*fb);
 
-   if (deleteFlag) {
-      (*fb)->Delete(*fb);
       *fb = NULL;
    }
 }
index 7f3254fe8ea1227852d3ad422f234dba5d28a395..4d76f3a90f7e9c9a32fb5f1090348c9ad69658bc 100644 (file)
@@ -43,7 +43,11 @@ extern void
 _mesa_free_framebuffer_data(struct gl_framebuffer *buffer);
 
 extern void
-_mesa_dereference_framebuffer(struct gl_framebuffer **fb);
+_mesa_reference_framebuffer(struct gl_framebuffer **ptr,
+                            struct gl_framebuffer *fb);
+
+extern void
+_mesa_unreference_framebuffer(struct gl_framebuffer **fb);
 
 extern void
 _mesa_resize_framebuffer(GLcontext *ctx, struct gl_framebuffer *fb,
index 313c8d43d629e706c9a99613fd3e3f3b3e344674..60f4948becf3218a7d32206ffb1c0b4095eb9220 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.1
+ * Version:  6.5.3
  *
- * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2007  Brian Paul   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"),
@@ -45,7 +45,7 @@ Delete_wrapper(struct gl_renderbuffer *rb)
    /* Decrement reference count on the buffer we're wrapping and delete
     * it if refcount hits zero.
     */
-   _mesa_dereference_renderbuffer(&rb->Wrapped);
+   _mesa_unreference_renderbuffer(&rb->Wrapped);
 
    /* delete myself */
    _mesa_delete_renderbuffer(rb);
index 6b18d60baffa787bf13b9f43fccfbbda2609d294..1cc95a7d3b4b12b2233ce53e38f139683ac1a354 100644 (file)
@@ -2089,32 +2089,33 @@ _mesa_remove_renderbuffer(struct gl_framebuffer *fb, GLuint bufferName)
    if (!rb)
       return;
 
-   _mesa_dereference_renderbuffer(&rb);
+   _mesa_unreference_renderbuffer(&rb);
 
    fb->Attachment[bufferName].Renderbuffer = NULL;
 }
 
 
 /**
- * Decrement the reference count on a renderbuffer and delete it when
+ * Decrement a renderbuffer object's reference count and delete it when
  * the refcount hits zero.
- * Note: we pass the address of a pointer and set it to NULL if we delete it.
+ * Note: we pass the address of a pointer.
  */
 void
-_mesa_dereference_renderbuffer(struct gl_renderbuffer **rb)
+_mesa_unreference_renderbuffer(struct gl_renderbuffer **rb)
 {
-   GLboolean deleteFlag = GL_FALSE;
+   assert(rb);
+   if (*rb) {
+      GLboolean deleteFlag = GL_FALSE;
 
-   _glthread_LOCK_MUTEX((*rb)->Mutex);
-   {
+      _glthread_LOCK_MUTEX((*rb)->Mutex);
       ASSERT((*rb)->RefCount > 0);
       (*rb)->RefCount--;
       deleteFlag = ((*rb)->RefCount == 0);
-   }
-   _glthread_UNLOCK_MUTEX((*rb)->Mutex);
+      _glthread_UNLOCK_MUTEX((*rb)->Mutex);
+
+      if (deleteFlag)
+         (*rb)->Delete(*rb);
 
-   if (deleteFlag) {
-      (*rb)->Delete(*rb);
       *rb = NULL;
    }
 }
index 74ca43c57abf769abbe08db140d3dc912e4f3deb..e1a0a5597927e612ecc2a9bf3fe8bd0e3ae9339d 100644 (file)
@@ -99,7 +99,7 @@ extern void
 _mesa_remove_renderbuffer(struct gl_framebuffer *fb, GLuint bufferName);
 
 extern void
-_mesa_dereference_renderbuffer(struct gl_renderbuffer **rb);
+_mesa_unreference_renderbuffer(struct gl_renderbuffer **rb);
 
 extern struct gl_renderbuffer *
 _mesa_new_depthstencil_renderbuffer(GLcontext *ctx, GLuint name);