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/null/null_sw_winsys.h"
34 #include "sw/xlib/xlib_sw_winsys.h"
35 #include "target-helpers/inline_sw_helper.h"
36 #include "state_tracker/drisw_api.h"
38 struct pipe_loader_sw_device
{
39 struct pipe_loader_device base
;
40 struct util_dl_library
*lib
;
44 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
46 static struct pipe_loader_ops pipe_loader_sw_ops
;
48 static struct sw_winsys
*(*backends
[])() = {
52 #ifdef HAVE_WINSYS_XLIB
54 pipe_loader_sw_probe_xlib(struct pipe_loader_device
**devs
, Display
*display
)
56 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
61 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
62 sdev
->base
.driver_name
= "swrast";
63 sdev
->base
.ops
= &pipe_loader_sw_ops
;
64 sdev
->ws
= xlib_create_sw_winsys(display
);
76 pipe_loader_sw_probe_dri(struct pipe_loader_device
**devs
, struct drisw_loader_funcs
*drisw_lf
)
78 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
83 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
84 sdev
->base
.driver_name
= "swrast";
85 sdev
->base
.ops
= &pipe_loader_sw_ops
;
86 sdev
->ws
= dri_create_sw_winsys(drisw_lf
);
97 pipe_loader_sw_probe_null(struct pipe_loader_device
**devs
)
99 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
104 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
105 sdev
->base
.driver_name
= "swrast";
106 sdev
->base
.ops
= &pipe_loader_sw_ops
;
107 sdev
->ws
= null_sw_create();
118 pipe_loader_sw_probe(struct pipe_loader_device
**devs
, int ndev
)
122 for (i
= 0; i
< Elements(backends
); i
++) {
124 struct pipe_loader_sw_device
*sdev
= CALLOC_STRUCT(pipe_loader_sw_device
);
125 /* TODO: handle CALLOC_STRUCT failure */
127 sdev
->base
.type
= PIPE_LOADER_DEVICE_SOFTWARE
;
128 sdev
->base
.driver_name
= "swrast";
129 sdev
->base
.ops
= &pipe_loader_sw_ops
;
130 sdev
->ws
= backends
[i
]();
131 devs
[i
] = &sdev
->base
;
139 pipe_loader_sw_release(struct pipe_loader_device
**dev
)
141 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(*dev
);
143 if (sdev
->ws
&& sdev
->ws
->destroy
)
144 sdev
->ws
->destroy(sdev
->ws
);
147 util_dl_close(sdev
->lib
);
153 static struct pipe_screen
*
154 pipe_loader_sw_create_screen(struct pipe_loader_device
*dev
,
155 const char *library_paths
)
157 struct pipe_loader_sw_device
*sdev
= pipe_loader_sw_device(dev
);
158 struct pipe_screen
*(*init
)(struct sw_winsys
*);
161 sdev
->lib
= pipe_loader_find_module(dev
, library_paths
);
165 init
= (void *)util_dl_get_proc_address(sdev
->lib
, "swrast_create_screen");
167 util_dl_close(sdev
->lib
);
172 return init(sdev
->ws
);
175 static struct pipe_loader_ops pipe_loader_sw_ops
= {
176 .create_screen
= pipe_loader_sw_create_screen
,
177 .release
= pipe_loader_sw_release