trace: Keep screen objects on lists
authorJakob Bornecrantz <jakob@vmware.com>
Fri, 17 Apr 2009 13:55:51 +0000 (15:55 +0200)
committerJakob Bornecrantz <jakob@vmware.com>
Fri, 17 Apr 2009 14:03:01 +0000 (16:03 +0200)
src/gallium/drivers/trace/tr_buffer.c
src/gallium/drivers/trace/tr_buffer.h
src/gallium/drivers/trace/tr_context.c
src/gallium/drivers/trace/tr_context.h
src/gallium/drivers/trace/tr_screen.c
src/gallium/drivers/trace/tr_screen.h
src/gallium/drivers/trace/tr_texture.c
src/gallium/drivers/trace/tr_texture.h

index 3cdb107dc6b14f33782ca490fbd6f37e0799a5b5..4f0eff6a5a4c37b7bebe5eae7c77d6f59d1b7c69 100644 (file)
 
 
 #include "util/u_memory.h"
+#include "util/u_simple_list.h"
 
 #include "tr_buffer.h"
 
-
 struct pipe_buffer *
 trace_buffer_create(struct trace_screen *tr_scr,
                     struct pipe_buffer *buffer)
@@ -52,6 +52,8 @@ trace_buffer_create(struct trace_screen *tr_scr,
    tr_buf->base.screen = &tr_scr->base;
    tr_buf->buffer = buffer;
 
+   trace_screen_add_to_list(tr_scr, buffers, tr_buf);
+
    return &tr_buf->base;
 
 error:
@@ -66,6 +68,8 @@ trace_buffer_destroy(struct trace_screen *tr_scr,
 {
    struct trace_buffer *tr_buf = trace_buffer(buffer);
 
+   trace_screen_remove_from_list(tr_scr, buffers, tr_buf);
+
    pipe_buffer_reference(&tr_buf->buffer, NULL);
    FREE(tr_buf);
 }
index bb8a3b2c3aa44ef85c79b42ded9180a93b7925cd..1a2d0b9aeae972d3c15f55d20689ce029e9f23ec 100644 (file)
@@ -41,6 +41,8 @@ struct trace_buffer
 
    struct pipe_buffer *buffer;
 
+   struct tr_list list;
+
    void *map;
    boolean range_flushed;
 };
index 696b6a4f59b7d7cc9c543782d317fbe4c9305f6c..38646f8aad3b12b87ea3fc529052c78d3e349a25 100644 (file)
@@ -26,6 +26,8 @@
  **************************************************************************/
 
 #include "util/u_memory.h"
+#include "util/u_simple_list.h"
+
 #include "pipe/p_screen.h"
 
 #include "tr_dump.h"
@@ -1014,16 +1016,17 @@ trace_context_flush(struct pipe_context *_pipe,
 static INLINE void
 trace_context_destroy(struct pipe_context *_pipe)
 {
+   struct trace_screen *tr_scr = trace_screen(_pipe->screen);
    struct trace_context *tr_ctx = trace_context(_pipe);
    struct pipe_context *pipe = tr_ctx->pipe;
 
    trace_dump_call_begin("pipe_context", "destroy");
-
    trace_dump_arg(ptr, pipe);
+   trace_dump_call_end();
 
-   pipe->destroy(pipe);
+   trace_screen_remove_from_list(tr_scr, contexts, tr_ctx);
 
-   trace_dump_call_end();
+   pipe->destroy(pipe);
 
    FREE(tr_ctx);
 }
@@ -1150,6 +1153,8 @@ trace_context_create(struct pipe_screen *_screen,
    trace_dump_ret(ptr, pipe);
    trace_dump_call_end();
 
+   trace_screen_add_to_list(tr_scr, contexts, tr_ctx);
+
    return &tr_ctx->base;
 
 error1:
index d02b22a069b0831d7f98240a0051720fc590fecf..2512a0a2328221f0eb61ef93f4255da859984a2f 100644 (file)
@@ -44,6 +44,8 @@ struct trace_context
    struct pipe_context base;
 
    struct pipe_context *pipe;
+
+   struct tr_list list;
 };
 
 
index 3e676f01559acaa98584417b84a28657d064f562..7205dfd1d99df2504760608ff4e6955a4b4340b3 100644 (file)
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 #include "util/u_memory.h"
+#include "util/u_simple_list.h"
 
 #include "tr_buffer.h"
 #include "tr_dump.h"
@@ -855,6 +856,12 @@ trace_screen_create(struct pipe_screen *screen)
 #else
    winsys = screen->winsys;
 #endif
+   pipe_mutex_init(tr_scr->list_mutex);
+   make_empty_list(&tr_scr->buffers);
+   make_empty_list(&tr_scr->contexts);
+   make_empty_list(&tr_scr->textures);
+   make_empty_list(&tr_scr->surfaces);
+   make_empty_list(&tr_scr->transfers);
 
    tr_scr->base.winsys = winsys;
    tr_scr->base.destroy = trace_screen_destroy;
index 8c65516b509731829b30445d981235321ca3cd08..59f254166d4dcb317903161c15302041e4e4fe77 100644 (file)
@@ -30,6 +30,7 @@
 
 
 #include "pipe/p_screen.h"
+#include "pipe/p_thread.h"
 
 
 #ifdef __cplusplus
@@ -37,6 +38,11 @@ extern "C" {
 #endif
 
 
+struct tr_list {
+   struct tr_list *next;
+   struct tr_list *prev;
+};
+
 /**
  * It often happens that new data is written directly to the user buffers
  * without mapping/unmapping. This flag marks user buffers, so that their
@@ -50,6 +56,18 @@ struct trace_screen
    struct pipe_screen base;
 
    struct pipe_screen *screen;
+
+   pipe_mutex list_mutex;
+   int num_buffers;
+   int num_contexts;
+   int num_textures;
+   int num_surfaces;
+   int num_transfers;
+   struct tr_list buffers;
+   struct tr_list contexts;
+   struct tr_list textures;
+   struct tr_list surfaces;
+   struct tr_list transfers;
 };
 
 
@@ -65,6 +83,21 @@ void
 trace_screen_user_buffer_update(struct pipe_screen *screen,
                                 struct pipe_buffer *buffer);
 
+#define trace_screen_add_to_list(tr_scr, name, obj) \
+   do {                                             \
+      pipe_mutex_lock(tr_scr->list_mutex);          \
+      insert_at_head(&tr_scr->name, &obj->list);    \
+      tr_scr->num_##name++;                         \
+      pipe_mutex_unlock(tr_scr->list_mutex);        \
+   } while (0)
+
+#define trace_screen_remove_from_list(tr_scr, name, obj) \
+   do {                                                  \
+      pipe_mutex_lock(tr_scr->list_mutex);               \
+      remove_from_list(&obj->list);                      \
+      tr_scr->num_##name--;                              \
+      pipe_mutex_unlock(tr_scr->list_mutex);             \
+   } while (0)
 
 #ifdef __cplusplus
 }
index f4e433792b1bdfa7e7e3b0f61597e5baff90270b..1f25fe38d4cc097dcb2acc226b7fca3d4a68737e 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "util/u_hash_table.h"
 #include "util/u_memory.h"
+#include "util/u_simple_list.h"
 
 #include "tr_screen.h"
 #include "tr_texture.h"
@@ -53,6 +54,8 @@ trace_texture_create(struct trace_screen *tr_scr,
    tr_tex->base.screen = &tr_scr->base;
    tr_tex->texture = texture;
 
+   trace_screen_add_to_list(tr_scr, textures, tr_tex);
+
    return &tr_tex->base;
 
 error:
@@ -64,6 +67,10 @@ error:
 void
 trace_texture_destroy(struct trace_texture *tr_tex)
 {
+   struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
+
+   trace_screen_remove_from_list(tr_scr, textures, tr_tex);
+
    pipe_texture_reference(&tr_tex->texture, NULL);
    FREE(tr_tex);
 }
@@ -73,6 +80,7 @@ struct pipe_surface *
 trace_surface_create(struct trace_texture *tr_tex,
                      struct pipe_surface *surface)
 {
+   struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
    struct trace_surface *tr_surf;
 
    if(!surface)
@@ -91,6 +99,8 @@ trace_surface_create(struct trace_texture *tr_tex,
    pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
    tr_surf->surface = surface;
 
+   trace_screen_add_to_list(tr_scr, surfaces, tr_surf);
+
    return &tr_surf->base;
 
 error:
@@ -102,6 +112,10 @@ error:
 void
 trace_surface_destroy(struct trace_surface *tr_surf)
 {
+   struct trace_screen *tr_scr = trace_screen(tr_surf->base.texture->screen);
+
+   trace_screen_remove_from_list(tr_scr, surfaces, tr_surf);
+
    pipe_texture_reference(&tr_surf->base.texture, NULL);
    pipe_surface_reference(&tr_surf->surface, NULL);
    FREE(tr_surf);
@@ -112,6 +126,7 @@ struct pipe_transfer *
 trace_transfer_create(struct trace_texture *tr_tex,
                      struct pipe_transfer *transfer)
 {
+   struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
    struct trace_transfer *tr_trans;
 
    if(!transfer)
@@ -130,6 +145,8 @@ trace_transfer_create(struct trace_texture *tr_tex,
    tr_trans->transfer = transfer;
    assert(tr_trans->base.texture == &tr_tex->base);
 
+   trace_screen_add_to_list(tr_scr, transfers, tr_trans);
+
    return &tr_trans->base;
 
 error:
@@ -141,7 +158,11 @@ error:
 void
 trace_transfer_destroy(struct trace_transfer *tr_trans)
 {
+   struct trace_screen *tr_scr = trace_screen(tr_trans->base.texture->screen);
    struct pipe_screen *screen = tr_trans->transfer->texture->screen;
+
+   trace_screen_remove_from_list(tr_scr, transfers, tr_trans);
+
    pipe_texture_reference(&tr_trans->base.texture, NULL);
    screen->tex_transfer_destroy(tr_trans->transfer);
    FREE(tr_trans);
index 14dafd8b2c3e6e1b03e69c27423873dd29a5a476..395e523e73a141e5cd0615a5a3535ae3c23620d7 100644 (file)
@@ -40,6 +40,8 @@ struct trace_texture
    struct pipe_texture base;
 
    struct pipe_texture *texture;
+
+   struct tr_list list;
 };
 
 
@@ -48,6 +50,8 @@ struct trace_surface
    struct pipe_surface base;
 
    struct pipe_surface *surface;
+
+   struct tr_list list;
 };
 
 
@@ -57,6 +61,8 @@ struct trace_transfer
 
    struct pipe_transfer *transfer;
 
+   struct tr_list list;
+
    void *map;
 };