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 #ifdef HAVE_PIPE_LOADER_KMS
32 #include "pipe_loader_priv.h"
34 #include "util/u_memory.h"
35 #include "util/u_dl.h"
36 #include "sw/dri/dri_sw_winsys.h"
37 #include "sw/kms-dri/kms_dri_sw_winsys.h"
38 #include "sw/null/null_sw_winsys.h"
39 #include "sw/wrapper/wrapper_sw_winsys.h"
40 #include "target-helpers/sw_helper_public.h"
41 #include "state_tracker/drisw_api.h"
42 #include "state_tracker/sw_driver.h"
43 #include "state_tracker/sw_winsys.h"
45 struct pipe_loader_sw_device
{
46 struct pipe_loader_device base
;
47 const struct sw_driver_descriptor
*dd
;
48 #ifndef GALLIUM_STATIC_TARGETS
49 struct util_dl_library
*lib
;
55 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
57 static const struct pipe_loader_ops pipe_loader_sw_ops
;
59 #ifdef GALLIUM_STATIC_TARGETS
60 static const struct sw_driver_descriptor driver_descriptors
= {
61 .create_screen
= sw_screen_create
,
63 #ifdef HAVE_PIPE_LOADER_DRI
66 .create_winsys
= dri_create_sw_winsys
,
69 #ifdef HAVE_PIPE_LOADER_KMS
72 .create_winsys
= kms_dri_create_winsys
,
76 * XXX: Do not include these two for non autotools builds.
77 * They don't have neither opencl nor nine, where these are used.
79 #ifndef DROP_PIPE_LOADER_MISC
82 .create_winsys
= null_sw_create
,
86 .create_winsys
= wrapper_sw_winsys_wrap_pipe_screen
,
95 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device
*sdev
)
97 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
98 sdev
->base
.driver_name
= "swrast";
99 sdev
->base
.ops
= &pipe_loader_sw_ops
;
102 #ifdef GALLIUM_STATIC_TARGETS
103 sdev
->dd
= &driver_descriptors
;
107 sdev
->lib
= pipe_loader_find_module("swrast", PIPE_SEARCH_DIR
);
111 sdev
->dd
= (const struct sw_driver_descriptor
*)
112 util_dl_get_proc_address(sdev
->lib
, "swrast_driver_descriptor");
115 util_dl_close(sdev
->lib
);
125 pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device
*sdev
)
127 #ifndef GALLIUM_STATIC_TARGETS
129 util_dl_close(sdev
->lib
);
133 #ifdef HAVE_PIPE_LOADER_DRI
135 pipe_loader_sw_probe_dri(struct pipe_loader_device
**devs
, const struct drisw_loader_funcs
*drisw_lf
)
137 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
143 if (!pipe_loader_sw_probe_init_common(sdev
))
146 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
147 if (strcmp(sdev
->dd
->winsys
[i
].name
, "dri") == 0) {
148 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(drisw_lf
);
159 pipe_loader_sw_probe_teardown_common(sdev
);
165 #ifdef HAVE_PIPE_LOADER_KMS
167 pipe_loader_sw_probe_kms(struct pipe_loader_device
**devs
, int fd
)
169 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
175 if (!pipe_loader_sw_probe_init_common(sdev
))
178 if (fd
< 0 || (sdev
->fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3)) < 0)
181 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
182 if (strcmp(sdev
->dd
->winsys
[i
].name
, "kms_dri") == 0) {
183 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(sdev
->fd
);
194 pipe_loader_sw_probe_teardown_common(sdev
);
203 pipe_loader_sw_probe_null(struct pipe_loader_device
**devs
)
205 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
211 if (!pipe_loader_sw_probe_init_common(sdev
))
214 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
215 if (strcmp(sdev
->dd
->winsys
[i
].name
, "null") == 0) {
216 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys();
227 pipe_loader_sw_probe_teardown_common(sdev
);
233 pipe_loader_sw_probe(struct pipe_loader_device
**devs
, int ndev
)
238 if (!pipe_loader_sw_probe_null(devs
)) {
247 pipe_loader_sw_probe_wrapped(struct pipe_loader_device
**dev
,
248 struct pipe_screen
*screen
)
250 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
256 if (!pipe_loader_sw_probe_init_common(sdev
))
259 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
260 if (strcmp(sdev
->dd
->winsys
[i
].name
, "wrapped") == 0) {
261 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(screen
);
272 pipe_loader_sw_probe_teardown_common(sdev
);
278 pipe_loader_sw_release(struct pipe_loader_device
**dev
)
280 UNUSED
struct pipe_loader_sw_device
*sdev
=
281 pipe_loader_sw_device(*dev
);
283 #ifndef GALLIUM_STATIC_TARGETS
285 util_dl_close(sdev
->lib
);
288 #ifdef HAVE_PIPE_LOADER_KMS
293 pipe_loader_base_release(dev
);
297 pipe_loader_sw_get_driconf_xml(struct pipe_loader_device
*dev
)
302 static struct pipe_screen
*
303 pipe_loader_sw_create_screen(struct pipe_loader_device
*dev
,
304 const struct pipe_screen_config
*config
)
306 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(dev
);
307 struct pipe_screen
*screen
;
309 screen
= sdev
->dd
->create_screen(sdev
->ws
);
311 sdev
->ws
->destroy(sdev
->ws
);
316 static const struct pipe_loader_ops pipe_loader_sw_ops
= {
317 .create_screen
= pipe_loader_sw_create_screen
,
318 .get_driconf_xml
= pipe_loader_sw_get_driconf_xml
,
319 .release
= pipe_loader_sw_release