radeon/uvd: try to place msg/fb buffer into GART
[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_flush_resource(struct pipe_context *_pipe,
653 struct pipe_resource *resource)
654 {
655 struct identity_context *id_pipe = identity_context(_pipe);
656 struct pipe_context *pipe = id_pipe->pipe;
657
658 pipe->flush_resource(pipe, resource);
659 }
660
661 static void
662 identity_clear(struct pipe_context *_pipe,
663 unsigned buffers,
664 const union pipe_color_union *color,
665 double depth,
666 unsigned stencil)
667 {
668 struct identity_context *id_pipe = identity_context(_pipe);
669 struct pipe_context *pipe = id_pipe->pipe;
670
671 pipe->clear(pipe,
672 buffers,
673 color,
674 depth,
675 stencil);
676 }
677
678 static void
679 identity_clear_render_target(struct pipe_context *_pipe,
680 struct pipe_surface *_dst,
681 const union pipe_color_union *color,
682 unsigned dstx, unsigned dsty,
683 unsigned width, unsigned height)
684 {
685 struct identity_context *id_pipe = identity_context(_pipe);
686 struct identity_surface *id_surface_dst = identity_surface(_dst);
687 struct pipe_context *pipe = id_pipe->pipe;
688 struct pipe_surface *dst = id_surface_dst->surface;
689
690 pipe->clear_render_target(pipe,
691 dst,
692 color,
693 dstx,
694 dsty,
695 width,
696 height);
697 }
698 static void
699 identity_clear_depth_stencil(struct pipe_context *_pipe,
700 struct pipe_surface *_dst,
701 unsigned clear_flags,
702 double depth,
703 unsigned stencil,
704 unsigned dstx, unsigned dsty,
705 unsigned width, unsigned height)
706 {
707 struct identity_context *id_pipe = identity_context(_pipe);
708 struct identity_surface *id_surface_dst = identity_surface(_dst);
709 struct pipe_context *pipe = id_pipe->pipe;
710 struct pipe_surface *dst = id_surface_dst->surface;
711
712 pipe->clear_depth_stencil(pipe,
713 dst,
714 clear_flags,
715 depth,
716 stencil,
717 dstx,
718 dsty,
719 width,
720 height);
721
722 }
723
724 static void
725 identity_flush(struct pipe_context *_pipe,
726 struct pipe_fence_handle **fence,
727 unsigned flags)
728 {
729 struct identity_context *id_pipe = identity_context(_pipe);
730 struct pipe_context *pipe = id_pipe->pipe;
731
732 pipe->flush(pipe, fence, flags);
733 }
734
735 static struct pipe_sampler_view *
736 identity_context_create_sampler_view(struct pipe_context *_pipe,
737 struct pipe_resource *_resource,
738 const struct pipe_sampler_view *templ)
739 {
740 struct identity_context *id_context = identity_context(_pipe);
741 struct identity_resource *id_resource = identity_resource(_resource);
742 struct pipe_context *pipe = id_context->pipe;
743 struct pipe_resource *resource = id_resource->resource;
744 struct pipe_sampler_view *result;
745
746 result = pipe->create_sampler_view(pipe,
747 resource,
748 templ);
749
750 if (result)
751 return identity_sampler_view_create(id_context, id_resource, result);
752 return NULL;
753 }
754
755 static void
756 identity_context_sampler_view_destroy(struct pipe_context *_pipe,
757 struct pipe_sampler_view *_view)
758 {
759 identity_sampler_view_destroy(identity_context(_pipe),
760 identity_sampler_view(_view));
761 }
762
763 static struct pipe_surface *
764 identity_context_create_surface(struct pipe_context *_pipe,
765 struct pipe_resource *_resource,
766 const struct pipe_surface *templ)
767 {
768 struct identity_context *id_context = identity_context(_pipe);
769 struct identity_resource *id_resource = identity_resource(_resource);
770 struct pipe_context *pipe = id_context->pipe;
771 struct pipe_resource *resource = id_resource->resource;
772 struct pipe_surface *result;
773
774 result = pipe->create_surface(pipe,
775 resource,
776 templ);
777
778 if (result)
779 return identity_surface_create(id_context, id_resource, result);
780 return NULL;
781 }
782
783 static void
784 identity_context_surface_destroy(struct pipe_context *_pipe,
785 struct pipe_surface *_surf)
786 {
787 identity_surface_destroy(identity_context(_pipe),
788 identity_surface(_surf));
789 }
790
791 static void *
792 identity_context_transfer_map(struct pipe_context *_context,
793 struct pipe_resource *_resource,
794 unsigned level,
795 unsigned usage,
796 const struct pipe_box *box,
797 struct pipe_transfer **transfer)
798 {
799 struct identity_context *id_context = identity_context(_context);
800 struct identity_resource *id_resource = identity_resource(_resource);
801 struct pipe_context *context = id_context->pipe;
802 struct pipe_resource *resource = id_resource->resource;
803 struct pipe_transfer *result;
804 void *map;
805
806 map = context->transfer_map(context,
807 resource,
808 level,
809 usage,
810 box, &result);
811
812 if (!map)
813 return NULL;
814
815 *transfer = identity_transfer_map(id_context, id_resource, result);
816 return *transfer ? map : NULL;
817 }
818
819 static void
820 identity_context_transfer_flush_region(struct pipe_context *_context,
821 struct pipe_transfer *_transfer,
822 const struct pipe_box *box)
823 {
824 struct identity_context *id_context = identity_context(_context);
825 struct identity_transfer *id_transfer = identity_transfer(_transfer);
826 struct pipe_context *context = id_context->pipe;
827 struct pipe_transfer *transfer = id_transfer->transfer;
828
829 context->transfer_flush_region(context,
830 transfer,
831 box);
832 }
833
834
835 static void
836 identity_context_transfer_unmap(struct pipe_context *_context,
837 struct pipe_transfer *_transfer)
838 {
839 struct identity_context *id_context = identity_context(_context);
840 struct identity_transfer *id_transfer = identity_transfer(_transfer);
841 struct pipe_context *context = id_context->pipe;
842 struct pipe_transfer *transfer = id_transfer->transfer;
843
844 context->transfer_unmap(context,
845 transfer);
846
847 identity_transfer_destroy(identity_context(_context),
848 identity_transfer(_transfer));
849 }
850
851
852 static void
853 identity_context_transfer_inline_write(struct pipe_context *_context,
854 struct pipe_resource *_resource,
855 unsigned level,
856 unsigned usage,
857 const struct pipe_box *box,
858 const void *data,
859 unsigned stride,
860 unsigned layer_stride)
861 {
862 struct identity_context *id_context = identity_context(_context);
863 struct identity_resource *id_resource = identity_resource(_resource);
864 struct pipe_context *context = id_context->pipe;
865 struct pipe_resource *resource = id_resource->resource;
866
867 context->transfer_inline_write(context,
868 resource,
869 level,
870 usage,
871 box,
872 data,
873 stride,
874 layer_stride);
875 }
876
877
878 struct pipe_context *
879 identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
880 {
881 struct identity_context *id_pipe;
882 (void)identity_screen(_screen);
883
884 id_pipe = CALLOC_STRUCT(identity_context);
885 if (!id_pipe) {
886 return NULL;
887 }
888
889 id_pipe->base.screen = _screen;
890 id_pipe->base.priv = pipe->priv; /* expose wrapped data */
891 id_pipe->base.draw = NULL;
892
893 id_pipe->base.destroy = identity_destroy;
894 id_pipe->base.draw_vbo = identity_draw_vbo;
895 id_pipe->base.create_query = identity_create_query;
896 id_pipe->base.destroy_query = identity_destroy_query;
897 id_pipe->base.begin_query = identity_begin_query;
898 id_pipe->base.end_query = identity_end_query;
899 id_pipe->base.get_query_result = identity_get_query_result;
900 id_pipe->base.create_blend_state = identity_create_blend_state;
901 id_pipe->base.bind_blend_state = identity_bind_blend_state;
902 id_pipe->base.delete_blend_state = identity_delete_blend_state;
903 id_pipe->base.create_sampler_state = identity_create_sampler_state;
904 id_pipe->base.bind_fragment_sampler_states = identity_bind_fragment_sampler_states;
905 id_pipe->base.bind_vertex_sampler_states = identity_bind_vertex_sampler_states;
906 id_pipe->base.delete_sampler_state = identity_delete_sampler_state;
907 id_pipe->base.create_rasterizer_state = identity_create_rasterizer_state;
908 id_pipe->base.bind_rasterizer_state = identity_bind_rasterizer_state;
909 id_pipe->base.delete_rasterizer_state = identity_delete_rasterizer_state;
910 id_pipe->base.create_depth_stencil_alpha_state = identity_create_depth_stencil_alpha_state;
911 id_pipe->base.bind_depth_stencil_alpha_state = identity_bind_depth_stencil_alpha_state;
912 id_pipe->base.delete_depth_stencil_alpha_state = identity_delete_depth_stencil_alpha_state;
913 id_pipe->base.create_fs_state = identity_create_fs_state;
914 id_pipe->base.bind_fs_state = identity_bind_fs_state;
915 id_pipe->base.delete_fs_state = identity_delete_fs_state;
916 id_pipe->base.create_vs_state = identity_create_vs_state;
917 id_pipe->base.bind_vs_state = identity_bind_vs_state;
918 id_pipe->base.delete_vs_state = identity_delete_vs_state;
919 id_pipe->base.create_vertex_elements_state = identity_create_vertex_elements_state;
920 id_pipe->base.bind_vertex_elements_state = identity_bind_vertex_elements_state;
921 id_pipe->base.delete_vertex_elements_state = identity_delete_vertex_elements_state;
922 id_pipe->base.set_blend_color = identity_set_blend_color;
923 id_pipe->base.set_stencil_ref = identity_set_stencil_ref;
924 id_pipe->base.set_clip_state = identity_set_clip_state;
925 id_pipe->base.set_sample_mask = identity_set_sample_mask;
926 id_pipe->base.set_constant_buffer = identity_set_constant_buffer;
927 id_pipe->base.set_framebuffer_state = identity_set_framebuffer_state;
928 id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple;
929 id_pipe->base.set_scissor_states = identity_set_scissor_states;
930 id_pipe->base.set_viewport_states = identity_set_viewport_states;
931 id_pipe->base.set_fragment_sampler_views = identity_set_fragment_sampler_views;
932 id_pipe->base.set_vertex_sampler_views = identity_set_vertex_sampler_views;
933 id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers;
934 id_pipe->base.set_index_buffer = identity_set_index_buffer;
935 id_pipe->base.resource_copy_region = identity_resource_copy_region;
936 id_pipe->base.clear = identity_clear;
937 id_pipe->base.clear_render_target = identity_clear_render_target;
938 id_pipe->base.clear_depth_stencil = identity_clear_depth_stencil;
939 id_pipe->base.flush = identity_flush;
940 id_pipe->base.create_surface = identity_context_create_surface;
941 id_pipe->base.surface_destroy = identity_context_surface_destroy;
942 id_pipe->base.create_sampler_view = identity_context_create_sampler_view;
943 id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy;
944 id_pipe->base.transfer_map = identity_context_transfer_map;
945 id_pipe->base.transfer_unmap = identity_context_transfer_unmap;
946 id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region;
947 id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write;
948 id_pipe->base.blit = identity_blit;
949 id_pipe->base.flush_resource = identity_flush_resource;
950
951 id_pipe->pipe = pipe;
952
953 return &id_pipe->base;
954 }