Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2010 Red Hat Inc.
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  8.  * license, and/or sell copies of the Software, and to permit persons to whom
  9.  * the Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice (including the next
  12.  * paragraph) shall be included in all copies or substantial portions of the
  13.  * Software.
  14.  *
  15.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  18.  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  19.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  20.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  21.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  */
  23. #include <stdio.h>
  24. #include <errno.h>
  25. #include "pipe/p_defines.h"
  26. #include "pipe/p_state.h"
  27. #include "pipe/p_context.h"
  28. #include "pipe/p_screen.h"
  29. #include "util/u_memory.h"
  30. #include "util/u_inlines.h"
  31. #include "util/u_format.h"
  32. #include "noop_public.h"
  33.  
  34. DEBUG_GET_ONCE_BOOL_OPTION(noop, "GALLIUM_NOOP", FALSE)
  35.  
  36. void noop_init_state_functions(struct pipe_context *ctx);
  37.  
  38. struct noop_pipe_screen {
  39.         struct pipe_screen      pscreen;
  40.         struct pipe_screen      *oscreen;
  41. };
  42.  
  43. /*
  44.  * query
  45.  */
  46. struct noop_query {
  47.         unsigned        query;
  48. };
  49. static struct pipe_query *noop_create_query(struct pipe_context *ctx, unsigned query_type, unsigned index)
  50. {
  51.         struct noop_query *query = CALLOC_STRUCT(noop_query);
  52.  
  53.         return (struct pipe_query *)query;
  54. }
  55.  
  56. static void noop_destroy_query(struct pipe_context *ctx, struct pipe_query *query)
  57. {
  58.         FREE(query);
  59. }
  60.  
  61. static boolean noop_begin_query(struct pipe_context *ctx, struct pipe_query *query)
  62. {
  63.    return true;
  64. }
  65.  
  66. static void noop_end_query(struct pipe_context *ctx, struct pipe_query *query)
  67. {
  68. }
  69.  
  70. static boolean noop_get_query_result(struct pipe_context *ctx,
  71.                                         struct pipe_query *query,
  72.                                         boolean wait,
  73.                                         union pipe_query_result *vresult)
  74. {
  75.         uint64_t *result = (uint64_t*)vresult;
  76.  
  77.         *result = 0;
  78.         return TRUE;
  79. }
  80.  
  81.  
  82. /*
  83.  * resource
  84.  */
  85. struct noop_resource {
  86.         struct pipe_resource    base;
  87.         unsigned                size;
  88.         char                    *data;
  89.         struct sw_displaytarget *dt;
  90. };
  91.  
  92. static struct pipe_resource *noop_resource_create(struct pipe_screen *screen,
  93.                                                 const struct pipe_resource *templ)
  94. {
  95.         struct noop_resource *nresource;
  96.         unsigned stride;
  97.  
  98.         nresource = CALLOC_STRUCT(noop_resource);
  99.         if (nresource == NULL)
  100.                 return NULL;
  101.  
  102.         stride = util_format_get_stride(templ->format, templ->width0);
  103.         nresource->base = *templ;
  104.         nresource->base.screen = screen;
  105.         nresource->size = stride * templ->height0 * templ->depth0;
  106.         nresource->data = MALLOC(nresource->size);
  107.         pipe_reference_init(&nresource->base.reference, 1);
  108.         if (nresource->data == NULL) {
  109.                 FREE(nresource);
  110.                 return NULL;
  111.         }
  112.         return &nresource->base;
  113. }
  114.  
  115. static struct pipe_resource *noop_resource_from_handle(struct pipe_screen *screen,
  116.                                                         const struct pipe_resource *templ,
  117.                                                         struct winsys_handle *handle)
  118. {
  119.         struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
  120.         struct pipe_screen *oscreen = noop_screen->oscreen;
  121.         struct pipe_resource *result;
  122.         struct pipe_resource *noop_resource;
  123.  
  124.         result = oscreen->resource_from_handle(oscreen, templ, handle);
  125.         noop_resource = noop_resource_create(screen, result);
  126.         pipe_resource_reference(&result, NULL);
  127.         return noop_resource;
  128. }
  129.  
  130. static boolean noop_resource_get_handle(struct pipe_screen *screen,
  131.                                         struct pipe_resource *resource,
  132.                                         struct winsys_handle *handle)
  133. {
  134.         return FALSE;
  135. }
  136.  
  137. static void noop_resource_destroy(struct pipe_screen *screen,
  138.                                         struct pipe_resource *resource)
  139. {
  140.         struct noop_resource *nresource = (struct noop_resource *)resource;
  141.  
  142.         FREE(nresource->data);
  143.         FREE(resource);
  144. }
  145.  
  146.  
  147. /*
  148.  * transfer
  149.  */
  150. static void *noop_transfer_map(struct pipe_context *pipe,
  151.                                struct pipe_resource *resource,
  152.                                unsigned level,
  153.                                enum pipe_transfer_usage usage,
  154.                                const struct pipe_box *box,
  155.                                struct pipe_transfer **ptransfer)
  156. {
  157.    struct pipe_transfer *transfer;
  158.    struct noop_resource *nresource = (struct noop_resource *)resource;
  159.  
  160.    transfer = CALLOC_STRUCT(pipe_transfer);
  161.    if (transfer == NULL)
  162.            return NULL;
  163.    pipe_resource_reference(&transfer->resource, resource);
  164.    transfer->level = level;
  165.    transfer->usage = usage;
  166.    transfer->box = *box;
  167.    transfer->stride = 1;
  168.    transfer->layer_stride = 1;
  169.    *ptransfer = transfer;
  170.  
  171.    return nresource->data;
  172. }
  173.  
  174. static void noop_transfer_flush_region(struct pipe_context *pipe,
  175.                                         struct pipe_transfer *transfer,
  176.                                         const struct pipe_box *box)
  177. {
  178. }
  179.  
  180. static void noop_transfer_unmap(struct pipe_context *pipe,
  181.                                 struct pipe_transfer *transfer)
  182. {
  183.    pipe_resource_reference(&transfer->resource, NULL);
  184.    FREE(transfer);
  185. }
  186.  
  187. static void noop_transfer_inline_write(struct pipe_context *pipe,
  188.                                         struct pipe_resource *resource,
  189.                                         unsigned level,
  190.                                         unsigned usage,
  191.                                         const struct pipe_box *box,
  192.                                         const void *data,
  193.                                         unsigned stride,
  194.                                         unsigned layer_stride)
  195. {
  196. }
  197.  
  198.  
  199. /*
  200.  * clear/copy
  201.  */
  202. static void noop_clear(struct pipe_context *ctx, unsigned buffers,
  203.                        const union pipe_color_union *color, double depth, unsigned stencil)
  204. {
  205. }
  206.  
  207. static void noop_clear_render_target(struct pipe_context *ctx,
  208.                                      struct pipe_surface *dst,
  209.                                      const union pipe_color_union *color,
  210.                                      unsigned dstx, unsigned dsty,
  211.                                      unsigned width, unsigned height)
  212. {
  213. }
  214.  
  215. static void noop_clear_depth_stencil(struct pipe_context *ctx,
  216.                                      struct pipe_surface *dst,
  217.                                      unsigned clear_flags,
  218.                                      double depth,
  219.                                      unsigned stencil,
  220.                                      unsigned dstx, unsigned dsty,
  221.                                      unsigned width, unsigned height)
  222. {
  223. }
  224.  
  225. static void noop_resource_copy_region(struct pipe_context *ctx,
  226.                                       struct pipe_resource *dst,
  227.                                       unsigned dst_level,
  228.                                       unsigned dstx, unsigned dsty, unsigned dstz,
  229.                                       struct pipe_resource *src,
  230.                                       unsigned src_level,
  231.                                       const struct pipe_box *src_box)
  232. {
  233. }
  234.  
  235.  
  236. static void noop_blit(struct pipe_context *ctx,
  237.                       const struct pipe_blit_info *info)
  238. {
  239. }
  240.  
  241.  
  242. static void
  243. noop_flush_resource(struct pipe_context *ctx,
  244.                     struct pipe_resource *resource)
  245. {
  246. }
  247.  
  248.  
  249. /*
  250.  * context
  251.  */
  252. static void noop_flush(struct pipe_context *ctx,
  253.                        struct pipe_fence_handle **fence,
  254.                        unsigned flags)
  255. {
  256. }
  257.  
  258. static void noop_destroy_context(struct pipe_context *ctx)
  259. {
  260.         FREE(ctx);
  261. }
  262.  
  263. static struct pipe_context *noop_create_context(struct pipe_screen *screen, void *priv)
  264. {
  265.         struct pipe_context *ctx = CALLOC_STRUCT(pipe_context);
  266.  
  267.         if (ctx == NULL)
  268.                 return NULL;
  269.         ctx->screen = screen;
  270.         ctx->priv = priv;
  271.         ctx->destroy = noop_destroy_context;
  272.         ctx->flush = noop_flush;
  273.         ctx->clear = noop_clear;
  274.         ctx->clear_render_target = noop_clear_render_target;
  275.         ctx->clear_depth_stencil = noop_clear_depth_stencil;
  276.         ctx->resource_copy_region = noop_resource_copy_region;
  277.         ctx->blit = noop_blit;
  278.         ctx->flush_resource = noop_flush_resource;
  279.         ctx->create_query = noop_create_query;
  280.         ctx->destroy_query = noop_destroy_query;
  281.         ctx->begin_query = noop_begin_query;
  282.         ctx->end_query = noop_end_query;
  283.         ctx->get_query_result = noop_get_query_result;
  284.         ctx->transfer_map = noop_transfer_map;
  285.         ctx->transfer_flush_region = noop_transfer_flush_region;
  286.         ctx->transfer_unmap = noop_transfer_unmap;
  287.         ctx->transfer_inline_write = noop_transfer_inline_write;
  288.         noop_init_state_functions(ctx);
  289.  
  290.         return ctx;
  291. }
  292.  
  293.  
  294. /*
  295.  * pipe_screen
  296.  */
  297. static void noop_flush_frontbuffer(struct pipe_screen *_screen,
  298.                                    struct pipe_resource *resource,
  299.                                    unsigned level, unsigned layer,
  300.                                    void *context_private, struct pipe_box *box)
  301. {
  302. }
  303.  
  304. static const char *noop_get_vendor(struct pipe_screen* pscreen)
  305. {
  306.         return "X.Org";
  307. }
  308.  
  309. static const char *noop_get_device_vendor(struct pipe_screen* pscreen)
  310. {
  311.         return "NONE";
  312. }
  313.  
  314. static const char *noop_get_name(struct pipe_screen* pscreen)
  315. {
  316.         return "NOOP";
  317. }
  318.  
  319. static int noop_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
  320. {
  321.         struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
  322.  
  323.         return screen->get_param(screen, param);
  324. }
  325.  
  326. static float noop_get_paramf(struct pipe_screen* pscreen,
  327.                              enum pipe_capf param)
  328. {
  329.         struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
  330.  
  331.         return screen->get_paramf(screen, param);
  332. }
  333.  
  334. static int noop_get_shader_param(struct pipe_screen* pscreen, unsigned shader, enum pipe_shader_cap param)
  335. {
  336.         struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
  337.  
  338.         return screen->get_shader_param(screen, shader, param);
  339. }
  340.  
  341. static boolean noop_is_format_supported(struct pipe_screen* pscreen,
  342.                                         enum pipe_format format,
  343.                                         enum pipe_texture_target target,
  344.                                         unsigned sample_count,
  345.                                         unsigned usage)
  346. {
  347.         struct pipe_screen *screen = ((struct noop_pipe_screen*)pscreen)->oscreen;
  348.  
  349.         return screen->is_format_supported(screen, format, target, sample_count, usage);
  350. }
  351.  
  352. static uint64_t noop_get_timestamp(struct pipe_screen *pscreen)
  353. {
  354.         return 0;
  355. }
  356.  
  357. static void noop_destroy_screen(struct pipe_screen *screen)
  358. {
  359.         struct noop_pipe_screen *noop_screen = (struct noop_pipe_screen*)screen;
  360.         struct pipe_screen *oscreen = noop_screen->oscreen;
  361.  
  362.         oscreen->destroy(oscreen);
  363.         FREE(screen);
  364. }
  365.  
  366. struct pipe_screen *noop_screen_create(struct pipe_screen *oscreen)
  367. {
  368.         struct noop_pipe_screen *noop_screen;
  369.         struct pipe_screen *screen;
  370.  
  371.         if (!debug_get_option_noop()) {
  372.                 return oscreen;
  373.         }
  374.  
  375.         noop_screen = CALLOC_STRUCT(noop_pipe_screen);
  376.         if (noop_screen == NULL) {
  377.                 return NULL;
  378.         }
  379.         noop_screen->oscreen = oscreen;
  380.         screen = &noop_screen->pscreen;
  381.  
  382.         screen->destroy = noop_destroy_screen;
  383.         screen->get_name = noop_get_name;
  384.         screen->get_vendor = noop_get_vendor;
  385.         screen->get_device_vendor = noop_get_device_vendor;
  386.         screen->get_param = noop_get_param;
  387.         screen->get_shader_param = noop_get_shader_param;
  388.         screen->get_paramf = noop_get_paramf;
  389.         screen->is_format_supported = noop_is_format_supported;
  390.         screen->context_create = noop_create_context;
  391.         screen->resource_create = noop_resource_create;
  392.         screen->resource_from_handle = noop_resource_from_handle;
  393.         screen->resource_get_handle = noop_resource_get_handle;
  394.         screen->resource_destroy = noop_resource_destroy;
  395.         screen->flush_frontbuffer = noop_flush_frontbuffer;
  396.         screen->get_timestamp = noop_get_timestamp;
  397.  
  398.         return screen;
  399. }
  400.