blob: bc9bc7121d58caf5ac2b23267d64c9c5e9b05f3b [file] [log] [blame]
Jakob Bornecrantzd60b2c62009-06-24 02:42:41 +02001/**************************************************************************
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_memory.h"
29
30#include "id_public.h"
31#include "id_screen.h"
32#include "id_objects.h"
33
34struct pipe_buffer *
35identity_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
57error:
58 pipe_buffer_reference(&buffer, NULL);
59 return NULL;
60}
61
62void
63identity_buffer_destroy(struct identity_buffer *id_buffer)
64{
65 pipe_buffer_reference(&id_buffer->buffer, NULL);
66 FREE(id_buffer);
67}
68
69
70struct pipe_texture *
71identity_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
93error:
94 pipe_texture_reference(&texture, NULL);
95 return NULL;
96}
97
98void
99identity_texture_destroy(struct identity_texture *id_texture)
100{
101 pipe_texture_reference(&id_texture->texture, NULL);
102 FREE(id_texture);
103}
104
105
106struct pipe_surface *
107identity_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
130error:
131 pipe_surface_reference(&surface, NULL);
132 return NULL;
133}
134
135void
136identity_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
144struct pipe_transfer *
145identity_transfer_create(struct identity_texture *id_texture,
146 struct pipe_transfer *transfer)
147{
148 struct identity_transfer *id_transfer;
149
150 if(!transfer)
151 goto error;
152
153 assert(transfer->texture == id_texture->texture);
154
155 id_transfer = CALLOC_STRUCT(identity_transfer);
156 if(!id_transfer)
157 goto error;
158
159 memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
160
161 id_transfer->base.texture = NULL;
162 pipe_texture_reference(&id_transfer->base.texture, &id_texture->base);
163 id_transfer->transfer = transfer;
164 assert(id_transfer->base.texture == &id_texture->base);
165
166 return &id_transfer->base;
167
168error:
169 transfer->texture->screen->tex_transfer_destroy(transfer);
170 return NULL;
171}
172
173void
174identity_transfer_destroy(struct identity_transfer *id_transfer)
175{
176 struct identity_screen *id_screen = identity_screen(id_transfer->base.texture->screen);
177 struct pipe_screen *screen = id_screen->screen;
178
179 pipe_texture_reference(&id_transfer->base.texture, NULL);
180 screen->tex_transfer_destroy(id_transfer->transfer);
181 FREE(id_transfer);
182}
Michal Krolf56b95e2009-11-19 08:18:58 +0100183
184struct pipe_video_surface *
185identity_video_surface_create(struct identity_screen *id_screen,
186 struct pipe_video_surface *video_surface)
187{
188 struct identity_video_surface *id_video_surface;
189
190 if (!video_surface) {
191 goto error;
192 }
193
194 assert(video_surface->screen == id_screen->screen);
195
196 id_video_surface = CALLOC_STRUCT(identity_video_surface);
197 if (!id_video_surface) {
198 goto error;
199 }
200
201 memcpy(&id_video_surface->base,
202 video_surface,
203 sizeof(struct pipe_video_surface));
204
205 pipe_reference_init(&id_video_surface->base.reference, 1);
206 id_video_surface->base.screen = &id_screen->base;
207 id_video_surface->video_surface = video_surface;
208
209 return &id_video_surface->base;
210
211error:
212 pipe_video_surface_reference(&video_surface, NULL);
213 return NULL;
214}
215
216void
217identity_video_surface_destroy(struct identity_video_surface *id_video_surface)
218{
219 pipe_video_surface_reference(&id_video_surface->video_surface, NULL);
220 FREE(id_video_surface);
221}