Skip to content

Commit 78c4e47

Browse files
committed
Copy blank tile to new buffer. Try to reuse blank tile when setting up rules
1 parent 074471e commit 78c4e47

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ int mapcache_cache_tile_get(mapcache_context *ctx, mapcache_cache *cache, mapcac
3737

3838
/* if tile is outside visible limits, return a blank tile */
3939
if (mapcache_ruleset_is_visible_tile(rule, tile) == MAPCACHE_FALSE) {
40-
tile->encoded_data = rule->hidden_tile;
40+
tile->encoded_data = mapcache_buffer_create(0, ctx->pool);
41+
mapcache_buffer_append(tile->encoded_data, rule->hidden_tile->size, rule->hidden_tile->buf);
4142
return MAPCACHE_SUCCESS;
4243
}
4344

lib/configuration_xml.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,9 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
817817

818818
// setup zoom level rules if configured
819819
if(ruleset) {
820+
mapcache_buffer *last_hidden_tile = NULL;
821+
unsigned int last_hidden_color;
822+
820823
// prepare one rule per zoom level. if rule is missing it will be NULL
821824
for(i = 0; i < grid->nlevels; i++) {
822825
mapcache_rule *rule = mapcache_ruleset_rule_find(ruleset->rules, i);
@@ -827,17 +830,24 @@ void parseTileset(mapcache_context *ctx, ezxml_t node, mapcache_cfg *config)
827830
if(rule->visible_extents) {
828831
int j;
829832

830-
// create empty tile in configured format to return when outside visible extent
831-
if(tileset->format) {
832-
rule_clone->hidden_tile = tileset->format->create_empty_image(ctx, tileset->format, grid->tile_sx, grid->tile_sy, rule->hidden_color);
833-
} else {
834-
rule_clone->hidden_tile = config->default_image_format->create_empty_image(ctx, config->default_image_format, grid->tile_sx, grid->tile_sy, rule->hidden_color);
835-
}
833+
// create blank tile in configured format to return when outside visible extent
834+
// try to reuse last tile if possible
835+
if(last_hidden_tile == NULL || last_hidden_color != rule->hidden_color) {
836+
if(tileset->format) {
837+
last_hidden_tile = tileset->format->create_empty_image(ctx, tileset->format, grid->tile_sx, grid->tile_sy, rule->hidden_color);
838+
} else {
839+
last_hidden_tile = config->default_image_format->create_empty_image(ctx, config->default_image_format, grid->tile_sx, grid->tile_sy, rule->hidden_color);
840+
}
836841

837-
if(GC_HAS_ERROR(ctx)) {
838-
return;
842+
if(GC_HAS_ERROR(ctx)) {
843+
return;
844+
}
845+
846+
last_hidden_color = rule->hidden_color;
839847
}
840848

849+
rule_clone->hidden_tile = last_hidden_tile;
850+
841851
// compute limits for extents
842852
for(j = 0; j < rule->visible_extents->nelts; j++) {
843853
mapcache_extent *visible_extent = APR_ARRAY_IDX(rule->visible_extents, j, mapcache_extent*);

0 commit comments

Comments
 (0)