r300g: release referenced objects in destroy_context
authorMarek Olšák <maraeo@gmail.com>
Sat, 26 Jun 2010 23:07:34 +0000 (01:07 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 27 Jun 2010 13:13:13 +0000 (15:13 +0200)
src/gallium/drivers/r300/r300_context.c

index b14db16f7cdcd59fd4b5aec22ca52b82d7a5f76d..c3c4c7491a3d6b23725f7887fd68967886a1c2f9 100644 (file)
 
 #include <inttypes.h>
 
-static void r300_destroy_context(struct pipe_context* context)
+static void r300_release_referenced_objects(struct r300_context *r300)
 {
-    struct r300_context* r300 = r300_context(context);
+    struct pipe_framebuffer_state *fb =
+            (struct pipe_framebuffer_state*)r300->fb_state.state;
+    struct r300_textures_state *textures =
+            (struct r300_textures_state*)r300->textures_state.state;
     struct r300_query *query, *temp;
-    struct r300_atom *atom;
+    unsigned i;
+
+    /* Framebuffer state. */
+    for (i = 0; i < fb->nr_cbufs; i++) {
+        pipe_surface_reference(&fb->cbufs[i], NULL);
+    }
+    pipe_surface_reference(&fb->zsbuf, NULL);
+
+    /* Textures. */
+    for (i = 0; i < textures->sampler_view_count; i++)
+        pipe_sampler_view_reference(
+                (struct pipe_sampler_view**)&textures->sampler_views[i], NULL);
 
+    /* The special dummy texture for texkill. */
     if (r300->texkill_sampler) {
         pipe_sampler_view_reference(
                 (struct pipe_sampler_view**)&r300->texkill_sampler,
                 NULL);
     }
 
+    /* The SWTCL VBO. */
+    pipe_resource_reference(&r300->vbo, NULL);
+
+    /* Vertex buffers. */
+    for (i = 0; i < r300->vertex_buffer_count; i++) {
+        pipe_resource_reference(&r300->vertex_buffer[i].buffer, NULL);
+    }
+
+    /* If there are any queries pending or not destroyed, remove them now. */
+    foreach_s(query, temp, &r300->query_list) {
+        remove_from_list(query);
+        FREE(query);
+    }
+}
+
+static void r300_destroy_context(struct pipe_context* context)
+{
+    struct r300_context* r300 = r300_context(context);
+    struct r300_atom *atom;
+
     util_blitter_destroy(r300->blitter);
     draw_destroy(r300->draw);
 
@@ -61,17 +96,13 @@ static void r300_destroy_context(struct pipe_context* context)
         }
     }
 
-    /* If there are any queries pending or not destroyed, remove them now. */
-    foreach_s(query, temp, &r300->query_list) {
-        remove_from_list(query);
-        FREE(query);
-    }
-
     u_upload_destroy(r300->upload_vb);
     u_upload_destroy(r300->upload_ib);
 
     translate_cache_destroy(r300->tran.translate_cache);
 
+    r300_release_referenced_objects(r300);
+
     FREE(r300->aa_state.state);
     FREE(r300->blend_color_state.state);
     FREE(r300->clip_state.state);