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_screen.h"
32 #include "id_objects.h"
33 #include "id_context.h"
37 struct pipe_resource
*
38 identity_resource_create(struct identity_screen
*id_screen
,
39 struct pipe_resource
*resource
)
41 struct identity_resource
*id_resource
;
46 assert(resource
->screen
== id_screen
->screen
);
48 id_resource
= CALLOC_STRUCT(identity_resource
);
52 memcpy(&id_resource
->base
, resource
, sizeof(struct pipe_resource
));
54 pipe_reference_init(&id_resource
->base
.reference
, 1);
55 id_resource
->base
.screen
= &id_screen
->base
;
56 id_resource
->resource
= resource
;
58 return &id_resource
->base
;
61 pipe_resource_reference(&resource
, NULL
);
66 identity_resource_destroy(struct identity_resource
*id_resource
)
68 pipe_resource_reference(&id_resource
->resource
, NULL
);
74 identity_surface_create(struct identity_context
*id_context
,
75 struct identity_resource
*id_resource
,
76 struct pipe_surface
*surface
)
78 struct identity_surface
*id_surface
;
83 assert(surface
->texture
== id_resource
->resource
);
85 id_surface
= CALLOC_STRUCT(identity_surface
);
89 memcpy(&id_surface
->base
, surface
, sizeof(struct pipe_surface
));
91 pipe_reference_init(&id_surface
->base
.reference
, 1);
92 id_surface
->base
.texture
= NULL
;
93 pipe_resource_reference(&id_surface
->base
.texture
, &id_resource
->base
);
94 id_surface
->surface
= surface
;
96 return &id_surface
->base
;
99 pipe_surface_reference(&surface
, NULL
);
104 identity_surface_destroy(struct identity_context
*id_context
,
105 struct identity_surface
*id_surface
)
107 pipe_resource_reference(&id_surface
->base
.texture
, NULL
);
108 id_context
->pipe
->surface_destroy(id_context
->pipe
,
109 id_surface
->surface
);
114 struct pipe_sampler_view
*
115 identity_sampler_view_create(struct identity_context
*id_context
,
116 struct identity_resource
*id_resource
,
117 struct pipe_sampler_view
*view
)
119 struct identity_sampler_view
*id_view
;
124 assert(view
->texture
== id_resource
->resource
);
126 id_view
= CALLOC_STRUCT(identity_sampler_view
);
128 id_view
->base
= *view
;
129 id_view
->base
.reference
.count
= 1;
130 id_view
->base
.texture
= NULL
;
131 pipe_resource_reference(&id_view
->base
.texture
, id_resource
->resource
);
132 id_view
->base
.context
= id_context
->pipe
;
133 id_view
->sampler_view
= view
;
135 return &id_view
->base
;
141 identity_sampler_view_destroy(struct identity_context
*id_context
,
142 struct identity_sampler_view
*id_view
)
144 pipe_resource_reference(&id_view
->base
.texture
, NULL
);
145 id_context
->pipe
->sampler_view_destroy(id_context
->pipe
,
146 id_view
->sampler_view
);
151 struct pipe_transfer
*
152 identity_transfer_create(struct identity_context
*id_context
,
153 struct identity_resource
*id_resource
,
154 struct pipe_transfer
*transfer
)
156 struct identity_transfer
*id_transfer
;
161 assert(transfer
->resource
== id_resource
->resource
);
163 id_transfer
= CALLOC_STRUCT(identity_transfer
);
167 memcpy(&id_transfer
->base
, transfer
, sizeof(struct pipe_transfer
));
169 id_transfer
->base
.resource
= NULL
;
170 id_transfer
->transfer
= transfer
;
172 pipe_resource_reference(&id_transfer
->base
.resource
, &id_resource
->base
);
173 assert(id_transfer
->base
.resource
== &id_resource
->base
);
175 return &id_transfer
->base
;
178 id_context
->pipe
->transfer_destroy(id_context
->pipe
, transfer
);
183 identity_transfer_destroy(struct identity_context
*id_context
,
184 struct identity_transfer
*id_transfer
)
186 pipe_resource_reference(&id_transfer
->base
.resource
, NULL
);
187 id_context
->pipe
->transfer_destroy(id_context
->pipe
,
188 id_transfer
->transfer
);