[libchamplain] Move fill_tile() call from view_load_visible_tiles() to an idle callback



commit e3e260fd40affa9d3dbf5964ba2b2c4d557000e7
Author: JiÅ?í Techet <techet gmail com>
Date:   Thu Mar 18 00:34:59 2010 +0100

    Move fill_tile() call from view_load_visible_tiles() to an idle callback
    
    Even though we load tiles asynchronously, the preparation steps take
    some time. Inside the inner loop of view_load_visible_tiles() the time
    is multiplied by the number of loaded tiles. For improved interactivity it
    is better to load tiles outside of the loop in idle functions so it can be
    interleaved with other main loop calls. This significantly improves
    interactivity in full screen launcher-gtk demo.
    
    Signed-off-by: JiÅ?í Techet <techet gmail com>
    
    add commit

 champlain/champlain-view.c |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)
---
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 9790e03..3b50dd6 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -124,6 +124,11 @@ typedef struct {
   ChamplainPolygon *polygon;
 } PolygonRedrawContext;
 
+typedef struct {
+  ChamplainTile *tile;
+  ChamplainMapSource *map_source;
+} FillTileCallbackData;
+
 struct _ChamplainViewPrivate
 {
   ClutterActor *stage;
@@ -233,6 +238,7 @@ static void champlain_view_go_to_with_duration (ChamplainView *view,
     gdouble longitude,
     guint duration);
 static gboolean perform_update_cb (ChamplainView *view);
+static gboolean fill_tile_cb (FillTileCallbackData *data);
 
 #define SCALE_HEIGHT  20
 #define SCALE_PADDING 10
@@ -2286,6 +2292,7 @@ view_load_visible_tiles (ChamplainView *view)
               if (!tile_map[(j - y_first) * x_count + (i - x_first)])
                 {
                   ChamplainTile *tile;
+                  FillTileCallbackData *data;
 
                   tile_map[(j - y_first) * x_count + (i - x_first)] = TRUE;
 
@@ -2299,7 +2306,16 @@ view_load_visible_tiles (ChamplainView *view)
                   view_position_tile (view, tile);
 
                   champlain_tile_set_state (tile, CHAMPLAIN_STATE_LOADING);
-                  champlain_map_source_fill_tile (priv->map_source, tile);
+
+                  data = g_new (FillTileCallbackData, 1);
+                  data->tile = tile;
+                  data->map_source = priv->map_source;
+
+                  g_object_add_weak_pointer (G_OBJECT (tile), (gpointer*)&data->tile);
+                  g_object_ref (priv->map_source);
+
+                  /* set priority high, otherwise tiles will be loaded after panning is done */
+                  g_idle_add_full (G_PRIORITY_HIGH_IDLE, (GSourceFunc) fill_tile_cb, data, NULL);
                 }
             }
           i += dirs[spiral_pos / arm_size + 1];
@@ -2314,6 +2330,24 @@ view_load_visible_tiles (ChamplainView *view)
   view_update_state (view);
 }
 
+static gboolean
+fill_tile_cb (FillTileCallbackData *data)
+{
+  ChamplainTile *tile = data->tile;
+  ChamplainMapSource *map_source = data->map_source;
+
+  if (data->tile)
+    {
+      g_object_remove_weak_pointer (G_OBJECT (data->tile), (gpointer*)&data->tile);
+      champlain_map_source_fill_tile (map_source, tile);
+    }
+
+  g_free (data);
+  g_object_unref (map_source);
+
+  return FALSE;
+}
+
 static void
 view_position_tile (ChamplainView* view,
     ChamplainTile* tile)



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