[Mesa-dev] [PATCH V2 1/9] mesa: create _mesa_attach_renderbuffer_without_ref() helper

Timothy Arceri tarceri at itsqueeze.com
Sat Apr 8 02:43:21 UTC 2017


This will be used to take ownership of freashly created renderbuffers,
avoiding the need to call the reference function which requires
locking.

V2: dereference any existing fb attachments and actually attach the
    new rb.
---
 src/mesa/main/renderbuffer.c | 23 +++++++++++++++++++++--
 src/mesa/main/renderbuffer.h |  5 +++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 1d24e9c..125463c 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -101,24 +101,28 @@ void
 {
    mtx_destroy(&rb->Mutex);
    free(rb->Label);
    free(rb);
 }
 
 
 /**
  * Attach a renderbuffer to a framebuffer.
  * \param bufferName  one of the BUFFER_x tokens
+ *
+ * This function avoids adding a reference and is therefore intended to be
+ * used with a freashly created renderbuffer.
  */
 void
-_mesa_add_renderbuffer(struct gl_framebuffer *fb,
-                       gl_buffer_index bufferName, struct gl_renderbuffer *rb)
+_mesa_add_renderbuffer_without_ref(struct gl_framebuffer *fb,
+                                   gl_buffer_index bufferName,
+                                   struct gl_renderbuffer *rb)
 {
    assert(fb);
    assert(rb);
    assert(bufferName < BUFFER_COUNT);
 
    /* There should be no previous renderbuffer on this attachment point,
     * with the exception of depth/stencil since the same renderbuffer may
     * be used for both.
     */
    assert(bufferName == BUFFER_DEPTH ||
@@ -128,20 +132,35 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb,
    /* winsys vs. user-created buffer cross check */
    if (_mesa_is_user_fbo(fb)) {
       assert(rb->Name);
    }
    else {
       assert(!rb->Name);
    }
 
    fb->Attachment[bufferName].Type = GL_RENDERBUFFER_EXT;
    fb->Attachment[bufferName].Complete = GL_TRUE;
+
+   _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer,
+                                NULL);
+   fb->Attachment[bufferName].Renderbuffer = rb;
+}
+
+/**
+ * Attach a renderbuffer to a framebuffer.
+ * \param bufferName  one of the BUFFER_x tokens
+ */
+void
+_mesa_add_renderbuffer(struct gl_framebuffer *fb,
+                       gl_buffer_index bufferName, struct gl_renderbuffer *rb)
+{
+   _mesa_add_renderbuffer_without_ref(fb, bufferName, rb);
    _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer, rb);
 }
 
 
 /**
  * Remove the named renderbuffer from the given framebuffer.
  * \param bufferName  one of the BUFFER_x tokens
  */
 void
 _mesa_remove_renderbuffer(struct gl_framebuffer *fb,
diff --git a/src/mesa/main/renderbuffer.h b/src/mesa/main/renderbuffer.h
index aa83120..a6f1439 100644
--- a/src/mesa/main/renderbuffer.h
+++ b/src/mesa/main/renderbuffer.h
@@ -40,20 +40,25 @@ struct gl_renderbuffer;
 extern void
 _mesa_init_renderbuffer(struct gl_renderbuffer *rb, GLuint name);
 
 extern struct gl_renderbuffer *
 _mesa_new_renderbuffer(struct gl_context *ctx, GLuint name);
 
 extern void
 _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb);
 
 extern void
+_mesa_add_renderbuffer_without_ref(struct gl_framebuffer *fb,
+                                   gl_buffer_index bufferName,
+                                   struct gl_renderbuffer *rb);
+
+extern void
 _mesa_add_renderbuffer(struct gl_framebuffer *fb,
                        gl_buffer_index bufferName, struct gl_renderbuffer *rb);
 
 extern void
 _mesa_remove_renderbuffer(struct gl_framebuffer *fb,
                           gl_buffer_index bufferName);
 
 extern void
 _mesa_reference_renderbuffer_(struct gl_renderbuffer **ptr,
                               struct gl_renderbuffer *rb);
-- 
2.9.3



More information about the mesa-dev mailing list