mesa: create _mesa_attach_renderbuffer_without_ref() helper
authorTimothy Arceri <tarceri@itsqueeze.com>
Sat, 8 Apr 2017 00:03:20 +0000 (10:03 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Mon, 10 Apr 2017 00:55:34 +0000 (10:55 +1000)
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.

v3: split out validation and attachment type/complete setting into
    a shared static function.

Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Tested-by: Bartosz Tomczyk <bartosz.tomczyk86@gmail.com>
src/mesa/main/renderbuffer.c
src/mesa/main/renderbuffer.h

index 4375b5b882caa8ce6551485fd0fb692f55d3de82..627bdca66c5726df03ce006864dc10ca33b3c007 100644 (file)
@@ -106,14 +106,10 @@ _mesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
    free(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)
+static void
+validate_and_init_renderbuffer_attachment(struct gl_framebuffer *fb,
+                                          gl_buffer_index bufferName,
+                                          struct gl_renderbuffer *rb)
 {
    assert(fb);
    assert(rb);
@@ -137,6 +133,37 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb,
 
    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
+ *
+ * This function avoids adding a reference and is therefore intended to be
+ * used with a freashly created renderbuffer.
+ */
+void
+_mesa_add_renderbuffer_without_ref(struct gl_framebuffer *fb,
+                                   gl_buffer_index bufferName,
+                                   struct gl_renderbuffer *rb)
+{
+   validate_and_init_renderbuffer_attachment(fb, bufferName, rb);
+
+   _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)
+{
+   validate_and_init_renderbuffer_attachment(fb, bufferName, rb);
    _mesa_reference_renderbuffer(&fb->Attachment[bufferName].Renderbuffer, rb);
 }
 
index aa83120c1e444c0040e867d69a5382039584a47a..a6f14394982d01d5c61c39f5c05ca0bfa9568cef 100644 (file)
@@ -46,6 +46,11 @@ _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);