[grits] Remove gdk threads



commit 7f81b781a2502cb1414d31f67af680b50f17e876
Author: Andy Spencer <andy753421 gmail com>
Date:   Sun Jan 20 05:00:03 2013 +0000

    Remove gdk threads

 src/grits-demo.c |    7 +------
 src/grits-test.c |    3 ---
 src/tile-test.c  |   33 +++++++++++++++++++++++----------
 3 files changed, 24 insertions(+), 19 deletions(-)
---
diff --git a/src/grits-demo.c b/src/grits-demo.c
index e5f18b6..05803be 100644
--- a/src/grits-demo.c
+++ b/src/grits-demo.c
@@ -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;
 }
diff --git a/src/grits-test.c b/src/grits-test.c
index 1a9a4cc..6c393e0 100644
--- a/src/grits-test.c
+++ b/src/grits-test.c
@@ -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());
 
diff --git a/src/tile-test.c b/src/tile-test.c
index 092c6d2..0951541 100644
--- a/src/tile-test.c
+++ b/src/tile-test.c
@@ -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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]