1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
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"
32
33 #include "tr_screen.h"
34 #include "tr_context.h"
35 #include "tr_texture.h"
36
37
38 struct pipe_resource *
trace_resource_create(struct trace_screen * tr_scr,struct pipe_resource * texture)39 trace_resource_create(struct trace_screen *tr_scr,
40 struct pipe_resource *texture)
41 {
42 struct trace_resource *tr_res;
43
44 if(!texture)
45 goto error;
46
47 assert(texture->screen == tr_scr->screen);
48
49 tr_res = CALLOC_STRUCT(trace_resource);
50 if(!tr_res)
51 goto error;
52
53 memcpy(&tr_res->base, texture, sizeof(struct pipe_resource));
54
55 pipe_reference_init(&tr_res->base.reference, 1);
56 tr_res->base.screen = &tr_scr->base;
57 tr_res->resource = texture;
58
59 return &tr_res->base;
60
61 error:
62 pipe_resource_reference(&texture, NULL);
63 return NULL;
64 }
65
66
67 void
trace_resource_destroy(struct trace_screen * tr_scr,struct trace_resource * tr_res)68 trace_resource_destroy(struct trace_screen *tr_scr,
69 struct trace_resource *tr_res)
70 {
71 pipe_resource_reference(&tr_res->resource, NULL);
72 FREE(tr_res);
73 }
74
75
76 struct pipe_surface *
trace_surf_create(struct trace_resource * tr_res,struct pipe_surface * surface)77 trace_surf_create(struct trace_resource *tr_res,
78 struct pipe_surface *surface)
79 {
80 struct trace_surface *tr_surf;
81
82 if(!surface)
83 goto error;
84
85 assert(surface->texture == tr_res->resource);
86
87 tr_surf = CALLOC_STRUCT(trace_surface);
88 if(!tr_surf)
89 goto error;
90
91 memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
92
93 pipe_reference_init(&tr_surf->base.reference, 1);
94 tr_surf->base.texture = NULL;
95 pipe_resource_reference(&tr_surf->base.texture, &tr_res->base);
96 tr_surf->surface = surface;
97
98 return &tr_surf->base;
99
100 error:
101 pipe_surface_reference(&surface, NULL);
102 return NULL;
103 }
104
105
106 void
trace_surf_destroy(struct trace_surface * tr_surf)107 trace_surf_destroy(struct trace_surface *tr_surf)
108 {
109 pipe_resource_reference(&tr_surf->base.texture, NULL);
110 pipe_surface_reference(&tr_surf->surface, NULL);
111 FREE(tr_surf);
112 }
113
114
115 struct pipe_transfer *
trace_transfer_create(struct trace_context * tr_ctx,struct trace_resource * tr_res,struct pipe_transfer * transfer)116 trace_transfer_create(struct trace_context *tr_ctx,
117 struct trace_resource *tr_res,
118 struct pipe_transfer *transfer)
119 {
120 struct trace_transfer *tr_trans;
121
122 if(!transfer)
123 goto error;
124
125 assert(transfer->resource == tr_res->resource);
126
127 tr_trans = CALLOC_STRUCT(trace_transfer);
128 if(!tr_trans)
129 goto error;
130
131 memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer));
132
133 tr_trans->base.resource = NULL;
134 tr_trans->transfer = transfer;
135
136 pipe_resource_reference(&tr_trans->base.resource, &tr_res->base);
137 assert(tr_trans->base.resource == &tr_res->base);
138
139 return &tr_trans->base;
140
141 error:
142 tr_ctx->pipe->transfer_destroy(tr_ctx->pipe, transfer);
143 return NULL;
144 }
145
146
147 void
trace_transfer_destroy(struct trace_context * tr_context,struct trace_transfer * tr_trans)148 trace_transfer_destroy(struct trace_context *tr_context,
149 struct trace_transfer *tr_trans)
150 {
151 struct pipe_context *context = tr_context->pipe;
152 struct pipe_transfer *transfer = tr_trans->transfer;
153
154 pipe_resource_reference(&tr_trans->base.resource, NULL);
155 context->transfer_destroy(context, transfer);
156 FREE(tr_trans);
157 }
158
159