07aa01818d383a686f191735c91a2cf449135eda
1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_memory.h"
31 #include "id_public.h"
32 #include "id_screen.h"
33 #include "id_objects.h"
36 identity_buffer_create(struct identity_screen
*id_screen
,
37 struct pipe_buffer
*buffer
)
39 struct identity_buffer
*id_buffer
;
44 assert(buffer
->screen
== id_screen
->screen
);
46 id_buffer
= CALLOC_STRUCT(identity_buffer
);
50 memcpy(&id_buffer
->base
, buffer
, sizeof(struct pipe_buffer
));
52 pipe_reference_init(&id_buffer
->base
.reference
, 1);
53 id_buffer
->base
.screen
= &id_screen
->base
;
54 id_buffer
->buffer
= buffer
;
56 return &id_buffer
->base
;
59 pipe_buffer_reference(&buffer
, NULL
);
64 identity_buffer_destroy(struct identity_buffer
*id_buffer
)
66 pipe_buffer_reference(&id_buffer
->buffer
, NULL
);
72 identity_texture_create(struct identity_screen
*id_screen
,
73 struct pipe_texture
*texture
)
75 struct identity_texture
*id_texture
;
80 assert(texture
->screen
== id_screen
->screen
);
82 id_texture
= CALLOC_STRUCT(identity_texture
);
86 memcpy(&id_texture
->base
, texture
, sizeof(struct pipe_texture
));
88 pipe_reference_init(&id_texture
->base
.reference
, 1);
89 id_texture
->base
.screen
= &id_screen
->base
;
90 id_texture
->texture
= texture
;
92 return &id_texture
->base
;
95 pipe_texture_reference(&texture
, NULL
);
100 identity_texture_destroy(struct identity_texture
*id_texture
)
102 pipe_texture_reference(&id_texture
->texture
, NULL
);
107 struct pipe_surface
*
108 identity_surface_create(struct identity_texture
*id_texture
,
109 struct pipe_surface
*surface
)
111 struct identity_surface
*id_surface
;
116 assert(surface
->texture
== id_texture
->texture
);
118 id_surface
= CALLOC_STRUCT(identity_surface
);
122 memcpy(&id_surface
->base
, surface
, sizeof(struct pipe_surface
));
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
;
129 return &id_surface
->base
;
132 pipe_surface_reference(&surface
, NULL
);
137 identity_surface_destroy(struct identity_surface
*id_surface
)
139 pipe_texture_reference(&id_surface
->base
.texture
, NULL
);
140 pipe_surface_reference(&id_surface
->surface
, NULL
);
145 struct pipe_transfer
*
146 identity_transfer_create(struct identity_texture
*id_texture
,
147 struct pipe_transfer
*transfer
)
149 struct identity_transfer
*id_transfer
;
154 assert(transfer
->texture
== id_texture
->texture
);
156 id_transfer
= CALLOC_STRUCT(identity_transfer
);
160 memcpy(&id_transfer
->base
, transfer
, sizeof(struct pipe_transfer
));
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
);
167 return &id_transfer
->base
;
170 transfer
->texture
->screen
->tex_transfer_destroy(transfer
);
175 identity_transfer_destroy(struct identity_transfer
*id_transfer
)
177 struct identity_screen
*id_screen
= identity_screen(id_transfer
->base
.texture
->screen
);
178 struct pipe_screen
*screen
= id_screen
->screen
;
180 pipe_texture_reference(&id_transfer
->base
.texture
, NULL
);
181 screen
->tex_transfer_destroy(id_transfer
->transfer
);
185 struct pipe_video_surface
*
186 identity_video_surface_create(struct identity_screen
*id_screen
,
187 struct pipe_video_surface
*video_surface
)
189 struct identity_video_surface
*id_video_surface
;
191 if (!video_surface
) {
195 assert(video_surface
->screen
== id_screen
->screen
);
197 id_video_surface
= CALLOC_STRUCT(identity_video_surface
);
198 if (!id_video_surface
) {
202 memcpy(&id_video_surface
->base
,
204 sizeof(struct pipe_video_surface
));
206 pipe_reference_init(&id_video_surface
->base
.reference
, 1);
207 id_video_surface
->base
.screen
= &id_screen
->base
;
208 id_video_surface
->video_surface
= video_surface
;
210 return &id_video_surface
->base
;
213 pipe_video_surface_reference(&video_surface
, NULL
);
218 identity_video_surface_destroy(struct identity_video_surface
*id_video_surface
)
220 pipe_video_surface_reference(&id_video_surface
->video_surface
, NULL
);
221 FREE(id_video_surface
);