1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
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 VMWARE 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_res
;
47 assert(texture
->screen
== tr_scr
->screen
);
49 tr_res
= CALLOC_STRUCT(trace_resource
);
53 memcpy(&tr_res
->base
, texture
, sizeof(struct pipe_resource
));
55 pipe_reference_init(&tr_res
->base
.reference
, 1);
56 tr_res
->base
.screen
= &tr_scr
->base
;
57 tr_res
->resource
= texture
;
62 pipe_resource_reference(&texture
, NULL
);
68 trace_resource_destroy(struct trace_screen
*tr_scr
,
69 struct trace_resource
*tr_res
)
71 pipe_resource_reference(&tr_res
->resource
, NULL
);
77 trace_surf_create(struct trace_context
*tr_ctx
,
78 struct trace_resource
*tr_res
,
79 struct pipe_surface
*surface
)
81 struct trace_surface
*tr_surf
;
86 assert(surface
->texture
== tr_res
->resource
);
88 tr_surf
= CALLOC_STRUCT(trace_surface
);
92 memcpy(&tr_surf
->base
, surface
, sizeof(struct pipe_surface
));
93 tr_surf
->base
.context
= &tr_ctx
->base
;
95 pipe_reference_init(&tr_surf
->base
.reference
, 1);
96 tr_surf
->base
.texture
= NULL
;
97 pipe_resource_reference(&tr_surf
->base
.texture
, &tr_res
->base
);
98 tr_surf
->surface
= surface
;
100 return &tr_surf
->base
;
103 pipe_surface_reference(&surface
, NULL
);
109 trace_surf_destroy(struct trace_surface
*tr_surf
)
111 trace_context_check(tr_surf
->base
.context
);
112 pipe_resource_reference(&tr_surf
->base
.texture
, NULL
);
113 pipe_surface_reference(&tr_surf
->surface
, NULL
);
118 struct pipe_transfer
*
119 trace_transfer_create(struct trace_context
*tr_ctx
,
120 struct trace_resource
*tr_res
,
121 struct pipe_transfer
*transfer
)
123 struct trace_transfer
*tr_trans
;
128 assert(transfer
->resource
== tr_res
->resource
);
130 tr_trans
= CALLOC_STRUCT(trace_transfer
);
134 memcpy(&tr_trans
->base
, transfer
, sizeof(struct pipe_transfer
));
136 tr_trans
->base
.resource
= NULL
;
137 tr_trans
->transfer
= transfer
;
139 pipe_resource_reference(&tr_trans
->base
.resource
, &tr_res
->base
);
140 assert(tr_trans
->base
.resource
== &tr_res
->base
);
142 return &tr_trans
->base
;
145 tr_ctx
->pipe
->transfer_unmap(tr_ctx
->pipe
, transfer
);
151 trace_transfer_destroy(struct trace_context
*tr_context
,
152 struct trace_transfer
*tr_trans
)
154 pipe_resource_reference(&tr_trans
->base
.resource
, NULL
);