1 /**************************************************************************
3 * Copyright 2009 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 **************************************************************************/
29 #include "pipe/p_context.h"
30 #include "util/u_memory.h"
32 #include "id_public.h"
33 #include "id_context.h"
34 #include "id_objects.h"
38 identity_destroy(struct pipe_context
*_pipe
)
40 struct identity_context
*id_pipe
= identity_context(_pipe
);
41 struct pipe_context
*pipe
= id_pipe
->pipe
;
49 identity_draw_arrays(struct pipe_context
*_pipe
,
54 struct identity_context
*id_pipe
= identity_context(_pipe
);
55 struct pipe_context
*pipe
= id_pipe
->pipe
;
57 return pipe
->draw_arrays(pipe
,
64 identity_draw_elements(struct pipe_context
*_pipe
,
65 struct pipe_buffer
*_indexBuffer
,
71 struct identity_context
*id_pipe
= identity_context(_pipe
);
72 struct identity_buffer
*id_buffer
= identity_buffer(_indexBuffer
);
73 struct pipe_context
*pipe
= id_pipe
->pipe
;
74 struct pipe_buffer
*indexBuffer
= id_buffer
->buffer
;
76 return pipe
->draw_elements(pipe
,
85 identity_draw_range_elements(struct pipe_context
*_pipe
,
86 struct pipe_buffer
*_indexBuffer
,
94 struct identity_context
*id_pipe
= identity_context(_pipe
);
95 struct identity_buffer
*id_buffer
= identity_buffer(_indexBuffer
);
96 struct pipe_context
*pipe
= id_pipe
->pipe
;
97 struct pipe_buffer
*indexBuffer
= id_buffer
->buffer
;
99 return pipe
->draw_range_elements(pipe
,
109 static struct pipe_query
*
110 identity_create_query(struct pipe_context
*_pipe
,
113 struct identity_context
*id_pipe
= identity_context(_pipe
);
114 struct pipe_context
*pipe
= id_pipe
->pipe
;
116 return pipe
->create_query(pipe
,
121 identity_destroy_query(struct pipe_context
*_pipe
,
122 struct pipe_query
*query
)
124 struct identity_context
*id_pipe
= identity_context(_pipe
);
125 struct pipe_context
*pipe
= id_pipe
->pipe
;
127 pipe
->destroy_query(pipe
,
132 identity_begin_query(struct pipe_context
*_pipe
,
133 struct pipe_query
*query
)
135 struct identity_context
*id_pipe
= identity_context(_pipe
);
136 struct pipe_context
*pipe
= id_pipe
->pipe
;
138 pipe
->begin_query(pipe
,
143 identity_end_query(struct pipe_context
*_pipe
,
144 struct pipe_query
*query
)
146 struct identity_context
*id_pipe
= identity_context(_pipe
);
147 struct pipe_context
*pipe
= id_pipe
->pipe
;
149 pipe
->end_query(pipe
,
154 identity_get_query_result(struct pipe_context
*_pipe
,
155 struct pipe_query
*query
,
159 struct identity_context
*id_pipe
= identity_context(_pipe
);
160 struct pipe_context
*pipe
= id_pipe
->pipe
;
162 return pipe
->get_query_result(pipe
,
169 identity_create_blend_state(struct pipe_context
*_pipe
,
170 const struct pipe_blend_state
*blend
)
172 struct identity_context
*id_pipe
= identity_context(_pipe
);
173 struct pipe_context
*pipe
= id_pipe
->pipe
;
175 return pipe
->create_blend_state(pipe
,
180 identity_bind_blend_state(struct pipe_context
*_pipe
,
183 struct identity_context
*id_pipe
= identity_context(_pipe
);
184 struct pipe_context
*pipe
= id_pipe
->pipe
;
186 pipe
->bind_blend_state(pipe
,
191 identity_delete_blend_state(struct pipe_context
*_pipe
,
194 struct identity_context
*id_pipe
= identity_context(_pipe
);
195 struct pipe_context
*pipe
= id_pipe
->pipe
;
197 pipe
->delete_blend_state(pipe
,
202 identity_create_sampler_state(struct pipe_context
*_pipe
,
203 const struct pipe_sampler_state
*sampler
)
205 struct identity_context
*id_pipe
= identity_context(_pipe
);
206 struct pipe_context
*pipe
= id_pipe
->pipe
;
208 return pipe
->create_sampler_state(pipe
,
213 identity_bind_fragment_sampler_states(struct pipe_context
*_pipe
,
214 unsigned num_samplers
,
217 struct identity_context
*id_pipe
= identity_context(_pipe
);
218 struct pipe_context
*pipe
= id_pipe
->pipe
;
220 pipe
->bind_fragment_sampler_states(pipe
,
226 identity_bind_vertex_sampler_states(struct pipe_context
*_pipe
,
227 unsigned num_samplers
,
230 struct identity_context
*id_pipe
= identity_context(_pipe
);
231 struct pipe_context
*pipe
= id_pipe
->pipe
;
233 pipe
->bind_vertex_sampler_states(pipe
,
239 identity_delete_sampler_state(struct pipe_context
*_pipe
,
242 struct identity_context
*id_pipe
= identity_context(_pipe
);
243 struct pipe_context
*pipe
= id_pipe
->pipe
;
245 pipe
->delete_sampler_state(pipe
,
250 identity_create_rasterizer_state(struct pipe_context
*_pipe
,
251 const struct pipe_rasterizer_state
*rasterizer
)
253 struct identity_context
*id_pipe
= identity_context(_pipe
);
254 struct pipe_context
*pipe
= id_pipe
->pipe
;
256 return pipe
->create_rasterizer_state(pipe
,
261 identity_bind_rasterizer_state(struct pipe_context
*_pipe
,
264 struct identity_context
*id_pipe
= identity_context(_pipe
);
265 struct pipe_context
*pipe
= id_pipe
->pipe
;
267 pipe
->bind_rasterizer_state(pipe
,
272 identity_delete_rasterizer_state(struct pipe_context
*_pipe
,
275 struct identity_context
*id_pipe
= identity_context(_pipe
);
276 struct pipe_context
*pipe
= id_pipe
->pipe
;
278 pipe
->delete_rasterizer_state(pipe
,
283 identity_create_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
284 const struct pipe_depth_stencil_alpha_state
*depth_stencil_alpha
)
286 struct identity_context
*id_pipe
= identity_context(_pipe
);
287 struct pipe_context
*pipe
= id_pipe
->pipe
;
289 return pipe
->create_depth_stencil_alpha_state(pipe
,
290 depth_stencil_alpha
);
294 identity_bind_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
295 void *depth_stencil_alpha
)
297 struct identity_context
*id_pipe
= identity_context(_pipe
);
298 struct pipe_context
*pipe
= id_pipe
->pipe
;
300 pipe
->bind_depth_stencil_alpha_state(pipe
,
301 depth_stencil_alpha
);
305 identity_delete_depth_stencil_alpha_state(struct pipe_context
*_pipe
,
306 void *depth_stencil_alpha
)
308 struct identity_context
*id_pipe
= identity_context(_pipe
);
309 struct pipe_context
*pipe
= id_pipe
->pipe
;
311 pipe
->delete_depth_stencil_alpha_state(pipe
,
312 depth_stencil_alpha
);
316 identity_create_fs_state(struct pipe_context
*_pipe
,
317 const struct pipe_shader_state
*fs
)
319 struct identity_context
*id_pipe
= identity_context(_pipe
);
320 struct pipe_context
*pipe
= id_pipe
->pipe
;
322 return pipe
->create_fs_state(pipe
,
327 identity_bind_fs_state(struct pipe_context
*_pipe
,
330 struct identity_context
*id_pipe
= identity_context(_pipe
);
331 struct pipe_context
*pipe
= id_pipe
->pipe
;
333 pipe
->bind_fs_state(pipe
,
338 identity_delete_fs_state(struct pipe_context
*_pipe
,
341 struct identity_context
*id_pipe
= identity_context(_pipe
);
342 struct pipe_context
*pipe
= id_pipe
->pipe
;
344 pipe
->delete_fs_state(pipe
,
349 identity_create_vs_state(struct pipe_context
*_pipe
,
350 const struct pipe_shader_state
*vs
)
352 struct identity_context
*id_pipe
= identity_context(_pipe
);
353 struct pipe_context
*pipe
= id_pipe
->pipe
;
355 return pipe
->create_vs_state(pipe
,
360 identity_bind_vs_state(struct pipe_context
*_pipe
,
363 struct identity_context
*id_pipe
= identity_context(_pipe
);
364 struct pipe_context
*pipe
= id_pipe
->pipe
;
366 pipe
->bind_vs_state(pipe
,
371 identity_delete_vs_state(struct pipe_context
*_pipe
,
374 struct identity_context
*id_pipe
= identity_context(_pipe
);
375 struct pipe_context
*pipe
= id_pipe
->pipe
;
377 pipe
->delete_vs_state(pipe
,
382 identity_set_blend_color(struct pipe_context
*_pipe
,
383 const struct pipe_blend_color
*blend_color
)
385 struct identity_context
*id_pipe
= identity_context(_pipe
);
386 struct pipe_context
*pipe
= id_pipe
->pipe
;
388 pipe
->set_blend_color(pipe
,
393 identity_set_clip_state(struct pipe_context
*_pipe
,
394 const struct pipe_clip_state
*clip
)
396 struct identity_context
*id_pipe
= identity_context(_pipe
);
397 struct pipe_context
*pipe
= id_pipe
->pipe
;
399 pipe
->set_clip_state(pipe
,
404 identity_set_constant_buffer(struct pipe_context
*_pipe
,
407 struct pipe_buffer
*_buffer
)
409 struct identity_context
*id_pipe
= identity_context(_pipe
);
410 struct pipe_context
*pipe
= id_pipe
->pipe
;
411 struct pipe_buffer
*unwrapped_buffer
;
412 struct pipe_buffer
*buffer
= NULL
;
414 /* XXX hmm? unwrap the input state */
416 unwrapped_buffer
= identity_buffer_unwrap(_buffer
);
417 buffer
= unwrapped_buffer
;
420 pipe
->set_constant_buffer(pipe
,
427 identity_set_framebuffer_state(struct pipe_context
*_pipe
,
428 const struct pipe_framebuffer_state
*_state
)
430 struct identity_context
*id_pipe
= identity_context(_pipe
);
431 struct pipe_context
*pipe
= id_pipe
->pipe
;
432 struct pipe_framebuffer_state unwrapped_state
;
433 struct pipe_framebuffer_state
*state
= NULL
;
436 /* unwrap the input state */
438 memcpy(&unwrapped_state
, _state
, sizeof(unwrapped_state
));
439 for(i
= 0; i
< _state
->nr_cbufs
; i
++)
440 unwrapped_state
.cbufs
[i
] = identity_surface_unwrap(_state
->cbufs
[i
]);
441 for (; i
< PIPE_MAX_COLOR_BUFS
; i
++)
442 unwrapped_state
.cbufs
[i
] = NULL
;
443 unwrapped_state
.zsbuf
= identity_surface_unwrap(_state
->zsbuf
);
444 state
= &unwrapped_state
;
447 pipe
->set_framebuffer_state(pipe
,
452 identity_set_polygon_stipple(struct pipe_context
*_pipe
,
453 const struct pipe_poly_stipple
*poly_stipple
)
455 struct identity_context
*id_pipe
= identity_context(_pipe
);
456 struct pipe_context
*pipe
= id_pipe
->pipe
;
458 pipe
->set_polygon_stipple(pipe
,
463 identity_set_scissor_state(struct pipe_context
*_pipe
,
464 const struct pipe_scissor_state
*scissor
)
466 struct identity_context
*id_pipe
= identity_context(_pipe
);
467 struct pipe_context
*pipe
= id_pipe
->pipe
;
469 pipe
->set_scissor_state(pipe
,
474 identity_set_viewport_state(struct pipe_context
*_pipe
,
475 const struct pipe_viewport_state
*viewport
)
477 struct identity_context
*id_pipe
= identity_context(_pipe
);
478 struct pipe_context
*pipe
= id_pipe
->pipe
;
480 pipe
->set_viewport_state(pipe
,
485 identity_set_fragment_sampler_textures(struct pipe_context
*_pipe
,
486 unsigned num_textures
,
487 struct pipe_texture
**_textures
)
489 struct identity_context
*id_pipe
= identity_context(_pipe
);
490 struct pipe_context
*pipe
= id_pipe
->pipe
;
491 struct pipe_texture
*unwrapped_textures
[PIPE_MAX_SAMPLERS
];
492 struct pipe_texture
**textures
= NULL
;
496 for (i
= 0; i
< num_textures
; i
++)
497 unwrapped_textures
[i
] = identity_texture_unwrap(_textures
[i
]);
498 for (; i
< PIPE_MAX_SAMPLERS
; i
++)
499 unwrapped_textures
[i
] = NULL
;
501 textures
= unwrapped_textures
;
504 pipe
->set_fragment_sampler_textures(pipe
,
510 identity_set_vertex_sampler_textures(struct pipe_context
*_pipe
,
511 unsigned num_textures
,
512 struct pipe_texture
**_textures
)
514 struct identity_context
*id_pipe
= identity_context(_pipe
);
515 struct pipe_context
*pipe
= id_pipe
->pipe
;
516 struct pipe_texture
*unwrapped_textures
[PIPE_MAX_VERTEX_SAMPLERS
];
517 struct pipe_texture
**textures
= NULL
;
521 for (i
= 0; i
< num_textures
; i
++)
522 unwrapped_textures
[i
] = identity_texture_unwrap(_textures
[i
]);
523 for (; i
< PIPE_MAX_VERTEX_SAMPLERS
; i
++)
524 unwrapped_textures
[i
] = NULL
;
526 textures
= unwrapped_textures
;
529 pipe
->set_vertex_sampler_textures(pipe
,
535 identity_set_vertex_buffers(struct pipe_context
*_pipe
,
536 unsigned num_buffers
,
537 const struct pipe_vertex_buffer
*_buffers
)
539 struct identity_context
*id_pipe
= identity_context(_pipe
);
540 struct pipe_context
*pipe
= id_pipe
->pipe
;
541 struct pipe_vertex_buffer unwrapped_buffers
[PIPE_MAX_SHADER_INPUTS
];
542 struct pipe_vertex_buffer
*buffers
= NULL
;
546 memcpy(unwrapped_buffers
, _buffers
, num_buffers
* sizeof(*_buffers
));
547 for (i
= 0; i
< num_buffers
; i
++)
548 unwrapped_buffers
[i
].buffer
= identity_buffer_unwrap(_buffers
[i
].buffer
);
549 buffers
= unwrapped_buffers
;
552 pipe
->set_vertex_buffers(pipe
,
558 identity_set_vertex_elements(struct pipe_context
*_pipe
,
559 unsigned num_elements
,
560 const struct pipe_vertex_element
*vertex_elements
)
562 struct identity_context
*id_pipe
= identity_context(_pipe
);
563 struct pipe_context
*pipe
= id_pipe
->pipe
;
565 pipe
->set_vertex_elements(pipe
,
571 identity_surface_copy(struct pipe_context
*_pipe
,
572 struct pipe_surface
*_dst
,
575 struct pipe_surface
*_src
,
581 struct identity_context
*id_pipe
= identity_context(_pipe
);
582 struct identity_surface
*id_surface_dst
= identity_surface(_dst
);
583 struct identity_surface
*id_surface_src
= identity_surface(_src
);
584 struct pipe_context
*pipe
= id_pipe
->pipe
;
585 struct pipe_surface
*dst
= id_surface_dst
->surface
;
586 struct pipe_surface
*src
= id_surface_src
->surface
;
588 pipe
->surface_copy(pipe
,
600 identity_surface_fill(struct pipe_context
*_pipe
,
601 struct pipe_surface
*_dst
,
608 struct identity_context
*id_pipe
= identity_context(_pipe
);
609 struct identity_surface
*id_surface_dst
= identity_surface(_dst
);
610 struct pipe_context
*pipe
= id_pipe
->pipe
;
611 struct pipe_surface
*dst
= id_surface_dst
->surface
;
613 pipe
->surface_fill(pipe
,
623 identity_clear(struct pipe_context
*_pipe
,
629 struct identity_context
*id_pipe
= identity_context(_pipe
);
630 struct pipe_context
*pipe
= id_pipe
->pipe
;
640 identity_flush(struct pipe_context
*_pipe
,
642 struct pipe_fence_handle
**fence
)
644 struct identity_context
*id_pipe
= identity_context(_pipe
);
645 struct pipe_context
*pipe
= id_pipe
->pipe
;
653 identity_is_texture_referenced(struct pipe_context
*_pipe
,
654 struct pipe_texture
*_texture
,
658 struct identity_context
*id_pipe
= identity_context(_pipe
);
659 struct identity_texture
*id_texture
= identity_texture(_texture
);
660 struct pipe_context
*pipe
= id_pipe
->pipe
;
661 struct pipe_texture
*texture
= id_texture
->texture
;
663 return pipe
->is_texture_referenced(pipe
,
670 identity_is_buffer_referenced(struct pipe_context
*_pipe
,
671 struct pipe_buffer
*_buffer
)
673 struct identity_context
*id_pipe
= identity_context(_pipe
);
674 struct identity_buffer
*id_buffer
= identity_buffer(_buffer
);
675 struct pipe_context
*pipe
= id_pipe
->pipe
;
676 struct pipe_buffer
*buffer
= id_buffer
->buffer
;
678 return pipe
->is_buffer_referenced(pipe
,
682 struct pipe_context
*
683 identity_context_create(struct pipe_screen
*_screen
, struct pipe_context
*pipe
)
685 struct identity_context
*id_pipe
;
686 (void)identity_screen(_screen
);
688 id_pipe
= CALLOC_STRUCT(identity_context
);
693 id_pipe
->base
.winsys
= NULL
;
694 id_pipe
->base
.screen
= _screen
;
695 id_pipe
->base
.priv
= pipe
->priv
;
696 id_pipe
->base
.draw
= NULL
;
698 id_pipe
->base
.destroy
= identity_destroy
;
699 id_pipe
->base
.draw_arrays
= identity_draw_arrays
;
700 id_pipe
->base
.draw_elements
= identity_draw_elements
;
701 id_pipe
->base
.draw_range_elements
= identity_draw_range_elements
;
702 id_pipe
->base
.create_query
= identity_create_query
;
703 id_pipe
->base
.destroy_query
= identity_destroy_query
;
704 id_pipe
->base
.begin_query
= identity_begin_query
;
705 id_pipe
->base
.end_query
= identity_end_query
;
706 id_pipe
->base
.get_query_result
= identity_get_query_result
;
707 id_pipe
->base
.create_blend_state
= identity_create_blend_state
;
708 id_pipe
->base
.bind_blend_state
= identity_bind_blend_state
;
709 id_pipe
->base
.delete_blend_state
= identity_delete_blend_state
;
710 id_pipe
->base
.create_sampler_state
= identity_create_sampler_state
;
711 id_pipe
->base
.bind_fragment_sampler_states
= identity_bind_fragment_sampler_states
;
712 id_pipe
->base
.bind_vertex_sampler_states
= identity_bind_vertex_sampler_states
;
713 id_pipe
->base
.delete_sampler_state
= identity_delete_sampler_state
;
714 id_pipe
->base
.create_rasterizer_state
= identity_create_rasterizer_state
;
715 id_pipe
->base
.bind_rasterizer_state
= identity_bind_rasterizer_state
;
716 id_pipe
->base
.delete_rasterizer_state
= identity_delete_rasterizer_state
;
717 id_pipe
->base
.create_depth_stencil_alpha_state
= identity_create_depth_stencil_alpha_state
;
718 id_pipe
->base
.bind_depth_stencil_alpha_state
= identity_bind_depth_stencil_alpha_state
;
719 id_pipe
->base
.delete_depth_stencil_alpha_state
= identity_delete_depth_stencil_alpha_state
;
720 id_pipe
->base
.create_fs_state
= identity_create_fs_state
;
721 id_pipe
->base
.bind_fs_state
= identity_bind_fs_state
;
722 id_pipe
->base
.delete_fs_state
= identity_delete_fs_state
;
723 id_pipe
->base
.create_vs_state
= identity_create_vs_state
;
724 id_pipe
->base
.bind_vs_state
= identity_bind_vs_state
;
725 id_pipe
->base
.delete_vs_state
= identity_delete_vs_state
;
726 id_pipe
->base
.set_blend_color
= identity_set_blend_color
;
727 id_pipe
->base
.set_clip_state
= identity_set_clip_state
;
728 id_pipe
->base
.set_constant_buffer
= identity_set_constant_buffer
;
729 id_pipe
->base
.set_framebuffer_state
= identity_set_framebuffer_state
;
730 id_pipe
->base
.set_polygon_stipple
= identity_set_polygon_stipple
;
731 id_pipe
->base
.set_scissor_state
= identity_set_scissor_state
;
732 id_pipe
->base
.set_viewport_state
= identity_set_viewport_state
;
733 id_pipe
->base
.set_fragment_sampler_textures
= identity_set_fragment_sampler_textures
;
734 id_pipe
->base
.set_vertex_sampler_textures
= identity_set_vertex_sampler_textures
;
735 id_pipe
->base
.set_vertex_buffers
= identity_set_vertex_buffers
;
736 id_pipe
->base
.set_vertex_elements
= identity_set_vertex_elements
;
737 id_pipe
->base
.surface_copy
= identity_surface_copy
;
738 id_pipe
->base
.surface_fill
= identity_surface_fill
;
739 id_pipe
->base
.clear
= identity_clear
;
740 id_pipe
->base
.flush
= identity_flush
;
741 id_pipe
->base
.is_texture_referenced
= identity_is_texture_referenced
;
742 id_pipe
->base
.is_buffer_referenced
= identity_is_buffer_referenced
;
744 id_pipe
->pipe
= pipe
;
746 return &id_pipe
->base
;