Home | History | Annotate | Download | only in identity
      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_state(struct pipe_context *_pipe,
    490                            const struct pipe_scissor_state *scissor)
    491 {
    492    struct identity_context *id_pipe = identity_context(_pipe);
    493    struct pipe_context *pipe = id_pipe->pipe;
    494 
    495    pipe->set_scissor_state(pipe,
    496                            scissor);
    497 }
    498 
    499 static void
    500 identity_set_viewport_state(struct pipe_context *_pipe,
    501                             const struct pipe_viewport_state *viewport)
    502 {
    503    struct identity_context *id_pipe = identity_context(_pipe);
    504    struct pipe_context *pipe = id_pipe->pipe;
    505 
    506    pipe->set_viewport_state(pipe,
    507                             viewport);
    508 }
    509 
    510 static void
    511 identity_set_sampler_views(struct pipe_context *_pipe,
    512                            unsigned shader,
    513                            unsigned start,
    514                            unsigned num,
    515                            struct pipe_sampler_view **_views)
    516 {
    517    struct identity_context *id_pipe = identity_context(_pipe);
    518    struct pipe_context *pipe = id_pipe->pipe;
    519    struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SAMPLERS];
    520    struct pipe_sampler_view **views = NULL;
    521    unsigned i;
    522 
    523    /* remove this when we have pipe->set_sampler_views(..., start, ...) */
    524    assert(start == 0);
    525 
    526    if (_views) {
    527       for (i = 0; i < num; i++)
    528          unwrapped_views[i] = identity_sampler_view_unwrap(_views[i]);
    529       for (; i < PIPE_MAX_SAMPLERS; i++)
    530          unwrapped_views[i] = NULL;
    531 
    532       views = unwrapped_views;
    533    }
    534 
    535    switch (shader) {
    536    case PIPE_SHADER_VERTEX:
    537       pipe->set_vertex_sampler_views(pipe, num, views);
    538       break;
    539    case PIPE_SHADER_GEOMETRY:
    540       pipe->set_geometry_sampler_views(pipe, num, views);
    541       break;
    542    case PIPE_SHADER_FRAGMENT:
    543       pipe->set_fragment_sampler_views(pipe, num, views);
    544       break;
    545    default:
    546       debug_error("Unexpected shader in identity_set_sampler_views()");
    547    }
    548 }
    549 
    550 static void
    551 identity_set_fragment_sampler_views(struct pipe_context *_pipe,
    552                                     unsigned num,
    553                                     struct pipe_sampler_view **_views)
    554 {
    555    identity_set_sampler_views(_pipe, PIPE_SHADER_FRAGMENT, 0, num, _views);
    556 }
    557 
    558 static void
    559 identity_set_vertex_sampler_views(struct pipe_context *_pipe,
    560                                   unsigned num,
    561                                   struct pipe_sampler_view **_views)
    562 {
    563    identity_set_sampler_views(_pipe, PIPE_SHADER_VERTEX, 0, num, _views);
    564 }
    565 
    566 static void
    567 identity_set_vertex_buffers(struct pipe_context *_pipe,
    568                             unsigned num_buffers,
    569                             const struct pipe_vertex_buffer *_buffers)
    570 {
    571    struct identity_context *id_pipe = identity_context(_pipe);
    572    struct pipe_context *pipe = id_pipe->pipe;
    573    struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
    574    struct pipe_vertex_buffer *buffers = NULL;
    575    unsigned i;
    576 
    577    if (num_buffers) {
    578       memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
    579       for (i = 0; i < num_buffers; i++)
    580          unwrapped_buffers[i].buffer = identity_resource_unwrap(_buffers[i].buffer);
    581       buffers = unwrapped_buffers;
    582    }
    583 
    584    pipe->set_vertex_buffers(pipe,
    585                             num_buffers,
    586                             buffers);
    587 }
    588 
    589 static void
    590 identity_set_index_buffer(struct pipe_context *_pipe,
    591                           const struct pipe_index_buffer *_ib)
    592 {
    593    struct identity_context *id_pipe = identity_context(_pipe);
    594    struct pipe_context *pipe = id_pipe->pipe;
    595    struct pipe_index_buffer unwrapped_ib, *ib = NULL;
    596 
    597    if (_ib) {
    598       unwrapped_ib = *_ib;
    599       unwrapped_ib.buffer = identity_resource_unwrap(_ib->buffer);
    600       ib = &unwrapped_ib;
    601    }
    602 
    603    pipe->set_index_buffer(pipe, ib);
    604 }
    605 
    606 static void
    607 identity_resource_copy_region(struct pipe_context *_pipe,
    608                               struct pipe_resource *_dst,
    609                               unsigned dst_level,
    610                               unsigned dstx,
    611                               unsigned dsty,
    612                               unsigned dstz,
    613                               struct pipe_resource *_src,
    614                               unsigned src_level,
    615                               const struct pipe_box *src_box)
    616 {
    617    struct identity_context *id_pipe = identity_context(_pipe);
    618    struct identity_resource *id_resource_dst = identity_resource(_dst);
    619    struct identity_resource *id_resource_src = identity_resource(_src);
    620    struct pipe_context *pipe = id_pipe->pipe;
    621    struct pipe_resource *dst = id_resource_dst->resource;
    622    struct pipe_resource *src = id_resource_src->resource;
    623 
    624    pipe->resource_copy_region(pipe,
    625                               dst,
    626                               dst_level,
    627                               dstx,
    628                               dsty,
    629                               dstz,
    630                               src,
    631                               src_level,
    632                               src_box);
    633 }
    634 
    635 static void
    636 identity_clear(struct pipe_context *_pipe,
    637                unsigned buffers,
    638                const union pipe_color_union *color,
    639                double depth,
    640                unsigned stencil)
    641 {
    642    struct identity_context *id_pipe = identity_context(_pipe);
    643    struct pipe_context *pipe = id_pipe->pipe;
    644 
    645    pipe->clear(pipe,
    646                buffers,
    647                color,
    648                depth,
    649                stencil);
    650 }
    651 
    652 static void
    653 identity_clear_render_target(struct pipe_context *_pipe,
    654                              struct pipe_surface *_dst,
    655                              const union pipe_color_union *color,
    656                              unsigned dstx, unsigned dsty,
    657                              unsigned width, unsigned height)
    658 {
    659    struct identity_context *id_pipe = identity_context(_pipe);
    660    struct identity_surface *id_surface_dst = identity_surface(_dst);
    661    struct pipe_context *pipe = id_pipe->pipe;
    662    struct pipe_surface *dst = id_surface_dst->surface;
    663 
    664    pipe->clear_render_target(pipe,
    665                              dst,
    666                              color,
    667                              dstx,
    668                              dsty,
    669                              width,
    670                              height);
    671 }
    672 static void
    673 identity_clear_depth_stencil(struct pipe_context *_pipe,
    674                              struct pipe_surface *_dst,
    675                              unsigned clear_flags,
    676                              double depth,
    677                              unsigned stencil,
    678                              unsigned dstx, unsigned dsty,
    679                              unsigned width, unsigned height)
    680 {
    681    struct identity_context *id_pipe = identity_context(_pipe);
    682    struct identity_surface *id_surface_dst = identity_surface(_dst);
    683    struct pipe_context *pipe = id_pipe->pipe;
    684    struct pipe_surface *dst = id_surface_dst->surface;
    685 
    686    pipe->clear_depth_stencil(pipe,
    687                              dst,
    688                              clear_flags,
    689                              depth,
    690                              stencil,
    691                              dstx,
    692                              dsty,
    693                              width,
    694                              height);
    695 
    696 }
    697 
    698 static void
    699 identity_flush(struct pipe_context *_pipe,
    700                struct pipe_fence_handle **fence)
    701 {
    702    struct identity_context *id_pipe = identity_context(_pipe);
    703    struct pipe_context *pipe = id_pipe->pipe;
    704 
    705    pipe->flush(pipe,
    706                fence);
    707 }
    708 
    709 static struct pipe_sampler_view *
    710 identity_context_create_sampler_view(struct pipe_context *_pipe,
    711                                      struct pipe_resource *_resource,
    712                                      const struct pipe_sampler_view *templ)
    713 {
    714    struct identity_context *id_context = identity_context(_pipe);
    715    struct identity_resource *id_resource = identity_resource(_resource);
    716    struct pipe_context *pipe = id_context->pipe;
    717    struct pipe_resource *resource = id_resource->resource;
    718    struct pipe_sampler_view *result;
    719 
    720    result = pipe->create_sampler_view(pipe,
    721                                       resource,
    722                                       templ);
    723 
    724    if (result)
    725       return identity_sampler_view_create(id_context, id_resource, result);
    726    return NULL;
    727 }
    728 
    729 static void
    730 identity_context_sampler_view_destroy(struct pipe_context *_pipe,
    731                                       struct pipe_sampler_view *_view)
    732 {
    733    identity_sampler_view_destroy(identity_context(_pipe),
    734                                  identity_sampler_view(_view));
    735 }
    736 
    737 static struct pipe_surface *
    738 identity_context_create_surface(struct pipe_context *_pipe,
    739                                 struct pipe_resource *_resource,
    740                                 const struct pipe_surface *templ)
    741 {
    742    struct identity_context *id_context = identity_context(_pipe);
    743    struct identity_resource *id_resource = identity_resource(_resource);
    744    struct pipe_context *pipe = id_context->pipe;
    745    struct pipe_resource *resource = id_resource->resource;
    746    struct pipe_surface *result;
    747 
    748    result = pipe->create_surface(pipe,
    749                                  resource,
    750                                  templ);
    751 
    752    if (result)
    753       return identity_surface_create(id_context, id_resource, result);
    754    return NULL;
    755 }
    756 
    757 static void
    758 identity_context_surface_destroy(struct pipe_context *_pipe,
    759                                  struct pipe_surface *_surf)
    760 {
    761    identity_surface_destroy(identity_context(_pipe),
    762                             identity_surface(_surf));
    763 }
    764 
    765 static struct pipe_transfer *
    766 identity_context_get_transfer(struct pipe_context *_context,
    767                               struct pipe_resource *_resource,
    768                               unsigned level,
    769                               unsigned usage,
    770                               const struct pipe_box *box)
    771 {
    772    struct identity_context *id_context = identity_context(_context);
    773    struct identity_resource *id_resource = identity_resource(_resource);
    774    struct pipe_context *context = id_context->pipe;
    775    struct pipe_resource *resource = id_resource->resource;
    776    struct pipe_transfer *result;
    777 
    778    result = context->get_transfer(context,
    779                                   resource,
    780                                   level,
    781                                   usage,
    782                                   box);
    783 
    784    if (result)
    785       return identity_transfer_create(id_context, id_resource, result);
    786    return NULL;
    787 }
    788 
    789 static void
    790 identity_context_transfer_destroy(struct pipe_context *_pipe,
    791                                   struct pipe_transfer *_transfer)
    792 {
    793    identity_transfer_destroy(identity_context(_pipe),
    794                              identity_transfer(_transfer));
    795 }
    796 
    797 static void *
    798 identity_context_transfer_map(struct pipe_context *_context,
    799                               struct pipe_transfer *_transfer)
    800 {
    801    struct identity_context *id_context = identity_context(_context);
    802    struct identity_transfer *id_transfer = identity_transfer(_transfer);
    803    struct pipe_context *context = id_context->pipe;
    804    struct pipe_transfer *transfer = id_transfer->transfer;
    805 
    806    return context->transfer_map(context,
    807                                 transfer);
    808 }
    809 
    810 
    811 
    812 static void
    813 identity_context_transfer_flush_region(struct pipe_context *_context,
    814                                        struct pipe_transfer *_transfer,
    815                                        const struct pipe_box *box)
    816 {
    817    struct identity_context *id_context = identity_context(_context);
    818    struct identity_transfer *id_transfer = identity_transfer(_transfer);
    819    struct pipe_context *context = id_context->pipe;
    820    struct pipe_transfer *transfer = id_transfer->transfer;
    821 
    822    context->transfer_flush_region(context,
    823                                   transfer,
    824                                   box);
    825 }
    826 
    827 
    828 static void
    829 identity_context_transfer_unmap(struct pipe_context *_context,
    830                                 struct pipe_transfer *_transfer)
    831 {
    832    struct identity_context *id_context = identity_context(_context);
    833    struct identity_transfer *id_transfer = identity_transfer(_transfer);
    834    struct pipe_context *context = id_context->pipe;
    835    struct pipe_transfer *transfer = id_transfer->transfer;
    836 
    837    context->transfer_unmap(context,
    838                            transfer);
    839 }
    840 
    841 
    842 static void
    843 identity_context_transfer_inline_write(struct pipe_context *_context,
    844                                        struct pipe_resource *_resource,
    845                                        unsigned level,
    846                                        unsigned usage,
    847                                        const struct pipe_box *box,
    848                                        const void *data,
    849                                        unsigned stride,
    850                                        unsigned layer_stride)
    851 {
    852    struct identity_context *id_context = identity_context(_context);
    853    struct identity_resource *id_resource = identity_resource(_resource);
    854    struct pipe_context *context = id_context->pipe;
    855    struct pipe_resource *resource = id_resource->resource;
    856 
    857    context->transfer_inline_write(context,
    858                                   resource,
    859                                   level,
    860                                   usage,
    861                                   box,
    862                                   data,
    863                                   stride,
    864                                   layer_stride);
    865 }
    866 
    867 
    868 struct pipe_context *
    869 identity_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
    870 {
    871    struct identity_context *id_pipe;
    872    (void)identity_screen(_screen);
    873 
    874    id_pipe = CALLOC_STRUCT(identity_context);
    875    if (!id_pipe) {
    876       return NULL;
    877    }
    878 
    879    id_pipe->base.screen = _screen;
    880    id_pipe->base.priv = pipe->priv; /* expose wrapped data */
    881    id_pipe->base.draw = NULL;
    882 
    883    id_pipe->base.destroy = identity_destroy;
    884    id_pipe->base.draw_vbo = identity_draw_vbo;
    885    id_pipe->base.create_query = identity_create_query;
    886    id_pipe->base.destroy_query = identity_destroy_query;
    887    id_pipe->base.begin_query = identity_begin_query;
    888    id_pipe->base.end_query = identity_end_query;
    889    id_pipe->base.get_query_result = identity_get_query_result;
    890    id_pipe->base.create_blend_state = identity_create_blend_state;
    891    id_pipe->base.bind_blend_state = identity_bind_blend_state;
    892    id_pipe->base.delete_blend_state = identity_delete_blend_state;
    893    id_pipe->base.create_sampler_state = identity_create_sampler_state;
    894    id_pipe->base.bind_fragment_sampler_states = identity_bind_fragment_sampler_states;
    895    id_pipe->base.bind_vertex_sampler_states = identity_bind_vertex_sampler_states;
    896    id_pipe->base.delete_sampler_state = identity_delete_sampler_state;
    897    id_pipe->base.create_rasterizer_state = identity_create_rasterizer_state;
    898    id_pipe->base.bind_rasterizer_state = identity_bind_rasterizer_state;
    899    id_pipe->base.delete_rasterizer_state = identity_delete_rasterizer_state;
    900    id_pipe->base.create_depth_stencil_alpha_state = identity_create_depth_stencil_alpha_state;
    901    id_pipe->base.bind_depth_stencil_alpha_state = identity_bind_depth_stencil_alpha_state;
    902    id_pipe->base.delete_depth_stencil_alpha_state = identity_delete_depth_stencil_alpha_state;
    903    id_pipe->base.create_fs_state = identity_create_fs_state;
    904    id_pipe->base.bind_fs_state = identity_bind_fs_state;
    905    id_pipe->base.delete_fs_state = identity_delete_fs_state;
    906    id_pipe->base.create_vs_state = identity_create_vs_state;
    907    id_pipe->base.bind_vs_state = identity_bind_vs_state;
    908    id_pipe->base.delete_vs_state = identity_delete_vs_state;
    909    id_pipe->base.create_vertex_elements_state = identity_create_vertex_elements_state;
    910    id_pipe->base.bind_vertex_elements_state = identity_bind_vertex_elements_state;
    911    id_pipe->base.delete_vertex_elements_state = identity_delete_vertex_elements_state;
    912    id_pipe->base.set_blend_color = identity_set_blend_color;
    913    id_pipe->base.set_stencil_ref = identity_set_stencil_ref;
    914    id_pipe->base.set_clip_state = identity_set_clip_state;
    915    id_pipe->base.set_sample_mask = identity_set_sample_mask;
    916    id_pipe->base.set_constant_buffer = identity_set_constant_buffer;
    917    id_pipe->base.set_framebuffer_state = identity_set_framebuffer_state;
    918    id_pipe->base.set_polygon_stipple = identity_set_polygon_stipple;
    919    id_pipe->base.set_scissor_state = identity_set_scissor_state;
    920    id_pipe->base.set_viewport_state = identity_set_viewport_state;
    921    id_pipe->base.set_fragment_sampler_views = identity_set_fragment_sampler_views;
    922    id_pipe->base.set_vertex_sampler_views = identity_set_vertex_sampler_views;
    923    id_pipe->base.set_vertex_buffers = identity_set_vertex_buffers;
    924    id_pipe->base.set_index_buffer = identity_set_index_buffer;
    925    id_pipe->base.resource_copy_region = identity_resource_copy_region;
    926    id_pipe->base.clear = identity_clear;
    927    id_pipe->base.clear_render_target = identity_clear_render_target;
    928    id_pipe->base.clear_depth_stencil = identity_clear_depth_stencil;
    929    id_pipe->base.flush = identity_flush;
    930    id_pipe->base.create_surface = identity_context_create_surface;
    931    id_pipe->base.surface_destroy = identity_context_surface_destroy;
    932    id_pipe->base.create_sampler_view = identity_context_create_sampler_view;
    933    id_pipe->base.sampler_view_destroy = identity_context_sampler_view_destroy;
    934    id_pipe->base.get_transfer = identity_context_get_transfer;
    935    id_pipe->base.transfer_destroy = identity_context_transfer_destroy;
    936    id_pipe->base.transfer_map = identity_context_transfer_map;
    937    id_pipe->base.transfer_unmap = identity_context_transfer_unmap;
    938    id_pipe->base.transfer_flush_region = identity_context_transfer_flush_region;
    939    id_pipe->base.transfer_inline_write = identity_context_transfer_inline_write;
    940 
    941    id_pipe->pipe = pipe;
    942 
    943    return &id_pipe->base;
    944 }
    945