summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/egl.c19
-rw-r--r--src/egl.h1
-rw-r--r--src/entry.c14
-rw-r--r--src/entry.h2
-rw-r--r--src/gl.c13
-rw-r--r--src/gl.h1
-rw-r--r--src/main.c37
-rw-r--r--src/surface.c7
-rw-r--r--src/surface.h1
9 files changed, 87 insertions, 8 deletions
diff --git a/src/egl.c b/src/egl.c
index 59f297b..5ee804a 100644
--- a/src/egl.c
+++ b/src/egl.c
@@ -97,11 +97,20 @@ void egl_create_context(struct egl *egl, struct wl_display *wl_display)
}
}
-void egl_log_error(const char *msg) {
+void egl_destroy(struct egl *egl)
+{
+ eglMakeCurrent(egl->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
+ eglDestroySurface(egl->display, egl->surface);
+ wl_egl_window_destroy(egl->window);
+}
+
+void egl_log_error(const char *msg)
+{
log_error("%s: %s\n", msg, egl_error_string());
}
-void egl_make_current(struct egl *egl) {
+void egl_make_current(struct egl *egl)
+{
bool result = eglMakeCurrent(
egl->display,
egl->surface,
@@ -113,11 +122,13 @@ void egl_make_current(struct egl *egl) {
}
}
-void egl_swap_buffers(struct egl *egl) {
+void egl_swap_buffers(struct egl *egl)
+{
eglSwapBuffers(egl->display, egl->surface);
}
-const char *egl_error_string() {
+const char *egl_error_string()
+{
switch(eglGetError()) {
case EGL_SUCCESS:
return "EGL_SUCCESS";
diff --git a/src/egl.h b/src/egl.h
index a705538..a3f17a2 100644
--- a/src/egl.h
+++ b/src/egl.h
@@ -17,6 +17,7 @@ void egl_create_window(
uint32_t width,
uint32_t height);
void egl_create_context(struct egl *egl, struct wl_display *wl_display);
+void egl_destroy(struct egl *egl);
void egl_log_error(const char *msg);
void egl_make_current(struct egl *egl);
void egl_swap_buffers(struct egl *egl);
diff --git a/src/entry.c b/src/entry.c
index 63b6f87..1f1a5b8 100644
--- a/src/entry.c
+++ b/src/entry.c
@@ -114,12 +114,21 @@ void entry_init(struct entry *entry, uint32_t scale)
entry->pangocairo.surface = surface;
entry->pangocairo.cr = cr;
+ entry->pangocairo.context = context;
entry->pangocairo.layout = layout;
entry->image.width = entry->surface.width;
entry->image.height = entry->surface.height;
entry->image.buffer = cairo_image_surface_get_data(surface);
}
+void entry_destroy(struct entry *entry)
+{
+ g_object_unref(entry->pangocairo.layout);
+ g_object_unref(entry->pangocairo.context);
+ cairo_destroy(entry->pangocairo.cr);
+ cairo_surface_destroy(entry->pangocairo.surface);
+}
+
void entry_update(struct entry *entry)
{
cairo_t *cr = entry->pangocairo.cr;
@@ -176,9 +185,10 @@ void calculate_font_extents(struct entry *entry, uint32_t scale)
PangoFont *font =
pango_context_load_font(context, font_description);
PangoFontDescription *desc = pango_font_describe(font);
- log_debug("Using font: %s\n",
- pango_font_description_to_string(desc));
+ char *string = pango_font_description_to_string(desc);
+ log_debug("Using font: %s\n", string);
+ g_free(string);
pango_font_description_free(desc);
g_object_unref(font);
}
diff --git a/src/entry.h b/src/entry.h
index f487410..05c459b 100644
--- a/src/entry.h
+++ b/src/entry.h
@@ -13,6 +13,7 @@ struct entry {
struct wl_subsurface *wl_subsurface;
struct image image;
struct {
+ PangoContext *context;
PangoLayout *layout;
cairo_surface_t *surface;
cairo_t *cr;
@@ -44,6 +45,7 @@ struct entry {
};
void entry_init(struct entry *entry, uint32_t scale);
+void entry_destroy(struct entry *entry);
void entry_update(struct entry *entry);
void entry_set_scale(struct entry *entry, uint32_t scale);
diff --git a/src/gl.c b/src/gl.c
index 74e7605..09c542e 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -141,6 +141,15 @@ void gl_initialise(struct gl *gl, struct image *texture)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl->ebo);
}
+void gl_destroy(struct gl *gl)
+{
+ glDeleteProgram(gl->shader);
+ glDeleteTextures(1, &gl->texture);
+ glDeleteBuffers(1, &gl->ebo);
+ glDeleteVertexArrays(1, &gl->vao);
+ glDeleteBuffers(1, &gl->vbo);
+}
+
void gl_clear(struct gl *gl, struct color *color)
{
glClearColor(color->r, color->g, color->b, color->a);
@@ -241,6 +250,10 @@ GLuint create_shader_program(const char *vert, const char *frag)
glAttachShader(shader, vertex_shader);
glAttachShader(shader, fragment_shader);
glLinkProgram(shader);
+ glDetachShader(shader, fragment_shader);
+ glDetachShader(shader, vertex_shader);
+ glDeleteShader(fragment_shader);
+ glDeleteShader(vertex_shader);
return shader;
}
diff --git a/src/gl.h b/src/gl.h
index 9f48bb8..d3da2b6 100644
--- a/src/gl.h
+++ b/src/gl.h
@@ -15,6 +15,7 @@ struct gl {
};
void gl_initialise(struct gl *gl, struct image *texture);
+void gl_destroy(struct gl *gl);
void gl_clear(struct gl *gl, struct color *color);
void gl_draw_texture(
struct gl *gl,
diff --git a/src/main.c b/src/main.c
index 0cd266a..7799653 100644
--- a/src/main.c
+++ b/src/main.c
@@ -830,10 +830,43 @@ int main(int argc, char *argv[])
}
}
- log_info("Window closed, performing cleanup.\n");
+ log_debug("Window closed, performing cleanup.\n");
+#ifdef DEBUG
+ /*
+ * For debug builds, try to cleanup as much as possible, to make using
+ * e.g. Valgrind easier. There's still a few unavoidable leaks though,
+ * mostly from OpenGL libs and Pango.
+ */
+ entry_destroy(&state.window.entry);
+ surface_destroy(&state.window.entry.surface);
+ surface_destroy(&state.window.surface);
+ if (state.window.background_image.buffer != NULL) {
+ free(state.window.background_image.buffer);
+ state.window.background_image.buffer = NULL;
+ }
+ eglTerminate(state.window.surface.egl.display);
+ wl_subsurface_destroy(state.window.entry.wl_subsurface);
+ wl_surface_destroy(state.window.entry.surface.wl_surface);
+ xdg_toplevel_destroy(state.window.xdg_toplevel);
+ xdg_surface_destroy(state.window.xdg_surface);
+ wl_surface_destroy(state.window.surface.wl_surface);
+ wl_keyboard_release(state.wl_keyboard);
+ wl_compositor_destroy(state.wl_compositor);
+ wl_subcompositor_destroy(state.wl_subcompositor);
+ wl_seat_release(state.wl_seat);
+ wl_output_release(state.wl_output);
+ xdg_wm_base_destroy(state.xdg_wm_base);
+ xkb_state_unref(state.xkb_state);
+ xkb_keymap_unref(state.xkb_keymap);
+ xkb_context_unref(state.xkb_context);
+ wl_registry_destroy(state.wl_registry);
+#endif
+ /*
+ * For release builds, skip straight to display disconnection and quit.
+ */
wl_display_disconnect(state.wl_display);
- log_info("Finished, exiting.\n");
+ log_debug("Finished, exiting.\n");
return 0;
}
diff --git a/src/surface.c b/src/surface.c
index 76abec9..81b2b58 100644
--- a/src/surface.c
+++ b/src/surface.c
@@ -19,6 +19,13 @@ void surface_initialise(
gl_initialise(&surface->gl, texture);
}
+void surface_destroy(struct surface *surface)
+{
+ egl_make_current(&surface->egl);
+ gl_destroy(&surface->gl);
+ egl_destroy(&surface->egl);
+}
+
void surface_draw(
struct surface *surface,
struct color *color,
diff --git a/src/surface.h b/src/surface.h
index bd79a80..b8b132f 100644
--- a/src/surface.h
+++ b/src/surface.h
@@ -19,6 +19,7 @@ void surface_initialise(
struct surface *surface,
struct wl_display *wl_display,
struct image *texture);
+void surface_destroy(struct surface *surface);
void surface_draw(
struct surface *surface,
struct color *color,