st/dri: factor out common init_screen code
authorGeorge Sapountzis <gsapountzis@gmail.com>
Fri, 26 Mar 2010 16:44:39 +0000 (18:44 +0200)
committerGeorge Sapountzis <gsapountzis@gmail.com>
Fri, 26 Mar 2010 16:44:39 +0000 (18:44 +0200)
src/gallium/state_trackers/dri/common/dri_screen.c
src/gallium/state_trackers/dri/common/dri_screen.h
src/gallium/state_trackers/dri/drm/dri1.c
src/gallium/state_trackers/dri/drm/dri2.c
src/gallium/state_trackers/dri/sw/drisw.c

index 53053a74c4c7b615f8cfc9127c6085a8cf5b8c90..cbd7563938e4de8c50e512930c402822b65138e0 100644 (file)
@@ -50,7 +50,6 @@
 #include "util/u_inlines.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_format.h"
-#include "state_tracker/drm_api.h"
 
 #include "util/u_debug.h"
 
@@ -63,9 +62,9 @@ PUBLIC const char __driConfigOptions[] =
    DRI_CONF_ALLOW_LARGE_TEXTURES(1)
    DRI_CONF_SECTION_END DRI_CONF_END;
 
-const uint __driNConfigOptions = 3;
+static const uint __driNConfigOptions = 3;
 
-const __DRIconfig **
+static const __DRIconfig **
 dri_fill_in_modes(struct dri_screen *screen,
                  unsigned pixel_bits)
 {
@@ -299,10 +298,8 @@ dri_destroy_option_cache(struct dri_screen * screen)
 }
 
 void
-dri_destroy_screen(__DRIscreen * sPriv)
+dri_destroy_screen_helper(struct dri_screen * screen)
 {
-   struct dri_screen *screen = dri_screen(sPriv);
-
    dri1_destroy_pipe_context(screen);
 
    if (screen->smapi)
@@ -312,12 +309,41 @@ dri_destroy_screen(__DRIscreen * sPriv)
       screen->pipe_screen->destroy(screen->pipe_screen);
 
    dri_destroy_option_cache(screen);
+}
+
+static void
+dri_destroy_screen(__DRIscreen * sPriv)
+{
+   struct dri_screen *screen = dri_screen(sPriv);
+
+   dri_destroy_screen_helper(screen);
 
    FREE(screen);
    sPriv->private = NULL;
    sPriv->extensions = NULL;
 }
 
+const __DRIconfig **
+dri_init_screen_helper(struct dri_screen *screen,
+                       struct drm_create_screen_arg *arg,
+                       unsigned pixel_bits)
+{
+   screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, arg);
+   if (!screen->pipe_screen) {
+      debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
+      return NULL;
+   }
+
+   screen->smapi = dri_create_st_manager(screen);
+   if (!screen->smapi)
+      return NULL;
+
+   driParseOptionInfo(&screen->optionCache,
+                      __driConfigOptions, __driNConfigOptions);
+
+   return dri_fill_in_modes(screen, pixel_bits);
+}
+
 #ifndef __NOT_HAVE_DRM_H
 
 const struct __DriverAPIRec driDriverAPI = {
index 4f59db37cfa35655d59ddc7ef748e7b55f4d1a37..e77bce17ae9b5ef7791a51b027920df4b8321ca1 100644 (file)
@@ -39,6 +39,7 @@
 #include "pipe/p_context.h"
 #include "pipe/p_state.h"
 #include "state_tracker/st_api.h"
+#include "state_tracker/drm_api.h"
 
 struct dri_screen
 {
@@ -97,17 +98,17 @@ dri_with_format(__DRIscreen * sPriv)
 
 #endif
 
-extern const uint __driNConfigOptions;
-
-const __DRIconfig **
-dri_fill_in_modes(struct dri_screen *screen, unsigned pixel_bits);
-
 void
 dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen,
                    const __GLcontextModes *mode);
 
+const __DRIconfig **
+dri_init_screen_helper(struct dri_screen *screen,
+                       struct drm_create_screen_arg *arg,
+                       unsigned pixel_bits);
+
 void
-dri_destroy_screen(__DRIscreen * sPriv);
+dri_destroy_screen_helper(struct dri_screen * screen);
 
 #endif
 
index 98bdb2936a1656caac1058694a72037360c70d92..aad098bb301587a45f74c48c3f8e376270a6f266 100644 (file)
@@ -469,8 +469,8 @@ dri1_copy_version(struct dri1_api_version *dst,
 const __DRIconfig **
 dri1_init_screen(__DRIscreen * sPriv)
 {
-   struct dri_screen *screen;
    const __DRIconfig **configs;
+   struct dri_screen *screen;
    struct dri1_create_screen_arg arg;
 
    screen = CALLOC_STRUCT(dri_screen);
@@ -495,32 +495,26 @@ dri1_init_screen(__DRIscreen * sPriv)
    dri1_copy_version(&arg.drm_version, &sPriv->drm_version);
    arg.api = NULL;
 
-   screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg.base);
-
-   if (!screen->pipe_screen || !arg.api) {
-      debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__);
-      goto out_no_screen;
-   }
-
-   __dri1_api_hooks = arg.api;
-
-   driParseOptionInfo(&screen->optionCache,
-                     __driConfigOptions, __driNConfigOptions);
-
    /**
     * FIXME: If the driver supports format conversion swapbuffer blits, we might
     * want to support other color bit depths than the server is currently
     * using.
     */
 
-   configs = dri_fill_in_modes(screen, sPriv->fbBPP);
+   configs = dri_init_screen_helper(screen, &arg.base, sPriv->fbBPP);
    if (!configs)
-      goto out_no_configs;
+      goto fail;
+
+   if (!arg.api) {
+      debug_printf("%s: failed to create dri1 screen\n", __FUNCTION__);
+      goto fail;
+   }
+
+   __dri1_api_hooks = arg.api;
 
    return configs;
- out_no_configs:
-   screen->pipe_screen->destroy(screen->pipe_screen);
- out_no_screen:
+fail:
+   dri_destroy_screen_helper(screen);
    FREE(screen);
    return NULL;
 }
index 854801d1ea157828d1eb996f19798cd9cd7500ea..c632f0fe4f365ca2c71c3b561a1d203747c441c5 100644 (file)
@@ -375,6 +375,7 @@ static const __DRIextension *dri_screen_extensions[] = {
 const __DRIconfig **
 dri2_init_screen(__DRIscreen * sPriv)
 {
+   const __DRIconfig **configs;
    struct dri_screen *screen;
    struct drm_create_screen_arg arg;
 
@@ -385,28 +386,22 @@ dri2_init_screen(__DRIscreen * sPriv)
    screen->api = drm_api_create();
    screen->sPriv = sPriv;
    screen->fd = sPriv->fd;
+
    sPriv->private = (void *)screen;
    sPriv->extensions = dri_screen_extensions;
-   arg.mode = DRM_CREATE_NORMAL;
 
-   screen->pipe_screen = screen->api->create_screen(screen->api, screen->fd, &arg);
-   if (!screen->pipe_screen) {
-      debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
-      goto fail;
-   }
+   arg.mode = DRM_CREATE_NORMAL;
 
-   screen->smapi = dri_create_st_manager(screen);
-   if (!screen->smapi)
+   configs = dri_init_screen_helper(screen, &arg, 32);
+   if (!configs)
       goto fail;
 
-   driParseOptionInfo(&screen->optionCache,
-                     __driConfigOptions, __driNConfigOptions);
-
    screen->auto_fake_front = dri_with_format(sPriv);
 
-   return dri_fill_in_modes(screen, 32);
+   return configs;
 fail:
-   dri_destroy_screen(sPriv);
+   dri_destroy_screen_helper(screen);
+   FREE(screen);
    return NULL;
 }
 
index d7c6577818f3ce8f348b95f2a98d1923c3a7d7fb..8999ae530f2fcb631aa6a68891ce4f0df7a01e18 100644 (file)
@@ -282,6 +282,7 @@ static const __DRIextension *drisw_screen_extensions[] = {
 const __DRIconfig **
 drisw_init_screen(__DRIscreen * sPriv)
 {
+   const __DRIconfig **configs;
    struct dri_screen *screen;
    struct drm_create_screen_arg arg;
 
@@ -292,26 +293,20 @@ drisw_init_screen(__DRIscreen * sPriv)
    screen->api = drm_api_create();
    screen->sPriv = sPriv;
    screen->fd = -1;
+
    sPriv->private = (void *)screen;
    sPriv->extensions = drisw_screen_extensions;
-   arg.mode = DRM_CREATE_DRISW;
 
-   screen->pipe_screen = screen->api->create_screen(screen->api, -1, &arg);
-   if (!screen->pipe_screen) {
-      debug_printf("%s: failed to create pipe_screen\n", __FUNCTION__);
-      goto fail;
-   }
+   arg.mode = DRM_CREATE_DRISW;
 
-   screen->smapi = dri_create_st_manager(screen);
-   if (!screen->smapi)
+   configs = dri_init_screen_helper(screen, &arg, 32);
+   if (!configs)
       goto fail;
 
-   driParseOptionInfo(&screen->optionCache,
-                      __driConfigOptions, __driNConfigOptions);
-
-   return dri_fill_in_modes(screen, 32);
+   return configs;
 fail:
-   dri_destroy_screen(sPriv);
+   dri_destroy_screen_helper(screen);
+   FREE(screen);
    return NULL;
 }