4f9b23263b9a0b9f8515ddb1f8e5f43b5da9e4d9
1 /**************************************************************************
3 * Copyright 2010 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"
30 #include "util/u_simple_list.h"
32 #include "rbug_screen.h"
33 #include "rbug_objects.h"
34 #include "rbug_context.h"
38 struct pipe_resource
*
39 rbug_resource_create(struct rbug_screen
*rb_screen
,
40 struct pipe_resource
*resource
)
42 struct rbug_resource
*rb_resource
;
47 assert(resource
->screen
== rb_screen
->screen
);
49 rb_resource
= CALLOC_STRUCT(rbug_resource
);
53 memcpy(&rb_resource
->base
, resource
, sizeof(struct pipe_resource
));
55 pipe_reference_init(&rb_resource
->base
.reference
, 1);
56 rb_resource
->base
.screen
= &rb_screen
->base
;
57 rb_resource
->resource
= resource
;
59 rbug_screen_add_to_list(rb_screen
, resources
, rb_resource
);
61 return &rb_resource
->base
;
64 pipe_resource_reference(&resource
, NULL
);
69 rbug_resource_destroy(struct rbug_resource
*rb_resource
)
71 struct rbug_screen
*rb_screen
= rbug_screen(rb_resource
->base
.screen
);
72 rbug_screen_remove_from_list(rb_screen
, resources
, rb_resource
);
74 pipe_resource_reference(&rb_resource
->resource
, NULL
);
80 rbug_surface_create(struct rbug_resource
*rb_resource
,
81 struct pipe_surface
*surface
)
83 struct rbug_surface
*rb_surface
;
88 assert(surface
->texture
== rb_resource
->resource
);
90 rb_surface
= CALLOC_STRUCT(rbug_surface
);
94 memcpy(&rb_surface
->base
, surface
, sizeof(struct pipe_surface
));
96 pipe_reference_init(&rb_surface
->base
.reference
, 1);
97 rb_surface
->base
.texture
= NULL
;
98 pipe_resource_reference(&rb_surface
->base
.texture
, &rb_resource
->base
);
99 rb_surface
->surface
= surface
;
101 return &rb_surface
->base
;
104 pipe_surface_reference(&surface
, NULL
);
109 rbug_surface_destroy(struct rbug_surface
*rb_surface
)
111 pipe_resource_reference(&rb_surface
->base
.texture
, NULL
);
112 pipe_surface_reference(&rb_surface
->surface
, NULL
);
117 struct pipe_sampler_view
*
118 rbug_sampler_view_create(struct rbug_context
*rb_context
,
119 struct rbug_resource
*rb_resource
,
120 struct pipe_sampler_view
*view
)
122 struct rbug_sampler_view
*rb_view
;
127 assert(view
->texture
== rb_resource
->resource
);
129 rb_view
= MALLOC(sizeof(struct rbug_sampler_view
));
131 rb_view
->base
= *view
;
132 rb_view
->base
.reference
.count
= 1;
133 rb_view
->base
.texture
= NULL
;
134 pipe_resource_reference(&rb_view
->base
.texture
, rb_resource
->resource
);
135 rb_view
->base
.context
= rb_context
->pipe
;
136 rb_view
->sampler_view
= view
;
138 return &rb_view
->base
;
144 rbug_sampler_view_destroy(struct rbug_context
*rb_context
,
145 struct rbug_sampler_view
*rb_view
)
147 pipe_resource_reference(&rb_view
->base
.texture
, NULL
);
148 rb_context
->pipe
->sampler_view_destroy(rb_context
->pipe
,
149 rb_view
->sampler_view
);
154 struct pipe_transfer
*
155 rbug_transfer_create(struct rbug_context
*rb_context
,
156 struct rbug_resource
*rb_resource
,
157 struct pipe_transfer
*transfer
)
159 struct rbug_transfer
*rb_transfer
;
164 assert(transfer
->resource
== rb_resource
->resource
);
166 rb_transfer
= CALLOC_STRUCT(rbug_transfer
);
170 memcpy(&rb_transfer
->base
, transfer
, sizeof(struct pipe_transfer
));
172 rb_transfer
->base
.resource
= NULL
;
173 rb_transfer
->transfer
= transfer
;
174 rb_transfer
->pipe
= rb_context
->pipe
;
176 pipe_resource_reference(&rb_transfer
->base
.resource
, &rb_resource
->base
);
177 assert(rb_transfer
->base
.resource
== &rb_resource
->base
);
179 return &rb_transfer
->base
;
182 rb_context
->pipe
->transfer_destroy(rb_context
->pipe
, transfer
);
187 rbug_transfer_destroy(struct rbug_context
*rb_context
,
188 struct rbug_transfer
*rb_transfer
)
190 pipe_resource_reference(&rb_transfer
->base
.resource
, NULL
);
191 rb_transfer
->pipe
->transfer_destroy(rb_context
->pipe
,
192 rb_transfer
->transfer
);