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
;
51 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
53 static const struct pipe_loader_ops pipe_loader_sw_ops
;
55 #ifdef GALLIUM_STATIC_TARGETS
56 static const struct sw_driver_descriptor driver_descriptors
= {
57 .create_screen
= sw_screen_create
,
59 #ifdef HAVE_PIPE_LOADER_DRI
62 .create_winsys
= dri_create_sw_winsys
,
65 #ifdef HAVE_PIPE_LOADER_KMS
68 .create_winsys
= kms_dri_create_winsys
,
72 * XXX: Do not include these two for non autotools builds.
73 * They don't have neither opencl nor nine, where these are used.
75 #ifndef DROP_PIPE_LOADER_MISC
78 .create_winsys
= null_sw_create
,
82 .create_winsys
= wrapper_sw_winsys_wrap_pipe_screen
,
91 pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device
*sdev
)
93 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
94 sdev
->base
.driver_name
= "swrast";
95 sdev
->base
.ops
= &pipe_loader_sw_ops
;
98 #ifdef GALLIUM_STATIC_TARGETS
99 sdev
->dd
= &driver_descriptors
;
103 sdev
->lib
= pipe_loader_find_module(&sdev
->base
, PIPE_SEARCH_DIR
);
107 sdev
->dd
= (const struct sw_driver_descriptor
*)
108 util_dl_get_proc_address(sdev
->lib
, "swrast_driver_descriptor");
111 util_dl_close(sdev
->lib
);
121 pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device
*sdev
)
123 #ifndef GALLIUM_STATIC_TARGETS
125 util_dl_close(sdev
->lib
);
129 #ifdef HAVE_PIPE_LOADER_DRI
131 pipe_loader_sw_probe_dri(struct pipe_loader_device
**devs
, struct drisw_loader_funcs
*drisw_lf
)
133 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
139 if (!pipe_loader_sw_probe_init_common(sdev
))
142 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
143 if (strcmp(sdev
->dd
->winsys
[i
].name
, "dri") == 0) {
144 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(drisw_lf
);
155 pipe_loader_sw_probe_teardown_common(sdev
);
161 #ifdef HAVE_PIPE_LOADER_KMS
163 pipe_loader_sw_probe_kms(struct pipe_loader_device
**devs
, int fd
)
165 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
171 if (!pipe_loader_sw_probe_init_common(sdev
))
176 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
177 if (strcmp(sdev
->dd
->winsys
[i
].name
, "kms_dri") == 0) {
178 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(fd
);
189 pipe_loader_sw_probe_teardown_common(sdev
);
196 pipe_loader_sw_probe_null(struct pipe_loader_device
**devs
)
198 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
204 if (!pipe_loader_sw_probe_init_common(sdev
))
207 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
208 if (strcmp(sdev
->dd
->winsys
[i
].name
, "null") == 0) {
209 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys();
220 pipe_loader_sw_probe_teardown_common(sdev
);
226 pipe_loader_sw_probe(struct pipe_loader_device
**devs
, int ndev
)
231 if (!pipe_loader_sw_probe_null(devs
)) {
240 pipe_loader_sw_probe_wrapped(struct pipe_loader_device
**dev
,
241 struct pipe_screen
*screen
)
243 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
249 if (!pipe_loader_sw_probe_init_common(sdev
))
252 for (i
= 0; sdev
->dd
->winsys
[i
].name
; i
++) {
253 if (strcmp(sdev
->dd
->winsys
[i
].name
, "wrapped") == 0) {
254 sdev
->ws
= sdev
->dd
->winsys
[i
].create_winsys(screen
);
265 pipe_loader_sw_probe_teardown_common(sdev
);
271 pipe_loader_sw_release(struct pipe_loader_device
**dev
)
273 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(*dev
);
275 #ifndef GALLIUM_STATIC_TARGETS
277 util_dl_close(sdev
->lib
);
280 #ifdef HAVE_PIPE_LOADER_KMS
289 static const struct drm_conf_ret
*
290 pipe_loader_sw_configuration(struct pipe_loader_device
*dev
,
296 static struct pipe_screen
*
297 pipe_loader_sw_create_screen(struct pipe_loader_device
*dev
,
300 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(dev
);
301 struct pipe_screen
*screen
;
303 screen
= sdev
->dd
->create_screen(sdev
->ws
);
305 sdev
->ws
->destroy(sdev
->ws
);
310 static const struct pipe_loader_ops pipe_loader_sw_ops
= {
311 .create_screen
= pipe_loader_sw_create_screen
,
312 .configuration
= pipe_loader_sw_configuration
,
313 .release
= pipe_loader_sw_release