Merge commit 'origin/master' into gallium-map-range
[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 tr_tex->base.screen = &tr_scr->base;
52 tr_tex->texture = texture;
53
54 return &tr_tex->base;
55
56 error:
57 pipe_texture_reference(&texture, NULL);
58 return NULL;
59 }
60
61
62 void
63 trace_texture_destroy(struct trace_screen *tr_scr,
64 struct pipe_texture *texture)
65 {
66 struct trace_texture *tr_tex = trace_texture(tr_scr, texture);
67 pipe_texture_reference(&tr_tex->texture, NULL);
68 FREE(tr_tex);
69 }
70
71
72 struct pipe_surface *
73 trace_surface_create(struct trace_texture *tr_tex,
74 struct pipe_surface *surface)
75 {
76 struct trace_surface *tr_surf;
77
78 if(!surface)
79 goto error;
80
81 assert(surface->texture == tr_tex->texture);
82
83 tr_surf = CALLOC_STRUCT(trace_surface);
84 if(!tr_surf)
85 goto error;
86
87 memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
88
89 tr_surf->base.texture = NULL;
90 pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
91 tr_surf->surface = surface;
92
93 return &tr_surf->base;
94
95 error:
96 pipe_surface_reference(&surface, NULL);
97 return NULL;
98 }
99
100
101 void
102 trace_surface_destroy(struct trace_texture *tr_tex,
103 struct pipe_surface *surface)
104 {
105 struct trace_surface *tr_surf = trace_surface(tr_tex, surface);
106 pipe_texture_reference(&tr_surf->base.texture, NULL);
107 pipe_surface_reference(&tr_surf->surface, NULL);
108 FREE(tr_surf);
109 }
110
111
112 struct pipe_transfer *
113 trace_transfer_create(struct trace_texture *tr_tex,
114 struct pipe_transfer *transfer)
115 {
116 struct trace_transfer *tr_trans;
117
118 if(!transfer)
119 goto error;
120
121 assert(transfer->texture == tr_tex->texture);
122
123 tr_trans = CALLOC_STRUCT(trace_transfer);
124 if(!tr_trans)
125 goto error;
126
127 memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer));
128
129 tr_trans->base.texture = NULL;
130 pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base);
131 tr_trans->transfer = transfer;
132
133 return &tr_trans->base;
134
135 error:
136 transfer->texture->screen->tex_transfer_destroy(transfer);
137 return NULL;
138 }
139
140
141 void
142 trace_transfer_destroy(struct trace_texture *tr_tex,
143 struct pipe_transfer *transfer)
144 {
145 struct trace_transfer *tr_trans = trace_transfer(tr_tex, transfer);
146 pipe_texture_reference(&tr_trans->base.texture, NULL);
147 transfer->texture->screen->tex_transfer_destroy(tr_trans->transfer);
148 FREE(tr_trans);
149 }
150