trace: Keep screen objects on lists
[mesa.git] / src / gallium / drivers / trace / tr_context.c
index c8949729047840a7144f34167c45dee05131fab5..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"
@@ -46,7 +48,7 @@ trace_buffer_unwrap(struct trace_context *tr_ctx,
    if(!buffer)
       return NULL;
 
-   tr_buf = trace_buffer(tr_scr, buffer);
+   tr_buf = trace_buffer(buffer);
 
    assert(tr_buf->buffer);
    assert(tr_buf->buffer->screen == tr_scr->screen);
@@ -58,16 +60,14 @@ static INLINE struct pipe_texture *
 trace_texture_unwrap(struct trace_context *tr_ctx,
                      struct pipe_texture *texture)
 {
-   struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
    struct trace_texture *tr_tex;
 
    if(!texture)
       return NULL;
 
-   tr_tex = trace_texture(tr_scr, texture);
+   tr_tex = trace_texture(texture);
 
    assert(tr_tex->texture);
-   assert(tr_tex->texture->screen == tr_scr->screen);
    return tr_tex->texture;
 }
 
@@ -77,7 +77,6 @@ trace_surface_unwrap(struct trace_context *tr_ctx,
                      struct pipe_surface *surface)
 {
    struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
-   struct trace_texture *tr_tex;
    struct trace_surface *tr_surf;
 
    if(!surface)
@@ -87,8 +86,7 @@ trace_surface_unwrap(struct trace_context *tr_ctx,
    if(!surface->texture)
       return surface;
 
-   tr_tex = trace_texture(tr_scr, surface->texture);
-   tr_surf = trace_surface(tr_tex, surface);
+   tr_surf = trace_surface(surface);
 
    assert(tr_surf->surface);
    assert(tr_surf->surface->texture->screen == tr_scr->screen);
@@ -146,9 +144,8 @@ trace_context_draw_elements(struct pipe_context *_pipe,
                           unsigned indexSize,
                           unsigned mode, unsigned start, unsigned count)
 {
-   struct trace_screen *tr_scr = trace_screen(_pipe->screen);
    struct trace_context *tr_ctx = trace_context(_pipe);
-   struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer);
+   struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
    struct pipe_context *pipe = tr_ctx->pipe;
    struct pipe_buffer *indexBuffer = tr_buf->buffer;
    boolean result;
@@ -184,9 +181,8 @@ trace_context_draw_range_elements(struct pipe_context *_pipe,
                                   unsigned start,
                                   unsigned count)
 {
-   struct trace_screen *tr_scr = trace_screen(_pipe->screen);
    struct trace_context *tr_ctx = trace_context(_pipe);
-   struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer);
+   struct trace_buffer *tr_buf = trace_buffer(_indexBuffer);
    struct pipe_context *pipe = tr_ctx->pipe;
    struct pipe_buffer *indexBuffer = tr_buf->buffer;
    boolean result;
@@ -973,21 +969,23 @@ trace_context_surface_fill(struct pipe_context *_pipe,
 
 static INLINE void
 trace_context_clear(struct pipe_context *_pipe,
-                    struct pipe_surface *surface,
-                    unsigned clearValue)
+                    unsigned buffers,
+                    const float *rgba,
+                    double depth,
+                    unsigned stencil)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
    struct pipe_context *pipe = tr_ctx->pipe;
 
-   surface = trace_surface_unwrap(tr_ctx, surface);
-
    trace_dump_call_begin("pipe_context", "clear");
 
    trace_dump_arg(ptr, pipe);
-   trace_dump_arg(ptr, surface);
-   trace_dump_arg(uint, clearValue);
+   trace_dump_arg(uint, buffers);
+   trace_dump_arg_array(float, rgba, 4);
+   trace_dump_arg(float, depth);
+   trace_dump_arg(uint, stencil);
 
-   pipe->clear(pipe, surface, clearValue);;
+   pipe->clear(pipe, buffers, rgba, depth, stencil);
 
    trace_dump_call_end();
 }
@@ -1018,28 +1016,75 @@ 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();
+
+   trace_screen_remove_from_list(tr_scr, contexts, tr_ctx);
 
    pipe->destroy(pipe);
 
+   FREE(tr_ctx);
+}
+
+static unsigned int
+trace_is_texture_referenced( struct pipe_context *_pipe,
+                           struct pipe_texture *_texture,
+                           unsigned face, unsigned level)
+{
+   struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_texture *tr_tex = trace_texture(_texture);
+   struct pipe_context *pipe = tr_ctx->pipe;
+   struct pipe_texture *texture = tr_tex->texture;
+   unsigned int referenced;
+
+   trace_dump_call_begin("pipe_context", "is_texture_referenced");
+   trace_dump_arg(ptr, pipe);
+   trace_dump_arg(ptr, texture);
+   trace_dump_arg(uint, face);
+   trace_dump_arg(uint, level);
+
+   referenced = pipe->is_texture_referenced(pipe, texture, face, level);
+
+   trace_dump_ret(uint, referenced);
    trace_dump_call_end();
 
-   FREE(tr_ctx);
+   return referenced;
 }
 
+static unsigned int
+trace_is_buffer_referenced( struct pipe_context *_pipe,
+                           struct pipe_buffer *_buf)
+{
+   struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_buffer *tr_buf = trace_buffer(_buf);
+   struct pipe_context *pipe = tr_ctx->pipe;
+   struct pipe_buffer *buf = tr_buf->buffer;
+   unsigned int referenced;
+
+   trace_dump_call_begin("pipe_context", "is_buffer_referenced");
+   trace_dump_arg(ptr, pipe);
+   trace_dump_arg(ptr, buf);
+
+   referenced = pipe->is_buffer_referenced(pipe, buf);
+
+   trace_dump_ret(uint, referenced);
+   trace_dump_call_end();
+
+   return referenced;
+}
 
 struct pipe_context *
 trace_context_create(struct pipe_screen *_screen,
                      struct pipe_context *pipe)
 {
-   struct trace_screen *tr_scr = trace_screen(_screen);
+   struct trace_screen *tr_scr;
    struct trace_context *tr_ctx;
-   struct pipe_screen *screen = tr_scr->screen;
+   struct pipe_screen *screen;
 
    if(!pipe)
       goto error1;
@@ -1047,6 +1092,9 @@ trace_context_create(struct pipe_screen *_screen,
    if(!trace_dump_enabled())
       goto error1;
 
+   tr_scr = trace_screen(_screen);
+   screen = tr_scr->screen;
+
    tr_ctx = CALLOC_STRUCT(trace_context);
    if(!tr_ctx)
       goto error1;
@@ -1095,6 +1143,8 @@ trace_context_create(struct pipe_screen *_screen,
    tr_ctx->base.surface_fill = trace_context_surface_fill;
    tr_ctx->base.clear = trace_context_clear;
    tr_ctx->base.flush = trace_context_flush;
+   tr_ctx->base.is_texture_referenced = trace_is_texture_referenced;
+   tr_ctx->base.is_buffer_referenced = trace_is_buffer_referenced;
 
    tr_ctx->pipe = pipe;
 
@@ -1103,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: