champlain-memphis-renderer.c 19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/*
 * Copyright (C) 2009 Simon Wenner <simon@wenner.ch>
 * Copyright (C) 2010 Jiri Techet <techet@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/*
 * SECTION:champlain-memphis-tile-source
 * @short_description: A map source that draws tiles locally
 *
 * The #ChamplainMemphisRenderer uses the rendering library
 * <ulink role="online-location" url="https://trac.openstreetmap.ch/trac/memphis/">
 * LibMemphis</ulink> to draw <ulink role="online-location" url="http://www.openstreetmap.org/">
 * OpenStreetMap</ulink> data. Tiles are rendered in separate threads.
 * It supports zoom levels 12 to 18.
 *
 * The map data is supplied by a #ChamplainMapDataSource.
 * #ChamplainLocalMapDataSource loads data from a local OSM file.
 * #ChamplainNetworkMapDataSource uses the OSM API to download data chunks.
 *
 * The output of the renderer can be configured with a Memphis rules XML file.
 * (TODO: link to the specification) The default rules only show
 * highways as thin black lines.
 * Once loaded, rules can be queried and edited.
 */


#define DEBUG_FLAG CHAMPLAIN_DEBUG_MEMPHIS
#include "champlain-debug.h"
#include "champlain-tile-cache.h"
#include "champlain-renderer.h"
#include "champlain-defines.h"
#include "champlain-enum-types.h"
#include "champlain-private.h"
#include "champlain-memphis-renderer.h"
#include "champlain-bounding-box.h"

#include <gdk/gdk.h>

#include <memphis/memphis.h>
#include <errno.h>
#include <string.h>

/* Tuning parameters */
#define MAX_THREADS 4

const gchar default_rules[] =
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
  "<rules version=\"0.1\" background=\"#ffffff\">"
63 64 65
  "<rule e=\"way\" k=\"highway\" v=\"*\">"
  "<line color=\"#000000\" width=\"1.0\"/>"
  "</rule>"
66 67 68 69 70 71 72 73 74
  "</rules>";

enum
{
  PROP_0,
  PROP_TILE_SIZE,
  PROP_BOUNDING_BOX
};

75 76 77 78 79 80 81
static void render (ChamplainRenderer *renderer,
    ChamplainTile *tile);
static void set_data (ChamplainRenderer *renderer,
    const gchar *data,
    guint size);
static void set_bounding_box (ChamplainMemphisRenderer *renderer,
    ChamplainBoundingBox *bbox);
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115


G_DEFINE_TYPE (ChamplainMemphisRenderer, champlain_memphis_renderer, CHAMPLAIN_TYPE_RENDERER)

#define GET_PRIVATE(o) \
  (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHAMPLAIN_TYPE_MEMPHIS_RENDERER, ChamplainMemphisRendererPrivate))

struct _ChamplainMemphisRendererPrivate
{
  MemphisRuleSet *rules;
  MemphisRenderer *renderer;
  GThreadPool *thpool;
  guint tile_size;
  ChamplainBoundingBox *bbox;
};

typedef struct _WorkerThreadData WorkerThreadData;

struct _WorkerThreadData
{
  gint x;
  gint y;
  guint z;
  guint size;

  ChamplainRenderer *renderer;
  ChamplainTile *tile;
  cairo_surface_t *cst;
};

/* lock to protect the renderer state while rendering */
GStaticRWLock MemphisLock = G_STATIC_RW_LOCK_INIT;


116 117 118
static void memphis_worker_thread (gpointer data,
    gpointer user_data);

119 120 121 122 123 124 125 126 127 128 129

static void
champlain_memphis_renderer_get_property (GObject *object,
    guint property_id,
    GValue *value,
    GParamSpec *pspec)
{
  ChamplainMemphisRenderer *renderer = CHAMPLAIN_MEMPHIS_RENDERER (object);

  switch (property_id)
    {
130 131 132 133 134 135 136 137 138 139
    case PROP_TILE_SIZE:
      g_value_set_uint (value, champlain_memphis_renderer_get_tile_size (renderer));
      break;

    case PROP_BOUNDING_BOX:
      g_value_set_boxed (value, champlain_memphis_renderer_get_bounding_box (renderer));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
140 141 142
    }
}

143

144 145 146 147 148 149 150 151 152 153
static void
champlain_memphis_renderer_set_property (GObject *object,
    guint property_id,
    const GValue *value,
    GParamSpec *pspec)
{
  ChamplainMemphisRenderer *renderer = CHAMPLAIN_MEMPHIS_RENDERER (object);

  switch (property_id)
    {
154 155 156 157 158 159 160 161 162 163
    case PROP_TILE_SIZE:
      champlain_memphis_renderer_set_tile_size (renderer, g_value_get_uint (value));
      break;

    case PROP_BOUNDING_BOX:
      set_bounding_box (renderer, g_value_get_boxed (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
164 165 166
    }
}

167

168 169 170
static void
champlain_memphis_renderer_dispose (GObject *object)
{
171
  ChamplainMemphisRenderer *renderer = CHAMPLAIN_MEMPHIS_RENDERER (object);
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
  ChamplainMemphisRendererPrivate *priv = renderer->priv;

  if (priv->thpool)
    {
      g_thread_pool_free (priv->thpool, FALSE, TRUE);
      priv->thpool = NULL;
    }
  if (priv->renderer)
    {
      memphis_renderer_free (priv->renderer);
      priv->renderer = NULL;
    }
  if (priv->rules)
    {
      memphis_rule_set_free (priv->rules);
      priv->rules = NULL;
    }

  G_OBJECT_CLASS (champlain_memphis_renderer_parent_class)->dispose (object);
}

193

194 195 196
static void
champlain_memphis_renderer_finalize (GObject *object)
{
197
  ChamplainMemphisRenderer *renderer = CHAMPLAIN_MEMPHIS_RENDERER (object);
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
  ChamplainMemphisRendererPrivate *priv = renderer->priv;

  champlain_bounding_box_free (priv->bbox);

  G_OBJECT_CLASS (champlain_memphis_renderer_parent_class)->finalize (object);
}


static void
champlain_memphis_renderer_class_init (ChamplainMemphisRendererClass *klass)
{
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
  ChamplainRendererClass *renderer_class = CHAMPLAIN_RENDERER_CLASS (klass);

  g_type_class_add_private (klass, sizeof (ChamplainMemphisRendererPrivate));

  object_class->get_property = champlain_memphis_renderer_get_property;
  object_class->set_property = champlain_memphis_renderer_set_property;
  object_class->dispose = champlain_memphis_renderer_dispose;
  object_class->finalize = champlain_memphis_renderer_finalize;

  renderer_class->set_data = set_data;
  renderer_class->render = render;

  g_object_class_install_property (object_class,
      PROP_TILE_SIZE,
      g_param_spec_uint ("tile-size",
          "Tile Size",
          "The size of the rendered tile",
          0,
          G_MAXINT,
          256,
          G_PARAM_READWRITE));

  /*
233 234 235 236 237 238
   * ChamplainMapDataSource:bounding-box:
   *
   * The bounding box of the area that contains map data.
   *
   * Since: 0.6
   */
239 240 241
  g_object_class_install_property (object_class,
      PROP_BOUNDING_BOX,
      g_param_spec_boxed ("bounding-box",
242 243 244 245
          "Bounding Box",
          "The bounding box of the renderer",
          CHAMPLAIN_TYPE_BOUNDING_BOX,
          G_PARAM_READWRITE));
246 247
}

248

249 250 251
static void
champlain_memphis_renderer_init (ChamplainMemphisRenderer *renderer)
{
252
  ChamplainMemphisRendererPrivate *priv = GET_PRIVATE (renderer);
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

  renderer->priv = priv;

  priv->rules = memphis_rule_set_new ();
  memphis_rule_set_load_from_data (priv->rules, default_rules,
      strlen (default_rules), NULL);

  priv->renderer = memphis_renderer_new_full (priv->rules, memphis_map_new ());

  priv->thpool = g_thread_pool_new (memphis_worker_thread, renderer,
      MAX_THREADS, FALSE, NULL);

  priv->bbox = NULL;
}

268 269 270

ChamplainMemphisRenderer *
champlain_memphis_renderer_new_full (guint tile_size)
271 272 273 274 275 276
{
  return g_object_new (CHAMPLAIN_TYPE_MEMPHIS_RENDERER, "tile-size", tile_size, NULL);
}


/*
277 278 279 280 281
 * Transform ARGB (Cairo) to RGBA (GdkPixbuf). RGBA is actualy reversed in
 * memory, so the transformation is ARGB -> ABGR (i.e. swapping B and R)
 */
static void
argb_to_rgba (guchar *data,
282 283 284
    guint size)
{
  guint32 *ptr;
285 286 287
  guint32 *endptr = (guint32 *) data + size / 4;

  for (ptr = (guint32 *) data; ptr < endptr; ptr++)
288 289 290
    *ptr = (*ptr & 0xFF00FF00) ^ ((*ptr & 0xFF0000) >> 16) ^ ((*ptr & 0xFF) << 16);
}

291

292 293 294 295 296 297
static gboolean
tile_loaded_cb (gpointer worker_data)
{
  WorkerThreadData *data = (WorkerThreadData *) worker_data;
  ChamplainTile *tile = data->tile;
  cairo_surface_t *cst = data->cst;
298
  ChamplainRenderer *renderer = CHAMPLAIN_RENDERER (data->renderer);
299 300 301 302 303
  ChamplainRenderCallbackData callback_data;
  cairo_t *cr_clutter;
  ClutterActor *actor;
  guint size = data->size;
  GError *error = NULL;
304
  GdkPixbuf *pixbuf = NULL;
305 306 307
  gchar *buffer = NULL;
  gsize buffer_size;

308
  g_slice_free (WorkerThreadData, data);
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332

  if (!tile)
    {
      DEBUG ("Tile destroyed while loading");
      goto error;
    }

  if (!cst)
    goto error;

  /* draw the clutter texture */
  actor = clutter_cairo_texture_new (size, size);

  cr_clutter = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE (actor));
  cairo_set_source_surface (cr_clutter, cst, 0, 0);
  cairo_paint (cr_clutter);
  cairo_destroy (cr_clutter);

  /* modify directly the buffer of cairo surface - we don't use it any more
     and we close the surface anyway */
  argb_to_rgba (cairo_image_surface_get_data (cst),
      cairo_image_surface_get_stride (cst) * cairo_image_surface_get_height (cst));

  pixbuf = gdk_pixbuf_new_from_data (cairo_image_surface_get_data (cst),
333 334
      GDK_COLORSPACE_RGB, TRUE, 8, size, size,
      cairo_image_surface_get_stride (cst), NULL, NULL);
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351

  if (!gdk_pixbuf_save_to_buffer (pixbuf, &buffer, &buffer_size, "png", &error, NULL))
    goto error;

  champlain_tile_set_content (tile, actor);

  callback_data.error = FALSE;
  callback_data.data = buffer;
  callback_data.size = buffer_size;
  goto finish;

error:
  callback_data.error = TRUE;
  callback_data.data = NULL;
  callback_data.size = 0;

finish:
352 353
  if (tile)
    g_signal_emit_by_name (tile, "render-complete", &callback_data);
354 355 356 357 358 359

  if (pixbuf)
    g_object_unref (pixbuf);
  if (cst)
    cairo_surface_destroy (cst);
  g_object_unref (renderer);
360
  g_object_unref (tile);
361 362 363 364 365
  g_free (buffer);

  return FALSE;
}

366

367 368 369 370
static void
memphis_worker_thread (gpointer worker_data,
    G_GNUC_UNUSED gpointer user_data)
{
371
  WorkerThreadData *data = (WorkerThreadData *) worker_data;
372 373 374 375 376
  ChamplainMemphisRenderer *renderer = CHAMPLAIN_MEMPHIS_RENDERER (data->renderer);
  gboolean has_data = TRUE;

  data->cst = NULL;

377 378 379 380
/* uncomment when libmemphis works correctly */
/*  g_static_rw_lock_reader_lock (&MemphisLock);
 *  has_data = memphis_renderer_tile_has_data (renderer->priv->renderer, data->x, data->y, data->z);
 *  g_static_rw_lock_reader_unlock (&MemphisLock); */
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401

  if (has_data)
    {
      cairo_t *cr;

      /* create a clutter-independant surface to draw on */
      data->cst = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, data->size, data->size);
      cr = cairo_create (data->cst);

      DEBUG ("Draw Tile (%d, %d, %d)", data->x, data->y, data->z);

      g_static_rw_lock_reader_lock (&MemphisLock);
      memphis_renderer_draw_tile (renderer->priv->renderer, cr, data->x, data->y, data->z);
      g_static_rw_lock_reader_unlock (&MemphisLock);

      cairo_destroy (cr);
    }

  clutter_threads_add_idle_full (G_PRIORITY_DEFAULT, tile_loaded_cb, data, NULL);
}

402

403 404
static void
render (ChamplainRenderer *renderer,
405
    ChamplainTile *tile)
406 407 408 409 410 411 412 413
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  ChamplainMemphisRendererPrivate *priv = CHAMPLAIN_MEMPHIS_RENDERER (renderer)->priv;
  GError *error = NULL;
  WorkerThreadData *data;

  DEBUG ("Render tile (%u, %u, %u)", champlain_tile_get_x (tile),
414 415
      champlain_tile_get_y (tile),
      champlain_tile_get_zoom_level (tile));
416

417
  data = g_slice_new (WorkerThreadData);
418 419 420 421 422 423 424
  data->x = champlain_tile_get_x (tile);
  data->y = champlain_tile_get_y (tile);
  data->z = champlain_tile_get_zoom_level (tile);
  data->size = priv->tile_size;
  data->tile = tile;
  data->renderer = renderer;

425
  g_object_ref (tile);
426 427 428 429 430 431 432
  g_object_ref (renderer);

  g_thread_pool_push (priv->thpool, data, &error);
  if (error)
    {
      g_error ("Thread pool error: %s", error->message);
      g_error_free (error);
433
      g_slice_free (WorkerThreadData, data);
434
      g_object_unref (renderer);
435
      g_object_unref (tile);
436 437 438
    }
}

439

440 441 442 443 444 445 446 447 448 449
static void
set_data (ChamplainRenderer *renderer,
    const gchar *data,
    guint size)
{
  ChamplainMemphisRendererPrivate *priv = GET_PRIVATE (renderer);
  ChamplainBoundingBox *bbox;
  GError *err = NULL;

  MemphisMap *map = memphis_map_new ();
450

451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
  memphis_map_load_from_data (map, data, size, &err);

  DEBUG ("BBox data received");

  if (err != NULL)
    {
      g_critical ("Can't load map data: \"%s\"", err->message);
      memphis_map_free (map);
      g_error_free (err);
      return;
    }

  g_static_rw_lock_writer_lock (&MemphisLock);
  memphis_renderer_set_map (priv->renderer, map);
  g_static_rw_lock_writer_unlock (&MemphisLock);

  bbox = champlain_bounding_box_new ();

  memphis_map_get_bounding_box (map, &bbox->left, &bbox->top,
      &bbox->right, &bbox->bottom);
  g_object_set (G_OBJECT (renderer), "bounding-box", bbox, NULL);
  champlain_bounding_box_free (bbox);
}

475

476
/*
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
 * champlain_memphis_renderer_load_rules:
 * @renderer: a #ChamplainMemphisRenderer
 * @rules_path: a path to a rules file
 *
 * Loads a Memphis rules file.
 *
 * Since: 0.6
 */
void
champlain_memphis_renderer_load_rules (
    ChamplainMemphisRenderer *renderer,
    const gchar *rules_path)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  ChamplainMemphisRendererPrivate *priv = renderer->priv;
  GError *err = NULL;

495
  /* TODO: Remove test when memphis handles invalid paths properly */
496 497 498 499 500 501 502 503 504 505 506
  if (!g_file_test (rules_path, G_FILE_TEST_EXISTS))
    {
      g_critical ("Error: \"%s\" does not exist.", rules_path);
      return;
    }

  g_static_rw_lock_writer_lock (&MemphisLock);
  if (rules_path)
    {
      memphis_rule_set_load_from_file (priv->rules, rules_path, &err);
      if (err != NULL)
507
        {
508 509
          g_critical ("Can't load rules file: \"%s\"", err->message);
          memphis_rule_set_load_from_data (priv->rules, default_rules,
510
              strlen (default_rules), NULL);
511 512 513
          g_static_rw_lock_writer_unlock (&MemphisLock);
          g_error_free (err);
          return;
514
        }
515 516 517
    }
  else
    memphis_rule_set_load_from_data (priv->rules, default_rules,
518
        strlen (default_rules), NULL);
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554

  g_static_rw_lock_writer_unlock (&MemphisLock);
}


/*
 * champlain_memphis_renderer_get_background_color:
 * @renderer: a #ChamplainMemphisRenderer
 *
 * Gets the background color of the map.
 *
 * Returns: the background color of the map as a newly-allocated
 * #ClutterColor.
 *
 * Since: 0.6
 */
ClutterColor *
champlain_memphis_renderer_get_background_color (
    ChamplainMemphisRenderer *renderer)
{
  g_return_val_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer), NULL);

  ClutterColor color;
  guint8 r, b, g, a;

  g_static_rw_lock_reader_lock (&MemphisLock);
  memphis_rule_set_get_bg_color (renderer->priv->rules, &r, &g, &b, &a);
  g_static_rw_lock_reader_unlock (&MemphisLock);

  color.red = r;
  color.green = g;
  color.blue = b;
  color.alpha = a;
  return clutter_color_copy (&color);
}

555

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
/*
 * champlain_memphis_renderer_set_background_color:
 * @renderer: a #ChamplainMemphisRenderer
 * @color: a #ClutterColor
 *
 * Sets the background color of the map from a #ClutterColor.
 *
 * Since: 0.6
 */
void
champlain_memphis_renderer_set_background_color (
    ChamplainMemphisRenderer *renderer,
    const ClutterColor *color)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  g_static_rw_lock_writer_lock (&MemphisLock);
  memphis_rule_set_set_bg_color (renderer->priv->rules, color->red,
574
      color->green, color->blue, color->alpha);
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
  g_static_rw_lock_writer_unlock (&MemphisLock);
}


/*
 * champlain_memphis_renderer_set_rule:
 * @renderer: a #ChamplainMemphisRenderer
 * @rule: a #MemphisRule
 *
 * Edits or adds a #ChamplainMemphisRule to the rules-set. New rules are appended
 *  to the list.
 *
 * Since: 0.6
 */
void
champlain_memphis_renderer_set_rule (ChamplainMemphisRenderer *renderer,
    ChamplainMemphisRule *rule)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer) &&
594
      MEMPHIS_RULE (rule));
595 596

  g_static_rw_lock_writer_lock (&MemphisLock);
597
  memphis_rule_set_set_rule (renderer->priv->rules, (MemphisRule *) rule);
598 599 600
  g_static_rw_lock_writer_unlock (&MemphisLock);
}

601

602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617
/*
 * champlain_memphis_renderer_get_rule:
 * @renderer: a #ChamplainMemphisRenderer
 * @id: an id string
 *
 * Gets the requested #ChamplainMemphisRule.
 *
 * Returns: the requested #ChamplainMemphisRule or NULL if none is found.
 *
 * Since: 0.6
 */
ChamplainMemphisRule *
champlain_memphis_renderer_get_rule (ChamplainMemphisRenderer *renderer,
    const gchar *id)
{
  g_return_val_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer) &&
618
      id != NULL, NULL);
619 620 621 622 623 624 625 626 627 628

  MemphisRule *rule;

  g_static_rw_lock_reader_lock (&MemphisLock);
  rule = memphis_rule_set_get_rule (renderer->priv->rules, id);
  g_static_rw_lock_reader_unlock (&MemphisLock);

  return (ChamplainMemphisRule *) rule;
}

629

630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
/*
 * champlain_memphis_renderer_get_rule_ids:
 * @renderer: a #ChamplainMemphisRenderer
 *
 * Get a list of rule id's.
 *
 * Returns: a #GList of id strings of the form:
 * key1|key2|...|keyN:value1|value2|...|valueM
 *
 * Example: "waterway:river|stream|canal"
 *
 * Since: 0.6
 */
GList *
champlain_memphis_renderer_get_rule_ids (ChamplainMemphisRenderer *renderer)
{
  g_return_val_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer), NULL);

  GList *list;

  g_static_rw_lock_reader_lock (&MemphisLock);
  list = memphis_rule_set_get_rule_ids (renderer->priv->rules);
  g_static_rw_lock_reader_unlock (&MemphisLock);

  return list;
}

657

658 659 660 661 662 663 664 665 666
/*
 * champlain_memphis_renderer_remove_rule:
 * @renderer: a #ChamplainMemphisRenderer
 * @id: an id string
 *
 * Removes the rule with the given id.
 *
 * Since: 0.6
 */
667 668
void
champlain_memphis_renderer_remove_rule (
669 670 671 672 673 674 675 676 677 678
    ChamplainMemphisRenderer *renderer,
    const gchar *id)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  g_static_rw_lock_writer_lock (&MemphisLock);
  memphis_rule_set_remove_rule (renderer->priv->rules, id);
  g_static_rw_lock_writer_unlock (&MemphisLock);
}

679

680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
void
champlain_memphis_renderer_set_tile_size (ChamplainMemphisRenderer *renderer,
    guint size)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  ChamplainMemphisRendererPrivate *priv = GET_PRIVATE (renderer);

  renderer->priv->tile_size = size;

  g_static_rw_lock_writer_lock (&MemphisLock);
  memphis_renderer_set_resolution (priv->renderer, size);
  g_static_rw_lock_writer_unlock (&MemphisLock);

  g_object_notify (G_OBJECT (renderer), "tile-size");
}

697

698 699 700 701 702 703 704 705
guint
champlain_memphis_renderer_get_tile_size (ChamplainMemphisRenderer *renderer)
{
  g_return_val_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer), 0);

  return renderer->priv->tile_size;
}

706

707 708 709 710 711 712 713 714 715 716
ChamplainBoundingBox *
champlain_memphis_renderer_get_bounding_box (ChamplainMemphisRenderer *renderer)
{
  g_return_val_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer), NULL);

  ChamplainMemphisRendererPrivate *priv = renderer->priv;

  return priv->bbox;
}

717

718 719 720 721 722 723 724 725 726 727
static void
set_bounding_box (ChamplainMemphisRenderer *renderer, ChamplainBoundingBox *bbox)
{
  g_return_if_fail (CHAMPLAIN_IS_MEMPHIS_RENDERER (renderer));

  ChamplainMemphisRendererPrivate *priv = renderer->priv;

  champlain_bounding_box_free (priv->bbox);
  priv->bbox = champlain_bounding_box_copy (bbox);
}