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