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