gallium: remove library_path argument from pipe_loader_create_screen()
[mesa.git] / src / gallium / auxiliary / pipe-loader / pipe_loader_sw.c
1 /**************************************************************************
2 *
3 * Copyright 2012 Francisco Jerez
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "pipe_loader_priv.h"
29
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/inline_sw_helper.h"
37 #include "state_tracker/drisw_api.h"
38
39 struct pipe_loader_sw_device {
40 struct pipe_loader_device base;
41 struct util_dl_library *lib;
42 struct sw_winsys *ws;
43 };
44
45 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
46
47 static struct pipe_loader_ops pipe_loader_sw_ops;
48
49 static struct sw_winsys *(*backends[])() = {
50 null_sw_create
51 };
52
53 #ifdef HAVE_PIPE_LOADER_DRI
54 bool
55 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
56 {
57 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
58
59 if (!sdev)
60 return false;
61
62 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
63 sdev->base.driver_name = "swrast";
64 sdev->base.ops = &pipe_loader_sw_ops;
65 sdev->ws = dri_create_sw_winsys(drisw_lf);
66 if (!sdev->ws) {
67 FREE(sdev);
68 return false;
69 }
70 *devs = &sdev->base;
71
72 return true;
73 }
74 #endif
75
76 #ifdef HAVE_PIPE_LOADER_KMS
77 bool
78 pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
79 {
80 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
81
82 if (!sdev)
83 return false;
84
85 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
86 sdev->base.driver_name = "swrast";
87 sdev->base.ops = &pipe_loader_sw_ops;
88 sdev->ws = kms_dri_create_winsys(fd);
89 if (!sdev->ws) {
90 FREE(sdev);
91 return false;
92 }
93 *devs = &sdev->base;
94
95 return true;
96 }
97 #endif
98
99 bool
100 pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
101 {
102 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
103
104 if (!sdev)
105 return false;
106
107 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
108 sdev->base.driver_name = "swrast";
109 sdev->base.ops = &pipe_loader_sw_ops;
110 sdev->ws = null_sw_create();
111 if (!sdev->ws) {
112 FREE(sdev);
113 return false;
114 }
115 *devs = &sdev->base;
116
117 return true;
118 }
119
120 int
121 pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
122 {
123 int i;
124
125 for (i = 0; i < Elements(backends); i++) {
126 if (i < ndev) {
127 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
128 /* TODO: handle CALLOC_STRUCT failure */
129
130 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
131 sdev->base.driver_name = "swrast";
132 sdev->base.ops = &pipe_loader_sw_ops;
133 sdev->ws = backends[i]();
134 devs[i] = &sdev->base;
135 }
136 }
137
138 return i;
139 }
140
141 boolean
142 pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
143 struct pipe_screen *screen)
144 {
145 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
146
147 if (!sdev)
148 return false;
149
150 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
151 sdev->base.driver_name = "swrast";
152 sdev->base.ops = &pipe_loader_sw_ops;
153 sdev->ws = wrapper_sw_winsys_wrap_pipe_screen(screen);
154
155 if (!sdev->ws) {
156 FREE(sdev);
157 return false;
158 }
159 *dev = &sdev->base;
160 return true;
161 }
162
163 static void
164 pipe_loader_sw_release(struct pipe_loader_device **dev)
165 {
166 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
167
168 if (sdev->lib)
169 util_dl_close(sdev->lib);
170
171 FREE(sdev);
172 *dev = NULL;
173 }
174
175 static const struct drm_conf_ret *
176 pipe_loader_sw_configuration(struct pipe_loader_device *dev,
177 enum drm_conf conf)
178 {
179 return NULL;
180 }
181
182 static struct pipe_screen *
183 pipe_loader_sw_create_screen(struct pipe_loader_device *dev)
184 {
185 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
186 struct pipe_screen *(*init)(struct sw_winsys *);
187
188 if (!sdev->lib)
189 sdev->lib = pipe_loader_find_module(&sdev->base, PIPE_SEARCH_DIR);
190 if (!sdev->lib)
191 return NULL;
192
193 init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
194 if (!init){
195 util_dl_close(sdev->lib);
196 sdev->lib = NULL;
197 return NULL;
198 }
199
200 return init(sdev->ws);
201 }
202
203 static struct pipe_loader_ops pipe_loader_sw_ops = {
204 .create_screen = pipe_loader_sw_create_screen,
205 .configuration = pipe_loader_sw_configuration,
206 .release = pipe_loader_sw_release
207 };