st/egl: reorganize backend initialization
authorChia-I Wu <olv@lunarg.com>
Sat, 25 Jun 2011 05:52:57 +0000 (14:52 +0900)
committerChia-I Wu <olv@lunarg.com>
Sat, 25 Jun 2011 07:23:20 +0000 (16:23 +0900)
Remove set_event_handler() and pass the event handler with
native_get_XXX_platform().  Add init_screen() so that the pipe screen is
created later.  This way we don't need to pass user_data to
create_display().

14 files changed:
src/gallium/state_trackers/egl/common/egl_g3d.c
src/gallium/state_trackers/egl/common/native.h
src/gallium/state_trackers/egl/drm/native_drm.c
src/gallium/state_trackers/egl/drm/native_drm.h
src/gallium/state_trackers/egl/fbdev/native_fbdev.c
src/gallium/state_trackers/egl/gdi/native_gdi.c
src/gallium/state_trackers/egl/wayland/native_drm.c
src/gallium/state_trackers/egl/wayland/native_shm.c
src/gallium/state_trackers/egl/wayland/native_wayland.c
src/gallium/state_trackers/egl/wayland/native_wayland.h
src/gallium/state_trackers/egl/x11/native_dri2.c
src/gallium/state_trackers/egl/x11/native_x11.c
src/gallium/state_trackers/egl/x11/native_x11.h
src/gallium/state_trackers/egl/x11/native_ximage.c

index 6a40f4d2a4bd248440d6ce2e46d4bb2d5e5c3ce6..7d1eafe3bec71ef21e7870855051f5bc49a3c3ec 100644 (file)
@@ -87,7 +87,7 @@ egl_g3d_lookup_egl_image(struct native_display *ndpy, void *egl_image)
    return resource;
 }
 
-static struct native_event_handler egl_g3d_native_event_handler = {
+static const struct native_event_handler egl_g3d_native_event_handler = {
    egl_g3d_invalid_surface,
    egl_g3d_new_drm_screen,
    egl_g3d_new_sw_screen,
@@ -110,40 +110,38 @@ egl_g3d_get_platform(_EGLDriver *drv, _EGLPlatformType plat)
       case _EGL_PLATFORM_WINDOWS:
          plat_name = "Windows";
 #ifdef HAVE_GDI_BACKEND
-         nplat = native_get_gdi_platform();
+         nplat = native_get_gdi_platform(&egl_g3d_native_event_handler);
 #endif
          break;
       case _EGL_PLATFORM_X11:
          plat_name = "X11";
 #ifdef HAVE_X11_BACKEND
-         nplat = native_get_x11_platform();
+         nplat = native_get_x11_platform(&egl_g3d_native_event_handler);
 #endif
         break;
       case _EGL_PLATFORM_WAYLAND:
          plat_name = "wayland";
 #ifdef HAVE_WAYLAND_BACKEND
-         nplat = native_get_wayland_platform();
+         nplat = native_get_wayland_platform(&egl_g3d_native_event_handler);
 #endif
          break;
       case _EGL_PLATFORM_DRM:
          plat_name = "DRM";
 #ifdef HAVE_DRM_BACKEND
-         nplat = native_get_drm_platform();
+         nplat = native_get_drm_platform(&egl_g3d_native_event_handler);
 #endif
          break;
       case _EGL_PLATFORM_FBDEV:
          plat_name = "FBDEV";
 #ifdef HAVE_FBDEV_BACKEND
-         nplat = native_get_fbdev_platform();
+         nplat = native_get_fbdev_platform(&egl_g3d_native_event_handler);
 #endif
          break;
       default:
          break;
       }
 
-      if (nplat)
-         nplat->set_event_handler(&egl_g3d_native_event_handler);
-      else
+      if (!nplat)
          _eglLog(_EGL_WARNING, "unsupported platform %s", plat_name);
 
       gdrv->platforms[plat] = nplat;
@@ -520,13 +518,20 @@ egl_g3d_initialize(_EGLDriver *drv, _EGLDisplay *dpy)
    gdpy->loader = gdrv->loader;
    dpy->DriverData = gdpy;
 
-   _eglLog(_EGL_INFO, "use %s for display %p", nplat->name, dpy->PlatformDisplay);
-   gdpy->native = nplat->create_display(dpy->PlatformDisplay,
-         dpy->Options.UseFallback, (void *) dpy);
+   _eglLog(_EGL_INFO, "use %s for display %p",
+         nplat->name, dpy->PlatformDisplay);
+   gdpy->native =
+      nplat->create_display(dpy->PlatformDisplay, dpy->Options.UseFallback);
    if (!gdpy->native) {
       _eglError(EGL_NOT_INITIALIZED, "eglInitialize(no usable display)");
       goto fail;
    }
+   gdpy->native->user_data = (void *) dpy;
+   if (!gdpy->native->init_screen(gdpy->native)) {
+      _eglError(EGL_NOT_INITIALIZED,
+            "eglInitialize(failed to initialize screen)");
+      goto fail;
+   }
 
    if (gdpy->loader->profile_masks[ST_API_OPENGL] & ST_PROFILE_DEFAULT_MASK)
       dpy->ClientAPIs |= EGL_OPENGL_BIT;
index cb261964864d381d7f880c32a1acda735f6d5c40..c0b8385cc6bfa11703053e507ea806a19a675b9c 100644 (file)
@@ -152,6 +152,11 @@ struct native_display {
     */
    void *user_data;
 
+   /**
+    * Initialize and create the pipe screen.
+    */
+   boolean (*init_screen)(struct native_display *ndpy);
+
    void (*destroy)(struct native_display *ndpy);
 
    /**
@@ -259,26 +264,29 @@ ndpy_uninit(struct native_display *ndpy)
 struct native_platform {
    const char *name;
 
-   void (*set_event_handler)(struct native_event_handler *handler);
-   struct native_display *(*create_display)(void *dpy,
-                                            boolean use_sw,
-                                            void *user_data);
+   /**
+    * Create the native display and usually establish a connection to the
+    * display server.
+    *
+    * No event should be generated at this stage.
+    */
+   struct native_display *(*create_display)(void *dpy, boolean use_sw);
 };
 
 const struct native_platform *
-native_get_gdi_platform(void);
+native_get_gdi_platform(const struct native_event_handler *event_handler);
 
 const struct native_platform *
-native_get_x11_platform(void);
+native_get_x11_platform(const struct native_event_handler *event_handler);
 
 const struct native_platform *
-native_get_wayland_platform(void);
+native_get_wayland_platform(const struct native_event_handler *event_handler);
 
 const struct native_platform *
-native_get_drm_platform(void);
+native_get_drm_platform(const struct native_event_handler *event_handler);
 
 const struct native_platform *
-native_get_fbdev_platform(void);
+native_get_fbdev_platform(const struct native_event_handler *event_handler);
 
 #ifdef __cplusplus
 }
index 57765cc281ff96ed0e52aca85cde076683bcdc51..de4eb852eb7913e4a93283d69988b633208a7951 100644 (file)
@@ -249,9 +249,15 @@ drm_create_pixmap_surface(struct native_display *ndpy,
    return drm_display_create_surface_from_resource(ndpy, bo->resource);
 }
 
+static boolean
+drm_display_init_screen(struct native_display *ndpy)
+{
+   return TRUE;
+}
+
 static struct native_display *
 drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
-                   struct native_event_handler *event_handler, void *user_data)
+                   const struct native_event_handler *event_handler)
 {
    struct drm_display *drmdpy;
 
@@ -267,10 +273,10 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
    gbmdrm->lookup_egl_image_data = &drmdpy->base;
 
    drmdpy->event_handler = event_handler;
-   drmdpy->base.user_data = user_data;
 
    drmdpy->base.screen = gbmdrm->screen;
 
+   drmdpy->base.init_screen = drm_display_init_screen;
    drmdpy->base.destroy = drm_display_destroy;
    drmdpy->base.get_param = drm_display_get_param;
    drmdpy->base.get_configs = drm_display_get_configs;
@@ -287,16 +293,10 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm,
    return &drmdpy->base;
 }
 
-static struct native_event_handler *drm_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
-   drm_event_handler = event_handler;
-}
+static const struct native_event_handler *drm_event_handler;
 
 static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
 {
    struct gbm_gallium_drm_device *gbm;
    int fd;
@@ -315,17 +315,17 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
        gbm->base.type != GBM_DRM_DRIVER_TYPE_GALLIUM)
       return NULL;
 
-   return drm_create_display(gbm, drm_event_handler, user_data);
+   return drm_create_display(gbm, drm_event_handler);
 }
 
 static const struct native_platform drm_platform = {
    "DRM", /* name */
-   native_set_event_handler,
    native_create_display
 };
 
 const struct native_platform *
-native_get_drm_platform(void)
+native_get_drm_platform(const struct native_event_handler *event_handler)
 {
+   drm_event_handler = event_handler;
    return &drm_platform;
 }
index f938edeada7b3a489d475a49a32cc7a833e65950..675a58a1922b37e8e4c88164dd20c0834a141aaa 100644 (file)
@@ -50,7 +50,7 @@ struct drm_surface;
 struct drm_display {
    struct native_display base;
 
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    int fd;
    char *device_name;
index e2fde00e975ebb98c34748d38fdecdc915e7de83..49e3728535dbd21f755dff414849b92be02d1691 100644 (file)
@@ -45,7 +45,7 @@ struct fbdev_display {
    struct native_display base;
 
    int fd;
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    struct fb_fix_screeninfo finfo;
    struct fb_var_screeninfo vinfo;
@@ -393,47 +393,35 @@ fbdev_display_init_configs(struct native_display *ndpy)
 }
 
 static boolean
-fbdev_display_init(struct native_display *ndpy)
+fbdev_display_init_screen(struct native_display *ndpy)
 {
    struct fbdev_display *fbdpy = fbdev_display(ndpy);
    struct sw_winsys *ws;
 
-   if (ioctl(fbdpy->fd, FBIOGET_FSCREENINFO, &fbdpy->finfo))
-      return FALSE;
-
-   if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &fbdpy->vinfo))
+   ws = fbdev_create_sw_winsys(fbdpy->fd, fbdpy->config.color_format);
+   if (!ws)
       return FALSE;
 
-   if (fbdpy->finfo.visual != FB_VISUAL_TRUECOLOR ||
-       fbdpy->finfo.type != FB_TYPE_PACKED_PIXELS)
+   fbdpy->base.screen = fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws);
+   if (!fbdpy->base.screen) {
+      if (ws->destroy)
+         ws->destroy(ws);
       return FALSE;
-
-   if (!fbdev_display_init_configs(&fbdpy->base) ||
-       !fbdev_display_init_connectors(&fbdpy->base) ||
-       !fbdev_display_init_modes(&fbdpy->base))
-      return FALSE;
-
-   ws = fbdev_create_sw_winsys(fbdpy->fd, fbdpy->config.color_format);
-   if (ws) {
-      fbdpy->base.screen =
-         fbdpy->event_handler->new_sw_screen(&fbdpy->base, ws);
    }
 
-   if (fbdpy->base.screen) {
-      if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen,
-               fbdpy->config.color_format, PIPE_TEXTURE_2D, 0,
-               PIPE_BIND_RENDER_TARGET)) {
-         fbdpy->base.screen->destroy(fbdpy->base.screen);
-         fbdpy->base.screen = NULL;
-      }
+   if (!fbdpy->base.screen->is_format_supported(fbdpy->base.screen,
+            fbdpy->config.color_format, PIPE_TEXTURE_2D, 0,
+            PIPE_BIND_RENDER_TARGET)) {
+      fbdpy->base.screen->destroy(fbdpy->base.screen);
+      fbdpy->base.screen = NULL;
+      return FALSE;
    }
 
-   return (fbdpy->base.screen != NULL);
+   return TRUE;
 }
 
 static struct native_display *
-fbdev_display_create(int fd, struct native_event_handler *event_handler,
-                     void *user_data)
+fbdev_display_create(int fd, const struct native_event_handler *event_handler)
 {
    struct fbdev_display *fbdpy;
 
@@ -443,13 +431,23 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler,
 
    fbdpy->fd = fd;
    fbdpy->event_handler = event_handler;
-   fbdpy->base.user_data = user_data;
 
-   if (!fbdev_display_init(&fbdpy->base)) {
-      FREE(fbdpy);
-      return NULL;
-   }
+   if (ioctl(fbdpy->fd, FBIOGET_FSCREENINFO, &fbdpy->finfo))
+      goto fail;
+
+   if (ioctl(fbdpy->fd, FBIOGET_VSCREENINFO, &fbdpy->vinfo))
+      goto fail;
+
+   if (fbdpy->finfo.visual != FB_VISUAL_TRUECOLOR ||
+       fbdpy->finfo.type != FB_TYPE_PACKED_PIXELS)
+      goto fail;
+
+   if (!fbdev_display_init_configs(&fbdpy->base) ||
+       !fbdev_display_init_connectors(&fbdpy->base) ||
+       !fbdev_display_init_modes(&fbdpy->base))
+      goto fail;
 
+   fbdpy->base.init_screen = fbdev_display_init_screen;
    fbdpy->base.destroy = fbdev_display_destroy;
    fbdpy->base.get_param = fbdev_display_get_param;
    fbdpy->base.get_configs = fbdev_display_get_configs;
@@ -457,18 +455,16 @@ fbdev_display_create(int fd, struct native_event_handler *event_handler,
    fbdpy->base.modeset = &fbdev_display_modeset;
 
    return &fbdpy->base;
-}
-
-static struct native_event_handler *fbdev_event_handler;
 
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
-   fbdev_event_handler = event_handler;
+fail:
+   FREE(fbdpy);
+   return NULL;
 }
 
+static const struct native_event_handler *fbdev_event_handler;
+
 static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
 {
    struct native_display *ndpy;
    int fd;
@@ -483,7 +479,7 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
    if (fd < 0)
       return NULL;
 
-   ndpy = fbdev_display_create(fd, fbdev_event_handler, user_data);
+   ndpy = fbdev_display_create(fd, fbdev_event_handler);
    if (!ndpy)
       close(fd);
 
@@ -492,12 +488,12 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
 
 static const struct native_platform fbdev_platform = {
    "FBDEV", /* name */
-   native_set_event_handler,
    native_create_display
 };
 
 const struct native_platform *
-native_get_fbdev_platform(void)
+native_get_fbdev_platform(const struct native_event_handler *event_handler)
 {
+   fbdev_event_handler = event_handler;
    return &fbdev_platform;
 }
index 5d0045f92ee5f0e647ad519a16d7580cb368d016..6bf0d4e46687841de290fc937e4927444b65cc0e 100644 (file)
@@ -41,7 +41,7 @@ struct gdi_display {
    struct native_display base;
 
    HDC hDC;
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    struct native_config *configs;
    int num_configs;
@@ -368,35 +368,39 @@ gdi_display_destroy(struct native_display *ndpy)
    FREE(gdpy);
 }
 
-static struct native_display *
-gdi_create_display(HDC hDC, struct native_event_handler *event_handler,
-                   void *user_data)
+static boolean
+gdi_display_init_screen(struct native_display *ndpy)
 {
-   struct gdi_display *gdpy;
+   struct gdi_display *gdpy = gdi_display(ndpy);
    struct sw_winsys *winsys;
 
-   gdpy = CALLOC_STRUCT(gdi_display);
-   if (!gdpy)
-      return NULL;
-
-   gdpy->hDC = hDC;
-   gdpy->event_handler = event_handler;
-   gdpy->base.user_data = user_data;
-
    winsys = gdi_create_sw_winsys();
-   if (!winsys) {
-      FREE(gdpy);
-      return NULL;
-   }
+   if (!winsys)
+      return FALSE;
 
    gdpy->base.screen = gdpy->event_handler->new_sw_screen(&gdpy->base, winsys);
    if (!gdpy->base.screen) {
       if (winsys->destroy)
          winsys->destroy(winsys);
-      FREE(gdpy);
-      return NULL;
+      return FALSE;
    }
 
+   return TRUE;
+}
+
+static struct native_display *
+gdi_create_display(HDC hDC, const struct native_event_handler *event_handler)
+{
+   struct gdi_display *gdpy;
+
+   gdpy = CALLOC_STRUCT(gdi_display);
+   if (!gdpy)
+      return NULL;
+
+   gdpy->hDC = hDC;
+   gdpy->event_handler = event_handler;
+
+   gdpy->base.init_screen = gdi_display_init_screen;
    gdpy->base.destroy = gdi_display_destroy;
    gdpy->base.get_param = gdi_display_get_param;
 
@@ -406,28 +410,22 @@ gdi_create_display(HDC hDC, struct native_event_handler *event_handler,
    return &gdpy->base;
 }
 
-static struct native_event_handler *gdi_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
-   gdi_event_handler = event_handler;
-}
+static const struct native_event_handler *gdi_event_handler;
 
 static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
 {
-   return gdi_create_display((HDC) dpy, gdi_event_handler, user_data);
+   return gdi_create_display((HDC) dpy, gdi_event_handler);
 }
 
 static const struct native_platform gdi_platform = {
    "GDI", /* name */
-   native_set_event_handler,
    native_create_display
 };
 
 const struct native_platform *
-native_get_gdi_platform(void)
+native_get_gdi_platform(const struct native_event_handler *event_handler)
 {
+   gdi_event_handler = event_handler;
    return &gdi_platform;
 }
index 8317022ce65357308c3f0c9f493156b2be2854b5..e34b24b58b1858b6bd2a59a01ad6bb1af000f128 100644 (file)
@@ -51,7 +51,7 @@
 struct wayland_drm_display {
    struct wayland_display base;
 
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    struct wl_drm *wl_drm;
    struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
@@ -285,8 +285,7 @@ static struct native_display_wayland_bufmgr wayland_drm_display_wayland_bufmgr =
 
 struct wayland_display *
 wayland_create_drm_display(struct wl_display *dpy,
-                           struct native_event_handler *event_handler,
-                           void *user_data)
+                           const struct native_event_handler *event_handler)
 {
    struct wayland_drm_display *drmdpy;
 
@@ -295,7 +294,6 @@ wayland_create_drm_display(struct wl_display *dpy,
       return NULL;
 
    drmdpy->event_handler = event_handler;
-   drmdpy->base.base.user_data = user_data;
 
    drmdpy->base.dpy = dpy;
    if (!drmdpy->base.dpy) {
@@ -303,10 +301,7 @@ wayland_create_drm_display(struct wl_display *dpy,
       return NULL;
    }
 
-   if (!wayland_drm_display_init_screen(&drmdpy->base.base)) {
-      wayland_drm_display_destroy(&drmdpy->base.base);
-      return NULL;
-   }
+   drmdpy->base.base.init_screen = wayland_drm_display_init_screen;
    drmdpy->base.base.destroy = wayland_drm_display_destroy;
    drmdpy->base.base.buffer = &wayland_drm_display_buffer;
    drmdpy->base.base.wayland_bufmgr = &wayland_drm_display_wayland_bufmgr;
index 8614a761abf29a7fa76dea60f379f40e4e03ba14..1c0799528fe49b3fa5f67843ae69875737f8490a 100644 (file)
@@ -47,7 +47,7 @@
 struct wayland_shm_display {
    struct wayland_display base;
 
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
    struct wl_shm *wl_shm;
 };
 
@@ -144,8 +144,7 @@ wayland_shm_display_init_screen(struct native_display *ndpy)
 
 struct wayland_display *
 wayland_create_shm_display(struct wl_display *dpy,
-                           struct native_event_handler *event_handler,
-                           void *user_data)
+                           const struct native_event_handler *event_handler)
 {
    struct wayland_shm_display *shmdpy;
 
@@ -154,7 +153,6 @@ wayland_create_shm_display(struct wl_display *dpy,
       return NULL;
 
    shmdpy->event_handler = event_handler;
-   shmdpy->base.base.user_data = user_data;
 
    shmdpy->base.dpy = dpy;
    if (!shmdpy->base.dpy) {
@@ -162,11 +160,7 @@ wayland_create_shm_display(struct wl_display *dpy,
       return NULL;
    }
 
-   if (!wayland_shm_display_init_screen(&shmdpy->base.base)) {
-      wayland_shm_display_destroy(&shmdpy->base.base);
-      return NULL;
-   }
-
+   shmdpy->base.base.init_screen = wayland_shm_display_init_screen;
    shmdpy->base.base.destroy = wayland_shm_display_destroy;
    shmdpy->base.create_buffer = wayland_create_shm_buffer;
 
index f183538e7b6d22b2a34c280c70f21c02dd0ba285..0672c543bc39f74a6c4449e149f6693116a4c8cf 100644 (file)
@@ -35,7 +35,7 @@
 
 #include "native_wayland.h"
 
-static struct native_event_handler *wayland_event_handler;
+static const struct native_event_handler *wayland_event_handler;
 
 static void
 sync_callback(void *data)
@@ -447,14 +447,8 @@ wayland_create_window_surface(struct native_display *ndpy,
    return &surface->base;
 }
 
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
-   wayland_event_handler = event_handler;
-}
-
 static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
 {
    struct wayland_display *display = NULL;
    boolean own_dpy = FALSE;
@@ -471,12 +465,10 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
    if (use_sw) {
       _eglLog(_EGL_INFO, "use software fallback");
       display = wayland_create_shm_display((struct wl_display *) dpy,
-                                           wayland_event_handler,
-                                           user_data);
+                                           wayland_event_handler);
    } else {
       display = wayland_create_drm_display((struct wl_display *) dpy,
-                                           wayland_event_handler,
-                                           user_data);
+                                           wayland_event_handler);
    }
 
    if (!display)
@@ -495,13 +487,13 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
 
 static const struct native_platform wayland_platform = {
    "wayland", /* name */
-   native_set_event_handler,
    native_create_display
 };
 
 const struct native_platform *
-native_get_wayland_platform(void)
+native_get_wayland_platform(const struct native_event_handler *event_handler)
 {
+   wayland_event_handler = event_handler;
    return &wayland_platform;
 }
 
index 81c7a8b4840c59e055dbf94e4cb9159f6ac8a8c3..5390f2f08c9790a041420fc1c8245ca4232f12b2 100644 (file)
@@ -103,11 +103,10 @@ wayland_config(const struct native_config *nconf)
 
 struct wayland_display *
 wayland_create_shm_display(struct wl_display *display,
-                           struct native_event_handler *event_handler,
-                           void *user_data);
+                           const struct native_event_handler *event_handler);
+
 struct wayland_display *
 wayland_create_drm_display(struct wl_display *display,
-                           struct native_event_handler *event_handler,
-                           void *user_data);
+                           const struct native_event_handler *event_handler);
 
 #endif /* _NATIVE_WAYLAND_H_ */
index a56d43428fc124aa616553b6b64276a35f5c2c8a..2a3a1062544213ce33a18c425c3d09f79126f633 100644 (file)
@@ -49,7 +49,7 @@ struct dri2_display {
    Display *dpy;
    boolean own_dpy;
 
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    struct x11_screen *xscr;
    int xscr_number;
@@ -870,8 +870,7 @@ static struct native_display_wayland_bufmgr dri2_display_wayland_bufmgr = {
 
 struct native_display *
 x11_create_dri2_display(Display *dpy,
-                        struct native_event_handler *event_handler,
-                        void *user_data)
+                        const struct native_event_handler *event_handler)
 {
    struct dri2_display *dri2dpy;
 
@@ -880,7 +879,6 @@ x11_create_dri2_display(Display *dpy,
       return NULL;
 
    dri2dpy->event_handler = event_handler;
-   dri2dpy->base.user_data = user_data;
 
    dri2dpy->dpy = dpy;
    if (!dri2dpy->dpy) {
@@ -899,11 +897,6 @@ x11_create_dri2_display(Display *dpy,
       return NULL;
    }
 
-   if (!dri2_display_init_screen(&dri2dpy->base)) {
-      dri2_display_destroy(&dri2dpy->base);
-      return NULL;
-   }
-
    dri2dpy->surfaces = util_hash_table_create(dri2_display_hash_table_hash,
          dri2_display_hash_table_compare);
    if (!dri2dpy->surfaces) {
@@ -911,6 +904,7 @@ x11_create_dri2_display(Display *dpy,
       return NULL;
    }
 
+   dri2dpy->base.init_screen = dri2_display_init_screen;
    dri2dpy->base.destroy = dri2_display_destroy;
    dri2dpy->base.get_param = dri2_display_get_param;
    dri2dpy->base.get_configs = dri2_display_get_configs;
index a0bcad4c7344a759e0e842b5fbb8b75de6c8a422..ef038b52152df1a3bbf4ba0240f6a1dbb7d08ecb 100644 (file)
 
 #include "native_x11.h"
 
-static struct native_event_handler *x11_event_handler;
-
-static void
-native_set_event_handler(struct native_event_handler *event_handler)
-{
-   x11_event_handler = event_handler;
-}
+static const struct native_event_handler *x11_event_handler;
 
 static struct native_display *
-native_create_display(void *dpy, boolean use_sw, void *user_data)
+native_create_display(void *dpy, boolean use_sw)
 {
    struct native_display *ndpy = NULL;
    boolean force_sw;
@@ -48,12 +42,10 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
 
    if (force_sw || use_sw) {
       _eglLog(_EGL_INFO, "use software fallback");
-      ndpy = x11_create_ximage_display((Display *) dpy,
-            x11_event_handler, user_data);
+      ndpy = x11_create_ximage_display((Display *) dpy, x11_event_handler);
    }
    else {
-      ndpy = x11_create_dri2_display((Display *) dpy,
-            x11_event_handler, user_data);
+      ndpy = x11_create_dri2_display((Display *) dpy, x11_event_handler);
    }
 
    return ndpy;
@@ -61,12 +53,12 @@ native_create_display(void *dpy, boolean use_sw, void *user_data)
 
 static const struct native_platform x11_platform = {
    "X11", /* name */
-   native_set_event_handler,
    native_create_display
 };
 
 const struct native_platform *
-native_get_x11_platform(void)
+native_get_x11_platform(const struct native_event_handler *event_handler)
 {
+   x11_event_handler = event_handler;
    return &x11_platform;
 }
index 8945117276e83698e95bb45615ae7ac14b68e698..d3c9270a667332171b4bb2daddf79326bbdae01f 100644 (file)
 
 struct native_display *
 x11_create_ximage_display(Display *dpy,
-                          struct native_event_handler *event_handler,
-                          void *user_data);
+                          const struct native_event_handler *event_handler);
 
 struct native_display *
 x11_create_dri2_display(Display *dpy,
-                        struct native_event_handler *event_handler,
-                        void *user_data);
+                        const struct native_event_handler *event_handler);
 
 #endif /* _NATIVE_X11_H_ */
index 8e32c6ff0c49b0bcdd9ac1ac9ec434c6631375ef..1bf7a1912b9b6d865d3cadfab3441e1995aa3ba4 100644 (file)
@@ -43,7 +43,7 @@ struct ximage_display {
    Display *dpy;
    boolean own_dpy;
 
-   struct native_event_handler *event_handler;
+   const struct native_event_handler *event_handler;
 
    struct x11_screen *xscr;
    int xscr_number;
@@ -484,13 +484,32 @@ ximage_display_destroy(struct native_display *ndpy)
    FREE(xdpy);
 }
 
+static boolean
+ximage_display_init_screen(struct native_display *ndpy)
+{
+   struct ximage_display *xdpy = ximage_display(ndpy);
+   struct sw_winsys *winsys;
+
+   winsys = xlib_create_sw_winsys(xdpy->dpy);
+   if (!winsys)
+      return FALSE;
+
+   xdpy->base.screen =
+      xdpy->event_handler->new_sw_screen(&xdpy->base, winsys);
+   if (!xdpy->base.screen) {
+      if (winsys->destroy)
+         winsys->destroy(winsys);
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
 struct native_display *
 x11_create_ximage_display(Display *dpy,
-                          struct native_event_handler *event_handler,
-                          void *user_data)
+                          const struct native_event_handler *event_handler)
 {
    struct ximage_display *xdpy;
-   struct sw_winsys *winsys = NULL;
 
    xdpy = CALLOC_STRUCT(ximage_display);
    if (!xdpy)
@@ -507,22 +526,17 @@ x11_create_ximage_display(Display *dpy,
    }
 
    xdpy->event_handler = event_handler;
-   xdpy->base.user_data = user_data;
 
    xdpy->xscr_number = DefaultScreen(xdpy->dpy);
    xdpy->xscr = x11_screen_create(xdpy->dpy, xdpy->xscr_number);
-   if (!xdpy->xscr)
-      goto fail;
-
-   winsys = xlib_create_sw_winsys(xdpy->dpy);
-   if (!winsys)
-      goto fail;
-
-   xdpy->base.screen =
-      xdpy->event_handler->new_sw_screen(&xdpy->base, winsys);
-   if (!xdpy->base.screen)
-      goto fail;
+   if (!xdpy->xscr) {
+      if (xdpy->own_dpy)
+         XCloseDisplay(xdpy->dpy);
+      FREE(xdpy);
+      return NULL;
+   }
 
+   xdpy->base.init_screen = ximage_display_init_screen;
    xdpy->base.destroy = ximage_display_destroy;
    xdpy->base.get_param = ximage_display_get_param;
 
@@ -532,14 +546,4 @@ x11_create_ximage_display(Display *dpy,
    xdpy->base.create_pixmap_surface = ximage_display_create_pixmap_surface;
 
    return &xdpy->base;
-
-fail:
-   if (winsys && winsys->destroy)
-      winsys->destroy(winsys);
-   if (xdpy->xscr)
-      x11_screen_destroy(xdpy->xscr);
-   if (xdpy->dpy && xdpy->own_dpy)
-      XCloseDisplay(xdpy->dpy);
-   FREE(xdpy);
-   return NULL;
 }