From f31bd3eb93cee49bcea03c2f24f7a9f285b2e767 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sat, 11 Feb 2012 17:32:27 +0000 Subject: [PATCH] Delay load the textures for label markers This makes the normal constructor thread-safe so they don't need to be created from a callback, the same should eventually be done for the icon markers. --- src/objects/grits-marker.c | 19 ++++++++++++------- src/objects/grits-marker.h | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/objects/grits-marker.c b/src/objects/grits-marker.c index 162e4bb..338cf1b 100644 --- a/src/objects/grits-marker.c +++ b/src/objects/grits-marker.c @@ -148,8 +148,6 @@ GritsMarker *grits_marker_new(const gchar *label) marker->label = g_strdup(label); - render_all(marker); - return marker; } @@ -207,6 +205,7 @@ GritsMarker *grits_marker_icon_new(const gchar *label, const gchar *filename, marker->outline = 2; marker->radius = 3; + /* this is the surface size, a guess really */ marker->width = marker->icon_width + 128; marker->height = marker->icon_height + 64; @@ -215,6 +214,7 @@ GritsMarker *grits_marker_icon_new(const gchar *label, const gchar *filename, marker->yoff = marker->height/2; marker->cairo = cairo_create(cairo_image_surface_create( CAIRO_FORMAT_ARGB32, marker->width, marker->height)); + /* clear the surface just in case */ cairo_set_operator(marker->cairo, CAIRO_OPERATOR_SOURCE); //cairo_set_source_rgba(marker->cairo, 1.0, 0.0, 0.0, 0.3); // debug @@ -241,6 +241,9 @@ static void grits_marker_draw(GritsObject *_marker, GritsOpenGL *opengl) gdouble width = cairo_image_surface_get_width(surface); gdouble height = cairo_image_surface_get_height(surface); + if (!marker->tex) + render_all(marker); + if (marker->ortho) { gdouble px, py, pz; grits_viewer_project(GRITS_VIEWER(opengl), @@ -303,12 +306,14 @@ static void grits_marker_finalize(GObject *_marker) { //g_debug("GritsMarker: finalize - %s", marker->label); GritsMarker *marker = GRITS_MARKER(_marker); - glDeleteTextures(1, &marker->tex); - cairo_surface_t *surface = cairo_get_target(marker->cairo); - cairo_surface_destroy(surface); - cairo_destroy(marker->cairo); + if (marker->tex) + glDeleteTextures(1, &marker->tex); + if (marker->cairo) { + cairo_surface_t *surface = cairo_get_target(marker->cairo); + cairo_surface_destroy(surface); + cairo_destroy(marker->cairo); + } g_free(marker->label); - glDeleteTextures(1, &marker->tex); } static void grits_marker_class_init(GritsMarkerClass *klass) diff --git a/src/objects/grits-marker.h b/src/objects/grits-marker.h index 0e44901..59e4ba2 100644 --- a/src/objects/grits-marker.h +++ b/src/objects/grits-marker.h @@ -46,6 +46,7 @@ struct _GritsMarker { gint xoff, yoff; /* center point offset */ gint icon_width, icon_height; /* size of icon for offsets */ gchar *label; + gchar *file; cairo_t *cairo; guint tex; gboolean ortho; -- 2.43.2