window: add display_destroy()
authorPekka Paalanen <ppaalanen@gmail.com>
Thu, 15 Dec 2011 13:20:04 +0000 (15:20 +0200)
committerPekka Paalanen <ppaalanen@gmail.com>
Thu, 22 Dec 2011 09:27:50 +0000 (11:27 +0200)
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 <ppaalanen@gmail.com>
clients/window.c
clients/window.h

index 0e95f8e..66fd00c 100644 (file)
@@ -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)
 {
@@ -2559,6 +2580,17 @@ display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
 }
 
 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)
 {
        display->user_data = data;
index 20bf4e2..91f3af1 100644 (file)
@@ -50,6 +50,9 @@ 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);
 
 void *