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 "glhd_screen.h"
32 #include "glhd_objects.h"
33 #include "glhd_context.h"
37 struct pipe_resource
*
38 galahad_resource_create(struct galahad_screen
*glhd_screen
,
39 struct pipe_resource
*resource
)
41 struct galahad_resource
*glhd_resource
;
46 assert(resource
->screen
== glhd_screen
->screen
);
48 glhd_resource
= CALLOC_STRUCT(galahad_resource
);
52 memcpy(&glhd_resource
->base
, resource
, sizeof(struct pipe_resource
));
54 pipe_reference_init(&glhd_resource
->base
.reference
, 1);
55 glhd_resource
->base
.screen
= &glhd_screen
->base
;
56 glhd_resource
->resource
= resource
;
58 return &glhd_resource
->base
;
61 pipe_resource_reference(&resource
, NULL
);
66 galahad_resource_destroy(struct galahad_resource
*glhd_resource
)
68 pipe_resource_reference(&glhd_resource
->resource
, NULL
);
74 galahad_surface_create(struct galahad_resource
*glhd_resource
,
75 struct pipe_surface
*surface
)
77 struct galahad_surface
*glhd_surface
;
82 assert(surface
->texture
== glhd_resource
->resource
);
84 glhd_surface
= CALLOC_STRUCT(galahad_surface
);
88 memcpy(&glhd_surface
->base
, surface
, sizeof(struct pipe_surface
));
90 pipe_reference_init(&glhd_surface
->base
.reference
, 1);
91 glhd_surface
->base
.texture
= NULL
;
92 pipe_resource_reference(&glhd_surface
->base
.texture
, &glhd_resource
->base
);
93 glhd_surface
->surface
= surface
;
95 return &glhd_surface
->base
;
98 pipe_surface_reference(&surface
, NULL
);
103 galahad_surface_destroy(struct galahad_surface
*glhd_surface
)
105 pipe_resource_reference(&glhd_surface
->base
.texture
, NULL
);
106 pipe_surface_reference(&glhd_surface
->surface
, NULL
);
111 struct pipe_sampler_view
*
112 galahad_sampler_view_create(struct galahad_context
*glhd_context
,
113 struct galahad_resource
*glhd_resource
,
114 struct pipe_sampler_view
*view
)
116 struct galahad_sampler_view
*glhd_view
;
121 assert(view
->texture
== glhd_resource
->resource
);
123 glhd_view
= CALLOC_STRUCT(galahad_sampler_view
);
125 glhd_view
->base
= *view
;
126 glhd_view
->base
.reference
.count
= 1;
127 glhd_view
->base
.texture
= NULL
;
128 pipe_resource_reference(&glhd_view
->base
.texture
, glhd_resource
->resource
);
129 glhd_view
->base
.context
= glhd_context
->pipe
;
130 glhd_view
->sampler_view
= view
;
132 return &glhd_view
->base
;
138 galahad_sampler_view_destroy(struct galahad_context
*glhd_context
,
139 struct galahad_sampler_view
*glhd_view
)
141 pipe_resource_reference(&glhd_view
->base
.texture
, NULL
);
142 glhd_context
->pipe
->sampler_view_destroy(glhd_context
->pipe
,
143 glhd_view
->sampler_view
);
148 struct pipe_transfer
*
149 galahad_transfer_create(struct galahad_context
*glhd_context
,
150 struct galahad_resource
*glhd_resource
,
151 struct pipe_transfer
*transfer
)
153 struct galahad_transfer
*glhd_transfer
;
158 assert(transfer
->resource
== glhd_resource
->resource
);
160 glhd_transfer
= CALLOC_STRUCT(galahad_transfer
);
164 memcpy(&glhd_transfer
->base
, transfer
, sizeof(struct pipe_transfer
));
166 glhd_transfer
->base
.resource
= NULL
;
167 glhd_transfer
->transfer
= transfer
;
169 pipe_resource_reference(&glhd_transfer
->base
.resource
, &glhd_resource
->base
);
170 assert(glhd_transfer
->base
.resource
== &glhd_resource
->base
);
172 return &glhd_transfer
->base
;
175 glhd_context
->pipe
->transfer_destroy(glhd_context
->pipe
, transfer
);
180 galahad_transfer_destroy(struct galahad_context
*glhd_context
,
181 struct galahad_transfer
*glhd_transfer
)
183 pipe_resource_reference(&glhd_transfer
->base
.resource
, NULL
);
184 glhd_context
->pipe
->transfer_destroy(glhd_context
->pipe
,
185 glhd_transfer
->transfer
);