@@ -94,7 +94,7 @@ tilecache_dispose(GObject *object)
9494
9595 FREESID (tilecache -> tilesource_changed_sid , tilecache -> tilesource );
9696 FREESID (tilecache -> tilesource_tiles_changed_sid , tilecache -> tilesource );
97- FREESID (tilecache -> tilesource_area_changed_sid , tilecache -> tilesource );
97+ FREESID (tilecache -> tilesource_collect_sid , tilecache -> tilesource );
9898 VIPS_UNREF (tilecache -> tilesource );
9999 VIPS_UNREF (tilecache -> background_texture );
100100
@@ -334,11 +334,11 @@ tilecache_find(Tilecache *tilecache, VipsRect *tile_rect, int z)
334334 return NULL ;
335335}
336336
337- /* Fetch a single tile. If we have this tile already, refresh if there are new
337+ /* Request a single tile. If we have this tile already, refresh if there are new
338338 * pixels available.
339339 */
340340static void
341- tilecache_get (Tilecache * tilecache , VipsRect * tile_rect , int z )
341+ tilecache_request (Tilecache * tilecache , VipsRect * tile_rect , int z )
342342{
343343 Tile * tile ;
344344
@@ -356,29 +356,30 @@ tilecache_get(Tilecache *tilecache, VipsRect *tile_rect, int z)
356356 }
357357
358358 if (!tile -> valid ) {
359- /* The tile might have no pixels, or might need refreshing
360- * because the bg render has finished with it.
361- */
362359#ifdef DEBUG_VERBOSE
363- printf ("tilecache_get : fetching left = %d, top = %d, "
360+ printf ("tilecache_request : fetching left = %d, top = %d, "
364361 "width = %d, height = %d, z = %d\n" ,
365362 tile_rect -> left , tile_rect -> top ,
366363 tile_rect -> width , tile_rect -> height ,
367364 z );
368365#endif /*DEBUG_VERBOSE*/
369366
370- tilesource_fill_tile (tilecache -> tilesource , tile );
367+ tilesource_request_tile (tilecache -> tilesource , tile );
371368 }
372369}
373370
374- /* Fetch the tiles in an area.
371+ /* Request tiles from an area. If they are not in cache, they will be computed
372+ * in the bg and delivered via _collect().
375373 *
376374 * render processes tiles in FIFO order, so we need to add in reverse order
377375 * of processing. We want repaint to happen in a spiral from the centre out,
378376 * so we have to add in a spiral from the outside in.
377+ *
378+ * We must be careful not to change tilesource if we have all these tiles
379+ * already (very common for thumbnails, for example).
379380 */
380381static void
381- tilecache_fetch_area (Tilecache * tilecache , VipsRect * viewport , int z )
382+ tilecache_request_area (Tilecache * tilecache , VipsRect * viewport , int z )
382383{
383384 int size0 = TILE_SIZE << z ;
384385
@@ -412,7 +413,7 @@ tilecache_fetch_area(Tilecache *tilecache, VipsRect *viewport, int z)
412413 for (x = left ; x < right ; x += size0 ) {
413414 tile_rect .left = x ;
414415 tile_rect .top = top ;
415- tilecache_get (tilecache , & tile_rect , z );
416+ tilecache_request (tilecache , & tile_rect , z );
416417 }
417418
418419 top += size0 ;
@@ -425,7 +426,7 @@ tilecache_fetch_area(Tilecache *tilecache, VipsRect *viewport, int z)
425426 for (x = left ; x < right ; x += size0 ) {
426427 tile_rect .left = x ;
427428 tile_rect .top = bottom - size0 ;
428- tilecache_get (tilecache , & tile_rect , z );
429+ tilecache_request (tilecache , & tile_rect , z );
429430 }
430431
431432 bottom -= size0 ;
@@ -438,7 +439,7 @@ tilecache_fetch_area(Tilecache *tilecache, VipsRect *viewport, int z)
438439 for (y = top ; y < bottom ; y += size0 ) {
439440 tile_rect .left = left ;
440441 tile_rect .top = y ;
441- tilecache_get (tilecache , & tile_rect , z );
442+ tilecache_request (tilecache , & tile_rect , z );
442443 }
443444
444445 left += size0 ;
@@ -451,7 +452,7 @@ tilecache_fetch_area(Tilecache *tilecache, VipsRect *viewport, int z)
451452 for (y = top ; y < bottom ; y += size0 ) {
452453 tile_rect .left = right - size0 ;
453454 tile_rect .top = y ;
454- tilecache_get (tilecache , & tile_rect , z );
455+ tilecache_request (tilecache , & tile_rect , z );
455456 }
456457
457458 right -= size0 ;
@@ -461,33 +462,35 @@ tilecache_fetch_area(Tilecache *tilecache, VipsRect *viewport, int z)
461462 }
462463}
463464
464- /* The bg render thread says some tiles have fresh pixels .
465+ /* A new tile is available from the bg render and must be collected .
465466 */
466467static void
467- tilecache_source_area_changed (Tilesource * tilesource ,
468+ tilecache_source_collect (Tilesource * tilesource ,
468469 VipsRect * dirty , int z , Tilecache * tilecache )
469470{
470471#ifdef DEBUG_VERBOSE
471- printf ("tilecache_source_area_changed : left = %d, top = %d, "
472+ printf ("tilecache_source_collect : left = %d, top = %d, "
472473 "width = %d, height = %d, z = %d\n" ,
473474 dirty -> left , dirty -> top ,
474475 dirty -> width , dirty -> height , z );
475476#endif /*DEBUG_VERBOSE*/
476477
477- /* Immediately fetch the updated tile. If we wait for snapshot, the
478- * animation page may have changed.
479- */
480- tilecache_fetch_area (tilecache , dirty , z );
478+ Tile * tile = tilecache_find ( tilecache , dirty , z );
479+ if ( tile &&
480+ ! tile -> valid ) {
481+ tilesource_collect_tile (tilecache -> tilesource , tile );
481482
482- tilecache_area_changed (tilecache , dirty , z );
483+ // things displaying us will need to redraw
484+ tilecache_area_changed (tilecache , dirty , z );
485+ }
483486}
484487
485488static void
486489tilecache_set_tilesource (Tilecache * tilecache , Tilesource * tilesource )
487490{
488491 FREESID (tilecache -> tilesource_changed_sid , tilecache -> tilesource );
489492 FREESID (tilecache -> tilesource_tiles_changed_sid , tilecache -> tilesource );
490- FREESID (tilecache -> tilesource_area_changed_sid , tilecache -> tilesource );
493+ FREESID (tilecache -> tilesource_collect_sid , tilecache -> tilesource );
491494 VIPS_UNREF (tilecache -> tilesource );
492495
493496 tilecache -> tilesource = tilesource ;
@@ -503,9 +506,9 @@ tilecache_set_tilesource(Tilecache *tilecache, Tilesource *tilesource)
503506 tilecache -> tilesource_tiles_changed_sid =
504507 g_signal_connect (tilesource , "tiles-changed" ,
505508 G_CALLBACK (tilecache_source_tiles_changed ), tilecache );
506- tilecache -> tilesource_area_changed_sid =
507- g_signal_connect (tilesource , "area-changed " ,
508- G_CALLBACK (tilecache_source_area_changed ), tilecache );
509+ tilecache -> tilesource_collect_sid =
510+ g_signal_connect (tilesource , "collect " ,
511+ G_CALLBACK (tilecache_source_collect ), tilecache );
509512
510513 /* Any tiles must be invalidated.
511514 */
@@ -946,7 +949,7 @@ tilecache_snapshot(Tilecache *tilecache, GtkSnapshot *snapshot,
946949 /* Fetch any tiles we are missing, update any tiles we have that have
947950 * been flagged as having pixels ready for fetching.
948951 */
949- tilecache_fetch_area (tilecache , & viewport , z );
952+ tilecache_request_area (tilecache , & viewport , z );
950953
951954 /* Find the set of visible tiles, sorted back to front.
952955 *
0 commit comments