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 <ppaalanen@gmail.com>
diff --git a/clients/window.c b/clients/window.c
index 0e95f8e..66fd00c 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -2379,6 +2379,12 @@
 	}
 }
 
+static void
+fini_xkb(struct display *display)
+{
+	xkb_free_keymap(display->xkb);
+}
+
 static int
 init_egl(struct display *d)
 {
@@ -2465,6 +2471,21 @@
 	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 @@
 }
 
 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;