egl_dri2: add dri2_load_driver_swrast
authorChia-I Wu <olv@lunarg.com>
Wed, 8 Jun 2011 08:33:55 +0000 (16:33 +0800)
committerChia-I Wu <olv@lunarg.com>
Mon, 13 Jun 2011 03:11:43 +0000 (11:11 +0800)
Refactor dri2_load_driver and add dri2_load_driver_swrast for loading
swrast DRI driver.

src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/drivers/dri2/platform_x11.c

index 3d5827e15a100fb057a5bf701cc6d0496215be06..a38bff5711d665d99009b1b431e2e33fa0433dd5 100644 (file)
@@ -334,8 +334,8 @@ dri2_bind_extensions(struct dri2_egl_display *dri2_dpy,
    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 @@ dri2_load_driver(_EGLDisplay *disp)
 
    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 @@ dri2_load_driver(_EGLDisplay *disp)
       _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;
 }
index 97f541b5e8326d532b78d866fa010a3134ad69fb..dd9eb94cf7a93eff6c50ad5c3b1857d6f89acf70 100644 (file)
@@ -182,6 +182,9 @@ extern const __DRIuseInvalidateExtension use_invalidate;
 EGLBoolean
 dri2_load_driver(_EGLDisplay *disp);
 
+EGLBoolean
+dri2_load_driver_swrast(_EGLDisplay *disp);
+
 EGLBoolean
 dri2_create_screen(_EGLDisplay *disp);
 
index 2e26ff00b67e655016ce5fb2ce54bf49c96bb950..8bff294c9e67ab05f4c8f099ecee0c279e1b6a79 100644 (file)
@@ -906,9 +906,7 @@ dri2_initialize_x11_swrast(_EGLDriver *drv, _EGLDisplay *disp)
       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;