i915tex: Make sure renderbuffers don't get deleted when flipping them.
authorMichel Dänzer <michel@tungstengraphics.com>
Mon, 26 Mar 2007 15:38:58 +0000 (17:38 +0200)
committerMichel Dänzer <michel@tungstengraphics.com>
Mon, 26 Mar 2007 15:38:58 +0000 (17:38 +0200)
Since the recent renderbuffer refcounting fixes it's no longer sufficient to
just remove the old renderbuffer from the framebuffer and then add the new one
because the former may decrease the reference count to 0 and delete the old
renderbuffer.

src/mesa/drivers/dri/i915tex/intel_fbo.c
src/mesa/drivers/dri/i915tex/intel_screen.c

index 8d43055382209486edafcc9b884d305a549f3666..9b84faaeb7d4a7fa3a7c84c2a4df0f3f1eab1ef5 100644 (file)
@@ -80,21 +80,33 @@ intel_flip_renderbuffers(struct intel_framebuffer *intel_fb)
 {
    int current_page = intel_fb->pf_current_page;
    int next_page = (current_page + 1) % intel_fb->pf_num_pages;
+   struct gl_renderbuffer *tmp_rb;
 
+   /* Exchange renderbuffers if necessary but make sure their reference counts
+    * are preserved.
+    */
    if (intel_fb->color_rb[current_page] &&
        intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer !=
        &intel_fb->color_rb[current_page]->Base) {
-      _mesa_remove_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT);
-      _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_FRONT_LEFT,
-                            &intel_fb->color_rb[current_page]->Base);
+      tmp_rb = NULL;
+      _mesa_reference_renderbuffer(&tmp_rb,
+        intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
+      tmp_rb = &intel_fb->color_rb[current_page]->Base;
+      _mesa_reference_renderbuffer(
+        &intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer, tmp_rb);
+      _mesa_reference_renderbuffer(&tmp_rb, NULL);
    }
 
    if (intel_fb->color_rb[next_page] &&
        intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer !=
        &intel_fb->color_rb[next_page]->Base) {
-      _mesa_remove_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT);
-      _mesa_add_renderbuffer(&intel_fb->Base, BUFFER_BACK_LEFT,
-                            &intel_fb->color_rb[next_page]->Base);
+      tmp_rb = NULL;
+      _mesa_reference_renderbuffer(&tmp_rb,
+        intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer);
+      tmp_rb = &intel_fb->color_rb[next_page]->Base;
+      _mesa_reference_renderbuffer(
+        &intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer, tmp_rb);
+      _mesa_reference_renderbuffer(&tmp_rb, NULL);
    }
 }
 
index a6342046b5fd2cc5d8d6a5a5f91af60793acf045..9034ee1b22306c57b7d08a1e288caa9420df4a69 100644 (file)
@@ -613,6 +613,8 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
                                &intel_fb->color_rb[1]->Base);
 
         if (screen->third.handle) {
+           struct gl_renderbuffer *tmp_rb = NULL;
+
            intel_fb->color_rb[2]
               = intel_create_renderbuffer(rgbFormat,
                                           screen->width, screen->height,
@@ -621,6 +623,7 @@ intelCreateBuffer(__DRIscreenPrivate * driScrnPriv,
                                           screen->cpp,
                                           screen->third.map);
            intel_set_span_functions(&intel_fb->color_rb[2]->Base);
+           _mesa_reference_renderbuffer(&tmp_rb, &intel_fb->color_rb[2]->Base);
         }
       }