]> Pileus Git - grits/commitdiff
Remove gdk threads
authorAndy Spencer <andy753421@gmail.com>
Sun, 20 Jan 2013 05:00:03 +0000 (05:00 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 21 Jan 2013 04:50:31 +0000 (04:50 +0000)
src/grits-demo.c
src/grits-test.c
src/tile-test.c

index e5f18b63af44ea0787b1c9d3978eab8c0ab5209e..05803be5db1b5338c10087d3af9919b6dab896c4 100644 (file)
@@ -166,15 +166,12 @@ static void restore_states(GtkUIManager *manager)
 
 int main(int argc, char **argv)
 {
-       gdk_threads_init();
        gtk_init(&argc, &argv);
 
        prefs   = grits_prefs_new(NULL, NULL);
        plugins = grits_plugins_new(g_getenv("GRITS_PLUGIN_PATH"), prefs);
        viewer  = grits_opengl_new(plugins, prefs);
 
-       gdk_threads_enter();
-
        GtkWidget    *notebook = NULL;
        GtkUIManager *manager  = setup_actions();
        GtkWidget    *window   = setup_window(manager, &notebook);
@@ -188,8 +185,6 @@ int main(int argc, char **argv)
        grits_plugins_free(plugins);
        g_object_unref(prefs);
 
-       gdk_threads_leave();
-
        g_debug("GritsDemo: main - refs=%d,%d",
                        G_OBJECT(manager)->ref_count,
                        G_OBJECT(window)->ref_count);
@@ -200,7 +195,7 @@ int main(int argc, char **argv)
        plugins = NULL;
        viewer  = NULL;
 
-       gdk_display_close(gdk_display_get_default());
+       //gdk_display_close(gdk_display_get_default());
 
        return 0;
 }
index 1a9a4cc5bea7cb2b1107bfe314f0438799dc8c83..6c393e081fd170f985139543391a0dbf31f08d8c 100644 (file)
@@ -65,14 +65,12 @@ static void load_plugin(GritsPlugins *plugins, gchar *name,
  ***********/
 int main(int argc, char **argv)
 {
-       gdk_threads_init();
        gtk_init(&argc, &argv);
 
        prefs   = grits_prefs_new(NULL, NULL);
        plugins = grits_plugins_new(g_getenv("GRITS_PLUGIN_PATH"), prefs);
        viewer  = grits_opengl_new(plugins, prefs);
 
-       gdk_threads_enter();
        GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        GtkWidget *vbox   = gtk_vbox_new(FALSE, 0);
        GtkWidget *config = gtk_notebook_new();
@@ -98,7 +96,6 @@ int main(int argc, char **argv)
 
        gtk_widget_show_all(config);
        gtk_main();
-       gdk_threads_leave();
 
        gdk_display_close(gdk_display_get_default());
 
index 092c6d2561084f812ea611e9cc5e473632b06d99..0951541116e89b05627fe78742f2713423050041 100644 (file)
@@ -29,6 +29,10 @@ struct CacheState {
        GtkWidget *progress;
 };
 
+struct LoadData {
+       GtkImage  *image;
+       GdkPixbuf *pixbuf;
+};
 
 void chunk_callback(gsize cur, gsize total, gpointer _state)
 {
@@ -47,6 +51,22 @@ void chunk_callback(gsize cur, gsize total, gpointer _state)
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(state->progress), (gdouble)cur/total);
 }
 
+gboolean load_callback(gpointer _data)
+{
+       struct LoadData *data = _data;
+       gtk_image_set_from_pixbuf(GTK_IMAGE(data->image), data->pixbuf);
+       g_free(data);
+       return FALSE;
+}
+
+void load_image(GtkImage *image, GdkPixbuf *pixbuf)
+{
+       struct LoadData *data = g_new0(struct LoadData, 1);
+       data->image  = image;
+       data->pixbuf = pixbuf;
+       g_idle_add(load_callback, data);
+}
+
 gpointer do_bmng_cache(gpointer _image)
 {
        GtkImage *image = _image;
@@ -63,9 +83,7 @@ gpointer do_bmng_cache(gpointer _image)
 
        g_message("Loading bmng image: [%s]", path);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-       gdk_threads_enter();
-       gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
-       gdk_threads_leave();
+       load_image(GTK_IMAGE(image), pixbuf);
 
        g_message("Cleaning bmng up");
        grits_wms_free(bmng_wms);
@@ -89,9 +107,7 @@ gpointer do_osm_cache(gpointer _image)
 
        g_message("Loading osm image: [%s]", path);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-       gdk_threads_enter();
-       gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
-       gdk_threads_leave();
+       load_image(GTK_IMAGE(image), pixbuf);
 
        g_message("Cleaning osm up");
        grits_wms_free(osm_wms);
@@ -114,9 +130,7 @@ gpointer do_osm2_cache(gpointer _image)
 
        g_message("Loading osm2 image: [%s]", path);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-       gdk_threads_enter();
-       gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
-       gdk_threads_leave();
+       load_image(GTK_IMAGE(image), pixbuf);
 
        g_message("Cleaning osm2 up");
        grits_tms_free(osm2_tms);
@@ -134,7 +148,6 @@ gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
 int main(int argc, char **argv)
 {
-       gdk_threads_init();
        gtk_init(&argc, &argv);
 
        GtkWidget *win        = gtk_window_new(GTK_WINDOW_TOPLEVEL);