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_hash_table.h"
29 #include "util/u_memory.h"
30 #include "util/u_simple_list.h"
32 #include "tr_screen.h"
33 #include "tr_texture.h"
37 trace_texture_create(struct trace_screen
*tr_scr
,
38 struct pipe_texture
*texture
)
40 struct trace_texture
*tr_tex
;
45 assert(texture
->screen
== tr_scr
->screen
);
47 tr_tex
= CALLOC_STRUCT(trace_texture
);
51 memcpy(&tr_tex
->base
, texture
, sizeof(struct pipe_texture
));
53 pipe_reference_init(&tr_tex
->base
.reference
, 1);
54 tr_tex
->base
.screen
= &tr_scr
->base
;
55 tr_tex
->texture
= texture
;
57 trace_screen_add_to_list(tr_scr
, textures
, tr_tex
);
62 pipe_texture_reference(&texture
, NULL
);
68 trace_texture_destroy(struct trace_texture
*tr_tex
)
70 struct trace_screen
*tr_scr
= trace_screen(tr_tex
->base
.screen
);
72 trace_screen_remove_from_list(tr_scr
, textures
, tr_tex
);
74 pipe_texture_reference(&tr_tex
->texture
, NULL
);
80 trace_surface_create(struct trace_texture
*tr_tex
,
81 struct pipe_surface
*surface
)
83 struct trace_screen
*tr_scr
= trace_screen(tr_tex
->base
.screen
);
84 struct trace_surface
*tr_surf
;
89 assert(surface
->texture
== tr_tex
->texture
);
91 tr_surf
= CALLOC_STRUCT(trace_surface
);
95 memcpy(&tr_surf
->base
, surface
, sizeof(struct pipe_surface
));
97 pipe_reference_init(&tr_surf
->base
.reference
, 1);
98 tr_surf
->base
.texture
= NULL
;
99 pipe_texture_reference(&tr_surf
->base
.texture
, &tr_tex
->base
);
100 tr_surf
->surface
= surface
;
102 trace_screen_add_to_list(tr_scr
, surfaces
, tr_surf
);
104 return &tr_surf
->base
;
107 pipe_surface_reference(&surface
, NULL
);
113 trace_surface_destroy(struct trace_surface
*tr_surf
)
115 struct trace_screen
*tr_scr
= trace_screen(tr_surf
->base
.texture
->screen
);
117 trace_screen_remove_from_list(tr_scr
, surfaces
, tr_surf
);
119 pipe_texture_reference(&tr_surf
->base
.texture
, NULL
);
120 pipe_surface_reference(&tr_surf
->surface
, NULL
);
125 struct pipe_transfer
*
126 trace_transfer_create(struct trace_texture
*tr_tex
,
127 struct pipe_transfer
*transfer
)
129 struct trace_screen
*tr_scr
= trace_screen(tr_tex
->base
.screen
);
130 struct trace_transfer
*tr_trans
;
135 assert(transfer
->texture
== tr_tex
->texture
);
137 tr_trans
= CALLOC_STRUCT(trace_transfer
);
141 memcpy(&tr_trans
->base
, transfer
, sizeof(struct pipe_transfer
));
143 tr_trans
->base
.texture
= NULL
;
144 pipe_texture_reference(&tr_trans
->base
.texture
, &tr_tex
->base
);
145 tr_trans
->transfer
= transfer
;
146 assert(tr_trans
->base
.texture
== &tr_tex
->base
);
148 trace_screen_add_to_list(tr_scr
, transfers
, tr_trans
);
150 return &tr_trans
->base
;
153 transfer
->texture
->screen
->tex_transfer_destroy(transfer
);
159 trace_transfer_destroy(struct trace_transfer
*tr_trans
)
161 struct trace_screen
*tr_scr
= trace_screen(tr_trans
->base
.texture
->screen
);
162 struct pipe_screen
*screen
= tr_trans
->transfer
->texture
->screen
;
164 trace_screen_remove_from_list(tr_scr
, transfers
, tr_trans
);
166 pipe_texture_reference(&tr_trans
->base
.texture
, NULL
);
167 screen
->tex_transfer_destroy(tr_trans
->transfer
);