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