glhd_context.c revision 3f758d4ed42f6b4c6bed60f8270ef908d3829ee5
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
31#include "util/u_format.h"
32#include "util/u_memory.h"
33#include "util/u_inlines.h"
34
35#include "glhd_context.h"
36#include "glhd_objects.h"
37
38
39static void
40galahad_destroy(struct pipe_context *_pipe)
41{
42   struct galahad_context *glhd_pipe = galahad_context(_pipe);
43   struct pipe_context *pipe = glhd_pipe->pipe;
44
45   pipe->destroy(pipe);
46
47   FREE(glhd_pipe);
48}
49
50static void
51galahad_draw_arrays(struct pipe_context *_pipe,
52                     unsigned prim,
53                     unsigned start,
54                     unsigned count)
55{
56   struct galahad_context *glhd_pipe = galahad_context(_pipe);
57   struct pipe_context *pipe = glhd_pipe->pipe;
58
59   pipe->draw_arrays(pipe,
60                     prim,
61                     start,
62                     count);
63}
64
65static void
66galahad_draw_elements(struct pipe_context *_pipe,
67                       struct pipe_resource *_indexResource,
68                       unsigned indexSize,
69                       int indexBias,
70                       unsigned prim,
71                       unsigned start,
72                       unsigned count)
73{
74   struct galahad_context *glhd_pipe = galahad_context(_pipe);
75   struct galahad_resource *glhd_resource = galahad_resource(_indexResource);
76   struct pipe_context *pipe = glhd_pipe->pipe;
77   struct pipe_resource *indexResource = glhd_resource->resource;
78
79   pipe->draw_elements(pipe,
80                       indexResource,
81                       indexSize,
82                       indexBias,
83                       prim,
84                       start,
85                       count);
86}
87
88static void
89galahad_draw_range_elements(struct pipe_context *_pipe,
90                             struct pipe_resource *_indexResource,
91                             unsigned indexSize,
92                             int indexBias,
93                             unsigned minIndex,
94                             unsigned maxIndex,
95                             unsigned mode,
96                             unsigned start,
97                             unsigned count)
98{
99   struct galahad_context *glhd_pipe = galahad_context(_pipe);
100   struct galahad_resource *glhd_resource = galahad_resource(_indexResource);
101   struct pipe_context *pipe = glhd_pipe->pipe;
102   struct pipe_resource *indexResource = glhd_resource->resource;
103
104   pipe->draw_range_elements(pipe,
105                             indexResource,
106                             indexSize,
107                             indexBias,
108                             minIndex,
109                             maxIndex,
110                             mode,
111                             start,
112                             count);
113}
114
115static struct pipe_query *
116galahad_create_query(struct pipe_context *_pipe,
117                      unsigned query_type)
118{
119   struct galahad_context *glhd_pipe = galahad_context(_pipe);
120   struct pipe_context *pipe = glhd_pipe->pipe;
121
122   return pipe->create_query(pipe,
123                             query_type);
124}
125
126static void
127galahad_destroy_query(struct pipe_context *_pipe,
128                       struct pipe_query *query)
129{
130   struct galahad_context *glhd_pipe = galahad_context(_pipe);
131   struct pipe_context *pipe = glhd_pipe->pipe;
132
133   pipe->destroy_query(pipe,
134                       query);
135}
136
137static void
138galahad_begin_query(struct pipe_context *_pipe,
139                     struct pipe_query *query)
140{
141   struct galahad_context *glhd_pipe = galahad_context(_pipe);
142   struct pipe_context *pipe = glhd_pipe->pipe;
143
144   pipe->begin_query(pipe,
145                     query);
146}
147
148static void
149galahad_end_query(struct pipe_context *_pipe,
150                   struct pipe_query *query)
151{
152   struct galahad_context *glhd_pipe = galahad_context(_pipe);
153   struct pipe_context *pipe = glhd_pipe->pipe;
154
155   pipe->end_query(pipe,
156                   query);
157}
158
159static boolean
160galahad_get_query_result(struct pipe_context *_pipe,
161                          struct pipe_query *query,
162                          boolean wait,
163                          void *result)
164{
165   struct galahad_context *glhd_pipe = galahad_context(_pipe);
166   struct pipe_context *pipe = glhd_pipe->pipe;
167
168   return pipe->get_query_result(pipe,
169                                 query,
170                                 wait,
171                                 result);
172}
173
174static void *
175galahad_create_blend_state(struct pipe_context *_pipe,
176                            const struct pipe_blend_state *blend)
177{
178   struct galahad_context *glhd_pipe = galahad_context(_pipe);
179   struct pipe_context *pipe = glhd_pipe->pipe;
180
181   return pipe->create_blend_state(pipe,
182                                   blend);
183}
184
185static void
186galahad_bind_blend_state(struct pipe_context *_pipe,
187                          void *blend)
188{
189   struct galahad_context *glhd_pipe = galahad_context(_pipe);
190   struct pipe_context *pipe = glhd_pipe->pipe;
191
192   pipe->bind_blend_state(pipe,
193                              blend);
194}
195
196static void
197galahad_delete_blend_state(struct pipe_context *_pipe,
198                            void *blend)
199{
200   struct galahad_context *glhd_pipe = galahad_context(_pipe);
201   struct pipe_context *pipe = glhd_pipe->pipe;
202
203   pipe->delete_blend_state(pipe,
204                            blend);
205}
206
207static void *
208galahad_create_sampler_state(struct pipe_context *_pipe,
209                              const struct pipe_sampler_state *sampler)
210{
211   struct galahad_context *glhd_pipe = galahad_context(_pipe);
212   struct pipe_context *pipe = glhd_pipe->pipe;
213
214   return pipe->create_sampler_state(pipe,
215                                     sampler);
216}
217
218static void
219galahad_bind_fragment_sampler_states(struct pipe_context *_pipe,
220                                      unsigned num_samplers,
221                                      void **samplers)
222{
223   struct galahad_context *glhd_pipe = galahad_context(_pipe);
224   struct pipe_context *pipe = glhd_pipe->pipe;
225
226   pipe->bind_fragment_sampler_states(pipe,
227                                      num_samplers,
228                                      samplers);
229}
230
231static void
232galahad_bind_vertex_sampler_states(struct pipe_context *_pipe,
233                                    unsigned num_samplers,
234                                    void **samplers)
235{
236   struct galahad_context *glhd_pipe = galahad_context(_pipe);
237   struct pipe_context *pipe = glhd_pipe->pipe;
238
239   pipe->bind_vertex_sampler_states(pipe,
240                                    num_samplers,
241                                    samplers);
242}
243
244static void
245galahad_delete_sampler_state(struct pipe_context *_pipe,
246                              void *sampler)
247{
248   struct galahad_context *glhd_pipe = galahad_context(_pipe);
249   struct pipe_context *pipe = glhd_pipe->pipe;
250
251   pipe->delete_sampler_state(pipe,
252                              sampler);
253}
254
255static void *
256galahad_create_rasterizer_state(struct pipe_context *_pipe,
257                                 const struct pipe_rasterizer_state *rasterizer)
258{
259   struct galahad_context *glhd_pipe = galahad_context(_pipe);
260   struct pipe_context *pipe = glhd_pipe->pipe;
261
262   return pipe->create_rasterizer_state(pipe,
263                                        rasterizer);
264}
265
266static void
267galahad_bind_rasterizer_state(struct pipe_context *_pipe,
268                               void *rasterizer)
269{
270   struct galahad_context *glhd_pipe = galahad_context(_pipe);
271   struct pipe_context *pipe = glhd_pipe->pipe;
272
273   pipe->bind_rasterizer_state(pipe,
274                               rasterizer);
275}
276
277static void
278galahad_delete_rasterizer_state(struct pipe_context *_pipe,
279                                 void *rasterizer)
280{
281   struct galahad_context *glhd_pipe = galahad_context(_pipe);
282   struct pipe_context *pipe = glhd_pipe->pipe;
283
284   pipe->delete_rasterizer_state(pipe,
285                                 rasterizer);
286}
287
288static void *
289galahad_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
290                                          const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
291{
292   struct galahad_context *glhd_pipe = galahad_context(_pipe);
293   struct pipe_context *pipe = glhd_pipe->pipe;
294
295   return pipe->create_depth_stencil_alpha_state(pipe,
296                                                 depth_stencil_alpha);
297}
298
299static void
300galahad_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
301                                        void *depth_stencil_alpha)
302{
303   struct galahad_context *glhd_pipe = galahad_context(_pipe);
304   struct pipe_context *pipe = glhd_pipe->pipe;
305
306   pipe->bind_depth_stencil_alpha_state(pipe,
307                                        depth_stencil_alpha);
308}
309
310static void
311galahad_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
312                                          void *depth_stencil_alpha)
313{
314   struct galahad_context *glhd_pipe = galahad_context(_pipe);
315   struct pipe_context *pipe = glhd_pipe->pipe;
316
317   pipe->delete_depth_stencil_alpha_state(pipe,
318                                          depth_stencil_alpha);
319}
320
321static void *
322galahad_create_fs_state(struct pipe_context *_pipe,
323                         const struct pipe_shader_state *fs)
324{
325   struct galahad_context *glhd_pipe = galahad_context(_pipe);
326   struct pipe_context *pipe = glhd_pipe->pipe;
327
328   return pipe->create_fs_state(pipe,
329                                fs);
330}
331
332static void
333galahad_bind_fs_state(struct pipe_context *_pipe,
334                       void *fs)
335{
336   struct galahad_context *glhd_pipe = galahad_context(_pipe);
337   struct pipe_context *pipe = glhd_pipe->pipe;
338
339   pipe->bind_fs_state(pipe,
340                       fs);
341}
342
343static void
344galahad_delete_fs_state(struct pipe_context *_pipe,
345                         void *fs)
346{
347   struct galahad_context *glhd_pipe = galahad_context(_pipe);
348   struct pipe_context *pipe = glhd_pipe->pipe;
349
350   pipe->delete_fs_state(pipe,
351                         fs);
352}
353
354static void *
355galahad_create_vs_state(struct pipe_context *_pipe,
356                         const struct pipe_shader_state *vs)
357{
358   struct galahad_context *glhd_pipe = galahad_context(_pipe);
359   struct pipe_context *pipe = glhd_pipe->pipe;
360
361   return pipe->create_vs_state(pipe,
362                                vs);
363}
364
365static void
366galahad_bind_vs_state(struct pipe_context *_pipe,
367                       void *vs)
368{
369   struct galahad_context *glhd_pipe = galahad_context(_pipe);
370   struct pipe_context *pipe = glhd_pipe->pipe;
371
372   pipe->bind_vs_state(pipe,
373                       vs);
374}
375
376static void
377galahad_delete_vs_state(struct pipe_context *_pipe,
378                         void *vs)
379{
380   struct galahad_context *glhd_pipe = galahad_context(_pipe);
381   struct pipe_context *pipe = glhd_pipe->pipe;
382
383   pipe->delete_vs_state(pipe,
384                         vs);
385}
386
387
388static void *
389galahad_create_vertex_elements_state(struct pipe_context *_pipe,
390                                      unsigned num_elements,
391                                      const struct pipe_vertex_element *vertex_elements)
392{
393   struct galahad_context *glhd_pipe = galahad_context(_pipe);
394   struct pipe_context *pipe = glhd_pipe->pipe;
395
396   return pipe->create_vertex_elements_state(pipe,
397                                             num_elements,
398                                             vertex_elements);
399}
400
401static void
402galahad_bind_vertex_elements_state(struct pipe_context *_pipe,
403                                    void *velems)
404{
405   struct galahad_context *glhd_pipe = galahad_context(_pipe);
406   struct pipe_context *pipe = glhd_pipe->pipe;
407
408   pipe->bind_vertex_elements_state(pipe,
409                                    velems);
410}
411
412static void
413galahad_delete_vertex_elements_state(struct pipe_context *_pipe,
414                                      void *velems)
415{
416   struct galahad_context *glhd_pipe = galahad_context(_pipe);
417   struct pipe_context *pipe = glhd_pipe->pipe;
418
419   pipe->delete_vertex_elements_state(pipe,
420                                      velems);
421}
422
423static void
424galahad_set_blend_color(struct pipe_context *_pipe,
425                         const struct pipe_blend_color *blend_color)
426{
427   struct galahad_context *glhd_pipe = galahad_context(_pipe);
428   struct pipe_context *pipe = glhd_pipe->pipe;
429
430   pipe->set_blend_color(pipe,
431                         blend_color);
432}
433
434static void
435galahad_set_stencil_ref(struct pipe_context *_pipe,
436                         const struct pipe_stencil_ref *stencil_ref)
437{
438   struct galahad_context *glhd_pipe = galahad_context(_pipe);
439   struct pipe_context *pipe = glhd_pipe->pipe;
440
441   pipe->set_stencil_ref(pipe,
442                         stencil_ref);
443}
444
445static void
446galahad_set_clip_state(struct pipe_context *_pipe,
447                        const struct pipe_clip_state *clip)
448{
449   struct galahad_context *glhd_pipe = galahad_context(_pipe);
450   struct pipe_context *pipe = glhd_pipe->pipe;
451
452   pipe->set_clip_state(pipe,
453                        clip);
454}
455
456static void
457galahad_set_sample_mask(struct pipe_context *_pipe,
458                         unsigned sample_mask)
459{
460   struct galahad_context *glhd_pipe = galahad_context(_pipe);
461   struct pipe_context *pipe = glhd_pipe->pipe;
462
463   pipe->set_sample_mask(pipe,
464                         sample_mask);
465}
466
467static void
468galahad_set_constant_buffer(struct pipe_context *_pipe,
469                             uint shader,
470                             uint index,
471                             struct pipe_resource *_resource)
472{
473   struct galahad_context *glhd_pipe = galahad_context(_pipe);
474   struct pipe_context *pipe = glhd_pipe->pipe;
475   struct pipe_resource *unwrapped_resource;
476   struct pipe_resource *resource = NULL;
477
478   /* XXX hmm? unwrap the input state */
479   if (_resource) {
480      unwrapped_resource = galahad_resource_unwrap(_resource);
481      resource = unwrapped_resource;
482   }
483
484   pipe->set_constant_buffer(pipe,
485                             shader,
486                             index,
487                             resource);
488}
489
490static void
491galahad_set_framebuffer_state(struct pipe_context *_pipe,
492                               const struct pipe_framebuffer_state *_state)
493{
494   struct galahad_context *glhd_pipe = galahad_context(_pipe);
495   struct pipe_context *pipe = glhd_pipe->pipe;
496   struct pipe_framebuffer_state unwrapped_state;
497   struct pipe_framebuffer_state *state = NULL;
498   unsigned i;
499
500   /* unwrap the input state */
501   if (_state) {
502      memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
503      for(i = 0; i < _state->nr_cbufs; i++)
504         unwrapped_state.cbufs[i] = galahad_surface_unwrap(_state->cbufs[i]);
505      for (; i < PIPE_MAX_COLOR_BUFS; i++)
506         unwrapped_state.cbufs[i] = NULL;
507      unwrapped_state.zsbuf = galahad_surface_unwrap(_state->zsbuf);
508      state = &unwrapped_state;
509   }
510
511   pipe->set_framebuffer_state(pipe,
512                               state);
513}
514
515static void
516galahad_set_polygon_stipple(struct pipe_context *_pipe,
517                             const struct pipe_poly_stipple *poly_stipple)
518{
519   struct galahad_context *glhd_pipe = galahad_context(_pipe);
520   struct pipe_context *pipe = glhd_pipe->pipe;
521
522   pipe->set_polygon_stipple(pipe,
523                             poly_stipple);
524}
525
526static void
527galahad_set_scissor_state(struct pipe_context *_pipe,
528                           const struct pipe_scissor_state *scissor)
529{
530   struct galahad_context *glhd_pipe = galahad_context(_pipe);
531   struct pipe_context *pipe = glhd_pipe->pipe;
532
533   pipe->set_scissor_state(pipe,
534                           scissor);
535}
536
537static void
538galahad_set_viewport_state(struct pipe_context *_pipe,
539                            const struct pipe_viewport_state *viewport)
540{
541   struct galahad_context *glhd_pipe = galahad_context(_pipe);
542   struct pipe_context *pipe = glhd_pipe->pipe;
543
544   pipe->set_viewport_state(pipe,
545                            viewport);
546}
547
548static void
549galahad_set_fragment_sampler_views(struct pipe_context *_pipe,
550                                    unsigned num,
551                                    struct pipe_sampler_view **_views)
552{
553   struct galahad_context *glhd_pipe = galahad_context(_pipe);
554   struct pipe_context *pipe = glhd_pipe->pipe;
555   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
556   struct pipe_sampler_view **views = NULL;
557   unsigned i;
558
559   if (_views) {
560      for (i = 0; i < num; i++)
561         unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
562      for (; i < PIPE_MAX_SAMPLERS; i++)
563         unwrapped_views[i] = NULL;
564
565      views = unwrapped_views;
566   }
567
568   pipe->set_fragment_sampler_views(pipe, num, views);
569}
570
571static void
572galahad_set_vertex_sampler_views(struct pipe_context *_pipe,
573                                  unsigned num,
574                                  struct pipe_sampler_view **_views)
575{
576   struct galahad_context *glhd_pipe = galahad_context(_pipe);
577   struct pipe_context *pipe = glhd_pipe->pipe;
578   struct pipe_sampler_view *unwrapped_views[PIPE_MAX_VERTEX_SAMPLERS];
579   struct pipe_sampler_view **views = NULL;
580   unsigned i;
581
582   if (_views) {
583      for (i = 0; i < num; i++)
584         unwrapped_views[i] = galahad_sampler_view_unwrap(_views[i]);
585      for (; i < PIPE_MAX_VERTEX_SAMPLERS; i++)
586         unwrapped_views[i] = NULL;
587
588      views = unwrapped_views;
589   }
590
591   pipe->set_vertex_sampler_views(pipe, num, views);
592}
593
594static void
595galahad_set_vertex_buffers(struct pipe_context *_pipe,
596                            unsigned num_buffers,
597                            const struct pipe_vertex_buffer *_buffers)
598{
599   struct galahad_context *glhd_pipe = galahad_context(_pipe);
600   struct pipe_context *pipe = glhd_pipe->pipe;
601   struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
602   struct pipe_vertex_buffer *buffers = NULL;
603   unsigned i;
604
605   if (num_buffers) {
606      memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
607      for (i = 0; i < num_buffers; i++)
608         unwrapped_buffers[i].buffer = galahad_resource_unwrap(_buffers[i].buffer);
609      buffers = unwrapped_buffers;
610   }
611
612   pipe->set_vertex_buffers(pipe,
613                            num_buffers,
614                            buffers);
615}
616static void
617galahad_resource_copy_region(struct pipe_context *_pipe,
618                              struct pipe_resource *_dst,
619                              struct pipe_subresource subdst,
620                              unsigned dstx,
621                              unsigned dsty,
622                              unsigned dstz,
623                              struct pipe_resource *_src,
624                              struct pipe_subresource subsrc,
625                              unsigned srcx,
626                              unsigned srcy,
627                              unsigned srcz,
628                              unsigned width,
629                              unsigned height)
630{
631   struct galahad_context *glhd_pipe = galahad_context(_pipe);
632   struct galahad_resource *glhd_resource_dst = galahad_resource(_dst);
633   struct galahad_resource *glhd_resource_src = galahad_resource(_src);
634   struct pipe_context *pipe = glhd_pipe->pipe;
635   struct pipe_resource *dst = glhd_resource_dst->resource;
636   struct pipe_resource *src = glhd_resource_src->resource;
637
638   if (_dst->format != _src->format) {
639      glhd_warn("Format mismatch: Source is %s, destination is %s",
640         util_format_short_name(_src->format),
641         util_format_short_name(_dst->format));
642   }
643
644   pipe->resource_copy_region(pipe,
645                              dst,
646                              subdst,
647                              dstx,
648                              dsty,
649                              dstz,
650                              src,
651                              subsrc,
652                              srcx,
653                              srcy,
654                              srcz,
655                              width,
656                              height);
657}
658
659static void
660galahad_clear(struct pipe_context *_pipe,
661               unsigned buffers,
662               const float *rgba,
663               double depth,
664               unsigned stencil)
665{
666   struct galahad_context *glhd_pipe = galahad_context(_pipe);
667   struct pipe_context *pipe = glhd_pipe->pipe;
668
669   pipe->clear(pipe,
670               buffers,
671               rgba,
672               depth,
673               stencil);
674}
675
676static void
677galahad_clear_render_target(struct pipe_context *_pipe,
678                             struct pipe_surface *_dst,
679                             const float *rgba,
680                             unsigned dstx, unsigned dsty,
681                             unsigned width, unsigned height)
682{
683   struct galahad_context *glhd_pipe = galahad_context(_pipe);
684   struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
685   struct pipe_context *pipe = glhd_pipe->pipe;
686   struct pipe_surface *dst = glhd_surface_dst->surface;
687
688   pipe->clear_render_target(pipe,
689                             dst,
690                             rgba,
691                             dstx,
692                             dsty,
693                             width,
694                             height);
695}
696static void
697galahad_clear_depth_stencil(struct pipe_context *_pipe,
698                             struct pipe_surface *_dst,
699                             unsigned clear_flags,
700                             double depth,
701                             unsigned stencil,
702                             unsigned dstx, unsigned dsty,
703                             unsigned width, unsigned height)
704{
705   struct galahad_context *glhd_pipe = galahad_context(_pipe);
706   struct galahad_surface *glhd_surface_dst = galahad_surface(_dst);
707   struct pipe_context *pipe = glhd_pipe->pipe;
708   struct pipe_surface *dst = glhd_surface_dst->surface;
709
710   pipe->clear_depth_stencil(pipe,
711                             dst,
712                             clear_flags,
713                             depth,
714                             stencil,
715                             dstx,
716                             dsty,
717                             width,
718                             height);
719
720}
721
722static void
723galahad_flush(struct pipe_context *_pipe,
724               unsigned flags,
725               struct pipe_fence_handle **fence)
726{
727   struct galahad_context *glhd_pipe = galahad_context(_pipe);
728   struct pipe_context *pipe = glhd_pipe->pipe;
729
730   pipe->flush(pipe,
731               flags,
732               fence);
733}
734
735static unsigned int
736galahad_is_resource_referenced(struct pipe_context *_pipe,
737                                struct pipe_resource *_resource,
738                                unsigned face,
739                                unsigned level)
740{
741   struct galahad_context *glhd_pipe = galahad_context(_pipe);
742   struct galahad_resource *glhd_resource = galahad_resource(_resource);
743   struct pipe_context *pipe = glhd_pipe->pipe;
744   struct pipe_resource *resource = glhd_resource->resource;
745
746   return pipe->is_resource_referenced(pipe,
747                                       resource,
748                                       face,
749                                       level);
750}
751
752static struct pipe_sampler_view *
753galahad_context_create_sampler_view(struct pipe_context *_pipe,
754                                     struct pipe_resource *_resource,
755                                     const struct pipe_sampler_view *templ)
756{
757   struct galahad_context *glhd_context = galahad_context(_pipe);
758   struct galahad_resource *glhd_resource = galahad_resource(_resource);
759   struct pipe_context *pipe = glhd_context->pipe;
760   struct pipe_resource *resource = glhd_resource->resource;
761   struct pipe_sampler_view *result;
762
763   result = pipe->create_sampler_view(pipe,
764                                      resource,
765                                      templ);
766
767   if (result)
768      return galahad_sampler_view_create(glhd_context, glhd_resource, result);
769   return NULL;
770}
771
772static void
773galahad_context_sampler_view_destroy(struct pipe_context *_pipe,
774                                      struct pipe_sampler_view *_view)
775{
776   galahad_sampler_view_destroy(galahad_context(_pipe),
777                                 galahad_sampler_view(_view));
778}
779
780static struct pipe_transfer *
781galahad_context_get_transfer(struct pipe_context *_context,
782                              struct pipe_resource *_resource,
783                              struct pipe_subresource sr,
784                              unsigned usage,
785                              const struct pipe_box *box)
786{
787   struct galahad_context *glhd_context = galahad_context(_context);
788   struct galahad_resource *glhd_resource = galahad_resource(_resource);
789   struct pipe_context *context = glhd_context->pipe;
790   struct pipe_resource *resource = glhd_resource->resource;
791   struct pipe_transfer *result;
792
793   result = context->get_transfer(context,
794                                  resource,
795                                  sr,
796                                  usage,
797                                  box);
798
799   if (result)
800      return galahad_transfer_create(glhd_context, glhd_resource, result);
801   return NULL;
802}
803
804static void
805galahad_context_transfer_destroy(struct pipe_context *_pipe,
806                                  struct pipe_transfer *_transfer)
807{
808   galahad_transfer_destroy(galahad_context(_pipe),
809                             galahad_transfer(_transfer));
810}
811
812static void *
813galahad_context_transfer_map(struct pipe_context *_context,
814                              struct pipe_transfer *_transfer)
815{
816   struct galahad_context *glhd_context = galahad_context(_context);
817   struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
818   struct pipe_context *context = glhd_context->pipe;
819   struct pipe_transfer *transfer = glhd_transfer->transfer;
820
821   return context->transfer_map(context,
822                                transfer);
823}
824
825
826
827static void
828galahad_context_transfer_flush_region(struct pipe_context *_context,
829                                       struct pipe_transfer *_transfer,
830                                       const struct pipe_box *box)
831{
832   struct galahad_context *glhd_context = galahad_context(_context);
833   struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
834   struct pipe_context *context = glhd_context->pipe;
835   struct pipe_transfer *transfer = glhd_transfer->transfer;
836
837   context->transfer_flush_region(context,
838                                  transfer,
839                                  box);
840}
841
842
843static void
844galahad_context_transfer_unmap(struct pipe_context *_context,
845                                struct pipe_transfer *_transfer)
846{
847   struct galahad_context *glhd_context = galahad_context(_context);
848   struct galahad_transfer *glhd_transfer = galahad_transfer(_transfer);
849   struct pipe_context *context = glhd_context->pipe;
850   struct pipe_transfer *transfer = glhd_transfer->transfer;
851
852   context->transfer_unmap(context,
853                           transfer);
854}
855
856
857static void
858galahad_context_transfer_inline_write(struct pipe_context *_context,
859                                       struct pipe_resource *_resource,
860                                       struct pipe_subresource sr,
861                                       unsigned usage,
862                                       const struct pipe_box *box,
863                                       const void *data,
864                                       unsigned stride,
865                                       unsigned slice_stride)
866{
867   struct galahad_context *glhd_context = galahad_context(_context);
868   struct galahad_resource *glhd_resource = galahad_resource(_resource);
869   struct pipe_context *context = glhd_context->pipe;
870   struct pipe_resource *resource = glhd_resource->resource;
871
872   context->transfer_inline_write(context,
873                                  resource,
874                                  sr,
875                                  usage,
876                                  box,
877                                  data,
878                                  stride,
879                                  slice_stride);
880}
881
882
883struct pipe_context *
884galahad_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
885{
886   struct galahad_context *glhd_pipe;
887   (void)galahad_screen(_screen);
888
889   glhd_pipe = CALLOC_STRUCT(galahad_context);
890   if (!glhd_pipe) {
891      return NULL;
892   }
893
894   glhd_pipe->base.winsys = NULL;
895   glhd_pipe->base.screen = _screen;
896   glhd_pipe->base.priv = pipe->priv; /* expose wrapped data */
897   glhd_pipe->base.draw = NULL;
898
899   glhd_pipe->base.destroy = galahad_destroy;
900   glhd_pipe->base.draw_arrays = galahad_draw_arrays;
901   glhd_pipe->base.draw_elements = galahad_draw_elements;
902   glhd_pipe->base.draw_range_elements = galahad_draw_range_elements;
903   glhd_pipe->base.create_query = galahad_create_query;
904   glhd_pipe->base.destroy_query = galahad_destroy_query;
905   glhd_pipe->base.begin_query = galahad_begin_query;
906   glhd_pipe->base.end_query = galahad_end_query;
907   glhd_pipe->base.get_query_result = galahad_get_query_result;
908   glhd_pipe->base.create_blend_state = galahad_create_blend_state;
909   glhd_pipe->base.bind_blend_state = galahad_bind_blend_state;
910   glhd_pipe->base.delete_blend_state = galahad_delete_blend_state;
911   glhd_pipe->base.create_sampler_state = galahad_create_sampler_state;
912   glhd_pipe->base.bind_fragment_sampler_states = galahad_bind_fragment_sampler_states;
913   glhd_pipe->base.bind_vertex_sampler_states = galahad_bind_vertex_sampler_states;
914   glhd_pipe->base.delete_sampler_state = galahad_delete_sampler_state;
915   glhd_pipe->base.create_rasterizer_state = galahad_create_rasterizer_state;
916   glhd_pipe->base.bind_rasterizer_state = galahad_bind_rasterizer_state;
917   glhd_pipe->base.delete_rasterizer_state = galahad_delete_rasterizer_state;
918   glhd_pipe->base.create_depth_stencil_alpha_state = galahad_create_depth_stencil_alpha_state;
919   glhd_pipe->base.bind_depth_stencil_alpha_state = galahad_bind_depth_stencil_alpha_state;
920   glhd_pipe->base.delete_depth_stencil_alpha_state = galahad_delete_depth_stencil_alpha_state;
921   glhd_pipe->base.create_fs_state = galahad_create_fs_state;
922   glhd_pipe->base.bind_fs_state = galahad_bind_fs_state;
923   glhd_pipe->base.delete_fs_state = galahad_delete_fs_state;
924   glhd_pipe->base.create_vs_state = galahad_create_vs_state;
925   glhd_pipe->base.bind_vs_state = galahad_bind_vs_state;
926   glhd_pipe->base.delete_vs_state = galahad_delete_vs_state;
927   glhd_pipe->base.create_vertex_elements_state = galahad_create_vertex_elements_state;
928   glhd_pipe->base.bind_vertex_elements_state = galahad_bind_vertex_elements_state;
929   glhd_pipe->base.delete_vertex_elements_state = galahad_delete_vertex_elements_state;
930   glhd_pipe->base.set_blend_color = galahad_set_blend_color;
931   glhd_pipe->base.set_stencil_ref = galahad_set_stencil_ref;
932   glhd_pipe->base.set_clip_state = galahad_set_clip_state;
933   glhd_pipe->base.set_sample_mask = galahad_set_sample_mask;
934   glhd_pipe->base.set_constant_buffer = galahad_set_constant_buffer;
935   glhd_pipe->base.set_framebuffer_state = galahad_set_framebuffer_state;
936   glhd_pipe->base.set_polygon_stipple = galahad_set_polygon_stipple;
937   glhd_pipe->base.set_scissor_state = galahad_set_scissor_state;
938   glhd_pipe->base.set_viewport_state = galahad_set_viewport_state;
939   glhd_pipe->base.set_fragment_sampler_views = galahad_set_fragment_sampler_views;
940   glhd_pipe->base.set_vertex_sampler_views = galahad_set_vertex_sampler_views;
941   glhd_pipe->base.set_vertex_buffers = galahad_set_vertex_buffers;
942   glhd_pipe->base.resource_copy_region = galahad_resource_copy_region;
943   glhd_pipe->base.clear = galahad_clear;
944   glhd_pipe->base.clear_render_target = galahad_clear_render_target;
945   glhd_pipe->base.clear_depth_stencil = galahad_clear_depth_stencil;
946   glhd_pipe->base.flush = galahad_flush;
947   glhd_pipe->base.is_resource_referenced = galahad_is_resource_referenced;
948   glhd_pipe->base.create_sampler_view = galahad_context_create_sampler_view;
949   glhd_pipe->base.sampler_view_destroy = galahad_context_sampler_view_destroy;
950   glhd_pipe->base.get_transfer = galahad_context_get_transfer;
951   glhd_pipe->base.transfer_destroy = galahad_context_transfer_destroy;
952   glhd_pipe->base.transfer_map = galahad_context_transfer_map;
953   glhd_pipe->base.transfer_unmap = galahad_context_transfer_unmap;
954   glhd_pipe->base.transfer_flush_region = galahad_context_transfer_flush_region;
955   glhd_pipe->base.transfer_inline_write = galahad_context_transfer_inline_write;
956
957   glhd_pipe->pipe = pipe;
958
959   return &glhd_pipe->base;
960}
961