X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fplugins%2Fsat.c;h=2d28da5ede3d7870dcb3a32084af80982ed8d9fb;hb=3e6721f082dd0b16dd5dd86c9eb6c2680731dbd0;hp=abe0b24fbb69640c9c560aaf557debd85076ae00;hpb=b5fde541db3eec5aa0b2d7f5b7a0725ad524f84c;p=grits diff --git a/src/plugins/sat.c b/src/plugins/sat.c index abe0b24..2d28da5 100644 --- a/src/plugins/sat.c +++ b/src/plugins/sat.c @@ -24,6 +24,7 @@ */ #include +#include #include #include @@ -38,23 +39,45 @@ 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); gint height = gdk_pixbuf_get_height(pixbuf); + /* Draw a border */ + //gint border = 10; + //gint stride = gdk_pixbuf_get_rowstride(pixbuf); + //for (int i = 0; i < border; i++) { + // memset(&pixels[( i)*stride], 0xff, stride); + // memset(&pixels[(height-i)*stride], 0xff, stride); + //} + //for (int i = 0; i < height; i++) { + // memset(&pixels[(i*stride)], 0xff, border*4); + // memset(&pixels[(i*stride)+((width-border)*4)], 0xff, border*4); + //} + guint *tex = g_new0(guint, 1); glGenTextures(1, tex); glBindTexture(GL_TEXTURE_2D, *tex); @@ -79,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()); } @@ -104,20 +119,21 @@ static gboolean _free_tile_cb(gpointer data) static void _free_tile(GisTile *tile, gpointer _sat) { GisPluginSat *sat = _sat; - g_debug("GisPluginSat: _free_tile: %p=%d", tile->data, *(guint*)tile->data); - g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL); + g_debug("GisPluginSat: _free_tile: %p", tile->data); + if (tile->data) + g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL); } static gpointer _update_tiles(gpointer _sat) { g_debug("GisPluginSat: _update_tiles"); GisPluginSat *sat = _sat; - g_mutex_lock(sat->mutex); - gdouble lat, lon, elev; - gis_viewer_get_location(sat->viewer, &lat, &lon, &elev); - gis_tile_update(sat->tiles, + if (!g_mutex_trylock(sat->mutex)) + return NULL; + GisPoint eye; + gis_viewer_get_location(sat->viewer, &eye.lat, &eye.lon, &eye.elev); + gis_tile_update(sat->tiles, &eye, MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH, - lat, lon, elev, _load_tile, sat); gis_tile_gc(sat->tiles, time(NULL)-10, _free_tile, sat); @@ -134,6 +150,13 @@ static void _on_location_changed(GisViewer *viewer, g_thread_create(_update_tiles, sat, FALSE, NULL); } +static gpointer _threaded_init(GisPluginSat *sat) +{ + _load_tile(sat->tiles, sat); + _update_tiles(sat); + return NULL; +} + /*********** * Methods * ***********/ @@ -152,15 +175,14 @@ GisPluginSat *gis_plugin_sat_new(GisViewer *viewer) sat->viewer = g_object_ref(viewer); /* Load initial tiles */ - _load_tile(sat->tiles, sat); - g_thread_create(_update_tiles, sat, FALSE, NULL); + g_thread_create((GThreadFunc)_threaded_init, sat, FALSE, NULL); /* Connect signals */ sat->sigid = g_signal_connect(sat->viewer, "location-changed", G_CALLBACK(_on_location_changed), sat); /* Add renderers */ - gis_viewer_add(viewer, GIS_OBJECT(sat->tiles), GIS_LEVEL_WORLD, 0); + gis_viewer_add(viewer, GIS_OBJECT(sat->tiles), GIS_LEVEL_WORLD, FALSE); return sat; }