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_set_edgeflags(struct pipe_context *_pipe,
50 const unsigned *bitfield)
52 struct identity_context *id_pipe = identity_context(_pipe);
53 struct pipe_context *pipe = id_pipe->pipe;
55 pipe->set_edgeflags(pipe,
60 identity_draw_arrays(struct pipe_context *_pipe,
65 struct identity_context *id_pipe = identity_context(_pipe);
66 struct pipe_context *pipe = id_pipe->pipe;
68 return pipe->draw_arrays(pipe,
75 identity_draw_elements(struct pipe_context *_pipe,
76 struct pipe_buffer *_indexBuffer,
82 struct identity_context *id_pipe = identity_context(_pipe);
83 struct identity_buffer *id_buffer = identity_buffer(_indexBuffer);
84 struct pipe_context *pipe = id_pipe->pipe;
85 struct pipe_buffer *indexBuffer = id_buffer->buffer;
87 return pipe->draw_elements(pipe,
96 identity_draw_range_elements(struct pipe_context *_pipe,
97 struct pipe_buffer *_indexBuffer,
105 struct identity_context *id_pipe = identity_context(_pipe);
106 struct identity_buffer *id_buffer = identity_buffer(_indexBuffer);
107 struct pipe_context *pipe = id_pipe->pipe;
108 struct pipe_buffer *indexBuffer = id_buffer->buffer;
110 return pipe->draw_range_elements(pipe,
120 static struct pipe_query *
121 identity_create_query(struct pipe_context *_pipe,
124 struct identity_context *id_pipe = identity_context(_pipe);
125 struct pipe_context *pipe = id_pipe->pipe;
127 return pipe->create_query(pipe,
132 identity_destroy_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->destroy_query(pipe,
143 identity_begin_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->begin_query(pipe,
154 identity_end_query(struct pipe_context *_pipe,
155 struct pipe_query *query)
157 struct identity_context *id_pipe = identity_context(_pipe);
158 struct pipe_context *pipe = id_pipe->pipe;
160 pipe->end_query(pipe,
165 identity_get_query_result(struct pipe_context *_pipe,
166 struct pipe_query *query,
170 struct identity_context *id_pipe = identity_context(_pipe);
171 struct pipe_context *pipe = id_pipe->pipe;
173 return pipe->get_query_result(pipe,
180 identity_create_blend_state(struct pipe_context *_pipe,
181 const struct pipe_blend_state *blend)
183 struct identity_context *id_pipe = identity_context(_pipe);
184 struct pipe_context *pipe = id_pipe->pipe;
186 return pipe->create_blend_state(pipe,
191 identity_bind_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->bind_blend_state(pipe,
202 identity_delete_blend_state(struct pipe_context *_pipe,
205 struct identity_context *id_pipe = identity_context(_pipe);
206 struct pipe_context *pipe = id_pipe->pipe;
208 pipe->delete_blend_state(pipe,
213 identity_create_sampler_state(struct pipe_context *_pipe,
214 const struct pipe_sampler_state *sampler)
216 struct identity_context *id_pipe = identity_context(_pipe);
217 struct pipe_context *pipe = id_pipe->pipe;
219 return pipe->create_sampler_state(pipe,
224 identity_bind_sampler_states(struct pipe_context *_pipe,
228 struct identity_context *id_pipe = identity_context(_pipe);
229 struct pipe_context *pipe = id_pipe->pipe;
231 pipe->bind_sampler_states(pipe,
237 identity_delete_sampler_state(struct pipe_context *_pipe,
240 struct identity_context *id_pipe = identity_context(_pipe);
241 struct pipe_context *pipe = id_pipe->pipe;
243 pipe->delete_sampler_state(pipe,
248 identity_create_rasterizer_state(struct pipe_context *_pipe,
249 const struct pipe_rasterizer_state *rasterizer)
251 struct identity_context *id_pipe = identity_context(_pipe);
252 struct pipe_context *pipe = id_pipe->pipe;
254 return pipe->create_rasterizer_state(pipe,
259 identity_bind_rasterizer_state(struct pipe_context *_pipe,
262 struct identity_context *id_pipe = identity_context(_pipe);
263 struct pipe_context *pipe = id_pipe->pipe;
265 pipe->bind_rasterizer_state(pipe,
270 identity_delete_rasterizer_state(struct pipe_context *_pipe,
273 struct identity_context *id_pipe = identity_context(_pipe);
274 struct pipe_context *pipe = id_pipe->pipe;
276 pipe->delete_rasterizer_state(pipe,
281 identity_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
282 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
284 struct identity_context *id_pipe = identity_context(_pipe);
285 struct pipe_context *pipe = id_pipe->pipe;
287 return pipe->create_depth_stencil_alpha_state(pipe,
288 depth_stencil_alpha);
292 identity_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
293 void *depth_stencil_alpha)
295 struct identity_context *id_pipe = identity_context(_pipe);
296 struct pipe_context *pipe = id_pipe->pipe;
298 pipe->bind_depth_stencil_alpha_state(pipe,
299 depth_stencil_alpha);
303 identity_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
304 void *depth_stencil_alpha)
306 struct identity_context *id_pipe = identity_context(_pipe);
307 struct pipe_context *pipe = id_pipe->pipe;
309 pipe->delete_depth_stencil_alpha_state(pipe,
310 depth_stencil_alpha);
314 identity_create_fs_state(struct pipe_context *_pipe,
315 const struct pipe_shader_state *fs)
317 struct identity_context *id_pipe = identity_context(_pipe);
318 struct pipe_context *pipe = id_pipe->pipe;
320 return pipe->create_fs_state(pipe,
325 identity_bind_fs_state(struct pipe_context *_pipe,
328 struct identity_context *id_pipe = identity_context(_pipe);
329 struct pipe_context *pipe = id_pipe->pipe;
331 pipe->bind_fs_state(pipe,
336 identity_delete_fs_state(struct pipe_context *_pipe,
339 struct identity_context *id_pipe = identity_context(_pipe);
340 struct pipe_context *pipe = id_pipe->pipe;
342 pipe->delete_fs_state(pipe,
347 identity_create_vs_state(struct pipe_context *_pipe,
348 const struct pipe_shader_state *vs)
350 struct identity_context *id_pipe = identity_context(_pipe);
351 struct pipe_context *pipe = id_pipe->pipe;
353 return pipe->create_vs_state(pipe,
358 identity_bind_vs_state(struct pipe_context *_pipe,
361 struct identity_context *id_pipe = identity_context(_pipe);
362 struct pipe_context *pipe = id_pipe->pipe;
364 pipe->bind_vs_state(pipe,
369 identity_delete_vs_state(struct pipe_context *_pipe,
372 struct identity_context *id_pipe = identity_context(_pipe);
373 struct pipe_context *pipe = id_pipe->pipe;
375 pipe->delete_vs_state(pipe,
380 identity_set_blend_color(struct pipe_context *_pipe,
381 const struct pipe_blend_color *blend_color)
383 struct identity_context *id_pipe = identity_context(_pipe);
384 struct pipe_context *pipe = id_pipe->pipe;
386 pipe->set_blend_color(pipe,
391 identity_set_clip_state(struct pipe_context *_pipe,
392 const struct pipe_clip_state *clip)
394 struct identity_context *id_pipe = identity_context(_pipe);
395 struct pipe_context *pipe = id_pipe->pipe;
397 pipe->set_clip_state(pipe,
402 identity_set_constant_buffer(struct pipe_context *_pipe,
405 const struct pipe_constant_buffer *_buffer)
407 struct identity_context *id_pipe = identity_context(_pipe);
408 struct pipe_context *pipe = id_pipe->pipe;
409 struct pipe_constant_buffer unwrapped_buffer;
410 struct pipe_constant_buffer *buffer = NULL;
412 /* unwrap the input state */
414 unwrapped_buffer.buffer = identity_buffer_unwrap(_buffer->buffer);
415 buffer = &unwrapped_buffer;
418 pipe->set_constant_buffer(pipe,
425 identity_set_framebuffer_state(struct pipe_context *_pipe,
426 const struct pipe_framebuffer_state *_state)
428 struct identity_context *id_pipe = identity_context(_pipe);
429 struct pipe_context *pipe = id_pipe->pipe;
430 struct pipe_framebuffer_state unwrapped_state;
431 struct pipe_framebuffer_state *state = NULL;
434 /* unwrap the input state */
436 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
437 for(i = 0; i < _state->nr_cbufs; i++)
438 unwrapped_state.cbufs[i] = identity_surface_unwrap(_state->cbufs[i]);
439 for (; i < PIPE_MAX_COLOR_BUFS; i++)
440 unwrapped_state.cbufs[i] = NULL;
441 unwrapped_state.zsbuf = identity_surface_unwrap(_state->zsbuf);
442 state = &unwrapped_state;
445 pipe->set_framebuffer_state(pipe,
450 identity_set_polygon_stipple(struct pipe_context *_pipe,
451 const struct pipe_poly_stipple *poly_stipple)
453 struct identity_context *id_pipe = identity_context(_pipe);
454 struct pipe_context *pipe = id_pipe->pipe;
456 pipe->set_polygon_stipple(pipe,
461 identity_set_scissor_state(struct pipe_context *_pipe,
462 const struct pipe_scissor_state *scissor)
464 struct identity_context *id_pipe = identity_context(_pipe);
465 struct pipe_context *pipe = id_pipe->pipe;
467 pipe->set_scissor_state(pipe,
472 identity_set_viewport_state(struct pipe_context *_pipe,
473 const struct pipe_viewport_state *viewport)
475 struct identity_context *id_pipe = identity_context(_pipe);
476 struct pipe_context *pipe = id_pipe->pipe;
478 pipe->set_viewport_state(pipe,
483 identity_set_sampler_textures(struct pipe_context *_pipe,
484 unsigned num_textures,
485 struct pipe_texture **_textures)
487 struct identity_context *id_pipe = identity_context(_pipe);
488 struct pipe_context *pipe = id_pipe->pipe;
489 struct pipe_texture *unwrapped_textures[PIPE_MAX_SAMPLERS];
490 struct pipe_texture **textures = NULL;
494 for (i = 0; i < num_textures; i++)
495 unwrapped_textures[i] = identity_texture_unwrap(_textures[i]);
496 for (; i < PIPE_MAX_SAMPLERS; i++)
497 unwrapped_textures[i] = NULL;
499 textures = unwrapped_textures;
502 pipe->set_sampler_textures(pipe,
508 identity_set_vertex_buffers(struct pipe_context *_pipe,
509 unsigned num_buffers,
510 const struct pipe_vertex_buffer *_buffers)
512 struct identity_context *id_pipe = identity_context(_pipe);
513 struct pipe_context *pipe = id_pipe->pipe;
514 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
515 struct pipe_vertex_buffer *buffers = NULL;
519 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
520 for (i = 0; i < num_buffers; i++)
521 unwrapped_buffers[i].buffer = identity_buffer_unwrap(_buffers[i].buffer);
522 buffers = unwrapped_buffers;
525 pipe->set_vertex_buffers(pipe,
531 identity_set_vertex_elements(struct pipe_context *_pipe,
532 unsigned num_elements,
533 const struct pipe_vertex_element *vertex_elements)
535 struct identity_context *id_pipe = identity_context(_pipe);
536 struct pipe_context *pipe = id_pipe->pipe;
538 pipe->set_vertex_elements(pipe,
544 identity_surface_copy(struct pipe_context *_pipe,
545 struct pipe_surface *_dst,
548 struct pipe_surface *_src,
554 struct identity_context *id_pipe = identity_context(_pipe);
555 struct identity_surface *id_surface_dst = identity_surface(_dst);
556 struct identity_surface *id_surface_src = identity_surface(_src);
557 struct pipe_context *pipe = id_pipe->pipe;
558 struct pipe_surface *dst = id_surface_dst->surface;
559 struct pipe_surface *src = id_surface_src->surface;
561 pipe->surface_copy(pipe,
573 identity_surface_fill(struct pipe_context *_pipe,
574 struct pipe_surface *_dst,
581 struct identity_context *id_pipe = identity_context(_pipe);
582 struct identity_surface *id_surface_dst = identity_surface(_dst);
583 struct pipe_context *pipe = id_pipe->pipe;
584 struct pipe_surface *dst = id_surface_dst->surface;
586 pipe->surface_fill(pipe,
596 identity_clear(struct pipe_context *_pipe,
602 struct identity_context *id_pipe = identity_context(_pipe);
603 struct pipe_context *pipe = id_pipe->pipe;
613 identity_flush(struct pipe_context *_pipe,
615 struct pipe_fence_handle **fence)
617 struct identity_context *id_pipe = identity_context(_pipe);
618 struct pipe_context *pipe = id_pipe->pipe;
626 identity_is_texture_referenced(struct pipe_context *_pipe,
627 struct pipe_texture *_texture,
631 struct identity_context *id_pipe = identity_context(_pipe);
632 struct identity_texture *id_texture = identity_texture(_texture);
633 struct pipe_context *pipe = id_pipe->pipe;
634 struct pipe_texture *texture = id_texture->texture;
636 return pipe->is_texture_referenced(pipe,
643 identity_is_buffer_referenced(struct pipe_context *_pipe,
644 struct pipe_buffer *_buffer)
646 struct identity_context *id_pipe = identity_context(_pipe);
647 struct identity_buffer *id_buffer = identity_buffer(_buffer);
648 struct pipe_context *pipe = id_pipe->pipe;
649 struct pipe_buffer *buffer = id_buffer->buffer;
651 return pipe->is_buffer_referenced(pipe,
655 struct pipe_context *
656 identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
658 struct identity_context *id_pipe;
659 (void)identity_screen(_screen);
661 id_pipe = CALLOC_STRUCT(identity_context);
666 id_pipe->base.winsys = NULL;
667 id_pipe->base.screen = _screen;
668 id_pipe->base.priv = pipe->priv;
669 id_pipe->base.draw = NULL;
671 id_pipe->base.destroy = identity_destroy;
672 id_pipe->base.set_edgeflags = identity_set_edgeflags;
673 id_pipe->base.draw_arrays = identity_draw_arrays;
674 id_pipe->base.draw_elements = identity_draw_elements;
675 id_pipe->base.draw_range_elements = identity_draw_range_elements;
676 id_pipe->base.create_query = identity_create_query;
677 id_pipe->base.destroy_query = identity_destroy_query;
678 id_pipe->base.begin_query = identity_begin_query;
679 id_pipe->base.end_query = identity_end_query;
680 id_pipe->base.get_query_result = identity_get_query_result;
681 id_pipe->base.create_blend_state = identity_create_blend_state;
682 id_pipe->base.bind_blend_state = identity_bind_blend_state;
683 id_pipe->base.delete_blend_state = identity_delete_blend_state;
684 id_pipe->base.create_sampler_state = identity_create_sampler_state;
685 id_pipe->base.bind_sampler_states = identity_bind_sampler_states;
686 id_pipe->base.delete_sampler_state = identity_delete_sampler_state;
687 id_pipe->base.create_rasterizer_state = identity_create_rasterizer_state;
688 id_pipe->base.bind_rasterizer_state = identity_bind_rasterizer_state;
689 id_pipe->base.delete_rasterizer_state = identity_delete_rasterizer_state;
690 id_pipe->base.create_depth_stencil_alpha_state = identity_create_depth_stencil_alpha_state;
691 id_pipe->base.bind_depth_stencil_alpha_state = identity_bind_depth_stencil_alpha_state;
692 id_pipe->base.delete_depth_stencil_alpha_state = identity_delete_depth_stencil_alpha_state;
693 id_pipe->base.create_fs_state = identity_create_fs_state;
694 id_pipe->base.bind_fs_state = identity_bind_fs_state;
695 id_pipe->base.delete_fs_state = identity_delete_fs_state;
696 id_pipe->base.create_vs_state = identity_create_vs_state;
697 id_pipe->base.bind_vs_state = identity_bind_vs_state;
698 id_pipe->base.delete_vs_state = identity_delete_vs_state;
699 id_pipe->base.set_blend_color = identity_set_blend_color;
700 id_pipe->base.set_clip_state = identity_set_clip_state;
701 id_pipe->base.set_constant_buffer = identity_set_constant_buffer;
702 id_pipe->base.set_framebuffer_state = identity_set_framebuffer_state;
703 id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple;
704 id_pipe->base.set_scissor_state = identity_set_scissor_state;
705 id_pipe->base.set_viewport_state = identity_set_viewport_state;
706 id_pipe->base.set_sampler_textures = identity_set_sampler_textures;
707 id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers;
708 id_pipe->base.set_vertex_elements = identity_set_vertex_elements;
709 id_pipe->base.surface_copy = identity_surface_copy;
710 id_pipe->base.surface_fill = identity_surface_fill;
711 id_pipe->base.clear = identity_clear;
712 id_pipe->base.flush = identity_flush;
713 id_pipe->base.is_texture_referenced = identity_is_texture_referenced;
714 id_pipe->base.is_buffer_referenced = identity_is_buffer_referenced;
716 id_pipe->pipe = pipe;
718 return &id_pipe->base;