trace: Fix args to buffer write
[mesa.git] / src / gallium / drivers / trace / tr_texture.c
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_hash_table.h"
29 #include "util/u_memory.h"
30
31 #include "tr_screen.h"
32 #include "tr_texture.h"
33
34
35 struct pipe_texture *
36 trace_texture_create(struct trace_screen *tr_scr,
37 struct pipe_texture *texture)
38 {
39 struct trace_texture *tr_tex;
40
41 if(!texture)
42 goto error;
43
44 assert(texture->screen == tr_scr->screen);
45
46 tr_tex = CALLOC_STRUCT(trace_texture);
47 if(!tr_tex)
48 goto error;
49
50 memcpy(&tr_tex->base, texture, sizeof(struct pipe_texture));
51
52 pipe_reference_init(&tr_tex->base.reference, 1);
53 tr_tex->base.screen = &tr_scr->base;
54 tr_tex->texture = texture;
55
56 return &tr_tex->base;
57
58 error:
59 pipe_texture_reference(&texture, NULL);
60 return NULL;
61 }
62
63
64 void
65 trace_texture_destroy(struct trace_screen *tr_scr,
66 struct pipe_texture *texture)
67 {
68 struct trace_texture *tr_tex = trace_texture(tr_scr, texture);
69 pipe_texture_reference(&tr_tex->texture, NULL);
70 FREE(tr_tex);
71 }
72
73
74 struct pipe_surface *
75 trace_surface_create(struct trace_texture *tr_tex,
76 struct pipe_surface *surface)
77 {
78 struct trace_surface *tr_surf;
79
80 if(!surface)
81 goto error;
82
83 assert(surface->texture == tr_tex->texture);
84
85 tr_surf = CALLOC_STRUCT(trace_surface);
86 if(!tr_surf)
87 goto error;
88
89 memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
90
91 pipe_reference_init(&tr_surf->base.reference, 1);
92 tr_surf->base.texture = NULL;
93 pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
94 tr_surf->surface = surface;
95
96 return &tr_surf->base;
97
98 error:
99 pipe_surface_reference(&surface, NULL);
100 return NULL;
101 }
102
103
104 void
105 trace_surface_destroy(struct trace_texture *tr_tex,
106 struct pipe_surface *surface)
107 {
108 struct trace_surface *tr_surf = trace_surface(tr_tex, surface);
109 pipe_texture_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 *
116 trace_transfer_create(struct trace_texture *tr_tex,
117 struct pipe_transfer *transfer)
118 {
119 struct trace_transfer *tr_trans;
120
121 if(!transfer)
122 goto error;
123
124 assert(transfer->texture == tr_tex->texture);
125
126 tr_trans = CALLOC_STRUCT(trace_transfer);
127 if(!tr_trans)
128 goto error;
129
130 memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer));
131
132 tr_trans->base.texture = NULL;
133 pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base);
134 tr_trans->transfer = transfer;
135 assert(tr_trans->base.texture == &tr_tex->base);
136
137 return &tr_trans->base;
138
139 error:
140 transfer->texture->screen->tex_transfer_destroy(transfer);
141 return NULL;
142 }
143
144
145 void
146 trace_transfer_destroy(struct trace_texture *tr_tex,
147 struct pipe_transfer *transfer)
148 {
149 struct trace_transfer *tr_trans = trace_transfer(tr_tex, transfer);
150 struct pipe_screen *screen = tr_trans->transfer->texture->screen;
151 pipe_texture_reference(&tr_trans->base.texture, NULL);
152 screen->tex_transfer_destroy(tr_trans->transfer);
153 FREE(tr_trans);
154 }
155