summaryrefslogtreecommitdiffstats
path: root/src/egl/drivers/dri2
diff options
context:
space:
mode:
authorGurchetan Singh <[email protected]>2017-10-02 13:43:57 -0700
committerEric Engestrom <[email protected]>2017-10-03 17:56:15 +0100
commit540c804297d813aa7df28d570e0407e332873c88 (patch)
tree3a3cc82a12ce377c78bd872bd57b9dc17925b2f6 /src/egl/drivers/dri2
parenta8e4a0f609c602010169ad88567496d96bee9690 (diff)
egl/surfaceless: add probe device helper function
This will help us initialize a software driver, if it's needed or requested. Reviewed-by: Emil Velikov <[email protected]> Reviewed-by: Eric Engestrom <[email protected]>
Diffstat (limited to 'src/egl/drivers/dri2')
-rw-r--r--src/egl/drivers/dri2/platform_surfaceless.c67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/egl/drivers/dri2/platform_surfaceless.c b/src/egl/drivers/dri2/platform_surfaceless.c
index 3c00ff44abf..f6aa217d39c 100644
--- a/src/egl/drivers/dri2/platform_surfaceless.c
+++ b/src/egl/drivers/dri2/platform_surfaceless.c
@@ -267,6 +267,44 @@ static const __DRIextension *image_loader_extensions[] = {
NULL,
};
+static bool
+surfaceless_probe_device(_EGLDisplay *dpy)
+{
+ struct dri2_egl_display *dri2_dpy = dpy->DriverData;
+ const int limit = 64;
+ const int base = 128;
+ int fd;
+ int i;
+
+ for (i = 0; i < limit; ++i) {
+ char *card_path;
+ if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)
+ continue;
+
+ fd = loader_open_device(card_path);
+ free(card_path);
+ if (fd < 0)
+ continue;
+
+ dri2_dpy->driver_name = loader_get_driver_for_fd(fd);
+ if (!dri2_dpy->driver_name) {
+ close(fd);
+ continue;
+ }
+
+ dri2_dpy->fd = fd;
+ if (dri2_load_driver_dri3(dpy))
+ return true;
+
+ close(fd);
+ dri2_dpy->fd = -1;
+ free(dri2_dpy->driver_name);
+ dri2_dpy->driver_name = NULL;
+ }
+
+ return false;
+}
+
EGLBoolean
dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
{
@@ -282,34 +320,7 @@ dri2_initialize_surfaceless(_EGLDriver *drv, _EGLDisplay *disp)
dri2_dpy->fd = -1;
disp->DriverData = (void *) dri2_dpy;
-
- const int limit = 64;
- const int base = 128;
- for (int i = 0; i < limit; ++i) {
- char *card_path;
- if (asprintf(&card_path, DRM_RENDER_DEV_NAME, DRM_DIR_NAME, base + i) < 0)
- continue;
-
- dri2_dpy->fd = loader_open_device(card_path);
-
- free(card_path);
- if (dri2_dpy->fd < 0)
- continue;
-
- dri2_dpy->driver_name = loader_get_driver_for_fd(dri2_dpy->fd);
- if (dri2_dpy->driver_name) {
- if (dri2_load_driver_dri3(disp)) {
- driver_loaded = 1;
- break;
- }
- free(dri2_dpy->driver_name);
- dri2_dpy->driver_name = NULL;
- }
- close(dri2_dpy->fd);
- dri2_dpy->fd = -1;
- }
-
- if (!driver_loaded) {
+ if (!surfaceless_probe_device(disp)) {
err = "DRI2: failed to load driver";
goto cleanup;
}