Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * Copyright 2010 Red Hat Inc. |
||
3 | * |
||
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
5 | * copy of this software and associated documentation files (the "Software"), |
||
6 | * to deal in the Software without restriction, including without limitation |
||
7 | * on the rights to use, copy, modify, merge, publish, distribute, sub |
||
8 | * license, and/or sell copies of the Software, and to permit persons to whom |
||
9 | * the Software is furnished to do so, subject to the following conditions: |
||
10 | * |
||
11 | * The above copyright notice and this permission notice (including the next |
||
12 | * paragraph) shall be included in all copies or substantial portions of the |
||
13 | * Software. |
||
14 | * |
||
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL |
||
18 | * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, |
||
19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
||
20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
||
21 | * USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
22 | */ |
||
23 | #include |
||
24 | #include |
||
25 | #include "pipe/p_defines.h" |
||
26 | #include "pipe/p_state.h" |
||
27 | #include "pipe/p_context.h" |
||
28 | #include "pipe/p_screen.h" |
||
29 | #include "util/u_memory.h" |
||
30 | #include "util/u_inlines.h" |
||
31 | #include "util/u_format.h" |
||
32 | #include "noop_public.h" |
||
33 | |||
34 | DEBUG_GET_ONCE_BOOL_OPTION(noop, "GALLIUM_NOOP", FALSE) |
||
35 | |||
36 | void noop_init_state_functions(struct pipe_context *ctx); |
||
37 | |||
38 | struct noop_pipe_screen { |
||
39 | struct pipe_screen pscreen; |
||
40 | struct pipe_screen *oscreen; |
||
41 | }; |
||
42 | |||
43 | /* |
||
44 | * query |
||
45 | */ |
||
46 | struct noop_query { |
||
47 | unsigned query; |
||
48 | }; |
||
49 | static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type) |
||
50 | { |
||
51 | struct noop_query *query = CALLOC_STRUCT(noop_query); |
||
52 | |||
53 | return (struct pipe_query *)query; |
||
54 | } |
||
55 | |||
56 | static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query) |
||
57 | { |
||
58 | FREE(query); |
||
59 | } |
||
60 | |||
61 | static void noop_begin_query(struct pipe_context *ctx, struct pipe_query *query) |
||
62 | { |
||
63 | } |
||
64 | |||
65 | static void noop_end_query(struct pipe_context *ctx, struct pipe_query *query) |
||
66 | { |
||
67 | } |
||
68 | |||
69 | static boolean noop_get_query_result(struct pipe_context *ctx, |
||
70 | struct pipe_query *query, |
||
71 | boolean wait, |
||
72 | union pipe_query_result *vresult) |
||
73 | { |
||
74 | uint64_t *result = (uint64_t*)vresult; |
||
75 | |||
76 | *result = 0; |
||
77 | return TRUE; |
||
78 | } |
||
79 | |||
80 | |||
81 | /* |
||
82 | * resource |
||
83 | */ |
||
84 | struct noop_resource { |
||
85 | struct pipe_resource base; |
||
86 | unsigned size; |
||
87 | char *data; |
||
88 | struct sw_displaytarget *dt; |
||
89 | }; |
||
90 | |||
91 | static struct pipe_resource *noop_resource_create(struct pipe_screen *screen, |
||
92 | const struct pipe_resource *templ) |
||
93 | { |
||
94 | struct noop_resource *nresource; |
||
95 | unsigned stride; |
||
96 | |||
97 | nresource = CALLOC_STRUCT(noop_resource); |
||
98 | if (nresource == NULL) |
||
99 | return NULL; |
||
100 | |||
101 | stride = util_format_get_stride(templ->format, templ->width0); |
||
102 | nresource->base = *templ; |
||
103 | nresource->base.screen = screen; |
||
104 | nresource->size = stride * templ->height0 * templ->depth0; |
||
105 | nresource->data = MALLOC(nresource->size); |
||
106 | pipe_reference_init(&nresource->base.reference, 1); |
||
107 | if (nresource->data == NULL) { |
||
108 | FREE(nresource); |
||
109 | return NULL; |
||
110 | } |
||
111 | return &nresource->base; |
||
112 | } |
||
113 | |||
114 | static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen, |
||
115 | const struct pipe_resource *templ, |
||
116 | struct winsys_handle *handle) |
||
117 | { |
||
118 | struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen; |
||
119 | struct pipe_screen *oscreen = noop_screen->oscreen; |
||
120 | struct pipe_resource *result; |
||
121 | struct pipe_resource *noop_resource; |
||
122 | |||
123 | result = oscreen->resource_from_handle(oscreen, templ, handle); |
||
124 | noop_resource = noop_resource_create(screen, result); |
||
125 | pipe_resource_reference(&result, NULL); |
||
126 | return noop_resource; |
||
127 | } |
||
128 | |||
129 | static boolean noop_resource_get_handle(struct pipe_screen *screen, |
||
130 | struct pipe_resource *resource, |
||
131 | struct winsys_handle *handle) |
||
132 | { |
||
133 | return FALSE; |
||
134 | } |
||
135 | |||
136 | static void noop_resource_destroy(struct pipe_screen *screen, |
||
137 | struct pipe_resource *resource) |
||
138 | { |
||
139 | struct noop_resource *nresource = (struct noop_resource *)resource; |
||
140 | |||
141 | FREE(nresource->data); |
||
142 | FREE(resource); |
||
143 | } |
||
144 | |||
145 | |||
146 | /* |
||
147 | * transfer |
||
148 | */ |
||
149 | static void *noop_transfer_map(struct pipe_context *pipe, |
||
150 | struct pipe_resource *resource, |
||
151 | unsigned level, |
||
152 | enum pipe_transfer_usage usage, |
||
153 | const struct pipe_box *box, |
||
154 | struct pipe_transfer **ptransfer) |
||
155 | { |
||
156 | struct pipe_transfer *transfer; |
||
157 | struct noop_resource *nresource = (struct noop_resource *)resource; |
||
158 | |||
159 | transfer = CALLOC_STRUCT(pipe_transfer); |
||
160 | if (transfer == NULL) |
||
161 | return NULL; |
||
162 | pipe_resource_reference(&transfer->resource, resource); |
||
163 | transfer->level = level; |
||
164 | transfer->usage = usage; |
||
165 | transfer->box = *box; |
||
166 | transfer->stride = 1; |
||
167 | transfer->layer_stride = 1; |
||
168 | *ptransfer = transfer; |
||
169 | |||
170 | return nresource->data; |
||
171 | } |
||
172 | |||
173 | static void noop_transfer_flush_region(struct pipe_context *pipe, |
||
174 | struct pipe_transfer *transfer, |
||
175 | const struct pipe_box *box) |
||
176 | { |
||
177 | } |
||
178 | |||
179 | static void noop_transfer_unmap(struct pipe_context *pipe, |
||
180 | struct pipe_transfer *transfer) |
||
181 | { |
||
182 | pipe_resource_reference(&transfer->resource, NULL); |
||
183 | FREE(transfer); |
||
184 | } |
||
185 | |||
186 | static void noop_transfer_inline_write(struct pipe_context *pipe, |
||
187 | struct pipe_resource *resource, |
||
188 | unsigned level, |
||
189 | unsigned usage, |
||
190 | const struct pipe_box *box, |
||
191 | const void *data, |
||
192 | unsigned stride, |
||
193 | unsigned layer_stride) |
||
194 | { |
||
195 | } |
||
196 | |||
197 | |||
198 | /* |
||
199 | * clear/copy |
||
200 | */ |
||
201 | static void noop_clear(struct pipe_context *ctx, unsigned buffers, |
||
202 | const union pipe_color_union *color, double depth, unsigned stencil) |
||
203 | { |
||
204 | } |
||
205 | |||
206 | static void noop_clear_render_target(struct pipe_context *ctx, |
||
207 | struct pipe_surface *dst, |
||
208 | const union pipe_color_union *color, |
||
209 | unsigned dstx, unsigned dsty, |
||
210 | unsigned width, unsigned height) |
||
211 | { |
||
212 | } |
||
213 | |||
214 | static void noop_clear_depth_stencil(struct pipe_context *ctx, |
||
215 | struct pipe_surface *dst, |
||
216 | unsigned clear_flags, |
||
217 | double depth, |
||
218 | unsigned stencil, |
||
219 | unsigned dstx, unsigned dsty, |
||
220 | unsigned width, unsigned height) |
||
221 | { |
||
222 | } |
||
223 | |||
224 | static void noop_resource_copy_region(struct pipe_context *ctx, |
||
225 | struct pipe_resource *dst, |
||
226 | unsigned dst_level, |
||
227 | unsigned dstx, unsigned dsty, unsigned dstz, |
||
228 | struct pipe_resource *src, |
||
229 | unsigned src_level, |
||
230 | const struct pipe_box *src_box) |
||
231 | { |
||
232 | } |
||
233 | |||
234 | |||
235 | static void noop_blit(struct pipe_context *ctx, |
||
236 | const struct pipe_blit_info *info) |
||
237 | { |
||
238 | } |
||
239 | |||
240 | |||
241 | /* |
||
242 | * context |
||
243 | */ |
||
244 | static void noop_flush(struct pipe_context *ctx, |
||
245 | struct pipe_fence_handle **fence, |
||
246 | unsigned flags) |
||
247 | { |
||
248 | } |
||
249 | |||
250 | static void noop_destroy_context(struct pipe_context *ctx) |
||
251 | { |
||
252 | FREE(ctx); |
||
253 | } |
||
254 | |||
255 | static struct pipe_context *noop_create_context(struct pipe_screen *screen, void *priv) |
||
256 | { |
||
257 | struct pipe_context *ctx = CALLOC_STRUCT(pipe_context); |
||
258 | |||
259 | if (ctx == NULL) |
||
260 | return NULL; |
||
261 | ctx->screen = screen; |
||
262 | ctx->priv = priv; |
||
263 | ctx->destroy = noop_destroy_context; |
||
264 | ctx->flush = noop_flush; |
||
265 | ctx->clear = noop_clear; |
||
266 | ctx->clear_render_target = noop_clear_render_target; |
||
267 | ctx->clear_depth_stencil = noop_clear_depth_stencil; |
||
268 | ctx->resource_copy_region = noop_resource_copy_region; |
||
269 | ctx->blit = noop_blit; |
||
270 | ctx->create_query = noop_create_query; |
||
271 | ctx->destroy_query = noop_destroy_query; |
||
272 | ctx->begin_query = noop_begin_query; |
||
273 | ctx->end_query = noop_end_query; |
||
274 | ctx->get_query_result = noop_get_query_result; |
||
275 | ctx->transfer_map = noop_transfer_map; |
||
276 | ctx->transfer_flush_region = noop_transfer_flush_region; |
||
277 | ctx->transfer_unmap = noop_transfer_unmap; |
||
278 | ctx->transfer_inline_write = noop_transfer_inline_write; |
||
279 | noop_init_state_functions(ctx); |
||
280 | |||
281 | return ctx; |
||
282 | } |
||
283 | |||
284 | |||
285 | /* |
||
286 | * pipe_screen |
||
287 | */ |
||
288 | static void noop_flush_frontbuffer(struct pipe_screen *_screen, |
||
289 | struct pipe_resource *resource, |
||
290 | unsigned level, unsigned layer, |
||
291 | void *context_private) |
||
292 | { |
||
293 | } |
||
294 | |||
295 | static const char *noop_get_vendor(struct pipe_screen* pscreen) |
||
296 | { |
||
297 | return "X.Org"; |
||
298 | } |
||
299 | |||
300 | static const char *noop_get_name(struct pipe_screen* pscreen) |
||
301 | { |
||
302 | return "NOOP"; |
||
303 | } |
||
304 | |||
305 | static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param) |
||
306 | { |
||
307 | struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen; |
||
308 | |||
309 | return screen->get_param(screen, param); |
||
310 | } |
||
311 | |||
312 | static float noop_get_paramf(struct pipe_screen* pscreen, |
||
313 | enum pipe_capf param) |
||
314 | { |
||
315 | struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen; |
||
316 | |||
317 | return screen->get_paramf(screen, param); |
||
318 | } |
||
319 | |||
320 | static int noop_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param) |
||
321 | { |
||
322 | struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen; |
||
323 | |||
324 | return screen->get_shader_param(screen, shader, param); |
||
325 | } |
||
326 | |||
327 | static boolean noop_is_format_supported(struct pipe_screen* pscreen, |
||
328 | enum pipe_format format, |
||
329 | enum pipe_texture_target target, |
||
330 | unsigned sample_count, |
||
331 | unsigned usage) |
||
332 | { |
||
333 | struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen; |
||
334 | |||
335 | return screen->is_format_supported(screen, format, target, sample_count, usage); |
||
336 | } |
||
337 | |||
338 | static uint64_t noop_get_timestamp(struct pipe_screen *pscreen) |
||
339 | { |
||
340 | return 0; |
||
341 | } |
||
342 | |||
343 | static void noop_destroy_screen(struct pipe_screen *screen) |
||
344 | { |
||
345 | struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen; |
||
346 | struct pipe_screen *oscreen = noop_screen->oscreen; |
||
347 | |||
348 | oscreen->destroy(oscreen); |
||
349 | FREE(screen); |
||
350 | } |
||
351 | |||
352 | struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen) |
||
353 | { |
||
354 | struct noop_pipe_screen *noop_screen; |
||
355 | struct pipe_screen *screen; |
||
356 | |||
357 | if (!debug_get_option_noop()) { |
||
358 | return oscreen; |
||
359 | } |
||
360 | |||
361 | noop_screen = CALLOC_STRUCT(noop_pipe_screen); |
||
362 | if (noop_screen == NULL) { |
||
363 | return NULL; |
||
364 | } |
||
365 | noop_screen->oscreen = oscreen; |
||
366 | screen = &noop_screen->pscreen; |
||
367 | |||
368 | screen->destroy = noop_destroy_screen; |
||
369 | screen->get_name = noop_get_name; |
||
370 | screen->get_vendor = noop_get_vendor; |
||
371 | screen->get_param = noop_get_param; |
||
372 | screen->get_shader_param = noop_get_shader_param; |
||
373 | screen->get_paramf = noop_get_paramf; |
||
374 | screen->is_format_supported = noop_is_format_supported; |
||
375 | screen->context_create = noop_create_context; |
||
376 | screen->resource_create = noop_resource_create; |
||
377 | screen->resource_from_handle = noop_resource_from_handle; |
||
378 | screen->resource_get_handle = noop_resource_get_handle; |
||
379 | screen->resource_destroy = noop_resource_destroy; |
||
380 | screen->flush_frontbuffer = noop_flush_frontbuffer; |
||
381 | screen->get_timestamp = noop_get_timestamp; |
||
382 | |||
383 | return screen; |
||
384 | } |