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_context *glhd_context,
75 struct galahad_resource *glhd_resource,
76 struct pipe_surface *surface)
78 struct galahad_surface *glhd_surface;
83 assert(surface->texture == glhd_resource->resource);
85 glhd_surface = CALLOC_STRUCT(galahad_surface);
89 memcpy(&glhd_surface->base, surface, sizeof(struct pipe_surface));
91 pipe_reference_init(&glhd_surface->base.reference, 1);
92 glhd_surface->base.texture = NULL;
93 pipe_resource_reference(&glhd_surface->base.texture, &glhd_resource->base);
94 glhd_surface->surface = surface;
96 return &glhd_surface->base;
99 pipe_surface_reference(&surface, NULL);
104 galahad_surface_destroy(struct galahad_context *glhd_context,
105 struct galahad_surface *glhd_surface)
107 pipe_resource_reference(&glhd_surface->base.texture, NULL);
108 glhd_context->pipe->surface_destroy(glhd_context->pipe, glhd_surface->surface);
113 struct pipe_sampler_view *
114 galahad_sampler_view_create(struct galahad_context *glhd_context,
115 struct galahad_resource *glhd_resource,
116 struct pipe_sampler_view *view)
118 struct galahad_sampler_view *glhd_view;
123 assert(view->texture == glhd_resource->resource);
125 glhd_view = CALLOC_STRUCT(galahad_sampler_view);
127 glhd_view->base = *view;
128 glhd_view->base.reference.count = 1;
129 glhd_view->base.texture = NULL;
130 pipe_resource_reference(&glhd_view->base.texture, glhd_resource->resource);
131 glhd_view->base.context = glhd_context->pipe;
132 glhd_view->sampler_view = view;
134 return &glhd_view->base;
140 galahad_sampler_view_destroy(struct galahad_context *glhd_context,
141 struct galahad_sampler_view *glhd_view)
143 pipe_resource_reference(&glhd_view->base.texture, NULL);
144 glhd_context->pipe->sampler_view_destroy(glhd_context->pipe,
145 glhd_view->sampler_view);
150 struct pipe_transfer *
151 galahad_transfer_create(struct galahad_context *glhd_context,
152 struct galahad_resource *glhd_resource,
153 struct pipe_transfer *transfer)
155 struct galahad_transfer *glhd_transfer;
160 assert(transfer->resource == glhd_resource->resource);
162 glhd_transfer = CALLOC_STRUCT(galahad_transfer);
166 memcpy(&glhd_transfer->base, transfer, sizeof(struct pipe_transfer));
168 glhd_transfer->base.resource = NULL;
169 glhd_transfer->transfer = transfer;
171 pipe_resource_reference(&glhd_transfer->base.resource, &glhd_resource->base);
172 assert(glhd_transfer->base.resource == &glhd_resource->base);
174 return &glhd_transfer->base;
177 glhd_context->pipe->transfer_destroy(glhd_context->pipe, transfer);
182 galahad_transfer_destroy(struct galahad_context *glhd_context,
183 struct galahad_transfer *glhd_transfer)
185 pipe_resource_reference(&glhd_transfer->base.resource, NULL);
186 glhd_context->pipe->transfer_destroy(glhd_context->pipe,
187 glhd_transfer->transfer);