Merge branch '7.8'
[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_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
97 error:
98 pipe_surface_reference(&surface, NULL);
99 return NULL;
100 }
101
102 void
103 identity_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
111 struct pipe_transfer *
112 identity_transfer_create(struct identity_context *id_context,
113 struct identity_resource *id_resource,
114 struct pipe_transfer *transfer)
115 {
116 struct identity_transfer *id_transfer;
117
118 if(!transfer)
119 goto error;
120
121 assert(transfer->resource == id_resource->resource);
122
123 id_transfer = CALLOC_STRUCT(identity_transfer);
124 if(!id_transfer)
125 goto error;
126
127 memcpy(&id_transfer->base, transfer, sizeof(struct pipe_transfer));
128
129 id_transfer->base.resource = NULL;
130 id_transfer->transfer = transfer;
131
132 pipe_resource_reference(&id_transfer->base.resource, &id_resource->base);
133 assert(id_transfer->base.resource == &id_resource->base);
134
135 return &id_transfer->base;
136
137 error:
138 id_context->pipe->transfer_destroy(id_context->pipe, transfer);
139 return NULL;
140 }
141
142 void
143 identity_transfer_destroy(struct identity_context *id_context,
144 struct identity_transfer *id_transfer)
145 {
146 pipe_resource_reference(&id_transfer->base.resource, NULL);
147 id_context->pipe->transfer_destroy(id_context->pipe,
148 id_transfer->transfer);
149 FREE(id_transfer);
150 }
151