From fe6079ac0987d78873d5aa582d780957056b7119 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Thu, 15 Dec 2011 15:20:04 +0200 Subject: [PATCH] window: add display_destroy() Add a function to destroy the 'struct display', supposedly with all contained resources, that are not explicitly created by the application. The implementation at this time is incomplete. It does clean up the following: - xkb structure is freed (needs new libxkbcommon from git) - EGL resources are freed - wl_display is flushed and destroyed Signed-off-by: Pekka Paalanen --- clients/window.c | 32 ++++++++++++++++++++++++++++++++ clients/window.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/clients/window.c b/clients/window.c index 0e95f8e97..66fd00c45 100644 --- a/clients/window.c +++ b/clients/window.c @@ -2379,6 +2379,12 @@ init_xkb(struct display *d) } } +static void +fini_xkb(struct display *display) +{ + xkb_free_keymap(display->xkb); +} + static int init_egl(struct display *d) { @@ -2465,6 +2471,21 @@ init_egl(struct display *d) return 0; } +static void +fini_egl(struct display *display) +{ +#ifdef HAVE_CAIRO_EGL + cairo_device_destroy(display->argb_device); + cairo_device_destroy(display->rgb_device); +#endif + + eglMakeCurrent(display->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + + eglTerminate(display->dpy); + eglReleaseThread(); +} + static int event_mask_update(uint32_t mask, void *data) { @@ -2558,6 +2579,17 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries) return d; } +void +display_destroy(struct display *display) +{ + fini_xkb(display); + fini_egl(display); + + wl_display_flush(display->display); + wl_display_destroy(display->display); + free(display); +} + void display_set_user_data(struct display *display, void *data) { diff --git a/clients/window.h b/clients/window.h index 20bf4e2b6..91f3af18d 100644 --- a/clients/window.h +++ b/clients/window.h @@ -49,6 +49,9 @@ struct rectangle { struct display * display_create(int *argc, char **argv[], const GOptionEntry *option_entries); +void +display_destroy(struct display *display); + void display_set_user_data(struct display *display, void *data);