2 * Copyright 2010 Red Hat Inc.
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:
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
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.
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"
34 DEBUG_GET_ONCE_BOOL_OPTION(noop
, "GALLIUM_NOOP", FALSE
)
36 void noop_init_state_functions(struct pipe_context
*ctx
);
38 struct noop_pipe_screen
{
39 struct pipe_screen pscreen
;
40 struct pipe_screen
*oscreen
;
49 static struct pipe_query
*noop_create_query(struct pipe_context
*ctx
, unsigned query_type
)
51 struct noop_query
*query
= CALLOC_STRUCT(noop_query
);
53 return (struct pipe_query
*)query
;
56 static void noop_destroy_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
61 static void noop_begin_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
65 static void noop_end_query(struct pipe_context
*ctx
, struct pipe_query
*query
)
69 static boolean
noop_get_query_result(struct pipe_context
*ctx
,
70 struct pipe_query
*query
,
72 union pipe_query_result
*vresult
)
74 uint64_t *result
= (uint64_t*)vresult
;
84 struct noop_resource
{
85 struct pipe_resource base
;
88 struct sw_displaytarget
*dt
;
91 static struct pipe_resource
*noop_resource_create(struct pipe_screen
*screen
,
92 const struct pipe_resource
*templ
)
94 struct noop_resource
*nresource
;
97 nresource
= CALLOC_STRUCT(noop_resource
);
98 if (nresource
== NULL
)
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
) {
111 return &nresource
->base
;
114 static struct pipe_resource
*noop_resource_from_handle(struct pipe_screen
*screen
,
115 const struct pipe_resource
*templ
,
116 struct winsys_handle
*handle
)
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
;
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
;
129 static boolean
noop_resource_get_handle(struct pipe_screen
*screen
,
130 struct pipe_resource
*resource
,
131 struct winsys_handle
*handle
)
136 static void noop_resource_destroy(struct pipe_screen
*screen
,
137 struct pipe_resource
*resource
)
139 struct noop_resource
*nresource
= (struct noop_resource
*)resource
;
141 FREE(nresource
->data
);
145 static struct pipe_resource
*noop_user_buffer_create(struct pipe_screen
*screen
,
146 void *ptr
, unsigned bytes
,
149 struct pipe_resource templ
;
151 templ
.target
= PIPE_BUFFER
;
152 templ
.format
= PIPE_FORMAT_R8_UNORM
;
153 templ
.usage
= PIPE_USAGE_IMMUTABLE
;
155 templ
.width0
= bytes
;
159 return noop_resource_create(screen
, &templ
);
166 static struct pipe_transfer
*noop_get_transfer(struct pipe_context
*context
,
167 struct pipe_resource
*resource
,
169 enum pipe_transfer_usage usage
,
170 const struct pipe_box
*box
)
172 struct pipe_transfer
*transfer
;
174 transfer
= CALLOC_STRUCT(pipe_transfer
);
175 if (transfer
== NULL
)
177 pipe_resource_reference(&transfer
->resource
, resource
);
178 transfer
->level
= level
;
179 transfer
->usage
= usage
;
180 transfer
->box
= *box
;
181 transfer
->stride
= 1;
182 transfer
->layer_stride
= 1;
186 static void *noop_transfer_map(struct pipe_context
*pipe
,
187 struct pipe_transfer
*transfer
)
189 struct noop_resource
*nresource
= (struct noop_resource
*)transfer
->resource
;
191 return nresource
->data
;
194 static void noop_transfer_flush_region(struct pipe_context
*pipe
,
195 struct pipe_transfer
*transfer
,
196 const struct pipe_box
*box
)
200 static void noop_transfer_unmap(struct pipe_context
*pipe
,
201 struct pipe_transfer
*transfer
)
205 static void noop_transfer_destroy(struct pipe_context
*pipe
,
206 struct pipe_transfer
*transfer
)
208 pipe_resource_reference(&transfer
->resource
, NULL
);
212 static void noop_transfer_inline_write(struct pipe_context
*pipe
,
213 struct pipe_resource
*resource
,
216 const struct pipe_box
*box
,
219 unsigned layer_stride
)
227 static void noop_clear(struct pipe_context
*ctx
, unsigned buffers
,
228 const union pipe_color_union
*color
, double depth
, unsigned stencil
)
232 static void noop_clear_render_target(struct pipe_context
*ctx
,
233 struct pipe_surface
*dst
,
234 const union pipe_color_union
*color
,
235 unsigned dstx
, unsigned dsty
,
236 unsigned width
, unsigned height
)
240 static void noop_clear_depth_stencil(struct pipe_context
*ctx
,
241 struct pipe_surface
*dst
,
242 unsigned clear_flags
,
245 unsigned dstx
, unsigned dsty
,
246 unsigned width
, unsigned height
)
250 static void noop_resource_copy_region(struct pipe_context
*ctx
,
251 struct pipe_resource
*dst
,
253 unsigned dstx
, unsigned dsty
, unsigned dstz
,
254 struct pipe_resource
*src
,
256 const struct pipe_box
*src_box
)
264 static void noop_flush(struct pipe_context
*ctx
,
265 struct pipe_fence_handle
**fence
)
269 static void noop_destroy_context(struct pipe_context
*ctx
)
274 static struct pipe_context
*noop_create_context(struct pipe_screen
*screen
, void *priv
)
276 struct pipe_context
*ctx
= CALLOC_STRUCT(pipe_context
);
280 ctx
->screen
= screen
;
282 ctx
->destroy
= noop_destroy_context
;
283 ctx
->flush
= noop_flush
;
284 ctx
->clear
= noop_clear
;
285 ctx
->clear_render_target
= noop_clear_render_target
;
286 ctx
->clear_depth_stencil
= noop_clear_depth_stencil
;
287 ctx
->resource_copy_region
= noop_resource_copy_region
;
288 ctx
->create_query
= noop_create_query
;
289 ctx
->destroy_query
= noop_destroy_query
;
290 ctx
->begin_query
= noop_begin_query
;
291 ctx
->end_query
= noop_end_query
;
292 ctx
->get_query_result
= noop_get_query_result
;
293 ctx
->get_transfer
= noop_get_transfer
;
294 ctx
->transfer_map
= noop_transfer_map
;
295 ctx
->transfer_flush_region
= noop_transfer_flush_region
;
296 ctx
->transfer_unmap
= noop_transfer_unmap
;
297 ctx
->transfer_destroy
= noop_transfer_destroy
;
298 ctx
->transfer_inline_write
= noop_transfer_inline_write
;
299 noop_init_state_functions(ctx
);
308 static void noop_flush_frontbuffer(struct pipe_screen
*_screen
,
309 struct pipe_resource
*resource
,
310 unsigned level
, unsigned layer
,
311 void *context_private
)
315 static const char *noop_get_vendor(struct pipe_screen
* pscreen
)
320 static const char *noop_get_name(struct pipe_screen
* pscreen
)
325 static int noop_get_param(struct pipe_screen
* pscreen
, enum pipe_cap param
)
327 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
329 return screen
->get_param(screen
, param
);
332 static float noop_get_paramf(struct pipe_screen
* pscreen
,
333 enum pipe_capf param
)
335 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
337 return screen
->get_paramf(screen
, param
);
340 static int noop_get_shader_param(struct pipe_screen
* pscreen
, unsigned shader
, enum pipe_shader_cap param
)
342 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
344 return screen
->get_shader_param(screen
, shader
, param
);
347 static boolean
noop_is_format_supported(struct pipe_screen
* pscreen
,
348 enum pipe_format format
,
349 enum pipe_texture_target target
,
350 unsigned sample_count
,
353 struct pipe_screen
*screen
= ((struct noop_pipe_screen
*)pscreen
)->oscreen
;
355 return screen
->is_format_supported(screen
, format
, target
, sample_count
, usage
);
358 static void noop_destroy_screen(struct pipe_screen
*screen
)
360 struct noop_pipe_screen
*noop_screen
= (struct noop_pipe_screen
*)screen
;
361 struct pipe_screen
*oscreen
= noop_screen
->oscreen
;
363 oscreen
->destroy(oscreen
);
367 struct pipe_screen
*noop_screen_create(struct pipe_screen
*oscreen
)
369 struct noop_pipe_screen
*noop_screen
;
370 struct pipe_screen
*screen
;
372 if (!debug_get_option_noop()) {
376 noop_screen
= CALLOC_STRUCT(noop_pipe_screen
);
377 if (noop_screen
== NULL
) {
380 noop_screen
->oscreen
= oscreen
;
381 screen
= &noop_screen
->pscreen
;
383 screen
->destroy
= noop_destroy_screen
;
384 screen
->get_name
= noop_get_name
;
385 screen
->get_vendor
= noop_get_vendor
;
386 screen
->get_param
= noop_get_param
;
387 screen
->get_shader_param
= noop_get_shader_param
;
388 screen
->get_paramf
= noop_get_paramf
;
389 screen
->is_format_supported
= noop_is_format_supported
;
390 screen
->context_create
= noop_create_context
;
391 screen
->resource_create
= noop_resource_create
;
392 screen
->resource_from_handle
= noop_resource_from_handle
;
393 screen
->resource_get_handle
= noop_resource_get_handle
;
394 screen
->resource_destroy
= noop_resource_destroy
;
395 screen
->user_buffer_create
= noop_user_buffer_create
;
396 screen
->flush_frontbuffer
= noop_flush_frontbuffer
;