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

Timothy Arceri tarceri at itsqueeze.com
Sat Apr 8 01:04:32 UTC 2017


This will be used to take ownership of freashly created renderbuffers,
avoiding the need to call the reference function which requires
locking.
---
 src/mesa/main/renderbuffer.c | 19 +++++++++++++++++--
 src/mesa/main/renderbuffer.h |  5 +++++
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/renderbuffer.c b/src/mesa/main/renderbuffer.c
index 1d24e9c..6fcff35 100644
--- a/src/mesa/main/renderbuffer.c
+++ b/src/mesa/main/renderbuffer.c
@@ -101,24 +101,28 @@ void
 _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    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_attach_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,31 @@ _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;
+}
+
+/**
+ * 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