swrast: take ownership rather than adding reference for new renderbuffers
authorTimothy Arceri <tarceri@itsqueeze.com>
Sat, 8 Apr 2017 00:35:57 +0000 (10:35 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 10 Apr 2017 00:55:34 +0000 (10:55 +1000)
This avoids locking in the reference calls and fixes a leak after the
RefCount initialisation was change from 0 to 1.

Fixes: 32141e53d1520 (mesa: tidy up renderbuffer RefCount initialisation)
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
src/mesa/drivers/dri/swrast/swrast.c
src/mesa/swrast/s_renderbuffer.c

index 0402232deb16994ce0d8c41f969278b3ecf1b486..f43ac608cf2fee4cb1204f817dad310ad6d9c2fd 100644 (file)
@@ -569,12 +569,14 @@ dri_create_buffer(__DRIscreen * sPriv,
 
     /* add front renderbuffer */
     frontrb = swrast_new_renderbuffer(visual, dPriv, GL_TRUE);
-    _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base.Base);
+    _mesa_add_renderbuffer_without_ref(fb, BUFFER_FRONT_LEFT,
+                                       &frontrb->Base.Base);
 
     /* add back renderbuffer */
     if (visual->doubleBufferMode) {
        backrb = swrast_new_renderbuffer(visual, dPriv, GL_FALSE);
-       _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base.Base);
+        _mesa_add_renderbuffer_without_ref(fb, BUFFER_BACK_LEFT,
+                                           &backrb->Base.Base);
     }
 
     /* add software renderbuffers */
index af09955484ec624f686f277d4f6c11f35891fa4e..940c7b710c8f43e039a180dbab06fdf7f54c3d78 100644 (file)
@@ -271,15 +271,10 @@ add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
          return GL_FALSE;
       }
 
-      /* Set refcount to 0 to avoid a leak since the _mesa_add_renderbuffer()
-       * call below will bump the initial refcount.
-       */
-      rb->RefCount = 0;
-
       rb->InternalFormat = GL_RGBA;
 
       rb->AllocStorage = soft_renderbuffer_storage;
-      _mesa_add_renderbuffer(fb, b, rb);
+      _mesa_add_renderbuffer_without_ref(fb, b, rb);
    }
 
    return GL_TRUE;
@@ -325,7 +320,7 @@ add_depth_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    }
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, rb);
 
    return GL_TRUE;
 }
@@ -363,7 +358,7 @@ add_stencil_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
    rb->InternalFormat = GL_STENCIL_INDEX8;
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_STENCIL, rb);
 
    return GL_TRUE;
 }
@@ -387,7 +382,7 @@ add_depth_stencil_renderbuffer(struct gl_context *ctx,
    rb->InternalFormat = GL_DEPTH_STENCIL;
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, rb);
    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
 
    return GL_TRUE;
@@ -425,7 +420,7 @@ add_accum_renderbuffer(struct gl_context *ctx, struct gl_framebuffer *fb,
 
    rb->InternalFormat = GL_RGBA16_SNORM;
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_ACCUM, rb);
 
    return GL_TRUE;
 }
@@ -470,7 +465,7 @@ add_aux_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
       rb->InternalFormat = GL_RGBA;
 
       rb->AllocStorage = soft_renderbuffer_storage;
-      _mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb);
+      _mesa_add_renderbuffer_without_ref(fb, BUFFER_AUX0 + i, rb);
    }
    return GL_TRUE;
 }