gallium: Add support for multiple viewports
[mesa.git] / src / gallium / drivers / identity / id_context.c
1 /**************************************************************************
2 *
3 * Copyright 2009 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
29 #include "pipe/p_context.h"
30 #include "util/u_memory.h"
31 #include "util/u_inlines.h"
32
33 #include "id_context.h"
34 #include "id_objects.h"
35
36
37 static void
38 identity_destroy(struct pipe_context *_pipe)
39 {
40 struct identity_context *id_pipe = identity_context(_pipe);
41 struct pipe_context *pipe = id_pipe->pipe;
42
43 pipe->destroy(pipe);
44
45 FREE(id_pipe);
46 }
47
48 static void
49 identity_draw_vbo(struct pipe_context *_pipe,
50 const struct pipe_draw_info *info)
51 {
52 struct identity_context *id_pipe = identity_context(_pipe);
53 struct pipe_context *pipe = id_pipe->pipe;
54
55 pipe->draw_vbo(pipe, info);
56 }
57
58 static struct pipe_query *
59 identity_create_query(struct pipe_context *_pipe,
60 unsigned query_type)
61 {
62 struct identity_context *id_pipe = identity_context(_pipe);
63 struct pipe_context *pipe = id_pipe->pipe;
64
65 return pipe->create_query(pipe,
66 query_type);
67 }
68
69 static void
70 identity_destroy_query(struct pipe_context *_pipe,
71 struct pipe_query *query)
72 {
73 struct identity_context *id_pipe = identity_context(_pipe);
74 struct pipe_context *pipe = id_pipe->pipe;
75
76 pipe->destroy_query(pipe,
77 query);
78 }
79
80 static void
81 identity_begin_query(struct pipe_context *_pipe,
82 struct pipe_query *query)
83 {
84 struct identity_context *id_pipe = identity_context(_pipe);
85 struct pipe_context *pipe = id_pipe->pipe;
86
87 pipe->begin_query(pipe,
88 query);
89 }
90
91 static void
92 identity_end_query(struct pipe_context *_pipe,
93 struct pipe_query *query)
94 {
95 struct identity_context *id_pipe = identity_context(_pipe);
96 struct pipe_context *pipe = id_pipe->pipe;
97
98 pipe->end_query(pipe,
99 query);
100 }
101
102 static boolean
103 identity_get_query_result(struct pipe_context *_pipe,
104 struct pipe_query *query,
105 boolean wait,
106 union pipe_query_result *result)
107 {
108 struct identity_context *id_pipe = identity_context(_pipe);
109 struct pipe_context *pipe = id_pipe->pipe;
110
111 return pipe->get_query_result(pipe,
112 query,
113 wait,
114 result);
115 }
116
117 static void *
118 identity_create_blend_state(struct pipe_context *_pipe,
119 const struct pipe_blend_state *blend)
120 {
121 struct identity_context *id_pipe = identity_context(_pipe);
122 struct pipe_context *pipe = id_pipe->pipe;
123
124 return pipe->create_blend_state(pipe,
125 blend);
126 }
127
128 static void
129 identity_bind_blend_state(struct pipe_context *_pipe,
130 void *blend)
131 {
132 struct identity_context *id_pipe = identity_context(_pipe);
133 struct pipe_context *pipe = id_pipe->pipe;
134
135 pipe->bind_blend_state(pipe,
136 blend);
137 }
138
139 static void
140 identity_delete_blend_state(struct pipe_context *_pipe,
141 void *blend)
142 {
143 struct identity_context *id_pipe = identity_context(_pipe);
144 struct pipe_context *pipe = id_pipe->pipe;
145
146 pipe->delete_blend_state(pipe,
147 blend);
148 }
149
150 static void *
151 identity_create_sampler_state(struct pipe_context *_pipe,
152 const struct pipe_sampler_state *sampler)
153 {
154 struct identity_context *id_pipe = identity_context(_pipe);
155 struct pipe_context *pipe = id_pipe->pipe;
156
157 return pipe->create_sampler_state(pipe,
158 sampler);
159 }
160
161 static void
162 identity_bind_sampler_states(struct pipe_context *_pipe,
163 unsigned shader,
164 unsigned start,
165 unsigned num_samplers,
166 void **samplers)
167 {
168 struct identity_context *id_pipe = identity_context(_pipe);
169 struct pipe_context *pipe = id_pipe->pipe;
170
171 /* remove this when we have pipe->bind_sampler_states(..., start, ...) */
172 assert(start == 0);
173
174 switch (shader) {
175 case PIPE_SHADER_VERTEX:
176 pipe->bind_vertex_sampler_states(pipe, num_samplers, samplers);
177 break;
178 case PIPE_SHADER_GEOMETRY:
179 pipe->bind_geometry_sampler_states(pipe, num_samplers, samplers);
180 break;
181 case PIPE_SHADER_FRAGMENT:
182 pipe->bind_fragment_sampler_states(pipe, num_samplers, samplers);
183 break;
184 default:
185 debug_error("Unexpected shader in identity_bind_sampler_states()");
186 }
187 }
188
189 static void
190 identity_bind_fragment_sampler_states(struct pipe_context *_pipe,
191 unsigned num_samplers,
192 void **samplers)
193 {
194 identity_bind_sampler_states(_pipe, PIPE_SHADER_FRAGMENT,
195 0, num_samplers, samplers);
196 }
197
198 static void
199 identity_bind_vertex_sampler_states(struct pipe_context *_pipe,
200 unsigned num_samplers,
201 void **samplers)
202 {
203 identity_bind_sampler_states(_pipe, PIPE_SHADER_VERTEX,
204 0, num_samplers, samplers);
205 }
206
207 static void
208 identity_delete_sampler_state(struct pipe_context *_pipe,
209 void *sampler)
210 {
211 struct identity_context *id_pipe = identity_context(_pipe);
212 struct pipe_context *pipe = id_pipe->pipe;
213
214 pipe->delete_sampler_state(pipe,
215 sampler);
216 }
217
218 static void *
219 identity_create_rasterizer_state(struct pipe_context *_pipe,
220 const struct pipe_rasterizer_state *rasterizer)
221 {
222 struct identity_context *id_pipe = identity_context(_pipe);
223 struct pipe_context *pipe = id_pipe->pipe;
224
225 return pipe->create_rasterizer_state(pipe,
226 rasterizer);
227 }
228
229 static void
230 identity_bind_rasterizer_state(struct pipe_context *_pipe,
231 void *rasterizer)
232 {
233 struct identity_context *id_pipe = identity_context(_pipe);
234 struct pipe_context *pipe = id_pipe->pipe;
235
236 pipe->bind_rasterizer_state(pipe,
237 rasterizer);
238 }
239
240 static void
241 identity_delete_rasterizer_state(struct pipe_context *_pipe,
242 void *rasterizer)
243 {
244 struct identity_context *id_pipe = identity_context(_pipe);
245 struct pipe_context *pipe = id_pipe->pipe;
246
247 pipe->delete_rasterizer_state(pipe,
248 rasterizer);
249 }
250
251 static void *
252 identity_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
253 const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
254 {
255 struct identity_context *id_pipe = identity_context(_pipe);
256 struct pipe_context *pipe = id_pipe->pipe;
257
258 return pipe->create_depth_stencil_alpha_state(pipe,
259 depth_stencil_alpha);
260 }
261
262 static void
263 identity_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
264 void *depth_stencil_alpha)
265 {
266 struct identity_context *id_pipe = identity_context(_pipe);
267 struct pipe_context *pipe = id_pipe->pipe;
268
269 pipe->bind_depth_stencil_alpha_state(pipe,
270 depth_stencil_alpha);
271 }
272
273 static void
274 identity_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
275 void *depth_stencil_alpha)
276 {
277 struct identity_context *id_pipe = identity_context(_pipe);
278 struct pipe_context *pipe = id_pipe->pipe;
279
280 pipe->delete_depth_stencil_alpha_state(pipe,
281 depth_stencil_alpha);
282 }
283
284 static void *
285 identity_create_fs_state(struct pipe_context *_pipe,
286 const struct pipe_shader_state *fs)
287 {
288 struct identity_context *id_pipe = identity_context(_pipe);
289 struct pipe_context *pipe = id_pipe->pipe;
290
291 return pipe->create_fs_state(pipe,
292 fs);
293 }
294
295 static void
296 identity_bind_fs_state(struct pipe_context *_pipe,
297 void *fs)
298 {
299 struct identity_context *id_pipe = identity_context(_pipe);
300 struct pipe_context *pipe = id_pipe->pipe;
301
302 pipe->bind_fs_state(pipe,
303 fs);
304 }
305
306 static void
307 identity_delete_fs_state(struct pipe_context *_pipe,
308 void *fs)
309 {
310 struct identity_context *id_pipe = identity_context(_pipe);
311 struct pipe_context *pipe = id_pipe->pipe;
312
313 pipe->delete_fs_state(pipe,
314 fs);
315 }
316
317 static void *
318 identity_create_vs_state(struct pipe_context *_pipe,
319 const struct pipe_shader_state *vs)
320 {
321 struct identity_context *id_pipe = identity_context(_pipe);
322 struct pipe_context *pipe = id_pipe->pipe;
323
324 return pipe->create_vs_state(pipe,
325 vs);
326 }
327
328 static void
329 identity_bind_vs_state(struct pipe_context *_pipe,
330 void *vs)
331 {
332 struct identity_context *id_pipe = identity_context(_pipe);
333 struct pipe_context *pipe = id_pipe->pipe;
334
335 pipe->bind_vs_state(pipe,
336 vs);
337 }
338
339 static void
340 identity_delete_vs_state(struct pipe_context *_pipe,
341 void *vs)
342 {
343 struct identity_context *id_pipe = identity_context(_pipe);
344 struct pipe_context *pipe = id_pipe->pipe;
345
346 pipe->delete_vs_state(pipe,
347 vs);
348 }
349
350
351 static void *
352 identity_create_vertex_elements_state(struct pipe_context *_pipe,
353 unsigned num_elements,
354 const struct pipe_vertex_element *vertex_elements)
355 {
356 struct identity_context *id_pipe = identity_context(_pipe);
357 struct pipe_context *pipe = id_pipe->pipe;
358
359 return pipe->create_vertex_elements_state(pipe,
360 num_elements,
361 vertex_elements);
362 }
363
364 static void
365 identity_bind_vertex_elements_state(struct pipe_context *_pipe,
366 void *velems)
367 {
368 struct identity_context *id_pipe = identity_context(_pipe);
369 struct pipe_context *pipe = id_pipe->pipe;
370
371 pipe->bind_vertex_elements_state(pipe,
372 velems);
373 }
374
375 static void
376 identity_delete_vertex_elements_state(struct pipe_context *_pipe,
377 void *velems)
378 {
379 struct identity_context *id_pipe = identity_context(_pipe);
380 struct pipe_context *pipe = id_pipe->pipe;
381
382 pipe->delete_vertex_elements_state(pipe,
383 velems);
384 }
385
386 static void
387 identity_set_blend_color(struct pipe_context *_pipe,
388 const struct pipe_blend_color *blend_color)
389 {
390 struct identity_context *id_pipe = identity_context(_pipe);
391 struct pipe_context *pipe = id_pipe->pipe;
392
393 pipe->set_blend_color(pipe,
394 blend_color);
395 }
396
397 static void
398 identity_set_stencil_ref(struct pipe_context *_pipe,
399 const struct pipe_stencil_ref *stencil_ref)
400 {
401 struct identity_context *id_pipe = identity_context(_pipe);
402 struct pipe_context *pipe = id_pipe->pipe;
403
404 pipe->set_stencil_ref(pipe,
405 stencil_ref);
406 }
407
408 static void
409 identity_set_clip_state(struct pipe_context *_pipe,
410 const struct pipe_clip_state *clip)
411 {
412 struct identity_context *id_pipe = identity_context(_pipe);
413 struct pipe_context *pipe = id_pipe->pipe;
414
415 pipe->set_clip_state(pipe,
416 clip);
417 }
418
419 static void
420 identity_set_sample_mask(struct pipe_context *_pipe,
421 unsigned sample_mask)
422 {
423 struct identity_context *id_pipe = identity_context(_pipe);
424 struct pipe_context *pipe = id_pipe->pipe;
425
426 pipe->set_sample_mask(pipe,
427 sample_mask);
428 }
429
430 static void
431 identity_set_constant_buffer(struct pipe_context *_pipe,
432 uint shader,
433 uint index,
434 struct pipe_constant_buffer *_cb)
435 {
436 struct identity_context *id_pipe = identity_context(_pipe);
437 struct pipe_context *pipe = id_pipe->pipe;
438 struct pipe_constant_buffer cb;
439
440 /* XXX hmm? unwrap the input state */
441 if (_cb) {
442 cb = *_cb;
443 cb.buffer = identity_resource_unwrap(_cb->buffer);
444 }
445
446 pipe->set_constant_buffer(pipe,
447 shader,
448 index,
449 _cb ? &cb : NULL);
450 }
451
452 static void
453 identity_set_framebuffer_state(struct pipe_context *_pipe,
454 const struct pipe_framebuffer_state *_state)
455 {
456 struct identity_context *id_pipe = identity_context(_pipe);
457 struct pipe_context *pipe = id_pipe->pipe;
458 struct pipe_framebuffer_state unwrapped_state;
459 struct pipe_framebuffer_state *state = NULL;
460 unsigned i;
461
462 /* unwrap the input state */
463 if (_state) {
464 memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
465 for(i = 0; i < _state->nr_cbufs; i++)
466 unwrapped_state.cbufs[i] = identity_surface_unwrap(_state->cbufs[i]);
467 for (; i < PIPE_MAX_COLOR_BUFS; i++)
468 unwrapped_state.cbufs[i] = NULL;
469 unwrapped_state.zsbuf = identity_surface_unwrap(_state->zsbuf);
470 state = &unwrapped_state;
471 }
472
473 pipe->set_framebuffer_state(pipe,
474 state);
475 }
476
477 static void
478 identity_set_polygon_stipple(struct pipe_context *_pipe,
479 const struct pipe_poly_stipple *poly_stipple)
480 {
481 struct identity_context *id_pipe = identity_context(_pipe);
482 struct pipe_context *pipe = id_pipe->pipe;
483
484 pipe->set_polygon_stipple(pipe,
485 poly_stipple);
486 }
487
488 static void
489 identity_set_scissor_states(struct pipe_context *_pipe,
490 unsigned start_slot,
491 unsigned num_scissors,
492 const struct pipe_scissor_state *scissor)
493 {
494 struct identity_context *id_pipe = identity_context(_pipe);
495 struct pipe_context *pipe = id_pipe->pipe;
496
497 pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
498 }
499
500 static void
501 identity_set_viewport_states(struct pipe_context *_pipe,
502 unsigned start_slot,
503 unsigned num_viewports,
504 const struct pipe_viewport_state *viewport)
505 {
506 struct identity_context *id_pipe = identity_context(_pipe);
507 struct pipe_context *pipe = id_pipe->pipe;
508
509 pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
510 }
511
512 static void
513 identity_set_sampler_views(struct pipe_context *_pipe,
514 unsigned shader,
515 unsigned start,
516 unsigned num,
517 struct pipe_sampler_view **_views)
518 {
519 struct identity_context *id_pipe = identity_context(_pipe);
520 struct pipe_context *pipe = id_pipe->pipe;
521 struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
522 struct pipe_sampler_view **views = NULL;
523 unsigned i;
524
525 /* remove this when we have pipe->set_sampler_views(..., start, ...) */
526 assert(start == 0);
527
528 if (_views) {
529 for (i = 0; i < num; i++)
530 unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]);
531 for (; i < PIPE_MAX_SAMPLERS; i++)
532 unwrapped_views[i] = NULL;
533
534 views = unwrapped_views;
535 }
536
537 switch (shader) {
538 case PIPE_SHADER_VERTEX:
539 pipe->set_vertex_sampler_views(pipe, num, views);
540 break;
541 case PIPE_SHADER_GEOMETRY:
542 pipe->set_geometry_sampler_views(pipe, num, views);
543 break;
544 case PIPE_SHADER_FRAGMENT:
545 pipe->set_fragment_sampler_views(pipe, num, views);
546 break;
547 default:
548 debug_error("Unexpected shader in identity_set_sampler_views()");
549 }
550 }
551
552 static void
553 identity_set_fragment_sampler_views(struct pipe_context *_pipe,
554 unsigned num,
555 struct pipe_sampler_view **_views)
556 {
557 identity_set_sampler_views(_pipe, PIPE_SHADER_FRAGMENT, 0, num, _views);
558 }
559
560 static void
561 identity_set_vertex_sampler_views(struct pipe_context *_pipe,
562 unsigned num,
563 struct pipe_sampler_view **_views)
564 {
565 identity_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, 0, num, _views);
566 }
567
568 static void
569 identity_set_vertex_buffers(struct pipe_context *_pipe,
570 unsigned start_slot, unsigned num_buffers,
571 const struct pipe_vertex_buffer *_buffers)
572 {
573 struct identity_context *id_pipe = identity_context(_pipe);
574 struct pipe_context *pipe = id_pipe->pipe;
575 struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
576 struct pipe_vertex_buffer *buffers = NULL;
577 unsigned i;
578
579 if (num_buffers) {
580 memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
581 for (i = 0; i < num_buffers; i++)
582 unwrapped_buffers[i].buffer = identity_resource_unwrap(_buffers[i].buffer);
583 buffers = unwrapped_buffers;
584 }
585
586 pipe->set_vertex_buffers(pipe,
587 start_slot, num_buffers,
588 buffers);
589 }
590
591 static void
592 identity_set_index_buffer(struct pipe_context *_pipe,
593 const struct pipe_index_buffer *_ib)
594 {
595 struct identity_context *id_pipe = identity_context(_pipe);
596 struct pipe_context *pipe = id_pipe->pipe;
597 struct pipe_index_buffer unwrapped_ib, *ib = NULL;
598
599 if (_ib) {
600 unwrapped_ib = *_ib;
601 unwrapped_ib.buffer = identity_resource_unwrap(_ib->buffer);
602 ib = &unwrapped_ib;
603 }
604
605 pipe->set_index_buffer(pipe, ib);
606 }
607
608 static void
609 identity_resource_copy_region(struct pipe_context *_pipe,
610 struct pipe_resource *_dst,
611 unsigned dst_level,
612 unsigned dstx,
613 unsigned dsty,
614 unsigned dstz,
615 struct pipe_resource *_src,
616 unsigned src_level,
617 const struct pipe_box *src_box)
618 {
619 struct identity_context *id_pipe = identity_context(_pipe);
620 struct identity_resource *id_resource_dst = identity_resource(_dst);
621 struct identity_resource *id_resource_src = identity_resource(_src);
622 struct pipe_context *pipe = id_pipe->pipe;
623 struct pipe_resource *dst = id_resource_dst->resource;
624 struct pipe_resource *src = id_resource_src->resource;
625
626 pipe->resource_copy_region(pipe,
627 dst,
628 dst_level,
629 dstx,
630 dsty,
631 dstz,
632 src,
633 src_level,
634 src_box);
635 }
636
637 static void
638 identity_blit(struct pipe_context *_pipe,
639 const struct pipe_blit_info *info)
640 {
641 struct identity_context *id_pipe = identity_context(_pipe);
642 struct pipe_context *pipe = id_pipe->pipe;
643 struct pipe_blit_info blit = *info;
644
645 blit.src.resource = identity_resource(blit.src.resource)->resource;
646 blit.dst.resource = identity_resource(blit.dst.resource)->resource;
647
648 pipe->blit(pipe, &blit);
649 }
650
651 static void
652 identity_clear(struct pipe_context *_pipe,
653 unsigned buffers,
654 const union pipe_color_union *color,
655 double depth,
656 unsigned stencil)
657 {
658 struct identity_context *id_pipe = identity_context(_pipe);
659 struct pipe_context *pipe = id_pipe->pipe;
660
661 pipe->clear(pipe,
662 buffers,
663 color,
664 depth,
665 stencil);
666 }
667
668 static void
669 identity_clear_render_target(struct pipe_context *_pipe,
670 struct pipe_surface *_dst,
671 const union pipe_color_union *color,
672 unsigned dstx, unsigned dsty,
673 unsigned width, unsigned height)
674 {
675 struct identity_context *id_pipe = identity_context(_pipe);
676 struct identity_surface *id_surface_dst = identity_surface(_dst);
677 struct pipe_context *pipe = id_pipe->pipe;
678 struct pipe_surface *dst = id_surface_dst->surface;
679
680 pipe->clear_render_target(pipe,
681 dst,
682 color,
683 dstx,
684 dsty,
685 width,
686 height);
687 }
688 static void
689 identity_clear_depth_stencil(struct pipe_context *_pipe,
690 struct pipe_surface *_dst,
691 unsigned clear_flags,
692 double depth,
693 unsigned stencil,
694 unsigned dstx, unsigned dsty,
695 unsigned width, unsigned height)
696 {
697 struct identity_context *id_pipe = identity_context(_pipe);
698 struct identity_surface *id_surface_dst = identity_surface(_dst);
699 struct pipe_context *pipe = id_pipe->pipe;
700 struct pipe_surface *dst = id_surface_dst->surface;
701
702 pipe->clear_depth_stencil(pipe,
703 dst,
704 clear_flags,
705 depth,
706 stencil,
707 dstx,
708 dsty,
709 width,
710 height);
711
712 }
713
714 static void
715 identity_flush(struct pipe_context *_pipe,
716 struct pipe_fence_handle **fence,
717 unsigned flags)
718 {
719 struct identity_context *id_pipe = identity_context(_pipe);
720 struct pipe_context *pipe = id_pipe->pipe;
721
722 pipe->flush(pipe, fence, flags);
723 }
724
725 static struct pipe_sampler_view *
726 identity_context_create_sampler_view(struct pipe_context *_pipe,
727 struct pipe_resource *_resource,
728 const struct pipe_sampler_view *templ)
729 {
730 struct identity_context *id_context = identity_context(_pipe);
731 struct identity_resource *id_resource = identity_resource(_resource);
732 struct pipe_context *pipe = id_context->pipe;
733 struct pipe_resource *resource = id_resource->resource;
734 struct pipe_sampler_view *result;
735
736 result = pipe->create_sampler_view(pipe,
737 resource,
738 templ);
739
740 if (result)
741 return identity_sampler_view_create(id_context, id_resource, result);
742 return NULL;
743 }
744
745 static void
746 identity_context_sampler_view_destroy(struct pipe_context *_pipe,
747 struct pipe_sampler_view *_view)
748 {
749 identity_sampler_view_destroy(identity_context(_pipe),
750 identity_sampler_view(_view));
751 }
752
753 static struct pipe_surface *
754 identity_context_create_surface(struct pipe_context *_pipe,
755 struct pipe_resource *_resource,
756 const struct pipe_surface *templ)
757 {
758 struct identity_context *id_context = identity_context(_pipe);
759 struct identity_resource *id_resource = identity_resource(_resource);
760 struct pipe_context *pipe = id_context->pipe;
761 struct pipe_resource *resource = id_resource->resource;
762 struct pipe_surface *result;
763
764 result = pipe->create_surface(pipe,
765 resource,
766 templ);
767
768 if (result)
769 return identity_surface_create(id_context, id_resource, result);
770 return NULL;
771 }
772
773 static void
774 identity_context_surface_destroy(struct pipe_context *_pipe,
775 struct pipe_surface *_surf)
776 {
777 identity_surface_destroy(identity_context(_pipe),
778 identity_surface(_surf));
779 }
780
781 static void *
782 identity_context_transfer_map(struct pipe_context *_context,
783 struct pipe_resource *_resource,
784 unsigned level,
785 unsigned usage,
786 const struct pipe_box *box,
787 struct pipe_transfer **transfer)
788 {
789 struct identity_context *id_context = identity_context(_context);
790 struct identity_resource *id_resource = identity_resource(_resource);
791 struct pipe_context *context = id_context->pipe;
792 struct pipe_resource *resource = id_resource->resource;
793 struct pipe_transfer *result;
794 void *map;
795
796 map = context->transfer_map(context,
797 resource,
798 level,
799 usage,
800 box, &result);
801
802 if (!map)
803 return NULL;
804
805 *transfer = identity_transfer_map(id_context, id_resource, result);
806 return *transfer ? map : NULL;
807 }
808
809 static void
810 identity_context_transfer_flush_region(struct pipe_context *_context,
811 struct pipe_transfer *_transfer,
812 const struct pipe_box *box)
813 {
814 struct identity_context *id_context = identity_context(_context);
815 struct identity_transfer *id_transfer = identity_transfer(_transfer);
816 struct pipe_context *context = id_context->pipe;
817 struct pipe_transfer *transfer = id_transfer->transfer;
818
819 context->transfer_flush_region(context,
820 transfer,
821 box);
822 }
823
824
825 static void
826 identity_context_transfer_unmap(struct pipe_context *_context,
827 struct pipe_transfer *_transfer)
828 {
829 struct identity_context *id_context = identity_context(_context);
830 struct identity_transfer *id_transfer = identity_transfer(_transfer);
831 struct pipe_context *context = id_context->pipe;
832 struct pipe_transfer *transfer = id_transfer->transfer;
833
834 context->transfer_unmap(context,
835 transfer);
836
837 identity_transfer_destroy(identity_context(_context),
838 identity_transfer(_transfer));
839 }
840
841
842 static void
843 identity_context_transfer_inline_write(struct pipe_context *_context,
844 struct pipe_resource *_resource,
845 unsigned level,
846 unsigned usage,
847 const struct pipe_box *box,
848 const void *data,
849 unsigned stride,
850 unsigned layer_stride)
851 {
852 struct identity_context *id_context = identity_context(_context);
853 struct identity_resource *id_resource = identity_resource(_resource);
854 struct pipe_context *context = id_context->pipe;
855 struct pipe_resource *resource = id_resource->resource;
856
857 context->transfer_inline_write(context,
858 resource,
859 level,
860 usage,
861 box,
862 data,
863 stride,
864 layer_stride);
865 }
866
867
868 struct pipe_context *
869 identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
870 {
871 struct identity_context *id_pipe;
872 (void)identity_screen(_screen);
873
874 id_pipe = CALLOC_STRUCT(identity_context);
875 if (!id_pipe) {
876 return NULL;
877 }
878
879 id_pipe->base.screen = _screen;
880 id_pipe->base.priv = pipe->priv; /* expose wrapped data */
881 id_pipe->base.draw = NULL;
882
883 id_pipe->base.destroy = identity_destroy;
884 id_pipe->base.draw_vbo = identity_draw_vbo;
885 id_pipe->base.create_query = identity_create_query;
886 id_pipe->base.destroy_query = identity_destroy_query;
887 id_pipe->base.begin_query = identity_begin_query;
888 id_pipe->base.end_query = identity_end_query;
889 id_pipe->base.get_query_result = identity_get_query_result;
890 id_pipe->base.create_blend_state = identity_create_blend_state;
891 id_pipe->base.bind_blend_state = identity_bind_blend_state;
892 id_pipe->base.delete_blend_state = identity_delete_blend_state;
893 id_pipe->base.create_sampler_state = identity_create_sampler_state;
894 id_pipe->base.bind_fragment_sampler_states = identity_bind_fragment_sampler_states;
895 id_pipe->base.bind_vertex_sampler_states = identity_bind_vertex_sampler_states;
896 id_pipe->base.delete_sampler_state = identity_delete_sampler_state;
897 id_pipe->base.create_rasterizer_state = identity_create_rasterizer_state;
898 id_pipe->base.bind_rasterizer_state = identity_bind_rasterizer_state;
899 id_pipe->base.delete_rasterizer_state = identity_delete_rasterizer_state;
900 id_pipe->base.create_depth_stencil_alpha_state = identity_create_depth_stencil_alpha_state;
901 id_pipe->base.bind_depth_stencil_alpha_state = identity_bind_depth_stencil_alpha_state;
902 id_pipe->base.delete_depth_stencil_alpha_state = identity_delete_depth_stencil_alpha_state;
903 id_pipe->base.create_fs_state = identity_create_fs_state;
904 id_pipe->base.bind_fs_state = identity_bind_fs_state;
905 id_pipe->base.delete_fs_state = identity_delete_fs_state;
906 id_pipe->base.create_vs_state = identity_create_vs_state;
907 id_pipe->base.bind_vs_state = identity_bind_vs_state;
908 id_pipe->base.delete_vs_state = identity_delete_vs_state;
909 id_pipe->base.create_vertex_elements_state = identity_create_vertex_elements_state;
910 id_pipe->base.bind_vertex_elements_state = identity_bind_vertex_elements_state;
911 id_pipe->base.delete_vertex_elements_state = identity_delete_vertex_elements_state;
912 id_pipe->base.set_blend_color = identity_set_blend_color;
913 id_pipe->base.set_stencil_ref = identity_set_stencil_ref;
914 id_pipe->base.set_clip_state = identity_set_clip_state;
915 id_pipe->base.set_sample_mask = identity_set_sample_mask;
916 id_pipe->base.set_constant_buffer = identity_set_constant_buffer;
917 id_pipe->base.set_framebuffer_state = identity_set_framebuffer_state;
918 id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple;
919 id_pipe->base.set_scissor_states = identity_set_scissor_states;
920 id_pipe->base.set_viewport_states = identity_set_viewport_states;
921 id_pipe->base.set_fragment_sampler_views = identity_set_fragment_sampler_views;
922 id_pipe->base.set_vertex_sampler_views = identity_set_vertex_sampler_views;
923 id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers;
924 id_pipe->base.set_index_buffer = identity_set_index_buffer;
925 id_pipe->base.resource_copy_region = identity_resource_copy_region;
926 id_pipe->base.clear = identity_clear;
927 id_pipe->base.clear_render_target = identity_clear_render_target;
928 id_pipe->base.clear_depth_stencil = identity_clear_depth_stencil;
929 id_pipe->base.flush = identity_flush;
930 id_pipe->base.create_surface = identity_context_create_surface;
931 id_pipe->base.surface_destroy = identity_context_surface_destroy;
932 id_pipe->base.create_sampler_view = identity_context_create_sampler_view;
933 id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy;
934 id_pipe->base.transfer_map = identity_context_transfer_map;
935 id_pipe->base.transfer_unmap = identity_context_transfer_unmap;
936 id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region;
937 id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write;
938 id_pipe->base.blit = identity_blit;
939
940 id_pipe->pipe = pipe;
941
942 return &id_pipe->base;
943 }