Subversion Repositories Kolibri OS

Rev

Rev 4358 | Go to most recent revision | 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 TUNGSTEN GRAPHICS 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/null/null_sw_winsys.h"
  33. #include "target-helpers/inline_sw_helper.h"
  34. //#include "state_tracker/xlib_sw_winsys.h"
  35.  
  36. struct pipe_loader_sw_device {
  37.    struct pipe_loader_device base;
  38.    struct util_dl_library *lib;
  39.    struct sw_winsys *ws;
  40. };
  41.  
  42. #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
  43.  
  44. static struct pipe_loader_ops pipe_loader_sw_ops;
  45.  
  46. static struct sw_winsys *(*backends[])() = {
  47. #ifdef HAVE_WINSYS_XLIB
  48.    x11_sw_create,
  49. #endif
  50.    null_sw_create
  51. };
  52.  
  53. int
  54. pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
  55. {
  56.    int i;
  57.  
  58.    for (i = 0; i < Elements(backends); i++) {
  59.       if (i < ndev) {
  60.          struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
  61.  
  62.          sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
  63.          sdev->base.driver_name = "swrast";
  64.          sdev->base.ops = &pipe_loader_sw_ops;
  65.          sdev->ws = backends[i]();
  66.          devs[i] = &sdev->base;
  67.       }
  68.    }
  69.  
  70.    return i;
  71. }
  72.  
  73. static void
  74. pipe_loader_sw_release(struct pipe_loader_device **dev)
  75. {
  76.    struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
  77.  
  78.    if (sdev->lib)
  79.       util_dl_close(sdev->lib);
  80.  
  81.    FREE(sdev);
  82.    *dev = NULL;
  83. }
  84.  
  85. static struct pipe_screen *
  86. pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
  87.                              const char *library_paths)
  88. {
  89.    struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
  90.    struct pipe_screen *(*init)(struct sw_winsys *);
  91.  
  92.    if (!sdev->lib)
  93.       sdev->lib = pipe_loader_find_module(dev, library_paths);
  94.    if (!sdev->lib)
  95.       return NULL;
  96.  
  97.    init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
  98.    if (!init)
  99.       return NULL;
  100.  
  101.    return init(sdev->ws);
  102. }
  103.  
  104. static struct pipe_loader_ops pipe_loader_sw_ops = {
  105.    .create_screen = pipe_loader_sw_create_screen,
  106.    .release = pipe_loader_sw_release
  107. };
  108.