[libgis] Move gdk_pixbuf calls to main thread



commit 3e6721f082dd0b16dd5dd86c9eb6c2680731dbd0
Author: Andy Spencer <andy753421 gmail com>
Date:   Mon May 3 07:43:11 2010 +0000

    Move gdk_pixbuf calls to main thread
    
    Hopefully this will fix some Win32 issues

 src/data/gis-http.c |    2 ++
 src/plugins/map.c   |   35 +++++++++++++++++++----------------
 src/plugins/sat.c   |   36 +++++++++++++++++++-----------------
 3 files changed, 40 insertions(+), 33 deletions(-)
---
diff --git a/src/data/gis-http.c b/src/data/gis-http.c
index b610fa3..f4c4ec5 100644
--- a/src/data/gis-http.c
+++ b/src/data/gis-http.c
@@ -226,6 +226,8 @@ GList *gis_http_available(GisHttp *http,
 		g_snprintf(tmp, sizeof(tmp), ".index.%x", g_random_int());
 		gchar *path = gis_http_fetch(http, index, tmp,
 				GIS_REFRESH, NULL, NULL);
+		if (!path)
+			return files;
 		gchar *html;
 		g_file_get_contents(path, &html, NULL, NULL);
 
diff --git a/src/plugins/map.c b/src/plugins/map.c
index 4be4607..5799ca0 100644
--- a/src/plugins/map.c
+++ b/src/plugins/map.c
@@ -47,18 +47,28 @@ static const guchar colormap[][2][4] = {
 struct _LoadTileData {
 	GisPluginMap *map;
 	GisTile      *tile;
-	GdkPixbuf    *pixbuf;
+	gchar        *path;
 };
 static gboolean _load_tile_cb(gpointer _data)
 {
 	struct _LoadTileData *data = _data;
-	GisPluginMap *map    = data->map;
-	GisTile      *tile   = data->tile;
-	GdkPixbuf    *pixbuf = data->pixbuf;
+	GisPluginMap *map  = data->map;
+	GisTile      *tile = data->tile;
+	gchar        *path = data->path;
 	g_free(data);
 
-	/* Create Texture */
+	/* Load pixbuf */
 	g_debug("GisPluginMap: _load_tile_cb start");
+	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
+	if (!pixbuf) {
+		g_warning("GisPluginMap: _load_tile - Error loading pixbuf %s", path);
+		g_remove(path);
+		g_free(path);
+		return FALSE;
+	}
+	g_free(path);
+
+	/* Create Texture */
 	guchar   *pixels = gdk_pixbuf_get_pixels(pixbuf);
 	gboolean  alpha  = gdk_pixbuf_get_has_alpha(pixbuf);
 	gint      width  = gdk_pixbuf_get_width(pixbuf);
@@ -102,18 +112,11 @@ static void _load_tile(GisTile *tile, gpointer _map)
 {
 	GisPluginMap *map = _map;
 	g_debug("GisPluginMap: _load_tile start %p", g_thread_self());
-	char *path = gis_wms_fetch(map->wms, tile, GIS_ONCE, NULL, NULL);
 	struct _LoadTileData *data = g_new0(struct _LoadTileData, 1);
-	data->map    = map;
-	data->tile   = tile;
-	data->pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-	if (data->pixbuf) {
-		g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
-	} else {
-		g_warning("GisPluginMap: _load_tile - Error loading pixbuf %s", path);
-		g_remove(path);
-	}
-	g_free(path);
+	data->map  = map;
+	data->tile = tile;
+	data->path = gis_wms_fetch(map->wms, tile, GIS_ONCE, NULL, NULL);
+	g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
 	g_debug("GisPluginMap: _load_tile end %p", g_thread_self());
 }
 
diff --git a/src/plugins/sat.c b/src/plugins/sat.c
index 5dc3c85..2d28da5 100644
--- a/src/plugins/sat.c
+++ b/src/plugins/sat.c
@@ -39,18 +39,28 @@
 struct _LoadTileData {
 	GisPluginSat *sat;
 	GisTile      *tile;
-	GdkPixbuf    *pixbuf;
+	gchar        *path;
 };
 static gboolean _load_tile_cb(gpointer _data)
 {
 	struct _LoadTileData *data = _data;
-	GisPluginSat *sat    = data->sat;
-	GisTile      *tile   = data->tile;
-	GdkPixbuf    *pixbuf = data->pixbuf;
+	GisPluginSat *sat  = data->sat;
+	GisTile      *tile = data->tile;
+	gchar        *path = data->path;
 	g_free(data);
 
-	/* Create Texture */
+	/* Load pixbuf */
 	g_debug("GisPluginSat: _load_tile_cb start");
+	GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
+	if (!pixbuf) {
+		g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path);
+		g_remove(path);
+		g_free(path);
+		return FALSE;
+	}
+	g_free(path);
+
+	/* Create Texture */
 	guchar   *pixels = gdk_pixbuf_get_pixels(pixbuf);
 	gboolean  alpha  = gdk_pixbuf_get_has_alpha(pixbuf);
 	gint      width  = gdk_pixbuf_get_width(pixbuf);
@@ -92,19 +102,11 @@ static void _load_tile(GisTile *tile, gpointer _sat)
 {
 	GisPluginSat *sat = _sat;
 	g_debug("GisPluginSat: _load_tile start %p", g_thread_self());
-	char *path = gis_wms_fetch(sat->wms, tile, GIS_ONCE, NULL, NULL);
 	struct _LoadTileData *data = g_new0(struct _LoadTileData, 1);
-	data->sat   = sat;
-	data->tile   = tile;
-	data->pixbuf = gdk_pixbuf_new_from_file(path, NULL);
-	if (data->pixbuf) {
-		g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
-	} else {
-		g_warning("GisPluginSat: _load_tile - Error loading pixbuf %s", path);
-		g_free(data);
-		g_remove(path);
-	}
-	g_free(path);
+	data->sat  = sat;
+	data->tile = tile;
+	data->path = gis_wms_fetch(sat->wms, tile, GIS_ONCE, NULL, NULL);
+	g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL);
 	g_debug("GisPluginSat: _load_tile end %p", g_thread_self());
 }
 



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