st: do proper refcounting for framebuffer surfaces
authorBrian Paul <brianp@vmware.com>
Mon, 11 May 2009 22:09:39 +0000 (16:09 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 11 May 2009 22:09:39 +0000 (16:09 -0600)
src/mesa/state_tracker/st_atom_framebuffer.c
src/mesa/state_tracker/st_context.c

index df0f0931eab38f7a5ab264616927e648731df7e2..536293683e9c2e2d0ad3db83f02809dafb1e6c56 100644 (file)
@@ -98,8 +98,6 @@ update_framebuffer_state( struct st_context *st )
    struct st_renderbuffer *strb;
    GLuint i;
 
-   memset(framebuffer, 0, sizeof(*framebuffer));
-
    framebuffer->width = fb->Width;
    framebuffer->height = fb->Height;
 
@@ -120,12 +118,19 @@ update_framebuffer_state( struct st_context *st )
          }
 
          if (strb->surface) {
-            framebuffer->cbufs[framebuffer->nr_cbufs] = strb->surface;
+            pipe_surface_reference(&framebuffer->cbufs[framebuffer->nr_cbufs],
+                                   strb->surface);
             framebuffer->nr_cbufs++;
          }
       }
    }
+   for (i = framebuffer->nr_cbufs; i < PIPE_MAX_COLOR_BUFS; i++) {
+      pipe_surface_reference(&framebuffer->cbufs[i], NULL);
+   }
 
+   /*
+    * Depth/Stencil renderbuffer/surface.
+    */
    strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
    if (strb) {
       strb = st_renderbuffer(strb->Base.Wrapped);
@@ -133,15 +138,14 @@ update_framebuffer_state( struct st_context *st )
          /* rendering to a GL texture, may have to update surface */
          update_renderbuffer_surface(st, strb);
       }
-
-      framebuffer->zsbuf = strb->surface;
+      pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
    }
    else {
       strb = st_renderbuffer(fb->Attachment[BUFFER_STENCIL].Renderbuffer);
       if (strb) {
          strb = st_renderbuffer(strb->Base.Wrapped);
          assert(strb->surface);
-         framebuffer->zsbuf = strb->surface;
+         pipe_surface_reference(&framebuffer->zsbuf, strb->surface);
       }
    }
 
index 2a1f21c51cad7b46d6a27ddbf191a27ea3ce792b..e536029e86ea062b734c8467f595c58a45a656bd 100644 (file)
@@ -233,6 +233,7 @@ void st_destroy_context( struct st_context *st )
    struct pipe_context *pipe = st->pipe;
    struct cso_context *cso = st->cso_context;
    GLcontext *ctx = st->ctx;
+   GLuint i;
 
    /* need to unbind and destroy CSO objects before anything else */
    cso_release_all(st->cso_context);
@@ -240,6 +241,12 @@ void st_destroy_context( struct st_context *st )
    st_reference_fragprog(st, &st->fp, NULL);
    st_reference_vertprog(st, &st->vp, NULL);
 
+   /* release framebuffer surfaces */
+   for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
+      pipe_surface_reference(&st->state.framebuffer.cbufs[i], NULL);
+   }
+   pipe_surface_reference(&st->state.framebuffer.zsbuf, NULL);
+
    _mesa_delete_program_cache(st->ctx, st->pixel_xfer.cache);
 
    _vbo_DestroyContext(st->ctx);