1/**************************************************************************
2 *
3 * Copyright 2010 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#ifndef RBUG_OBJECTS_H
29#define RBUG_OBJECTS_H
30
31
32#include "pipe/p_compiler.h"
33#include "pipe/p_state.h"
34
35#include "rbug_screen.h"
36
37struct rbug_context;
38
39
40struct rbug_resource
41{
42   struct pipe_resource base;
43
44   struct pipe_resource *resource;
45
46   struct rbug_list list;
47};
48
49
50enum rbug_shader_type
51{
52   RBUG_SHADER_GEOM,
53   RBUG_SHADER_VERTEX,
54   RBUG_SHADER_FRAGMENT,
55};
56
57struct rbug_shader
58{
59   struct rbug_list list;
60
61   void *shader;
62   void *tokens;
63   void *replaced_shader;
64   void *replaced_tokens;
65
66   enum rbug_shader_type type;
67   boolean disabled;
68};
69
70
71struct rbug_sampler_view
72{
73   struct pipe_sampler_view base;
74
75   struct pipe_sampler_view *sampler_view;
76};
77
78
79struct rbug_surface
80{
81   struct pipe_surface base;
82
83   struct pipe_surface *surface;
84};
85
86
87struct rbug_transfer
88{
89   struct pipe_transfer base;
90
91   struct pipe_context *pipe;
92   struct pipe_transfer *transfer;
93};
94
95
96static INLINE struct rbug_resource *
97rbug_resource(struct pipe_resource *_resource)
98{
99   if (!_resource)
100      return NULL;
101   (void)rbug_screen(_resource->screen);
102   return (struct rbug_resource *)_resource;
103}
104
105static INLINE struct rbug_sampler_view *
106rbug_sampler_view(struct pipe_sampler_view *_sampler_view)
107{
108   if (!_sampler_view)
109      return NULL;
110   (void)rbug_resource(_sampler_view->texture);
111   return (struct rbug_sampler_view *)_sampler_view;
112}
113
114static INLINE struct rbug_surface *
115rbug_surface(struct pipe_surface *_surface)
116{
117   if (!_surface)
118      return NULL;
119   (void)rbug_resource(_surface->texture);
120   return (struct rbug_surface *)_surface;
121}
122
123static INLINE struct rbug_transfer *
124rbug_transfer(struct pipe_transfer *_transfer)
125{
126   if (!_transfer)
127      return NULL;
128   (void)rbug_resource(_transfer->resource);
129   return (struct rbug_transfer *)_transfer;
130}
131
132static INLINE struct rbug_shader *
133rbug_shader(void *_state)
134{
135   if (!_state)
136      return NULL;
137   return (struct rbug_shader *)_state;
138}
139
140static INLINE struct pipe_resource *
141rbug_resource_unwrap(struct pipe_resource *_resource)
142{
143   if (!_resource)
144      return NULL;
145   return rbug_resource(_resource)->resource;
146}
147
148static INLINE struct pipe_sampler_view *
149rbug_sampler_view_unwrap(struct pipe_sampler_view *_sampler_view)
150{
151   if (!_sampler_view)
152      return NULL;
153   return rbug_sampler_view(_sampler_view)->sampler_view;
154}
155
156static INLINE struct pipe_surface *
157rbug_surface_unwrap(struct pipe_surface *_surface)
158{
159   if (!_surface)
160      return NULL;
161   return rbug_surface(_surface)->surface;
162}
163
164static INLINE struct pipe_transfer *
165rbug_transfer_unwrap(struct pipe_transfer *_transfer)
166{
167   if (!_transfer)
168      return NULL;
169   return rbug_transfer(_transfer)->transfer;
170}
171
172static INLINE void *
173rbug_shader_unwrap(void *_state)
174{
175   struct rbug_shader *shader;
176   if (!_state)
177      return NULL;
178
179   shader = rbug_shader(_state);
180   return shader->replaced_shader ? shader->replaced_shader : shader->shader;
181}
182
183
184struct pipe_resource *
185rbug_resource_create(struct rbug_screen *rb_screen,
186                     struct pipe_resource *resource);
187
188void
189rbug_resource_destroy(struct rbug_resource *rb_resource);
190
191struct pipe_surface *
192rbug_surface_create(struct rbug_context *rb_context,
193                    struct rbug_resource *rb_resource,
194                    struct pipe_surface *surface);
195
196void
197rbug_surface_destroy(struct rbug_context *rb_context,
198                     struct rbug_surface *rb_surface);
199
200struct pipe_sampler_view *
201rbug_sampler_view_create(struct rbug_context *rb_context,
202                         struct rbug_resource *rb_resource,
203                         struct pipe_sampler_view *view);
204
205void
206rbug_sampler_view_destroy(struct rbug_context *rb_context,
207                          struct rbug_sampler_view *rb_sampler_view);
208
209struct pipe_transfer *
210rbug_transfer_create(struct rbug_context *rb_context,
211                     struct rbug_resource *rb_resource,
212                     struct pipe_transfer *transfer);
213
214void
215rbug_transfer_destroy(struct rbug_context *rb_context,
216                      struct rbug_transfer *rb_transfer);
217
218void *
219rbug_shader_create(struct rbug_context *rb_context,
220                   const struct pipe_shader_state *state,
221                   void *result, enum rbug_shader_type type);
222
223void
224rbug_shader_destroy(struct rbug_context *rb_context,
225                    struct rbug_shader *rb_shader);
226
227
228#endif /* RBUG_OBJECTS_H */
229