1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_hash_table.h"
30 #include "util/u_memory.h"
31 #include "util/u_simple_list.h"
33 #include "tr_screen.h"
34 #include "tr_context.h"
35 #include "tr_texture.h"
38 struct pipe_resource
*
39 trace_resource_create(struct trace_screen
*tr_scr
,
40 struct pipe_resource
*texture
)
42 struct trace_resource
*tr_tex
;
47 assert(texture
->screen
== tr_scr
->screen
);
49 tr_tex
= CALLOC_STRUCT(trace_resource
);
53 memcpy(&tr_tex
->base
, texture
, sizeof(struct pipe_resource
));
55 pipe_reference_init(&tr_tex
->base
.reference
, 1);
56 tr_tex
->base
.screen
= &tr_scr
->base
;
57 tr_tex
->resource
= texture
;
59 trace_screen_add_to_list(tr_scr
, textures
, tr_tex
);
64 pipe_resource_reference(&texture
, NULL
);
70 trace_resource_destroy(struct trace_screen
*tr_scr
,
71 struct trace_resource
*tr_tex
)
73 trace_screen_remove_from_list(tr_scr
, textures
, tr_tex
);
75 pipe_resource_reference(&tr_tex
->resource
, NULL
);
81 trace_surface_create(struct trace_resource
*tr_tex
,
82 struct pipe_surface
*surface
)
84 struct trace_screen
*tr_scr
= trace_screen(tr_tex
->base
.screen
);
85 struct trace_surface
*tr_surf
;
90 assert(surface
->texture
== tr_tex
->resource
);
92 tr_surf
= CALLOC_STRUCT(trace_surface
);
96 memcpy(&tr_surf
->base
, surface
, sizeof(struct pipe_surface
));
98 pipe_reference_init(&tr_surf
->base
.reference
, 1);
99 tr_surf
->base
.texture
= NULL
;
100 pipe_resource_reference(&tr_surf
->base
.texture
, &tr_tex
->base
);
101 tr_surf
->surface
= surface
;
103 trace_screen_add_to_list(tr_scr
, surfaces
, tr_surf
);
105 return &tr_surf
->base
;
108 pipe_surface_reference(&surface
, NULL
);
114 trace_surface_destroy(struct trace_surface
*tr_surf
)
116 struct trace_screen
*tr_scr
= trace_screen(tr_surf
->base
.texture
->screen
);
118 trace_screen_remove_from_list(tr_scr
, surfaces
, tr_surf
);
120 pipe_resource_reference(&tr_surf
->base
.texture
, NULL
);
121 pipe_surface_reference(&tr_surf
->surface
, NULL
);
126 struct pipe_transfer
*
127 trace_transfer_create(struct trace_context
*tr_ctx
,
128 struct trace_resource
*tr_tex
,
129 struct pipe_transfer
*transfer
)
131 struct trace_screen
*tr_scr
= trace_screen(tr_tex
->base
.screen
);
132 struct trace_transfer
*tr_trans
;
137 assert(transfer
->resource
== tr_tex
->resource
);
139 tr_trans
= CALLOC_STRUCT(trace_transfer
);
143 memcpy(&tr_trans
->base
, transfer
, sizeof(struct pipe_transfer
));
145 tr_trans
->base
.resource
= NULL
;
146 tr_trans
->transfer
= transfer
;
148 pipe_resource_reference(&tr_trans
->base
.resource
, &tr_tex
->base
);
149 assert(tr_trans
->base
.resource
== &tr_tex
->base
);
151 trace_screen_add_to_list(tr_scr
, transfers
, tr_trans
);
153 return &tr_trans
->base
;
156 tr_ctx
->pipe
->transfer_destroy(tr_ctx
->pipe
, transfer
);
162 trace_transfer_destroy(struct trace_context
*tr_context
,
163 struct trace_transfer
*tr_trans
)
165 struct trace_screen
*tr_scr
= trace_screen(tr_context
->base
.screen
);
166 struct pipe_context
*context
= tr_context
->pipe
;
167 struct pipe_transfer
*transfer
= tr_trans
->transfer
;
169 trace_screen_remove_from_list(tr_scr
, transfers
, tr_trans
);
171 pipe_resource_reference(&tr_trans
->base
.resource
, NULL
);
172 context
->transfer_destroy(context
, transfer
);