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/os_file.h"
35 #include "util/u_memory.h"
36 #include "util/u_dl.h"
37 #include "sw/dri/dri_sw_winsys.h"
38 #include "sw/kms-dri/kms_dri_sw_winsys.h"
39 #include "sw/null/null_sw_winsys.h"
40 #include "sw/wrapper/wrapper_sw_winsys.h"
41 #include "target-helpers/sw_helper_public.h"
42 #include "frontend/drisw_api.h"
43 #include "frontend/sw_driver.h"
44 #include "frontend/sw_winsys.h"
46 struct pipe_loader_sw_device
{
47 struct pipe_loader_device base
;
48 const struct sw_driver_descriptor
*dd
;
49 #ifndef GALLIUM_STATIC_TARGETS
50 struct util_dl_library
*lib
;
56 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
58 static const struct pipe_loader_ops pipe_loader_sw_ops
;
60 #ifdef GALLIUM_STATIC_TARGETS
61 static const struct sw_driver_descriptor driver_descriptors
= {
62 .create_screen
= sw_screen_create
,
64 #ifdef HAVE_PIPE_LOADER_DRI
67 .create_winsys
= dri_create_sw_winsys
,
70 #ifdef HAVE_PIPE_LOADER_KMS
73 .create_winsys
= kms_dri_create_winsys
,
77 * XXX: Do not include these two for non autotools builds.
78 * They don't have neither opencl nor nine, where these are used.
80 #ifndef DROP_PIPE_LOADER_MISC
83 .create_winsys
= null_sw_create
,
87 .create_winsys
= wrapper_sw_winsys_wrap_pipe_screen
,
96 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device
*sdev
)
98 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
99 sdev
->base
.driver_name
= "swrast";
100 sdev
->base
.ops
= &pipe_loader_sw_ops
;
103 #ifdef GALLIUM_STATIC_TARGETS
104 sdev
->dd
= &driver_descriptors
;
108 sdev
->lib
= pipe_loader_find_module("swrast", PIPE_SEARCH_DIR
);
112 sdev
->dd
= (const struct sw_driver_descriptor
*)
113 util_dl_get_proc_address(sdev
->lib
, "swrast_driver_descriptor");
116 util_dl_close(sdev
->lib
);
126 pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device
*sdev
)
128 #ifndef GALLIUM_STATIC_TARGETS
130 util_dl_close(sdev
->lib
);
134 #ifdef HAVE_PIPE_LOADER_DRI
136 pipe_loader_sw_probe_dri(struct pipe_loader_device
**devs
, const struct drisw_loader_funcs
*drisw_lf
)
138 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
144 if (!pipe_loader_sw_probe_init_common(sdev
))
147 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
148 if (strcmp(sdev
->dd
->winsys
[i
].name
, "dri") == 0) {
149 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(drisw_lf
);
160 pipe_loader_sw_probe_teardown_common(sdev
);
166 #ifdef HAVE_PIPE_LOADER_KMS
168 pipe_loader_sw_probe_kms(struct pipe_loader_device
**devs
, int fd
)
170 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
176 if (!pipe_loader_sw_probe_init_common(sdev
))
179 if (fd
< 0 || (sdev
->fd
= os_dupfd_cloexec(fd
)) < 0)
182 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
183 if (strcmp(sdev
->dd
->winsys
[i
].name
, "kms_dri") == 0) {
184 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(sdev
->fd
);
195 pipe_loader_sw_probe_teardown_common(sdev
);
204 pipe_loader_sw_probe_null(struct pipe_loader_device
**devs
)
206 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
212 if (!pipe_loader_sw_probe_init_common(sdev
))
215 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
216 if (strcmp(sdev
->dd
->winsys
[i
].name
, "null") == 0) {
217 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys();
228 pipe_loader_sw_probe_teardown_common(sdev
);
234 pipe_loader_sw_probe(struct pipe_loader_device
**devs
, int ndev
)
239 if (!pipe_loader_sw_probe_null(devs
)) {
248 pipe_loader_sw_probe_wrapped(struct pipe_loader_device
**dev
,
249 struct pipe_screen
*screen
)
251 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
257 if (!pipe_loader_sw_probe_init_common(sdev
))
260 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
261 if (strcmp(sdev
->dd
->winsys
[i
].name
, "wrapped") == 0) {
262 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(screen
);
273 pipe_loader_sw_probe_teardown_common(sdev
);
279 pipe_loader_sw_release(struct pipe_loader_device
**dev
)
281 UNUSED
struct pipe_loader_sw_device
*sdev
=
282 pipe_loader_sw_device(*dev
);
284 #ifndef GALLIUM_STATIC_TARGETS
286 util_dl_close(sdev
->lib
);
289 #ifdef HAVE_PIPE_LOADER_KMS
294 pipe_loader_base_release(dev
);
298 pipe_loader_sw_get_driconf_xml(struct pipe_loader_device
*dev
)
303 static struct pipe_screen
*
304 pipe_loader_sw_create_screen(struct pipe_loader_device
*dev
,
305 const struct pipe_screen_config
*config
)
307 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(dev
);
308 struct pipe_screen
*screen
;
310 screen
= sdev
->dd
->create_screen(sdev
->ws
);
312 sdev
->ws
->destroy(sdev
->ws
);
317 static const struct pipe_loader_ops pipe_loader_sw_ops
= {
318 .create_screen
= pipe_loader_sw_create_screen
,
319 .get_driconf_xml
= pipe_loader_sw_get_driconf_xml
,
320 .release
= pipe_loader_sw_release