aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c
blob: 696ba2c5338cb4466a12f8c075477d53b822d1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/**************************************************************************
 *
 * Copyright 2012 Francisco Jerez
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

#include "pipe_loader_priv.h"

#include "util/u_memory.h"
#include "util/u_dl.h"
#include "sw/dri/dri_sw_winsys.h"
#include "sw/kms-dri/kms_dri_sw_winsys.h"
#include "sw/null/null_sw_winsys.h"
#include "sw/wrapper/wrapper_sw_winsys.h"
#include "target-helpers/sw_helper_public.h"
#include "state_tracker/drisw_api.h"
#include "state_tracker/sw_driver.h"
#include "state_tracker/sw_winsys.h"

struct pipe_loader_sw_device {
   struct pipe_loader_device base;
   const struct sw_driver_descriptor *dd;
#ifndef GALLIUM_STATIC_TARGETS
   struct util_dl_library *lib;
#endif
   struct sw_winsys *ws;
   int fd;
};

#define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)

static const struct pipe_loader_ops pipe_loader_sw_ops;

#ifdef GALLIUM_STATIC_TARGETS
static const struct sw_driver_descriptor driver_descriptors = {
   .create_screen = sw_screen_create,
   .winsys = {
#ifdef HAVE_PIPE_LOADER_DRI
      {
         .name = "dri",
         .create_winsys = dri_create_sw_winsys,
      },
#endif
#ifdef HAVE_PIPE_LOADER_KMS
      {
         .name = "kms_dri",
         .create_winsys = kms_dri_create_winsys,
      },
#endif
/**
 * XXX: Do not include these two for non autotools builds.
 * They don't have neither opencl nor nine, where these are used.
 */
#ifndef DROP_PIPE_LOADER_MISC
      {
         .name = "null",
         .create_winsys = null_sw_create,
      },
      {
         .name = "wrapped",
         .create_winsys = wrapper_sw_winsys_wrap_pipe_screen,
      },
#endif
      { 0 },
   }
};
#endif

static bool
pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device *sdev)
{
   sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
   sdev->base.driver_name = "swrast";
   sdev->base.ops = &pipe_loader_sw_ops;
   sdev->fd = -1;

#ifdef GALLIUM_STATIC_TARGETS
   sdev->dd = &driver_descriptors;
   if (!sdev->dd)
      return false;
#else
   sdev->lib = pipe_loader_find_module(&sdev->base, PIPE_SEARCH_DIR);
   if (!sdev->lib)
      return false;

   sdev->dd = (const struct sw_driver_descriptor *)
      util_dl_get_proc_address(sdev->lib, "swrast_driver_descriptor");

   if (!sdev->dd){
      util_dl_close(sdev->lib);
      sdev->lib = NULL;
      return false;
   }
#endif

   return true;
}

static void
pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device *sdev)
{
#ifndef GALLIUM_STATIC_TARGETS
   if (sdev->lib)
      util_dl_close(sdev->lib);
#endif
}

#ifdef HAVE_PIPE_LOADER_DRI
bool
pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
{
   struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
   int i;

   if (!sdev)
      return false;

   if (!pipe_loader_sw_probe_init_common(sdev))
      goto fail;

   for (i = 0; sdev->dd->winsys[i].name; i++) {
      if (strcmp(sdev->dd->winsys[i].name, "dri") == 0) {
         sdev->ws = sdev->dd->winsys[i].create_winsys(drisw_lf);
         break;
      }
   }
   if (!sdev->ws)
      goto fail;

   *devs = &sdev->base;
   return true;

fail:
   pipe_loader_sw_probe_teardown_common(sdev);
   FREE(sdev);
   return false;
}
#endif

#ifdef HAVE_PIPE_LOADER_KMS
bool
pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
{
   struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
   int i;

   if (!sdev)
      return false;

   if (!pipe_loader_sw_probe_init_common(sdev))
      goto fail;

   sdev->fd = fd;

   for (i = 0; sdev->dd->winsys[i].name; i++) {
      if (strcmp(sdev->dd->winsys[i].name, "kms_dri") == 0) {
         sdev->ws = sdev->dd->winsys[i].create_winsys(fd);
         break;
      }
   }
   if (!sdev->ws)
      goto fail;

   *devs = &sdev->base;
   return true;

fail:
   pipe_loader_sw_probe_teardown_common(sdev);
   FREE(sdev);
   return false;
}
#endif

bool
pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
{
   struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
   int i;

   if (!sdev)
      return false;

   if (!pipe_loader_sw_probe_init_common(sdev))
      goto fail;

   for (i = 0; sdev->dd->winsys[i].name; i++) {
      if (strcmp(sdev->dd->winsys[i].name, "null") == 0) {
         sdev->ws = sdev->dd->winsys[i].create_winsys();
         break;
      }
   }
   if (!sdev->ws)
      goto fail;

   *devs = &sdev->base;
   return true;

fail:
   pipe_loader_sw_probe_teardown_common(sdev);
   FREE(sdev);
   return false;
}

int
pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
{
   int i = 1;

   if (i <= ndev) {
      if (!pipe_loader_sw_probe_null(devs)) {
         i--;
      }
   }

   return i;
}

boolean
pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
                             struct pipe_screen *screen)
{
   struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
   int i;

   if (!sdev)
      return false;

   if (!pipe_loader_sw_probe_init_common(sdev))
      goto fail;

   for (i = 0; sdev->dd->winsys[i].name; i++) {
      if (strcmp(sdev->dd->winsys[i].name, "wrapped") == 0) {
         sdev->ws = sdev->dd->winsys[i].create_winsys(screen);
         break;
      }
   }
   if (!sdev->ws)
      goto fail;

   *dev = &sdev->base;
   return true;

fail:
   pipe_loader_sw_probe_teardown_common(sdev);
   FREE(sdev);
   return false;
}

static void
pipe_loader_sw_release(struct pipe_loader_device **dev)
{
   struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);

#ifndef GALLIUM_STATIC_TARGETS
   if (sdev->lib)
      util_dl_close(sdev->lib);
#endif

#ifdef HAVE_PIPE_LOADER_KMS
   if (sdev->fd != -1)
      close(sdev->fd);
#endif

   pipe_loader_base_release(dev);
}

static const struct drm_conf_ret *
pipe_loader_sw_configuration(struct pipe_loader_device *dev,
                             enum drm_conf conf)
{
   return NULL;
}

static struct pipe_screen *
pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
                             const struct pipe_screen_config *config)
{
   struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
   struct pipe_screen *screen;

   screen = sdev->dd->create_screen(sdev->ws);
   if (!screen)
      sdev->ws->destroy(sdev->ws);

   return screen;
}

static const struct pipe_loader_ops pipe_loader_sw_ops = {
   .create_screen = pipe_loader_sw_create_screen,
   .configuration = pipe_loader_sw_configuration,
   .release = pipe_loader_sw_release
};