vk/0.170.2: Update to the new VK_EXT_KHR_swapchain extensions
[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/null/null_sw_winsys.h"
34 #include "sw/wrapper/wrapper_sw_winsys.h"
35 #include "target-helpers/inline_sw_helper.h"
36 #include "state_tracker/drisw_api.h"
37
38 struct pipe_loader_sw_device {
39 struct pipe_loader_device base;
40 struct util_dl_library *lib;
41 struct sw_winsys *ws;
42 };
43
44 #define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
45
46 static struct pipe_loader_ops pipe_loader_sw_ops;
47
48 static struct sw_winsys *(*backends[])() = {
49 null_sw_create
50 };
51
52 #ifdef HAVE_PIPE_LOADER_DRI
53 bool
54 pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
55 {
56 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
57
58 if (!sdev)
59 return false;
60
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 = dri_create_sw_winsys(drisw_lf);
65 if (!sdev->ws) {
66 FREE(sdev);
67 return false;
68 }
69 *devs = &sdev->base;
70
71 return true;
72 }
73 #endif
74
75 bool
76 pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
77 {
78 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
79
80 if (!sdev)
81 return false;
82
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 = null_sw_create();
87 if (!sdev->ws) {
88 FREE(sdev);
89 return false;
90 }
91 *devs = &sdev->base;
92
93 return true;
94 }
95
96 int
97 pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
98 {
99 int i;
100
101 for (i = 0; i < Elements(backends); i++) {
102 if (i < ndev) {
103 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
104 /* TODO: handle CALLOC_STRUCT failure */
105
106 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
107 sdev->base.driver_name = "swrast";
108 sdev->base.ops = &pipe_loader_sw_ops;
109 sdev->ws = backends[i]();
110 devs[i] = &sdev->base;
111 }
112 }
113
114 return i;
115 }
116
117 boolean
118 pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
119 struct pipe_screen *screen)
120 {
121 struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
122
123 if (!sdev)
124 return false;
125
126 sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
127 sdev->base.driver_name = "swrast";
128 sdev->base.ops = &pipe_loader_sw_ops;
129 sdev->ws = wrapper_sw_winsys_wrap_pipe_screen(screen);
130
131 if (!sdev->ws) {
132 FREE(sdev);
133 return false;
134 }
135 *dev = &sdev->base;
136 return true;
137 }
138
139 static void
140 pipe_loader_sw_release(struct pipe_loader_device **dev)
141 {
142 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
143
144 if (sdev->lib)
145 util_dl_close(sdev->lib);
146
147 FREE(sdev);
148 *dev = NULL;
149 }
150
151 static const struct drm_conf_ret *
152 pipe_loader_sw_configuration(struct pipe_loader_device *dev,
153 enum drm_conf conf)
154 {
155 return NULL;
156 }
157
158 static struct pipe_screen *
159 pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
160 const char *library_paths)
161 {
162 struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
163 struct pipe_screen *(*init)(struct sw_winsys *);
164
165 if (!sdev->lib)
166 sdev->lib = pipe_loader_find_module(dev, library_paths);
167 if (!sdev->lib)
168 return NULL;
169
170 init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
171 if (!init){
172 util_dl_close(sdev->lib);
173 sdev->lib = NULL;
174 return NULL;
175 }
176
177 return init(sdev->ws);
178 }
179
180 static struct pipe_loader_ops pipe_loader_sw_ops = {
181 .create_screen = pipe_loader_sw_create_screen,
182 .configuration = pipe_loader_sw_configuration,
183 .release = pipe_loader_sw_release
184 };