Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2012 Francisco Jerez
  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. #include "pipe_loader_priv.h"
  29.  
  30. #include "util/u_memory.h"
  31. #include "util/u_dl.h"
  32. #include "sw/dri/dri_sw_winsys.h"
  33. #include "sw/null/null_sw_winsys.h"
  34. #include "sw/wrapper/wrapper_sw_winsys.h"
  35. #ifdef HAVE_PIPE_LOADER_XLIB
  36. /* Explicitly wrap the header to ease build without X11 headers */
  37. #include "sw/xlib/xlib_sw_winsys.h"
  38. #endif
  39. #include "target-helpers/inline_sw_helper.h"
  40. #include "state_tracker/drisw_api.h"
  41.  
  42. struct pipe_loader_sw_device {
  43.    struct pipe_loader_device base;
  44.    struct util_dl_library *lib;
  45.    struct sw_winsys *ws;
  46. };
  47.  
  48. #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
  49.  
  50. static struct pipe_loader_ops pipe_loader_sw_ops;
  51.  
  52. static struct sw_winsys *(*backends[])() = {
  53.    null_sw_create
  54. };
  55.  
  56. #ifdef HAVE_PIPE_LOADER_XLIB
  57. bool
  58. pipe_loader_sw_probe_xlib(struct pipe_loader_device **devs, Display *display)
  59. {
  60.    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  61.  
  62.    if (!sdev)
  63.       return false;
  64.  
  65.    sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  66.    sdev->base.driver_name = "swrast";
  67.    sdev->base.ops = &pipe_loader_sw_ops;
  68.    sdev->ws = xlib_create_sw_winsys(display);
  69.    if (!sdev->ws) {
  70.       FREE(sdev);
  71.       return false;
  72.    }
  73.    *devs = &sdev->base;
  74.  
  75.    return true;
  76. }
  77. #endif
  78.  
  79. #ifdef HAVE_PIPE_LOADER_DRI
  80. bool
  81. pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
  82. {
  83.    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  84.  
  85.    if (!sdev)
  86.       return false;
  87.  
  88.    sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  89.    sdev->base.driver_name = "swrast";
  90.    sdev->base.ops = &pipe_loader_sw_ops;
  91.    sdev->ws = dri_create_sw_winsys(drisw_lf);
  92.    if (!sdev->ws) {
  93.       FREE(sdev);
  94.       return false;
  95.    }
  96.    *devs = &sdev->base;
  97.  
  98.    return true;
  99. }
  100. #endif
  101.  
  102. bool
  103. pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
  104. {
  105.    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  106.  
  107.    if (!sdev)
  108.       return false;
  109.  
  110.    sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  111.    sdev->base.driver_name = "swrast";
  112.    sdev->base.ops = &pipe_loader_sw_ops;
  113.    sdev->ws = null_sw_create();
  114.    if (!sdev->ws) {
  115.       FREE(sdev);
  116.       return false;
  117.    }
  118.    *devs = &sdev->base;
  119.  
  120.    return true;
  121. }
  122.  
  123. int
  124. pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
  125. {
  126.    int i;
  127.  
  128.    for (i = 0; i < Elements(backends); i++) {
  129.       if (i < ndev) {
  130.          struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  131.          /* TODO: handle CALLOC_STRUCT failure */
  132.  
  133.          sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  134.          sdev->base.driver_name = "swrast";
  135.          sdev->base.ops = &pipe_loader_sw_ops;
  136.          sdev->ws = backends[i]();
  137.          devs[i] = &sdev->base;
  138.       }
  139.    }
  140.  
  141.    return i;
  142. }
  143.  
  144. boolean
  145. pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
  146.                              struct pipe_screen *screen)
  147. {
  148.    struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  149.  
  150.    if (!sdev)
  151.       return false;
  152.  
  153.    sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  154.    sdev->base.driver_name = "swrast";
  155.    sdev->base.ops = &pipe_loader_sw_ops;
  156.    sdev->ws = wrapper_sw_winsys_wrap_pipe_screen(screen);
  157.  
  158.    if (!sdev->ws) {
  159.       FREE(sdev);
  160.       return false;
  161.    }
  162.    *dev = &sdev->base;
  163.    return true;
  164. }
  165.  
  166. static void
  167. pipe_loader_sw_release(struct pipe_loader_device **dev)
  168. {
  169.    struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
  170.  
  171.    if (sdev->lib)
  172.       util_dl_close(sdev->lib);
  173.  
  174.    FREE(sdev);
  175.    *dev = NULL;
  176. }
  177.  
  178. static const struct drm_conf_ret *
  179. pipe_loader_sw_configuration(struct pipe_loader_device *dev,
  180.                              enum drm_conf conf)
  181. {
  182.    return NULL;
  183. }
  184.  
  185. static struct pipe_screen *
  186. pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
  187.                              const char *library_paths)
  188. {
  189.    struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
  190.    struct pipe_screen *(*init)(struct sw_winsys *);
  191.  
  192.    if (!sdev->lib)
  193.       sdev->lib = pipe_loader_find_module(dev, library_paths);
  194.    if (!sdev->lib)
  195.       return NULL;
  196.  
  197.    init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
  198.    if (!init){
  199.       util_dl_close(sdev->lib);
  200.       sdev->lib = NULL;
  201.       return NULL;
  202.    }
  203.  
  204.    return init(sdev->ws);
  205. }
  206.  
  207. static struct pipe_loader_ops pipe_loader_sw_ops = {
  208.    .create_screen = pipe_loader_sw_create_screen,
  209.    .configuration = pipe_loader_sw_configuration,
  210.    .release = pipe_loader_sw_release
  211. };
  212.