egl_dri2: add dri2_load_driver_swrast
Refactor dri2_load_driver and add dri2_load_driver_swrast for loading
swrast DRI driver.
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 3d5827e..a38bff5 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -334,8 +334,8 @@
return ret;
}
-EGLBoolean
-dri2_load_driver(_EGLDisplay *disp)
+static const __DRIextension **
+dri2_open_driver(_EGLDisplay *disp)
{
struct dri2_egl_display *dri2_dpy = disp->DriverData;
const __DRIextension **extensions;
@@ -374,9 +374,9 @@
if (dri2_dpy->driver == NULL) {
_eglLog(_EGL_WARNING,
- "DRI2: failed to open any driver (search paths %s)",
- search_paths);
- return EGL_FALSE;
+ "DRI2: failed to open %s (search paths %s)",
+ dri2_dpy->driver_name, search_paths);
+ return NULL;
}
_eglLog(_EGL_DEBUG, "DRI2: dlopen(%s)", path);
@@ -385,20 +385,44 @@
_eglLog(_EGL_WARNING,
"DRI2: driver exports no extensions (%s)", dlerror());
dlclose(dri2_dpy->driver);
+ }
+
+ return extensions;
+}
+
+EGLBoolean
+dri2_load_driver(_EGLDisplay *disp)
+{
+ struct dri2_egl_display *dri2_dpy = disp->DriverData;
+ const __DRIextension **extensions;
+
+ extensions = dri2_open_driver(disp);
+ if (!extensions)
+ return EGL_FALSE;
+
+ if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) {
+ dlclose(dri2_dpy->driver);
return EGL_FALSE;
}
- if (strcmp(dri2_dpy->driver_name, "swrast") == 0) {
- if (!dri2_bind_extensions(dri2_dpy, swrast_driver_extensions, extensions)) {
- dlclose(dri2_dpy->driver);
- return EGL_FALSE;
- }
- } else {
- if (!dri2_bind_extensions(dri2_dpy, dri2_driver_extensions, extensions)) {
- dlclose(dri2_dpy->driver);
- return EGL_FALSE;
- }
- }
+ return EGL_TRUE;
+}
+
+EGLBoolean
+dri2_load_driver_swrast(_EGLDisplay *disp)
+{
+ struct dri2_egl_display *dri2_dpy = disp->DriverData;
+ const __DRIextension **extensions;
+
+ dri2_dpy->driver_name = "swrast";
+ extensions = dri2_open_driver(disp);
+ if (!extensions)
+ return EGL_FALSE;
+
+ if (!dri2_bind_extensions(dri2_dpy, swrast_driver_extensions, extensions)) {
+ dlclose(dri2_dpy->driver);
+ return EGL_FALSE;
+ }
return EGL_TRUE;
}
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 97f541b..dd9eb94 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -183,6 +183,9 @@
dri2_load_driver(_EGLDisplay *disp);
EGLBoolean
+dri2_load_driver_swrast(_EGLDisplay *disp);
+
+EGLBoolean
dri2_create_screen(_EGLDisplay *disp);
struct dri2_egl_config *
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index 2e26ff0..8bff294 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -906,9 +906,7 @@
goto cleanup_dpy;
}
- dri2_dpy->driver_name = dri2_strndup("swrast", strlen("swrast"));
-
- if (!dri2_load_driver(disp))
+ if (!dri2_load_driver_swrast(disp))
goto cleanup_conn;
dri2_dpy->swrast_loader_extension.base.name = __DRI_SWRAST_LOADER;