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