]> Pileus Git - grits/commitdiff
Delay load the textures for label markers
authorAndy Spencer <andy753421@gmail.com>
Sat, 11 Feb 2012 17:32:27 +0000 (17:32 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 12 Feb 2012 07:00:20 +0000 (07:00 +0000)
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
src/objects/grits-marker.h

index 162e4bbdbac445fd7acf2a918dbc634399339c0a..338cf1b76af416d2becffb8b4ed0fa680009b858 100644 (file)
@@ -148,8 +148,6 @@ GritsMarker *grits_marker_new(const gchar *label)
 
        marker->label = g_strdup(label);
 
 
        marker->label = g_strdup(label);
 
-       render_all(marker);
-
        return marker;
 }
 
        return marker;
 }
 
@@ -207,6 +205,7 @@ GritsMarker *grits_marker_icon_new(const gchar *label, const gchar *filename,
 
        marker->outline =   2;
        marker->radius  =   3;
 
        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;
        /* 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));
        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
        /* 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);
 
        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),
        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);
 {
        //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);
        g_free(marker->label);
-       glDeleteTextures(1, &marker->tex);
 }
 
 static void grits_marker_class_init(GritsMarkerClass *klass)
 }
 
 static void grits_marker_class_init(GritsMarkerClass *klass)
index 0e44901754eb79abd9633ab4bc2d0d5b31a2043c..59e4ba243d88455ac6dafe12cb29c20b814dc1f7 100644 (file)
@@ -46,6 +46,7 @@ struct _GritsMarker {
        gint       xoff, yoff;              /* center point offset */
        gint       icon_width, icon_height; /* size of icon for offsets */
        gchar     *label;
        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;
        cairo_t   *cairo;
        guint      tex;
        gboolean   ortho;