id_objects.c revision ee2c6d748de170e0ffc30bb4a8366526a1a25f65
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
37struct pipe_resource *
38identity_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
60error:
61   pipe_resource_reference(&resource, NULL);
62   return NULL;
63}
64
65void
66identity_resource_destroy(struct identity_resource *id_resource)
67{
68   pipe_resource_reference(&id_resource->resource, NULL);
69   FREE(id_resource);
70}
71
72
73struct pipe_surface *
74identity_surface_create(struct identity_resource *id_resource,
75                        struct pipe_surface *surface)
76{
77   struct identity_surface *id_surface;
78
79   if(!surface)
80      goto error;
81
82   assert(surface->texture == id_resource->resource);
83
84   id_surface = CALLOC_STRUCT(identity_surface);
85   if(!id_surface)
86      goto error;
87
88   memcpy(&id_surface->base, surface, sizeof(struct pipe_surface));
89
90   pipe_reference_init(&id_surface->base.reference, 1);
91   id_surface->base.texture = NULL;
92   pipe_resource_reference(&id_surface->base.texture, &id_resource->base);
93   id_surface->surface = surface;
94
95   return &id_surface->base;
96
97error:
98   pipe_surface_reference(&surface, NULL);
99   return NULL;
100}
101
102void
103identity_surface_destroy(struct identity_surface *id_surface)
104{
105   pipe_resource_reference(&id_surface->base.texture, NULL);
106   pipe_surface_reference(&id_surface->surface, NULL);
107   FREE(id_surface);
108}
109
110
111struct pipe_sampler_view *
112identity_sampler_view_create(struct identity_context *id_context,
113                             struct identity_resource *id_resource,
114                             struct pipe_sampler_view *view)
115{
116   struct identity_sampler_view *id_view;
117
118   if (!view)
119      goto error;
120
121   assert(view->texture == id_resource->resource);
122
123   id_view = CALLOC_STRUCT(identity_sampler_view);
124
125   id_view->base = *view;
126   id_view->base.reference.count = 1;
127   id_view->base.texture = NULL;
128   pipe_resource_reference(&id_view->base.texture, id_resource->resource);
129   id_view->base.context = id_context->pipe;
130
131   return &id_view->base;
132error:
133   return NULL;
134}
135
136void
137identity_sampler_view_destroy(struct identity_context *id_context,
138                              struct identity_sampler_view *id_view)
139{
140   pipe_resource_reference(&id_view->base.texture, NULL);
141   id_context->pipe->sampler_view_destroy(id_context->pipe,
142                                          id_view->sampler_view);
143   FREE(id_view);
144}
145
146
147struct pipe_transfer *
148identity_transfer_create(struct identity_context *id_context,
149                         struct identity_resource *id_resource,
150                         struct pipe_transfer *transfer)
151{
152   struct identity_transfer *id_transfer;
153
154   if(!transfer)
155      goto error;
156
157   assert(transfer->resource == id_resource->resource);
158
159   id_transfer = CALLOC_STRUCT(identity_transfer);
160   if(!id_transfer)
161      goto error;
162
163   memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
164
165   id_transfer->base.resource = NULL;
166   id_transfer->transfer = transfer;
167
168   pipe_resource_reference(&id_transfer->base.resource, &id_resource->base);
169   assert(id_transfer->base.resource == &id_resource->base);
170
171   return &id_transfer->base;
172
173error:
174   id_context->pipe->transfer_destroy(id_context->pipe, transfer);
175   return NULL;
176}
177
178void
179identity_transfer_destroy(struct identity_context *id_context,
180                          struct identity_transfer *id_transfer)
181{
182   pipe_resource_reference(&id_transfer->base.resource, NULL);
183   id_context->pipe->transfer_destroy(id_context->pipe,
184                                      id_transfer->transfer);
185   FREE(id_transfer);
186}
187
188