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