gallium: implement blit in driver wrappers
[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
36
37 struct pipe_resource *
38 identity_resource_create(struct identity_screen *id_screen,
39 struct pipe_resource *resource)
40 {
41 struct identity_resource *id_resource;
42
43 if(!resource)
44 goto error;
45
46 assert(resource->screen == id_screen->screen);
47
48 id_resource = CALLOC_STRUCT(identity_resource);
49 if(!id_resource)
50 goto error;
51
52 memcpy(&id_resource->base, resource, sizeof(struct pipe_resource));
53
54 pipe_reference_init(&id_resource->base.reference, 1);
55 id_resource->base.screen = &id_screen->base;
56 id_resource->resource = resource;
57
58 return &id_resource->base;
59
60 error:
61 pipe_resource_reference(&resource, NULL);
62 return NULL;
63 }
64
65 void
66 identity_resource_destroy(struct identity_resource *id_resource)
67 {
68 pipe_resource_reference(&id_resource->resource, NULL);
69 FREE(id_resource);
70 }
71
72
73 struct pipe_surface *
74 identity_surface_create(struct identity_context *id_context,
75 struct identity_resource *id_resource,
76 struct pipe_surface *surface)
77 {
78 struct identity_surface *id_surface;
79
80 if(!surface)
81 goto error;
82
83 assert(surface->texture == id_resource->resource);
84
85 id_surface = CALLOC_STRUCT(identity_surface);
86 if(!id_surface)
87 goto error;
88
89 memcpy(&id_surface->base, surface, sizeof(struct pipe_surface));
90
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;
95
96 return &id_surface->base;
97
98 error:
99 pipe_surface_reference(&surface, NULL);
100 return NULL;
101 }
102
103 void
104 identity_surface_destroy(struct identity_context *id_context,
105 struct identity_surface *id_surface)
106 {
107 pipe_resource_reference(&id_surface->base.texture, NULL);
108 id_context->pipe->surface_destroy(id_context->pipe,
109 id_surface->surface);
110 FREE(id_surface);
111 }
112
113
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)
118 {
119 struct identity_sampler_view *id_view;
120
121 if (!view)
122 goto error;
123
124 assert(view->texture == id_resource->resource);
125
126 id_view = CALLOC_STRUCT(identity_sampler_view);
127
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;
134
135 return &id_view->base;
136 error:
137 return NULL;
138 }
139
140 void
141 identity_sampler_view_destroy(struct identity_context *id_context,
142 struct identity_sampler_view *id_view)
143 {
144 pipe_resource_reference(&id_view->base.texture, NULL);
145 id_context->pipe->sampler_view_destroy(id_context->pipe,
146 id_view->sampler_view);
147 FREE(id_view);
148 }
149
150
151 struct pipe_transfer *
152 identity_transfer_create(struct identity_context *id_context,
153 struct identity_resource *id_resource,
154 struct pipe_transfer *transfer)
155 {
156 struct identity_transfer *id_transfer;
157
158 if(!transfer)
159 goto error;
160
161 assert(transfer->resource == id_resource->resource);
162
163 id_transfer = CALLOC_STRUCT(identity_transfer);
164 if(!id_transfer)
165 goto error;
166
167 memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
168
169 id_transfer->base.resource = NULL;
170 id_transfer->transfer = transfer;
171
172 pipe_resource_reference(&id_transfer->base.resource, &id_resource->base);
173 assert(id_transfer->base.resource == &id_resource->base);
174
175 return &id_transfer->base;
176
177 error:
178 id_context->pipe->transfer_destroy(id_context->pipe, transfer);
179 return NULL;
180 }
181
182 void
183 identity_transfer_destroy(struct identity_context *id_context,
184 struct identity_transfer *id_transfer)
185 {
186 pipe_resource_reference(&id_transfer->base.resource, NULL);
187 id_context->pipe->transfer_destroy(id_context->pipe,
188 id_transfer->transfer);
189 FREE(id_transfer);
190 }
191