summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2011-06-25 14:52:57 +0900
committerChia-I Wu <[email protected]>2011-06-25 16:23:20 +0900
commit73df31eedd0f33c8a9907855cb247c8f87964c48 (patch)
treeb8ea98593122e687b3f27a1c6ee40647f65549d6
parentac8f59b23ed8256bcce40c47b5773669b00ba78a (diff)
st/egl: reorganize backend initialization
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().
-rw-r--r--src/gallium/state_trackers/egl/common/egl_g3d.c29
-rw-r--r--src/gallium/state_trackers/egl/common/native.h26
-rw-r--r--src/gallium/state_trackers/egl/drm/native_drm.c26
-rw-r--r--src/gallium/state_trackers/egl/drm/native_drm.h2
-rw-r--r--src/gallium/state_trackers/egl/fbdev/native_fbdev.c84
-rw-r--r--src/gallium/state_trackers/egl/gdi/native_gdi.c58
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_drm.c11
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_shm.c12
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_wayland.c20
-rw-r--r--src/gallium/state_trackers/egl/wayland/native_wayland.h7
-rw-r--r--src/gallium/state_trackers/egl/x11/native_dri2.c12
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.c20
-rw-r--r--src/gallium/state_trackers/egl/x11/native_x11.h6
-rw-r--r--src/gallium/state_trackers/egl/x11/native_ximage.c56
14 files changed, 172 insertions, 197 deletions
diff --git a/src/gallium/state_trackers/egl/common/egl_g3d.c b/src/gallium/state_trackers/egl/common/egl_g3d.c
index 6a40f4d2a4b..7d1eafe3bec 100644
--- a/src/gallium/state_trackers/egl/common/egl_g3d.c
+++ b/src/gallium/state_trackers/egl/common/egl_g3d.c
@@ -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;
diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h
index cb261964864..c0b8385cc6b 100644
--- a/src/gallium/state_trackers/egl/common/native.h
+++ b/src/gallium/state_trackers/egl/common/native.h
@@ -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
}
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c
index 57765cc281f..de4eb852eb7 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.c
+++ b/src/gallium/state_trackers/egl/drm/native_drm.c
@@ -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;
}
diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h
index f938edeada7..675a58a1922 100644
--- a/src/gallium/state_trackers/egl/drm/native_drm.h
+++ b/src/gallium/state_trackers/egl/drm/native_drm.h
@@ -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;
diff --git a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
index e2fde00e975..49e3728535d 100644
--- a/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
+++ b/src/gallium/state_trackers/egl/fbdev/native_fbdev.c
@@ -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;
}
diff --git a/src/gallium/state_trackers/egl/gdi/native_gdi.c b/src/gallium/state_trackers/egl/gdi/native_gdi.c
index 5d0045f92ee..6bf0d4e4668 100644
--- a/src/gallium/state_trackers/egl/gdi/native_gdi.c
+++ b/src/gallium/state_trackers/egl/gdi/native_gdi.c
@@ -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;
}
diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
index 8317022ce65..e34b24b58b1 100644
--- a/src/gallium/state_trackers/egl/wayland/native_drm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
@@ -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;
diff --git a/src/gallium/state_trackers/egl/wayland/native_shm.c b/src/gallium/state_trackers/egl/wayland/native_shm.c
index 8614a761abf..1c0799528fe 100644
--- a/src/gallium/state_trackers/egl/wayland/native_shm.c
+++ b/src/gallium/state_trackers/egl/wayland/native_shm.c
@@ -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;
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.c b/src/gallium/state_trackers/egl/wayland/native_wayland.c
index f183538e7b6..0672c543bc3 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.c
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.c
@@ -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;
}
diff --git a/src/gallium/state_trackers/egl/wayland/native_wayland.h b/src/gallium/state_trackers/egl/wayland/native_wayland.h
index 81c7a8b4840..5390f2f08c9 100644
--- a/src/gallium/state_trackers/egl/wayland/native_wayland.h
+++ b/src/gallium/state_trackers/egl/wayland/native_wayland.h
@@ -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_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
index a56d43428fc..2a3a1062544 100644
--- a/src/gallium/state_trackers/egl/x11/native_dri2.c
+++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
@@ -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;
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.c b/src/gallium/state_trackers/egl/x11/native_x11.c
index a0bcad4c734..ef038b52152 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.c
+++ b/src/gallium/state_trackers/egl/x11/native_x11.c
@@ -30,16 +30,10 @@
#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;
}
diff --git a/src/gallium/state_trackers/egl/x11/native_x11.h b/src/gallium/state_trackers/egl/x11/native_x11.h
index 8945117276e..d3c9270a667 100644
--- a/src/gallium/state_trackers/egl/x11/native_x11.h
+++ b/src/gallium/state_trackers/egl/x11/native_x11.h
@@ -31,12 +31,10 @@
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_ */
diff --git a/src/gallium/state_trackers/egl/x11/native_ximage.c b/src/gallium/state_trackers/egl/x11/native_ximage.c
index 8e32c6ff0c4..1bf7a1912b9 100644
--- a/src/gallium/state_trackers/egl/x11/native_ximage.c
+++ b/src/gallium/state_trackers/egl/x11/native_ximage.c
@@ -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;
}