d818e21bb8214e65dc815678f46f410decba2ef0
[profile/ivi/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_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_texture *
39 trace_texture_create(struct trace_screen *tr_scr,
40                      struct pipe_texture *texture)
41 {
42    struct trace_texture *tr_tex;
43
44    if(!texture)
45       goto error;
46
47    assert(texture->screen == tr_scr->screen);
48
49    tr_tex = CALLOC_STRUCT(trace_texture);
50    if(!tr_tex)
51       goto error;
52
53    memcpy(&tr_tex->base, texture, sizeof(struct pipe_texture));
54
55    pipe_reference_init(&tr_tex->base.reference, 1);
56    tr_tex->base.screen = &tr_scr->base;
57    tr_tex->texture = texture;
58
59    trace_screen_add_to_list(tr_scr, textures, tr_tex);
60
61    return &tr_tex->base;
62
63 error:
64    pipe_texture_reference(&texture, NULL);
65    return NULL;
66 }
67
68
69 void
70 trace_texture_destroy(struct trace_texture *tr_tex)
71 {
72    struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
73
74    trace_screen_remove_from_list(tr_scr, textures, tr_tex);
75
76    pipe_texture_reference(&tr_tex->texture, NULL);
77    FREE(tr_tex);
78 }
79
80
81 struct pipe_surface *
82 trace_surface_create(struct trace_texture *tr_tex,
83                      struct pipe_surface *surface)
84 {
85    struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
86    struct trace_surface *tr_surf;
87
88    if(!surface)
89       goto error;
90
91    assert(surface->texture == tr_tex->texture);
92
93    tr_surf = CALLOC_STRUCT(trace_surface);
94    if(!tr_surf)
95       goto error;
96
97    memcpy(&tr_surf->base, surface, sizeof(struct pipe_surface));
98
99    pipe_reference_init(&tr_surf->base.reference, 1);
100    tr_surf->base.texture = NULL;
101    pipe_texture_reference(&tr_surf->base.texture, &tr_tex->base);
102    tr_surf->surface = surface;
103
104    trace_screen_add_to_list(tr_scr, surfaces, tr_surf);
105
106    return &tr_surf->base;
107
108 error:
109    pipe_surface_reference(&surface, NULL);
110    return NULL;
111 }
112
113
114 void
115 trace_surface_destroy(struct trace_surface *tr_surf)
116 {
117    struct trace_screen *tr_scr = trace_screen(tr_surf->base.texture->screen);
118
119    trace_screen_remove_from_list(tr_scr, surfaces, tr_surf);
120
121    pipe_texture_reference(&tr_surf->base.texture, NULL);
122    pipe_surface_reference(&tr_surf->surface, NULL);
123    FREE(tr_surf);
124 }
125
126
127 struct pipe_transfer *
128 trace_transfer_create(struct trace_context *tr_ctx,
129                       struct trace_texture *tr_tex,
130                       struct pipe_transfer *transfer)
131 {
132    struct trace_screen *tr_scr = trace_screen(tr_tex->base.screen);
133    struct trace_transfer *tr_trans;
134
135    if(!transfer)
136       goto error;
137
138    assert(transfer->texture == tr_tex->texture);
139
140    tr_trans = CALLOC_STRUCT(trace_transfer);
141    if(!tr_trans)
142       goto error;
143
144    memcpy(&tr_trans->base, transfer, sizeof(struct pipe_transfer));
145
146    tr_trans->base.texture = NULL;
147    tr_trans->transfer = transfer;
148
149    pipe_texture_reference(&tr_trans->base.texture, &tr_tex->base);
150    assert(tr_trans->base.texture == &tr_tex->base);
151
152    trace_screen_add_to_list(tr_scr, transfers, tr_trans);
153
154    return &tr_trans->base;
155
156 error:
157    tr_ctx->pipe->tex_transfer_destroy(tr_ctx->pipe, transfer);
158    return NULL;
159 }
160
161
162 void
163 trace_transfer_destroy(struct trace_context *tr_context,
164                        struct trace_transfer *tr_trans)
165 {
166    struct trace_screen *tr_scr = trace_screen(tr_context->base.screen);
167    struct pipe_context *context = tr_context->pipe;
168    struct pipe_transfer *transfer = tr_trans->transfer;
169
170    trace_screen_remove_from_list(tr_scr, transfers, tr_trans);
171
172    pipe_texture_reference(&tr_trans->base.texture, NULL);
173    context->tex_transfer_destroy(context, transfer);
174    FREE(tr_trans);
175 }
176