91831404b8b0d554349f4bfa7e7ca6423c8dc858
[mesa.git] / src / gallium / drivers / identity / id_objects.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
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 VMWARE 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_memory.h"
30
31 #include "id_screen.h"
32 #include "id_objects.h"
33
34 struct pipe_buffer *
35 identity_buffer_create(struct identity_screen *id_screen,
36 struct pipe_buffer *buffer)
37 {
38 struct identity_buffer *id_buffer;
39
40 if(!buffer)
41 goto error;
42
43 assert(buffer->screen == id_screen->screen);
44
45 id_buffer = CALLOC_STRUCT(identity_buffer);
46 if(!id_buffer)
47 goto error;
48
49 memcpy(&id_buffer->base, buffer, sizeof(struct pipe_buffer));
50
51 pipe_reference_init(&id_buffer->base.reference, 1);
52 id_buffer->base.screen = &id_screen->base;
53 id_buffer->buffer = buffer;
54
55 return &id_buffer->base;
56
57 error:
58 pipe_buffer_reference(&buffer, NULL);
59 return NULL;
60 }
61
62 void
63 identity_buffer_destroy(struct identity_buffer *id_buffer)
64 {
65 pipe_buffer_reference(&id_buffer->buffer, NULL);
66 FREE(id_buffer);
67 }
68
69
70 struct pipe_texture *
71 identity_texture_create(struct identity_screen *id_screen,
72 struct pipe_texture *texture)
73 {
74 struct identity_texture *id_texture;
75
76 if(!texture)
77 goto error;
78
79 assert(texture->screen == id_screen->screen);
80
81 id_texture = CALLOC_STRUCT(identity_texture);
82 if(!id_texture)
83 goto error;
84
85 memcpy(&id_texture->base, texture, sizeof(struct pipe_texture));
86
87 pipe_reference_init(&id_texture->base.reference, 1);
88 id_texture->base.screen = &id_screen->base;
89 id_texture->texture = texture;
90
91 return &id_texture->base;
92
93 error:
94 pipe_texture_reference(&texture, NULL);
95 return NULL;
96 }
97
98 void
99 identity_texture_destroy(struct identity_texture *id_texture)
100 {
101 pipe_texture_reference(&id_texture->texture, NULL);
102 FREE(id_texture);
103 }
104
105
106 struct pipe_surface *
107 identity_surface_create(struct identity_texture *id_texture,
108 struct pipe_surface *surface)
109 {
110 struct identity_surface *id_surface;
111
112 if(!surface)
113 goto error;
114
115 assert(surface->texture == id_texture->texture);
116
117 id_surface = CALLOC_STRUCT(identity_surface);
118 if(!id_surface)
119 goto error;
120
121 memcpy(&id_surface->base, surface, sizeof(struct pipe_surface));
122
123 pipe_reference_init(&id_surface->base.reference, 1);
124 id_surface->base.texture = NULL;
125 pipe_texture_reference(&id_surface->base.texture, &id_texture->base);
126 id_surface->surface = surface;
127
128 return &id_surface->base;
129
130 error:
131 pipe_surface_reference(&surface, NULL);
132 return NULL;
133 }
134
135 void
136 identity_surface_destroy(struct identity_surface *id_surface)
137 {
138 pipe_texture_reference(&id_surface->base.texture, NULL);
139 pipe_surface_reference(&id_surface->surface, NULL);
140 FREE(id_surface);
141 }
142
143
144 struct pipe_transfer *
145 identity_transfer_create(struct identity_context *id_context,
146 struct identity_texture *id_texture,
147 struct pipe_transfer *transfer)
148 {
149 struct identity_transfer *id_transfer;
150
151 if(!transfer)
152 goto error;
153
154 assert(transfer->texture == id_texture->texture);
155
156 id_transfer = CALLOC_STRUCT(identity_transfer);
157 if(!id_transfer)
158 goto error;
159
160 memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
161
162 id_transfer->base.texture = NULL;
163 pipe_texture_reference(&id_transfer->base.texture, &id_texture->base);
164 id_transfer->transfer = transfer;
165 assert(id_transfer->base.texture == &id_texture->base);
166
167 return &id_transfer->base;
168
169 error:
170 transfer->pipe->tex_transfer_destroy(transfer);
171 return NULL;
172 }
173
174 void
175 identity_transfer_destroy(struct identity_transfer *id_transfer)
176 {
177 pipe_texture_reference(&id_transfer->base.texture, NULL);
178 id_transfer->transfer->pipe->tex_transfer_destroy(id_transfer->transfer);
179 FREE(id_transfer);
180 }
181
182 struct pipe_video_surface *
183 identity_video_surface_create(struct identity_screen *id_screen,
184 struct pipe_video_surface *video_surface)
185 {
186 struct identity_video_surface *id_video_surface;
187
188 if (!video_surface) {
189 goto error;
190 }
191
192 assert(video_surface->screen == id_screen->screen);
193
194 id_video_surface = CALLOC_STRUCT(identity_video_surface);
195 if (!id_video_surface) {
196 goto error;
197 }
198
199 memcpy(&id_video_surface->base,
200 video_surface,
201 sizeof(struct pipe_video_surface));
202
203 pipe_reference_init(&id_video_surface->base.reference, 1);
204 id_video_surface->base.screen = &id_screen->base;
205 id_video_surface->video_surface = video_surface;
206
207 return &id_video_surface->base;
208
209 error:
210 pipe_video_surface_reference(&video_surface, NULL);
211 return NULL;
212 }
213
214 void
215 identity_video_surface_destroy(struct identity_video_surface *id_video_surface)
216 {
217 pipe_video_surface_reference(&id_video_surface->video_surface, NULL);
218 FREE(id_video_surface);
219 }