* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "util/u_memory.h"
#include "util/u_dl.h"
+#include "sw/dri/dri_sw_winsys.h"
+#include "sw/kms-dri/kms_dri_sw_winsys.h"
#include "sw/null/null_sw_winsys.h"
-#include "target-helpers/inline_sw_helper.h"
-#include "state_tracker/xlib_sw_winsys.h"
+#include "sw/wrapper/wrapper_sw_winsys.h"
+#include "target-helpers/sw_helper_public.h"
+#include "state_tracker/drisw_api.h"
+#include "state_tracker/sw_driver.h"
+#include "state_tracker/sw_winsys.h"
struct pipe_loader_sw_device {
struct pipe_loader_device base;
+ const struct sw_driver_descriptor *dd;
+#ifndef GALLIUM_STATIC_TARGETS
struct util_dl_library *lib;
+#endif
struct sw_winsys *ws;
+ int fd;
};
#define pipe_loader_sw_device(dev) ((struct pipe_loader_sw_device *)dev)
-static struct pipe_loader_ops pipe_loader_sw_ops;
+static const struct pipe_loader_ops pipe_loader_sw_ops;
-static struct sw_winsys *(*backends[])() = {
-#ifdef HAVE_WINSYS_XLIB
- x11_sw_create,
+#ifdef GALLIUM_STATIC_TARGETS
+static const struct sw_driver_descriptor driver_descriptors = {
+ .create_screen = sw_screen_create,
+ .winsys = {
+#ifdef HAVE_PIPE_LOADER_DRI
+ {
+ .name = "dri",
+ .create_winsys = dri_create_sw_winsys,
+ },
+#endif
+#ifdef HAVE_PIPE_LOADER_KMS
+ {
+ .name = "kms_dri",
+ .create_winsys = kms_dri_create_winsys,
+ },
+#endif
+/**
+ * XXX: Do not include these two for non autotools builds.
+ * They don't have neither opencl nor nine, where these are used.
+ */
+#ifndef DROP_PIPE_LOADER_MISC
+ {
+ .name = "null",
+ .create_winsys = null_sw_create,
+ },
+ {
+ .name = "wrapped",
+ .create_winsys = wrapper_sw_winsys_wrap_pipe_screen,
+ },
#endif
- null_sw_create
+ { 0 },
+ }
};
+#endif
+
+static bool
+pipe_loader_sw_probe_init_common(struct pipe_loader_sw_device *sdev)
+{
+ sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
+ sdev->base.driver_name = "swrast";
+ sdev->base.ops = &pipe_loader_sw_ops;
+ sdev->fd = -1;
+
+#ifdef GALLIUM_STATIC_TARGETS
+ sdev->dd = &driver_descriptors;
+ if (!sdev->dd)
+ return false;
+#else
+ sdev->lib = pipe_loader_find_module("swrast", PIPE_SEARCH_DIR);
+ if (!sdev->lib)
+ return false;
+
+ sdev->dd = (const struct sw_driver_descriptor *)
+ util_dl_get_proc_address(sdev->lib, "swrast_driver_descriptor");
+
+ if (!sdev->dd){
+ util_dl_close(sdev->lib);
+ sdev->lib = NULL;
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+static void
+pipe_loader_sw_probe_teardown_common(struct pipe_loader_sw_device *sdev)
+{
+#ifndef GALLIUM_STATIC_TARGETS
+ if (sdev->lib)
+ util_dl_close(sdev->lib);
+#endif
+}
+
+#ifdef HAVE_PIPE_LOADER_DRI
+bool
+pipe_loader_sw_probe_dri(struct pipe_loader_device **devs, struct drisw_loader_funcs *drisw_lf)
+{
+ struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+ int i;
+
+ if (!sdev)
+ return false;
+
+ if (!pipe_loader_sw_probe_init_common(sdev))
+ goto fail;
+
+ for (i = 0; sdev->dd->winsys[i].name; i++) {
+ if (strcmp(sdev->dd->winsys[i].name, "dri") == 0) {
+ sdev->ws = sdev->dd->winsys[i].create_winsys(drisw_lf);
+ break;
+ }
+ }
+ if (!sdev->ws)
+ goto fail;
+
+ *devs = &sdev->base;
+ return true;
+
+fail:
+ pipe_loader_sw_probe_teardown_common(sdev);
+ FREE(sdev);
+ return false;
+}
+#endif
+
+#ifdef HAVE_PIPE_LOADER_KMS
+bool
+pipe_loader_sw_probe_kms(struct pipe_loader_device **devs, int fd)
+{
+ struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+ int i;
+
+ if (!sdev)
+ return false;
+
+ if (!pipe_loader_sw_probe_init_common(sdev))
+ goto fail;
+
+ sdev->fd = fd;
+
+ for (i = 0; sdev->dd->winsys[i].name; i++) {
+ if (strcmp(sdev->dd->winsys[i].name, "kms_dri") == 0) {
+ sdev->ws = sdev->dd->winsys[i].create_winsys(fd);
+ break;
+ }
+ }
+ if (!sdev->ws)
+ goto fail;
+
+ *devs = &sdev->base;
+ return true;
+
+fail:
+ pipe_loader_sw_probe_teardown_common(sdev);
+ FREE(sdev);
+ return false;
+}
+#endif
+
+bool
+pipe_loader_sw_probe_null(struct pipe_loader_device **devs)
+{
+ struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+ int i;
+
+ if (!sdev)
+ return false;
+
+ if (!pipe_loader_sw_probe_init_common(sdev))
+ goto fail;
+
+ for (i = 0; sdev->dd->winsys[i].name; i++) {
+ if (strcmp(sdev->dd->winsys[i].name, "null") == 0) {
+ sdev->ws = sdev->dd->winsys[i].create_winsys();
+ break;
+ }
+ }
+ if (!sdev->ws)
+ goto fail;
+
+ *devs = &sdev->base;
+ return true;
+
+fail:
+ pipe_loader_sw_probe_teardown_common(sdev);
+ FREE(sdev);
+ return false;
+}
int
pipe_loader_sw_probe(struct pipe_loader_device **devs, int ndev)
{
+ int i = 1;
+
+ if (i <= ndev) {
+ if (!pipe_loader_sw_probe_null(devs)) {
+ i--;
+ }
+ }
+
+ return i;
+}
+
+boolean
+pipe_loader_sw_probe_wrapped(struct pipe_loader_device **dev,
+ struct pipe_screen *screen)
+{
+ struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
int i;
- for (i = 0; i < Elements(backends); i++) {
- if (i < ndev) {
- struct pipe_loader_sw_device *sdev = CALLOC_STRUCT(pipe_loader_sw_device);
+ if (!sdev)
+ return false;
+
+ if (!pipe_loader_sw_probe_init_common(sdev))
+ goto fail;
- sdev->base.type = PIPE_LOADER_DEVICE_SOFTWARE;
- sdev->base.driver_name = "swrast";
- sdev->base.ops = &pipe_loader_sw_ops;
- sdev->ws = backends[i]();
- devs[i] = &sdev->base;
+ for (i = 0; sdev->dd->winsys[i].name; i++) {
+ if (strcmp(sdev->dd->winsys[i].name, "wrapped") == 0) {
+ sdev->ws = sdev->dd->winsys[i].create_winsys(screen);
+ break;
}
}
+ if (!sdev->ws)
+ goto fail;
- return i;
+ *dev = &sdev->base;
+ return true;
+
+fail:
+ pipe_loader_sw_probe_teardown_common(sdev);
+ FREE(sdev);
+ return false;
}
static void
pipe_loader_sw_release(struct pipe_loader_device **dev)
{
- struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(*dev);
+ MAYBE_UNUSED struct pipe_loader_sw_device *sdev =
+ pipe_loader_sw_device(*dev);
+#ifndef GALLIUM_STATIC_TARGETS
if (sdev->lib)
util_dl_close(sdev->lib);
+#endif
- FREE(sdev);
- *dev = NULL;
+#ifdef HAVE_PIPE_LOADER_KMS
+ if (sdev->fd != -1)
+ close(sdev->fd);
+#endif
+
+ pipe_loader_base_release(dev);
+}
+
+static const struct drm_conf_ret *
+pipe_loader_sw_configuration(struct pipe_loader_device *dev,
+ enum drm_conf conf)
+{
+ return NULL;
}
static struct pipe_screen *
pipe_loader_sw_create_screen(struct pipe_loader_device *dev,
- const char *library_paths)
+ const struct pipe_screen_config *config)
{
struct pipe_loader_sw_device *sdev = pipe_loader_sw_device(dev);
- struct pipe_screen *(*init)(struct sw_winsys *);
-
- if (!sdev->lib)
- sdev->lib = pipe_loader_find_module(dev, library_paths);
- if (!sdev->lib)
- return NULL;
+ struct pipe_screen *screen;
- init = (void *)util_dl_get_proc_address(sdev->lib, "swrast_create_screen");
- if (!init)
- return NULL;
+ screen = sdev->dd->create_screen(sdev->ws);
+ if (!screen)
+ sdev->ws->destroy(sdev->ws);
- return init(sdev->ws);
+ return screen;
}
-static struct pipe_loader_ops pipe_loader_sw_ops = {
+static const struct pipe_loader_ops pipe_loader_sw_ops = {
.create_screen = pipe_loader_sw_create_screen,
+ .configuration = pipe_loader_sw_configuration,
.release = pipe_loader_sw_release
};