Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2010 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. #include "util/simple_list.h"
  33.  
  34. #include "rbug/rbug_context.h"
  35.  
  36. #include "rbug_context.h"
  37. #include "rbug_objects.h"
  38.  
  39.  
  40. static void
  41. rbug_destroy(struct pipe_context *_pipe)
  42. {
  43.    struct rbug_screen *rb_screen = rbug_screen(_pipe->screen);
  44.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  45.    struct pipe_context *pipe = rb_pipe->pipe;
  46.  
  47.    rbug_screen_remove_from_list(rb_screen, contexts, rb_pipe);
  48.  
  49.    pipe_mutex_lock(rb_pipe->call_mutex);
  50.    pipe->destroy(pipe);
  51.    rb_pipe->pipe = NULL;
  52.    pipe_mutex_unlock(rb_pipe->call_mutex);
  53.  
  54.    FREE(rb_pipe);
  55. }
  56.  
  57. static void
  58. rbug_draw_block_locked(struct rbug_context *rb_pipe, int flag)
  59. {
  60.  
  61.    if (rb_pipe->draw_blocker & flag) {
  62.       rb_pipe->draw_blocked |= flag;
  63.    } else if ((rb_pipe->draw_rule.blocker & flag) &&
  64.               (rb_pipe->draw_blocker & RBUG_BLOCK_RULE)) {
  65.       unsigned k;
  66.       boolean block = FALSE;
  67.       unsigned sh;
  68.  
  69.       debug_printf("%s (%p %p) (%p %p) (%p %u) (%p %u)\n", __FUNCTION__,
  70.                    (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_FRAGMENT],
  71.                    (void *) rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT],
  72.                    (void *) rb_pipe->draw_rule.shader[PIPE_SHADER_VERTEX],
  73.                    (void *) rb_pipe->curr.shader[PIPE_SHADER_VERTEX],
  74.                    (void *) rb_pipe->draw_rule.surf, 0,
  75.                    (void *) rb_pipe->draw_rule.texture, 0);
  76.       for (sh = 0; sh < PIPE_SHADER_TYPES; sh++) {
  77.          if (rb_pipe->draw_rule.shader[sh] &&
  78.              rb_pipe->draw_rule.shader[sh] == rb_pipe->curr.shader[sh])
  79.             block = TRUE;
  80.       }
  81.  
  82.       if (rb_pipe->draw_rule.surf &&
  83.           rb_pipe->draw_rule.surf == rb_pipe->curr.zsbuf)
  84.             block = TRUE;
  85.       if (rb_pipe->draw_rule.surf)
  86.          for (k = 0; k < rb_pipe->curr.nr_cbufs; k++)
  87.             if (rb_pipe->draw_rule.surf == rb_pipe->curr.cbufs[k])
  88.                block = TRUE;
  89.       if (rb_pipe->draw_rule.texture) {
  90.          for (sh = 0; sh < Elements(rb_pipe->curr.num_views); sh++) {
  91.             for (k = 0; k < rb_pipe->curr.num_views[sh]; k++) {
  92.                if (rb_pipe->draw_rule.texture == rb_pipe->curr.texs[sh][k]) {
  93.                   block = TRUE;
  94.                   sh = PIPE_SHADER_TYPES; /* to break out of both loops */
  95.                   break;
  96.                }
  97.             }
  98.          }
  99.       }
  100.  
  101.       if (block)
  102.          rb_pipe->draw_blocked |= (flag | RBUG_BLOCK_RULE);
  103.    }
  104.  
  105.    if (rb_pipe->draw_blocked)
  106.       rbug_notify_draw_blocked(rb_pipe);
  107.  
  108.    /* wait for rbug to clear the blocked flag */
  109.    while (rb_pipe->draw_blocked & flag) {
  110.       rb_pipe->draw_blocked |= flag;
  111.       pipe_condvar_wait(rb_pipe->draw_cond, rb_pipe->draw_mutex);
  112.    }
  113.  
  114. }
  115.  
  116. static void
  117. rbug_draw_vbo(struct pipe_context *_pipe, const struct pipe_draw_info *info)
  118. {
  119.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  120.    struct pipe_context *pipe = rb_pipe->pipe;
  121.  
  122.    pipe_mutex_lock(rb_pipe->draw_mutex);
  123.    rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_BEFORE);
  124.  
  125.    pipe_mutex_lock(rb_pipe->call_mutex);
  126.    /* XXX loop over PIPE_SHADER_x here */
  127.    if (!(rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] && rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT]->disabled) &&
  128.        !(rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] && rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY]->disabled) &&
  129.        !(rb_pipe->curr.shader[PIPE_SHADER_VERTEX] && rb_pipe->curr.shader[PIPE_SHADER_VERTEX]->disabled))
  130.       pipe->draw_vbo(pipe, info);
  131.    pipe_mutex_unlock(rb_pipe->call_mutex);
  132.  
  133.    rbug_draw_block_locked(rb_pipe, RBUG_BLOCK_AFTER);
  134.    pipe_mutex_unlock(rb_pipe->draw_mutex);
  135. }
  136.  
  137. static struct pipe_query *
  138. rbug_create_query(struct pipe_context *_pipe,
  139.                   unsigned query_type,
  140.                   unsigned index)
  141. {
  142.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  143.    struct pipe_context *pipe = rb_pipe->pipe;
  144.    struct pipe_query *query;
  145.  
  146.    pipe_mutex_lock(rb_pipe->call_mutex);
  147.    query = pipe->create_query(pipe,
  148.                               query_type,
  149.                               index);
  150.    pipe_mutex_unlock(rb_pipe->call_mutex);
  151.    return query;
  152. }
  153.  
  154. static void
  155. rbug_destroy_query(struct pipe_context *_pipe,
  156.                    struct pipe_query *query)
  157. {
  158.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  159.    struct pipe_context *pipe = rb_pipe->pipe;
  160.  
  161.    pipe_mutex_lock(rb_pipe->call_mutex);
  162.    pipe->destroy_query(pipe,
  163.                        query);
  164.    pipe_mutex_unlock(rb_pipe->call_mutex);
  165. }
  166.  
  167. static boolean
  168. rbug_begin_query(struct pipe_context *_pipe,
  169.                  struct pipe_query *query)
  170. {
  171.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  172.    struct pipe_context *pipe = rb_pipe->pipe;
  173.    boolean ret;
  174.  
  175.    pipe_mutex_lock(rb_pipe->call_mutex);
  176.    ret = pipe->begin_query(pipe, query);
  177.    pipe_mutex_unlock(rb_pipe->call_mutex);
  178.    return ret;
  179. }
  180.  
  181. static void
  182. rbug_end_query(struct pipe_context *_pipe,
  183.                struct pipe_query *query)
  184. {
  185.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  186.    struct pipe_context *pipe = rb_pipe->pipe;
  187.  
  188.    pipe_mutex_lock(rb_pipe->call_mutex);
  189.    pipe->end_query(pipe,
  190.                    query);
  191.    pipe_mutex_unlock(rb_pipe->call_mutex);
  192. }
  193.  
  194. static boolean
  195. rbug_get_query_result(struct pipe_context *_pipe,
  196.                       struct pipe_query *query,
  197.                       boolean wait,
  198.                       union pipe_query_result *result)
  199. {
  200.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  201.    struct pipe_context *pipe = rb_pipe->pipe;
  202.    boolean ret;
  203.  
  204.    pipe_mutex_lock(rb_pipe->call_mutex);
  205.    ret = pipe->get_query_result(pipe,
  206.                                 query,
  207.                                 wait,
  208.                                 result);
  209.    pipe_mutex_unlock(rb_pipe->call_mutex);
  210.  
  211.    return ret;
  212. }
  213.  
  214. static void *
  215. rbug_create_blend_state(struct pipe_context *_pipe,
  216.                         const struct pipe_blend_state *blend)
  217. {
  218.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  219.    struct pipe_context *pipe = rb_pipe->pipe;
  220.    void *ret;
  221.  
  222.    pipe_mutex_lock(rb_pipe->call_mutex);
  223.    ret = pipe->create_blend_state(pipe,
  224.                                   blend);
  225.    pipe_mutex_unlock(rb_pipe->call_mutex);
  226.  
  227.    return ret;
  228. }
  229.  
  230. static void
  231. rbug_bind_blend_state(struct pipe_context *_pipe,
  232.                       void *blend)
  233. {
  234.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  235.    struct pipe_context *pipe = rb_pipe->pipe;
  236.  
  237.    pipe_mutex_lock(rb_pipe->call_mutex);
  238.    pipe->bind_blend_state(pipe,
  239.                           blend);
  240.    pipe_mutex_unlock(rb_pipe->call_mutex);
  241. }
  242.  
  243. static void
  244. rbug_delete_blend_state(struct pipe_context *_pipe,
  245.                         void *blend)
  246. {
  247.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  248.    struct pipe_context *pipe = rb_pipe->pipe;
  249.  
  250.    pipe_mutex_lock(rb_pipe->call_mutex);
  251.    pipe->delete_blend_state(pipe,
  252.                             blend);
  253.    pipe_mutex_unlock(rb_pipe->call_mutex);
  254. }
  255.  
  256. static void *
  257. rbug_create_sampler_state(struct pipe_context *_pipe,
  258.                           const struct pipe_sampler_state *sampler)
  259. {
  260.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  261.    struct pipe_context *pipe = rb_pipe->pipe;
  262.    void *ret;
  263.  
  264.    pipe_mutex_lock(rb_pipe->call_mutex);
  265.    ret = pipe->create_sampler_state(pipe,
  266.                                     sampler);
  267.    pipe_mutex_unlock(rb_pipe->call_mutex);
  268.  
  269.    return ret;
  270. }
  271.  
  272. static void
  273. rbug_bind_sampler_states(struct pipe_context *_pipe, unsigned shader,
  274.                          unsigned start, unsigned count,
  275.                          void **samplers)
  276. {
  277.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  278.    struct pipe_context *pipe = rb_pipe->pipe;
  279.  
  280.    pipe_mutex_lock(rb_pipe->call_mutex);
  281.    pipe->bind_sampler_states(pipe, shader, start, count, samplers);
  282.    pipe_mutex_unlock(rb_pipe->call_mutex);
  283. }
  284.  
  285. static void
  286. rbug_delete_sampler_state(struct pipe_context *_pipe,
  287.                           void *sampler)
  288. {
  289.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  290.    struct pipe_context *pipe = rb_pipe->pipe;
  291.  
  292.    pipe_mutex_lock(rb_pipe->call_mutex);
  293.    pipe->delete_sampler_state(pipe,
  294.                               sampler);
  295.    pipe_mutex_unlock(rb_pipe->call_mutex);
  296. }
  297.  
  298. static void *
  299. rbug_create_rasterizer_state(struct pipe_context *_pipe,
  300.                              const struct pipe_rasterizer_state *rasterizer)
  301. {
  302.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  303.    struct pipe_context *pipe = rb_pipe->pipe;
  304.    void *ret;
  305.  
  306.    pipe_mutex_lock(rb_pipe->call_mutex);
  307.    ret = pipe->create_rasterizer_state(pipe,
  308.                                        rasterizer);
  309.    pipe_mutex_unlock(rb_pipe->call_mutex);
  310.  
  311.    return ret;
  312. }
  313.  
  314. static void
  315. rbug_bind_rasterizer_state(struct pipe_context *_pipe,
  316.                            void *rasterizer)
  317. {
  318.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  319.    struct pipe_context *pipe = rb_pipe->pipe;
  320.  
  321.    pipe_mutex_lock(rb_pipe->call_mutex);
  322.    pipe->bind_rasterizer_state(pipe,
  323.                                rasterizer);
  324.    pipe_mutex_unlock(rb_pipe->call_mutex);
  325. }
  326.  
  327. static void
  328. rbug_delete_rasterizer_state(struct pipe_context *_pipe,
  329.                              void *rasterizer)
  330. {
  331.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  332.    struct pipe_context *pipe = rb_pipe->pipe;
  333.  
  334.    pipe_mutex_lock(rb_pipe->call_mutex);
  335.    pipe->delete_rasterizer_state(pipe,
  336.                                  rasterizer);
  337.    pipe_mutex_unlock(rb_pipe->call_mutex);
  338. }
  339.  
  340. static void *
  341. rbug_create_depth_stencil_alpha_state(struct pipe_context *_pipe,
  342.                                       const struct pipe_depth_stencil_alpha_state *depth_stencil_alpha)
  343. {
  344.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  345.    struct pipe_context *pipe = rb_pipe->pipe;
  346.    void *ret;
  347.  
  348.    pipe_mutex_lock(rb_pipe->call_mutex);
  349.    ret = pipe->create_depth_stencil_alpha_state(pipe,
  350.                                                 depth_stencil_alpha);
  351.    pipe_mutex_unlock(rb_pipe->call_mutex);
  352.  
  353.    return ret;
  354. }
  355.  
  356. static void
  357. rbug_bind_depth_stencil_alpha_state(struct pipe_context *_pipe,
  358.                                     void *depth_stencil_alpha)
  359. {
  360.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  361.    struct pipe_context *pipe = rb_pipe->pipe;
  362.  
  363.    pipe_mutex_lock(rb_pipe->call_mutex);
  364.    pipe->bind_depth_stencil_alpha_state(pipe,
  365.                                         depth_stencil_alpha);
  366.    pipe_mutex_unlock(rb_pipe->call_mutex);
  367. }
  368.  
  369. static void
  370. rbug_delete_depth_stencil_alpha_state(struct pipe_context *_pipe,
  371.                                       void *depth_stencil_alpha)
  372. {
  373.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  374.    struct pipe_context *pipe = rb_pipe->pipe;
  375.  
  376.    pipe_mutex_lock(rb_pipe->call_mutex);
  377.    pipe->delete_depth_stencil_alpha_state(pipe,
  378.                                           depth_stencil_alpha);
  379.    pipe_mutex_unlock(rb_pipe->call_mutex);
  380. }
  381.  
  382. static void *
  383. rbug_create_fs_state(struct pipe_context *_pipe,
  384.                      const struct pipe_shader_state *state)
  385. {
  386.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  387.    struct pipe_context *pipe = rb_pipe->pipe;
  388.    void *result;
  389.  
  390.    pipe_mutex_lock(rb_pipe->call_mutex);
  391.    result = pipe->create_fs_state(pipe, state);
  392.    pipe_mutex_unlock(rb_pipe->call_mutex);
  393.  
  394.    if (!result)
  395.       return NULL;
  396.  
  397.    return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_FRAGMENT);
  398. }
  399.  
  400. static void
  401. rbug_bind_fs_state(struct pipe_context *_pipe,
  402.                    void *_fs)
  403. {
  404.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  405.    struct pipe_context *pipe = rb_pipe->pipe;
  406.    void *fs;
  407.  
  408.    pipe_mutex_lock(rb_pipe->call_mutex);
  409.  
  410.    fs = rbug_shader_unwrap(_fs);
  411.    rb_pipe->curr.shader[PIPE_SHADER_FRAGMENT] = rbug_shader(_fs);
  412.    pipe->bind_fs_state(pipe,
  413.                        fs);
  414.  
  415.    pipe_mutex_unlock(rb_pipe->call_mutex);
  416. }
  417.  
  418. static void
  419. rbug_delete_fs_state(struct pipe_context *_pipe,
  420.                      void *_fs)
  421. {
  422.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  423.    struct rbug_shader *rb_shader = rbug_shader(_fs);
  424.  
  425.    pipe_mutex_lock(rb_pipe->call_mutex);
  426.    rbug_shader_destroy(rb_pipe, rb_shader);
  427.    pipe_mutex_unlock(rb_pipe->call_mutex);
  428. }
  429.  
  430. static void *
  431. rbug_create_vs_state(struct pipe_context *_pipe,
  432.                      const struct pipe_shader_state *state)
  433. {
  434.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  435.    struct pipe_context *pipe = rb_pipe->pipe;
  436.    void *result;
  437.  
  438.    pipe_mutex_lock(rb_pipe->call_mutex);
  439.    result = pipe->create_vs_state(pipe, state);
  440.    pipe_mutex_unlock(rb_pipe->call_mutex);
  441.  
  442.    if (!result)
  443.       return NULL;
  444.  
  445.    return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_VERTEX);
  446. }
  447.  
  448. static void
  449. rbug_bind_vs_state(struct pipe_context *_pipe,
  450.                    void *_vs)
  451. {
  452.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  453.    struct pipe_context *pipe = rb_pipe->pipe;
  454.    void *vs;
  455.  
  456.    pipe_mutex_lock(rb_pipe->call_mutex);
  457.  
  458.    vs = rbug_shader_unwrap(_vs);
  459.    rb_pipe->curr.shader[PIPE_SHADER_VERTEX] = rbug_shader(_vs);
  460.    pipe->bind_vs_state(pipe,
  461.                        vs);
  462.  
  463.    pipe_mutex_unlock(rb_pipe->call_mutex);
  464. }
  465.  
  466. static void
  467. rbug_delete_vs_state(struct pipe_context *_pipe,
  468.                      void *_vs)
  469. {
  470.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  471.    struct rbug_shader *rb_shader = rbug_shader(_vs);
  472.  
  473.    pipe_mutex_unlock(rb_pipe->call_mutex);
  474.    rbug_shader_destroy(rb_pipe, rb_shader);
  475.    pipe_mutex_unlock(rb_pipe->call_mutex);
  476. }
  477.  
  478. static void *
  479. rbug_create_gs_state(struct pipe_context *_pipe,
  480.                      const struct pipe_shader_state *state)
  481. {
  482.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  483.    struct pipe_context *pipe = rb_pipe->pipe;
  484.    void *result;
  485.  
  486.    pipe_mutex_lock(rb_pipe->call_mutex);
  487.    result = pipe->create_gs_state(pipe, state);
  488.    pipe_mutex_unlock(rb_pipe->call_mutex);
  489.  
  490.    if (!result)
  491.       return NULL;
  492.  
  493.    return rbug_shader_create(rb_pipe, state, result, RBUG_SHADER_GEOM);
  494. }
  495.  
  496. static void
  497. rbug_bind_gs_state(struct pipe_context *_pipe,
  498.                    void *_gs)
  499. {
  500.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  501.    struct pipe_context *pipe = rb_pipe->pipe;
  502.    void *gs;
  503.  
  504.    pipe_mutex_lock(rb_pipe->call_mutex);
  505.  
  506.    gs = rbug_shader_unwrap(_gs);
  507.    rb_pipe->curr.shader[PIPE_SHADER_GEOMETRY] = rbug_shader(_gs);
  508.    pipe->bind_gs_state(pipe,
  509.                        gs);
  510.  
  511.    pipe_mutex_unlock(rb_pipe->call_mutex);
  512. }
  513.  
  514. static void
  515. rbug_delete_gs_state(struct pipe_context *_pipe,
  516.                      void *_gs)
  517. {
  518.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  519.    struct rbug_shader *rb_shader = rbug_shader(_gs);
  520.  
  521.    pipe_mutex_lock(rb_pipe->call_mutex);
  522.    rbug_shader_destroy(rb_pipe, rb_shader);
  523.    pipe_mutex_unlock(rb_pipe->call_mutex);
  524. }
  525.  
  526. static void *
  527. rbug_create_vertex_elements_state(struct pipe_context *_pipe,
  528.                                   unsigned num_elements,
  529.                                   const struct pipe_vertex_element *vertex_elements)
  530. {
  531.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  532.    struct pipe_context *pipe = rb_pipe->pipe;
  533.    void *ret;
  534.  
  535.    pipe_mutex_lock(rb_pipe->call_mutex);
  536.    ret = pipe->create_vertex_elements_state(pipe,
  537.                                              num_elements,
  538.                                              vertex_elements);
  539.    pipe_mutex_unlock(rb_pipe->call_mutex);
  540.  
  541.    return ret;
  542. }
  543.  
  544. static void
  545. rbug_bind_vertex_elements_state(struct pipe_context *_pipe,
  546.                                 void *velems)
  547. {
  548.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  549.    struct pipe_context *pipe = rb_pipe->pipe;
  550.  
  551.    pipe_mutex_lock(rb_pipe->call_mutex);
  552.    pipe->bind_vertex_elements_state(pipe,
  553.                                     velems);
  554.    pipe_mutex_unlock(rb_pipe->call_mutex);
  555. }
  556.  
  557. static void
  558. rbug_delete_vertex_elements_state(struct pipe_context *_pipe,
  559.                                   void *velems)
  560. {
  561.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  562.    struct pipe_context *pipe = rb_pipe->pipe;
  563.  
  564.    pipe_mutex_lock(rb_pipe->call_mutex);
  565.    pipe->delete_vertex_elements_state(pipe,
  566.                                       velems);
  567.    pipe_mutex_unlock(rb_pipe->call_mutex);
  568. }
  569.  
  570. static void
  571. rbug_set_blend_color(struct pipe_context *_pipe,
  572.                      const struct pipe_blend_color *blend_color)
  573. {
  574.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  575.    struct pipe_context *pipe = rb_pipe->pipe;
  576.  
  577.    pipe_mutex_lock(rb_pipe->call_mutex);
  578.    pipe->set_blend_color(pipe,
  579.                          blend_color);
  580.    pipe_mutex_unlock(rb_pipe->call_mutex);
  581. }
  582.  
  583. static void
  584. rbug_set_stencil_ref(struct pipe_context *_pipe,
  585.                      const struct pipe_stencil_ref *stencil_ref)
  586. {
  587.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  588.    struct pipe_context *pipe = rb_pipe->pipe;
  589.  
  590.    pipe_mutex_lock(rb_pipe->call_mutex);
  591.    pipe->set_stencil_ref(pipe,
  592.                          stencil_ref);
  593.    pipe_mutex_unlock(rb_pipe->call_mutex);
  594. }
  595.  
  596. static void
  597. rbug_set_clip_state(struct pipe_context *_pipe,
  598.                     const struct pipe_clip_state *clip)
  599. {
  600.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  601.    struct pipe_context *pipe = rb_pipe->pipe;
  602.  
  603.    pipe_mutex_lock(rb_pipe->call_mutex);
  604.    pipe->set_clip_state(pipe,
  605.                         clip);
  606.    pipe_mutex_unlock(rb_pipe->call_mutex);
  607. }
  608.  
  609. static void
  610. rbug_set_constant_buffer(struct pipe_context *_pipe,
  611.                          uint shader,
  612.                          uint index,
  613.                          struct pipe_constant_buffer *_cb)
  614. {
  615.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  616.    struct pipe_context *pipe = rb_pipe->pipe;
  617.    struct pipe_constant_buffer cb;
  618.  
  619.    /* XXX hmm? unwrap the input state */
  620.    if (_cb) {
  621.       cb = *_cb;
  622.       cb.buffer = rbug_resource_unwrap(_cb->buffer);
  623.    }
  624.  
  625.    pipe_mutex_lock(rb_pipe->call_mutex);
  626.    pipe->set_constant_buffer(pipe,
  627.                              shader,
  628.                              index,
  629.                              _cb ? &cb : NULL);
  630.    pipe_mutex_unlock(rb_pipe->call_mutex);
  631. }
  632.  
  633. static void
  634. rbug_set_framebuffer_state(struct pipe_context *_pipe,
  635.                            const struct pipe_framebuffer_state *_state)
  636. {
  637.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  638.    struct pipe_context *pipe = rb_pipe->pipe;
  639.    struct pipe_framebuffer_state unwrapped_state;
  640.    struct pipe_framebuffer_state *state = NULL;
  641.    unsigned i;
  642.  
  643.    /* must protect curr status */
  644.    pipe_mutex_lock(rb_pipe->call_mutex);
  645.  
  646.    rb_pipe->curr.nr_cbufs = 0;
  647.    memset(rb_pipe->curr.cbufs, 0, sizeof(rb_pipe->curr.cbufs));
  648.    rb_pipe->curr.zsbuf = NULL;
  649.  
  650.    /* unwrap the input state */
  651.    if (_state) {
  652.       memcpy(&unwrapped_state, _state, sizeof(unwrapped_state));
  653.  
  654.       rb_pipe->curr.nr_cbufs = _state->nr_cbufs;
  655.       for(i = 0; i < _state->nr_cbufs; i++) {
  656.          unwrapped_state.cbufs[i] = rbug_surface_unwrap(_state->cbufs[i]);
  657.          if (_state->cbufs[i])
  658.             rb_pipe->curr.cbufs[i] = rbug_resource(_state->cbufs[i]->texture);
  659.       }
  660.       unwrapped_state.zsbuf = rbug_surface_unwrap(_state->zsbuf);
  661.       if (_state->zsbuf)
  662.          rb_pipe->curr.zsbuf = rbug_resource(_state->zsbuf->texture);
  663.       state = &unwrapped_state;
  664.    }
  665.  
  666.    pipe->set_framebuffer_state(pipe,
  667.                                state);
  668.  
  669.    pipe_mutex_unlock(rb_pipe->call_mutex);
  670. }
  671.  
  672. static void
  673. rbug_set_polygon_stipple(struct pipe_context *_pipe,
  674.                          const struct pipe_poly_stipple *poly_stipple)
  675. {
  676.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  677.    struct pipe_context *pipe = rb_pipe->pipe;
  678.  
  679.    pipe_mutex_lock(rb_pipe->call_mutex);
  680.    pipe->set_polygon_stipple(pipe,
  681.                              poly_stipple);
  682.    pipe_mutex_unlock(rb_pipe->call_mutex);
  683. }
  684.  
  685. static void
  686. rbug_set_scissor_states(struct pipe_context *_pipe,
  687.                         unsigned start_slot,
  688.                         unsigned num_scissors,
  689.                         const struct pipe_scissor_state *scissor)
  690. {
  691.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  692.    struct pipe_context *pipe = rb_pipe->pipe;
  693.  
  694.    pipe_mutex_lock(rb_pipe->call_mutex);
  695.    pipe->set_scissor_states(pipe, start_slot, num_scissors, scissor);
  696.    pipe_mutex_unlock(rb_pipe->call_mutex);
  697. }
  698.  
  699. static void
  700. rbug_set_viewport_states(struct pipe_context *_pipe,
  701.                          unsigned start_slot,
  702.                          unsigned num_viewports,
  703.                          const struct pipe_viewport_state *viewport)
  704. {
  705.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  706.    struct pipe_context *pipe = rb_pipe->pipe;
  707.  
  708.    pipe_mutex_lock(rb_pipe->call_mutex);
  709.    pipe->set_viewport_states(pipe, start_slot, num_viewports, viewport);
  710.    pipe_mutex_unlock(rb_pipe->call_mutex);
  711. }
  712.  
  713. static void
  714. rbug_set_sampler_views(struct pipe_context *_pipe,
  715.                        unsigned shader,
  716.                        unsigned start,
  717.                        unsigned num,
  718.                        struct pipe_sampler_view **_views)
  719. {
  720.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  721.    struct pipe_context *pipe = rb_pipe->pipe;
  722.    struct pipe_sampler_view *unwrapped_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
  723.    struct pipe_sampler_view **views = NULL;
  724.    unsigned i;
  725.  
  726.    assert(start == 0); /* XXX fix */
  727.  
  728.    /* must protect curr status */
  729.    pipe_mutex_lock(rb_pipe->call_mutex);
  730.  
  731.    rb_pipe->curr.num_views[shader] = 0;
  732.    memset(rb_pipe->curr.views[shader], 0, sizeof(rb_pipe->curr.views[shader]));
  733.    memset(rb_pipe->curr.texs[shader], 0, sizeof(rb_pipe->curr.texs[shader]));
  734.    memset(unwrapped_views, 0, sizeof(unwrapped_views));
  735.  
  736.    if (_views) {
  737.       rb_pipe->curr.num_views[shader] = num;
  738.       for (i = 0; i < num; i++) {
  739.          rb_pipe->curr.views[shader][i] = rbug_sampler_view(_views[i]);
  740.          rb_pipe->curr.texs[shader][i] = rbug_resource(_views[i] ? _views[i]->texture : NULL);
  741.          unwrapped_views[i] = rbug_sampler_view_unwrap(_views[i]);
  742.       }
  743.       views = unwrapped_views;
  744.    }
  745.  
  746.    pipe->set_sampler_views(pipe, shader, start, num, views);
  747.  
  748.    pipe_mutex_unlock(rb_pipe->call_mutex);
  749. }
  750.  
  751. static void
  752. rbug_set_vertex_buffers(struct pipe_context *_pipe,
  753.                         unsigned start_slot, unsigned num_buffers,
  754.                         const struct pipe_vertex_buffer *_buffers)
  755. {
  756.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  757.    struct pipe_context *pipe = rb_pipe->pipe;
  758.    struct pipe_vertex_buffer unwrapped_buffers[PIPE_MAX_SHADER_INPUTS];
  759.    struct pipe_vertex_buffer *buffers = NULL;
  760.    unsigned i;
  761.  
  762.    pipe_mutex_lock(rb_pipe->call_mutex);
  763.  
  764.    if (num_buffers && _buffers) {
  765.       memcpy(unwrapped_buffers, _buffers, num_buffers * sizeof(*_buffers));
  766.       for (i = 0; i < num_buffers; i++)
  767.          unwrapped_buffers[i].buffer = rbug_resource_unwrap(_buffers[i].buffer);
  768.       buffers = unwrapped_buffers;
  769.    }
  770.  
  771.    pipe->set_vertex_buffers(pipe, start_slot,
  772.                             num_buffers,
  773.                             buffers);
  774.  
  775.    pipe_mutex_unlock(rb_pipe->call_mutex);
  776. }
  777.  
  778. static void
  779. rbug_set_index_buffer(struct pipe_context *_pipe,
  780.                       const struct pipe_index_buffer *_ib)
  781. {
  782.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  783.    struct pipe_context *pipe = rb_pipe->pipe;
  784.    struct pipe_index_buffer unwrapped_ib, *ib = NULL;
  785.  
  786.    if (_ib) {
  787.       unwrapped_ib = *_ib;
  788.       unwrapped_ib.buffer = rbug_resource_unwrap(_ib->buffer);
  789.       ib = &unwrapped_ib;
  790.    }
  791.  
  792.    pipe_mutex_lock(rb_pipe->call_mutex);
  793.    pipe->set_index_buffer(pipe, ib);
  794.    pipe_mutex_unlock(rb_pipe->call_mutex);
  795. }
  796.  
  797. static void
  798. rbug_set_sample_mask(struct pipe_context *_pipe,
  799.                      unsigned sample_mask)
  800. {
  801.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  802.    struct pipe_context *pipe = rb_pipe->pipe;
  803.  
  804.    pipe_mutex_lock(rb_pipe->call_mutex);
  805.    pipe->set_sample_mask(pipe, sample_mask);
  806.    pipe_mutex_unlock(rb_pipe->call_mutex);
  807. }
  808.  
  809. static struct pipe_stream_output_target *
  810. rbug_create_stream_output_target(struct pipe_context *_pipe,
  811.                                  struct pipe_resource *_res,
  812.                                  unsigned buffer_offset, unsigned buffer_size)
  813. {
  814.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  815.    struct pipe_context *pipe = rb_pipe->pipe;
  816.    struct pipe_resource *res = rbug_resource_unwrap(_res);
  817.    struct pipe_stream_output_target *target;
  818.  
  819.    pipe_mutex_lock(rb_pipe->call_mutex);
  820.    target = pipe->create_stream_output_target(pipe, res, buffer_offset,
  821.                                               buffer_size);
  822.    pipe_mutex_unlock(rb_pipe->call_mutex);
  823.    return target;
  824. }
  825.  
  826. static void
  827. rbug_stream_output_target_destroy(struct pipe_context *_pipe,
  828.                                   struct pipe_stream_output_target *target)
  829. {
  830.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  831.    struct pipe_context *pipe = rb_pipe->pipe;
  832.  
  833.    pipe_mutex_lock(rb_pipe->call_mutex);
  834.    pipe->stream_output_target_destroy(pipe, target);
  835.    pipe_mutex_unlock(rb_pipe->call_mutex);
  836. }
  837.  
  838. static void
  839. rbug_set_stream_output_targets(struct pipe_context *_pipe,
  840.                                unsigned num_targets,
  841.                                struct pipe_stream_output_target **targets,
  842.                                const unsigned *offsets)
  843. {
  844.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  845.    struct pipe_context *pipe = rb_pipe->pipe;
  846.  
  847.    pipe_mutex_lock(rb_pipe->call_mutex);
  848.    pipe->set_stream_output_targets(pipe, num_targets, targets, offsets);
  849.    pipe_mutex_unlock(rb_pipe->call_mutex);
  850. }
  851.  
  852. static void
  853. rbug_resource_copy_region(struct pipe_context *_pipe,
  854.                           struct pipe_resource *_dst,
  855.                           unsigned dst_level,
  856.                           unsigned dstx,
  857.                           unsigned dsty,
  858.                           unsigned dstz,
  859.                           struct pipe_resource *_src,
  860.                           unsigned src_level,
  861.                           const struct pipe_box *src_box)
  862. {
  863.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  864.    struct rbug_resource *rb_resource_dst = rbug_resource(_dst);
  865.    struct rbug_resource *rb_resource_src = rbug_resource(_src);
  866.    struct pipe_context *pipe = rb_pipe->pipe;
  867.    struct pipe_resource *dst = rb_resource_dst->resource;
  868.    struct pipe_resource *src = rb_resource_src->resource;
  869.  
  870.    pipe_mutex_lock(rb_pipe->call_mutex);
  871.    pipe->resource_copy_region(pipe,
  872.                               dst,
  873.                               dst_level,
  874.                               dstx,
  875.                               dsty,
  876.                               dstz,
  877.                               src,
  878.                               src_level,
  879.                               src_box);
  880.    pipe_mutex_unlock(rb_pipe->call_mutex);
  881. }
  882.  
  883. static void
  884. rbug_blit(struct pipe_context *_pipe, const struct pipe_blit_info *_blit_info)
  885. {
  886.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  887.    struct rbug_resource *rb_resource_dst = rbug_resource(_blit_info->dst.resource);
  888.    struct rbug_resource *rb_resource_src = rbug_resource(_blit_info->src.resource);
  889.    struct pipe_context *pipe = rb_pipe->pipe;
  890.    struct pipe_resource *dst = rb_resource_dst->resource;
  891.    struct pipe_resource *src = rb_resource_src->resource;
  892.    struct pipe_blit_info blit_info;
  893.  
  894.    blit_info = *_blit_info;
  895.    blit_info.dst.resource = dst;
  896.    blit_info.src.resource = src;
  897.  
  898.    pipe_mutex_lock(rb_pipe->call_mutex);
  899.    pipe->blit(pipe, &blit_info);
  900.    pipe_mutex_unlock(rb_pipe->call_mutex);
  901. }
  902.  
  903. static void
  904. rbug_flush_resource(struct pipe_context *_pipe,
  905.                     struct pipe_resource *_res)
  906. {
  907.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  908.    struct rbug_resource *rb_resource_res = rbug_resource(_res);
  909.    struct pipe_context *pipe = rb_pipe->pipe;
  910.    struct pipe_resource *res = rb_resource_res->resource;
  911.  
  912.    pipe_mutex_lock(rb_pipe->call_mutex);
  913.    pipe->flush_resource(pipe, res);
  914.    pipe_mutex_unlock(rb_pipe->call_mutex);
  915. }
  916.  
  917. static void
  918. rbug_clear(struct pipe_context *_pipe,
  919.            unsigned buffers,
  920.            const union pipe_color_union *color,
  921.            double depth,
  922.            unsigned stencil)
  923. {
  924.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  925.    struct pipe_context *pipe = rb_pipe->pipe;
  926.  
  927.    pipe_mutex_lock(rb_pipe->call_mutex);
  928.    pipe->clear(pipe,
  929.                buffers,
  930.                color,
  931.                depth,
  932.                stencil);
  933.    pipe_mutex_unlock(rb_pipe->call_mutex);
  934. }
  935.  
  936. static void
  937. rbug_clear_render_target(struct pipe_context *_pipe,
  938.                          struct pipe_surface *_dst,
  939.                          const union pipe_color_union *color,
  940.                          unsigned dstx, unsigned dsty,
  941.                          unsigned width, unsigned height)
  942. {
  943.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  944.    struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
  945.    struct pipe_context *pipe = rb_pipe->pipe;
  946.    struct pipe_surface *dst = rb_surface_dst->surface;
  947.  
  948.    pipe_mutex_lock(rb_pipe->call_mutex);
  949.    pipe->clear_render_target(pipe,
  950.                              dst,
  951.                              color,
  952.                              dstx,
  953.                              dsty,
  954.                              width,
  955.                              height);
  956.    pipe_mutex_unlock(rb_pipe->call_mutex);
  957. }
  958.  
  959. static void
  960. rbug_clear_depth_stencil(struct pipe_context *_pipe,
  961.                          struct pipe_surface *_dst,
  962.                          unsigned clear_flags,
  963.                          double depth,
  964.                          unsigned stencil,
  965.                          unsigned dstx, unsigned dsty,
  966.                          unsigned width, unsigned height)
  967. {
  968.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  969.    struct rbug_surface *rb_surface_dst = rbug_surface(_dst);
  970.    struct pipe_context *pipe = rb_pipe->pipe;
  971.    struct pipe_surface *dst = rb_surface_dst->surface;
  972.  
  973.    pipe_mutex_lock(rb_pipe->call_mutex);
  974.    pipe->clear_depth_stencil(pipe,
  975.                              dst,
  976.                              clear_flags,
  977.                              depth,
  978.                              stencil,
  979.                              dstx,
  980.                              dsty,
  981.                              width,
  982.                              height);
  983.    pipe_mutex_unlock(rb_pipe->call_mutex);
  984. }
  985.  
  986. static void
  987. rbug_flush(struct pipe_context *_pipe,
  988.            struct pipe_fence_handle **fence,
  989.            unsigned flags)
  990. {
  991.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  992.    struct pipe_context *pipe = rb_pipe->pipe;
  993.  
  994.    pipe_mutex_lock(rb_pipe->call_mutex);
  995.    pipe->flush(pipe, fence, flags);
  996.    pipe_mutex_unlock(rb_pipe->call_mutex);
  997. }
  998.  
  999. static struct pipe_sampler_view *
  1000. rbug_context_create_sampler_view(struct pipe_context *_pipe,
  1001.                                  struct pipe_resource *_resource,
  1002.                                  const struct pipe_sampler_view *templ)
  1003. {
  1004.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  1005.    struct rbug_resource *rb_resource = rbug_resource(_resource);
  1006.    struct pipe_context *pipe = rb_pipe->pipe;
  1007.    struct pipe_resource *resource = rb_resource->resource;
  1008.    struct pipe_sampler_view *result;
  1009.  
  1010.    pipe_mutex_lock(rb_pipe->call_mutex);
  1011.    result = pipe->create_sampler_view(pipe,
  1012.                                       resource,
  1013.                                       templ);
  1014.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1015.  
  1016.    if (result)
  1017.       return rbug_sampler_view_create(rb_pipe, rb_resource, result);
  1018.    return NULL;
  1019. }
  1020.  
  1021. static void
  1022. rbug_context_sampler_view_destroy(struct pipe_context *_pipe,
  1023.                                   struct pipe_sampler_view *_view)
  1024. {
  1025.    rbug_sampler_view_destroy(rbug_context(_pipe),
  1026.                              rbug_sampler_view(_view));
  1027. }
  1028.  
  1029. static struct pipe_surface *
  1030. rbug_context_create_surface(struct pipe_context *_pipe,
  1031.                             struct pipe_resource *_resource,
  1032.                             const struct pipe_surface *surf_tmpl)
  1033. {
  1034.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  1035.    struct rbug_resource *rb_resource = rbug_resource(_resource);
  1036.    struct pipe_context *pipe = rb_pipe->pipe;
  1037.    struct pipe_resource *resource = rb_resource->resource;
  1038.    struct pipe_surface *result;
  1039.  
  1040.    pipe_mutex_lock(rb_pipe->call_mutex);
  1041.    result = pipe->create_surface(pipe,
  1042.                                  resource,
  1043.                                  surf_tmpl);
  1044.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1045.  
  1046.    if (result)
  1047.       return rbug_surface_create(rb_pipe, rb_resource, result);
  1048.    return NULL;
  1049. }
  1050.  
  1051. static void
  1052. rbug_context_surface_destroy(struct pipe_context *_pipe,
  1053.                              struct pipe_surface *_surface)
  1054. {
  1055.    struct rbug_context *rb_pipe = rbug_context(_pipe);
  1056.    struct rbug_surface *rb_surface = rbug_surface(_surface);
  1057.  
  1058.    pipe_mutex_lock(rb_pipe->call_mutex);
  1059.    rbug_surface_destroy(rb_pipe,
  1060.                         rb_surface);
  1061.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1062. }
  1063.  
  1064.  
  1065.  
  1066. static void *
  1067. rbug_context_transfer_map(struct pipe_context *_context,
  1068.                           struct pipe_resource *_resource,
  1069.                           unsigned level,
  1070.                           unsigned usage,
  1071.                           const struct pipe_box *box,
  1072.                           struct pipe_transfer **transfer)
  1073. {
  1074.    struct rbug_context *rb_pipe = rbug_context(_context);
  1075.    struct rbug_resource *rb_resource = rbug_resource(_resource);
  1076.    struct pipe_context *context = rb_pipe->pipe;
  1077.    struct pipe_resource *resource = rb_resource->resource;
  1078.    struct pipe_transfer *result;
  1079.    void *map;
  1080.  
  1081.    pipe_mutex_lock(rb_pipe->call_mutex);
  1082.    map = context->transfer_map(context,
  1083.                                resource,
  1084.                                level,
  1085.                                usage,
  1086.                                box, &result);
  1087.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1088.  
  1089.    *transfer = rbug_transfer_create(rb_pipe, rb_resource, result);
  1090.    return *transfer ? map : NULL;
  1091. }
  1092.  
  1093. static void
  1094. rbug_context_transfer_flush_region(struct pipe_context *_context,
  1095.                                    struct pipe_transfer *_transfer,
  1096.                                    const struct pipe_box *box)
  1097. {
  1098.    struct rbug_context *rb_pipe = rbug_context(_context);
  1099.    struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
  1100.    struct pipe_context *context = rb_pipe->pipe;
  1101.    struct pipe_transfer *transfer = rb_transfer->transfer;
  1102.  
  1103.    pipe_mutex_lock(rb_pipe->call_mutex);
  1104.    context->transfer_flush_region(context,
  1105.                                   transfer,
  1106.                                   box);
  1107.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1108. }
  1109.  
  1110.  
  1111. static void
  1112. rbug_context_transfer_unmap(struct pipe_context *_context,
  1113.                             struct pipe_transfer *_transfer)
  1114. {
  1115.    struct rbug_context *rb_pipe = rbug_context(_context);
  1116.    struct rbug_transfer *rb_transfer = rbug_transfer(_transfer);
  1117.    struct pipe_context *context = rb_pipe->pipe;
  1118.    struct pipe_transfer *transfer = rb_transfer->transfer;
  1119.  
  1120.    pipe_mutex_lock(rb_pipe->call_mutex);
  1121.    context->transfer_unmap(context,
  1122.                            transfer);
  1123.    rbug_transfer_destroy(rb_pipe,
  1124.                          rb_transfer);
  1125.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1126. }
  1127.  
  1128.  
  1129. static void
  1130. rbug_context_transfer_inline_write(struct pipe_context *_context,
  1131.                                    struct pipe_resource *_resource,
  1132.                                    unsigned level,
  1133.                                    unsigned usage,
  1134.                                    const struct pipe_box *box,
  1135.                                    const void *data,
  1136.                                    unsigned stride,
  1137.                                    unsigned layer_stride)
  1138. {
  1139.    struct rbug_context *rb_pipe = rbug_context(_context);
  1140.    struct rbug_resource *rb_resource = rbug_resource(_resource);
  1141.    struct pipe_context *context = rb_pipe->pipe;
  1142.    struct pipe_resource *resource = rb_resource->resource;
  1143.  
  1144.    pipe_mutex_lock(rb_pipe->call_mutex);
  1145.    context->transfer_inline_write(context,
  1146.                                   resource,
  1147.                                   level,
  1148.                                   usage,
  1149.                                   box,
  1150.                                   data,
  1151.                                   stride,
  1152.                                   layer_stride);
  1153.    pipe_mutex_unlock(rb_pipe->call_mutex);
  1154. }
  1155.  
  1156.  
  1157. struct pipe_context *
  1158. rbug_context_create(struct pipe_screen *_screen, struct pipe_context *pipe)
  1159. {
  1160.    struct rbug_context *rb_pipe;
  1161.    struct rbug_screen *rb_screen = rbug_screen(_screen);
  1162.  
  1163.    if (!rb_screen)
  1164.       return NULL;
  1165.  
  1166.    rb_pipe = CALLOC_STRUCT(rbug_context);
  1167.    if (!rb_pipe)
  1168.       return NULL;
  1169.  
  1170.    pipe_mutex_init(rb_pipe->draw_mutex);
  1171.    pipe_condvar_init(rb_pipe->draw_cond);
  1172.    pipe_mutex_init(rb_pipe->call_mutex);
  1173.    pipe_mutex_init(rb_pipe->list_mutex);
  1174.    make_empty_list(&rb_pipe->shaders);
  1175.  
  1176.    rb_pipe->base.screen = _screen;
  1177.    rb_pipe->base.priv = pipe->priv; /* expose wrapped data */
  1178.    rb_pipe->base.draw = NULL;
  1179.  
  1180.    rb_pipe->base.destroy = rbug_destroy;
  1181.    rb_pipe->base.draw_vbo = rbug_draw_vbo;
  1182.    rb_pipe->base.create_query = rbug_create_query;
  1183.    rb_pipe->base.destroy_query = rbug_destroy_query;
  1184.    rb_pipe->base.begin_query = rbug_begin_query;
  1185.    rb_pipe->base.end_query = rbug_end_query;
  1186.    rb_pipe->base.get_query_result = rbug_get_query_result;
  1187.    rb_pipe->base.create_blend_state = rbug_create_blend_state;
  1188.    rb_pipe->base.bind_blend_state = rbug_bind_blend_state;
  1189.    rb_pipe->base.delete_blend_state = rbug_delete_blend_state;
  1190.    rb_pipe->base.create_sampler_state = rbug_create_sampler_state;
  1191.    rb_pipe->base.bind_sampler_states = rbug_bind_sampler_states;
  1192.    rb_pipe->base.delete_sampler_state = rbug_delete_sampler_state;
  1193.    rb_pipe->base.create_rasterizer_state = rbug_create_rasterizer_state;
  1194.    rb_pipe->base.bind_rasterizer_state = rbug_bind_rasterizer_state;
  1195.    rb_pipe->base.delete_rasterizer_state = rbug_delete_rasterizer_state;
  1196.    rb_pipe->base.create_depth_stencil_alpha_state = rbug_create_depth_stencil_alpha_state;
  1197.    rb_pipe->base.bind_depth_stencil_alpha_state = rbug_bind_depth_stencil_alpha_state;
  1198.    rb_pipe->base.delete_depth_stencil_alpha_state = rbug_delete_depth_stencil_alpha_state;
  1199.    rb_pipe->base.create_fs_state = rbug_create_fs_state;
  1200.    rb_pipe->base.bind_fs_state = rbug_bind_fs_state;
  1201.    rb_pipe->base.delete_fs_state = rbug_delete_fs_state;
  1202.    rb_pipe->base.create_vs_state = rbug_create_vs_state;
  1203.    rb_pipe->base.bind_vs_state = rbug_bind_vs_state;
  1204.    rb_pipe->base.delete_vs_state = rbug_delete_vs_state;
  1205.    rb_pipe->base.create_gs_state = rbug_create_gs_state;
  1206.    rb_pipe->base.bind_gs_state = rbug_bind_gs_state;
  1207.    rb_pipe->base.delete_gs_state = rbug_delete_gs_state;
  1208.    rb_pipe->base.create_vertex_elements_state = rbug_create_vertex_elements_state;
  1209.    rb_pipe->base.bind_vertex_elements_state = rbug_bind_vertex_elements_state;
  1210.    rb_pipe->base.delete_vertex_elements_state = rbug_delete_vertex_elements_state;
  1211.    rb_pipe->base.set_blend_color = rbug_set_blend_color;
  1212.    rb_pipe->base.set_stencil_ref = rbug_set_stencil_ref;
  1213.    rb_pipe->base.set_clip_state = rbug_set_clip_state;
  1214.    rb_pipe->base.set_constant_buffer = rbug_set_constant_buffer;
  1215.    rb_pipe->base.set_framebuffer_state = rbug_set_framebuffer_state;
  1216.    rb_pipe->base.set_polygon_stipple = rbug_set_polygon_stipple;
  1217.    rb_pipe->base.set_scissor_states = rbug_set_scissor_states;
  1218.    rb_pipe->base.set_viewport_states = rbug_set_viewport_states;
  1219.    rb_pipe->base.set_sampler_views = rbug_set_sampler_views;
  1220.    rb_pipe->base.set_vertex_buffers = rbug_set_vertex_buffers;
  1221.    rb_pipe->base.set_index_buffer = rbug_set_index_buffer;
  1222.    rb_pipe->base.set_sample_mask = rbug_set_sample_mask;
  1223.    rb_pipe->base.create_stream_output_target = rbug_create_stream_output_target;
  1224.    rb_pipe->base.stream_output_target_destroy = rbug_stream_output_target_destroy;
  1225.    rb_pipe->base.set_stream_output_targets = rbug_set_stream_output_targets;
  1226.    rb_pipe->base.resource_copy_region = rbug_resource_copy_region;
  1227.    rb_pipe->base.blit = rbug_blit;
  1228.    rb_pipe->base.flush_resource = rbug_flush_resource;
  1229.    rb_pipe->base.clear = rbug_clear;
  1230.    rb_pipe->base.clear_render_target = rbug_clear_render_target;
  1231.    rb_pipe->base.clear_depth_stencil = rbug_clear_depth_stencil;
  1232.    rb_pipe->base.flush = rbug_flush;
  1233.    rb_pipe->base.create_sampler_view = rbug_context_create_sampler_view;
  1234.    rb_pipe->base.sampler_view_destroy = rbug_context_sampler_view_destroy;
  1235.    rb_pipe->base.create_surface = rbug_context_create_surface;
  1236.    rb_pipe->base.surface_destroy = rbug_context_surface_destroy;
  1237.    rb_pipe->base.transfer_map = rbug_context_transfer_map;
  1238.    rb_pipe->base.transfer_unmap = rbug_context_transfer_unmap;
  1239.    rb_pipe->base.transfer_flush_region = rbug_context_transfer_flush_region;
  1240.    rb_pipe->base.transfer_inline_write = rbug_context_transfer_inline_write;
  1241.  
  1242.    rb_pipe->pipe = pipe;
  1243.  
  1244.    rbug_screen_add_to_list(rb_screen, contexts, rb_pipe);
  1245.  
  1246.    if (debug_get_bool_option("GALLIUM_RBUG_START_BLOCKED", FALSE)) {
  1247.       rb_pipe->draw_blocked = RBUG_BLOCK_BEFORE;
  1248.    }
  1249.  
  1250.    return &rb_pipe->base;
  1251. }
  1252.