1 /**************************************************************************
3 * Copyright 2012 Francisco Jerez
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "pipe_loader_priv.h"
30 #include "util/u_memory.h"
31 #include "util/u_dl.h"
32 #include "sw/dri/dri_sw_winsys.h"
33 #include "sw/kms-dri/kms_dri_sw_winsys.h"
34 #include "sw/null/null_sw_winsys.h"
35 #include "sw/wrapper/wrapper_sw_winsys.h"
36 #include "target-helpers/sw_helper_public.h"
37 #include "state_tracker/drisw_api.h"
38 #include "state_tracker/sw_driver.h"
39 #include "state_tracker/sw_winsys.h"
41 struct pipe_loader_sw_device
{
42 struct pipe_loader_device base
;
43 const struct sw_driver_descriptor
*dd
;
44 #ifndef GALLIUM_STATIC_TARGETS
45 struct util_dl_library
*lib
;
50 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
52 static const struct pipe_loader_ops pipe_loader_sw_ops
;
54 #ifdef GALLIUM_STATIC_TARGETS
55 static const struct sw_driver_descriptor driver_descriptors
= {
56 .create_screen
= sw_screen_create
,
58 #ifdef HAVE_PIPE_LOADER_DRI
61 .create_winsys
= dri_create_sw_winsys
,
64 #ifdef HAVE_PIPE_LOADER_KMS
67 .create_winsys
= kms_dri_create_winsys
,
71 * XXX: Do not include these two for non autotools builds.
72 * They don't have neither opencl nor nine, where these are used.
74 #ifndef DROP_PIPE_LOADER_MISC
77 .create_winsys
= null_sw_create
,
81 .create_winsys
= wrapper_sw_winsys_wrap_pipe_screen
,
90 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device
*sdev
)
92 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
93 sdev
->base
.driver_name
= "swrast";
94 sdev
->base
.ops
= &pipe_loader_sw_ops
;
96 #ifdef GALLIUM_STATIC_TARGETS
97 sdev
->dd
= &driver_descriptors
;
101 sdev
->lib
= pipe_loader_find_module(&sdev
->base
, PIPE_SEARCH_DIR
);
105 sdev
->dd
= (const struct sw_driver_descriptor
*)
106 util_dl_get_proc_address(sdev
->lib
, "swrast_driver_descriptor");
109 util_dl_close(sdev
->lib
);
119 pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device
*sdev
)
121 #ifndef GALLIUM_STATIC_TARGETS
123 util_dl_close(sdev
->lib
);
127 #ifdef HAVE_PIPE_LOADER_DRI
129 pipe_loader_sw_probe_dri(struct pipe_loader_device
**devs
, struct drisw_loader_funcs
*drisw_lf
)
131 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
137 if (!pipe_loader_sw_probe_init_common(sdev
))
140 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
141 if (strcmp(sdev
->dd
->winsys
[i
].name
, "dri") == 0) {
142 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(drisw_lf
);
153 pipe_loader_sw_probe_teardown_common(sdev
);
159 #ifdef HAVE_PIPE_LOADER_KMS
161 pipe_loader_sw_probe_kms(struct pipe_loader_device
**devs
, int fd
)
163 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
169 if (!pipe_loader_sw_probe_init_common(sdev
))
172 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
173 if (strcmp(sdev
->dd
->winsys
[i
].name
, "kms_dri") == 0) {
174 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(fd
);
185 pipe_loader_sw_probe_teardown_common(sdev
);
192 pipe_loader_sw_probe_null(struct pipe_loader_device
**devs
)
194 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
200 if (!pipe_loader_sw_probe_init_common(sdev
))
203 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
204 if (strcmp(sdev
->dd
->winsys
[i
].name
, "null") == 0) {
205 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys();
216 pipe_loader_sw_probe_teardown_common(sdev
);
222 pipe_loader_sw_probe(struct pipe_loader_device
**devs
, int ndev
)
227 if (!pipe_loader_sw_probe_null(devs
)) {
236 pipe_loader_sw_probe_wrapped(struct pipe_loader_device
**dev
,
237 struct pipe_screen
*screen
)
239 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
245 if (!pipe_loader_sw_probe_init_common(sdev
))
248 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
249 if (strcmp(sdev
->dd
->winsys
[i
].name
, "wrapped") == 0) {
250 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(screen
);
261 pipe_loader_sw_probe_teardown_common(sdev
);
267 pipe_loader_sw_release(struct pipe_loader_device
**dev
)
269 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(*dev
);
271 #ifndef GALLIUM_STATIC_TARGETS
273 util_dl_close(sdev
->lib
);
280 static const struct drm_conf_ret
*
281 pipe_loader_sw_configuration(struct pipe_loader_device
*dev
,
287 static struct pipe_screen
*
288 pipe_loader_sw_create_screen(struct pipe_loader_device
*dev
)
290 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(dev
);
291 struct pipe_screen
*screen
;
293 screen
= sdev
->dd
->create_screen(sdev
->ws
);
295 sdev
->ws
->destroy(sdev
->ws
);
300 static const struct pipe_loader_ops pipe_loader_sw_ops
= {
301 .create_screen
= pipe_loader_sw_create_screen
,
302 .configuration
= pipe_loader_sw_configuration
,
303 .release
= pipe_loader_sw_release