From 4956da61b9112618cd0ae7e247ca532582648cb7 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 21 Apr 2015 12:05:37 +0200 Subject: Introduce the ResourceLoader ResourceLoader will handle all the tile changes and notifications through the Source object owned by the Style. This object lives entirely on the Map thread and should be only accessed by it. The observer will receive notifications every time the tile data changes and this will probably trigger a new rendering operation. This first patch will delegate Source loading to the ResourceLoader. --- src/mbgl/map/map_context.cpp | 17 +++++++++----- src/mbgl/map/map_context.hpp | 7 +++++- src/mbgl/map/resource_loader.cpp | 48 ++++++++++++++++++++++++++++++++++++++++ src/mbgl/map/resource_loader.hpp | 47 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 7 deletions(-) create mode 100644 src/mbgl/map/resource_loader.cpp create mode 100644 src/mbgl/map/resource_loader.hpp diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 4e0a04472..c14cedb03 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -62,6 +62,7 @@ MapContext::~MapContext() { // Explicit resets currently necessary because these abandon resources that need to be // cleaned up by env.performCleanup(); + resourceLoader.reset(); style.reset(); sprite.reset(); painter.reset(); @@ -141,6 +142,7 @@ util::ptr MapContext::getSprite() { void MapContext::loadStyleJSON(const std::string& json, const std::string& base) { assert(Environment::currentlyOn(ThreadType::Map)); + resourceLoader.reset(); sprite.reset(); style.reset(); @@ -153,12 +155,10 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base) const std::string glyphURL = util::mapbox::normalizeGlyphsURL(style->glyph_url, data.getAccessToken()); glyphStore->setURL(glyphURL); - for (const auto& source : style->sources) { - source->load(data.getAccessToken(), env, [this]() { - assert(Environment::currentlyOn(ThreadType::Map)); - triggerUpdate(); - }); - } + resourceLoader = util::make_unique(); + resourceLoader->setAccessToken(data.getAccessToken()); + resourceLoader->setObserver(this); + resourceLoader->setStyle(style.get()); triggerUpdate(Update::Zoom); } @@ -299,4 +299,9 @@ void MapContext::onLowMemory() { view.invalidate([this] { render(); }); } +void MapContext::onTileDataChanged() { + assert(Environment::currentlyOn(ThreadType::Map)); + triggerUpdate(); +} + } diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 93670fd1f..6941c3040 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -32,7 +33,7 @@ class StillImage; struct LatLng; struct LatLngBounds; -class MapContext { +class MapContext : public ResourceLoader::Observer { public: MapContext(uv_loop_t*, View&, FileSource&, MapData&, bool startPaused); ~MapContext(); @@ -58,6 +59,9 @@ public: void setSourceTileCacheSize(size_t size); void onLowMemory(); + // ResourceLoader::Observer implementation. + void onTileDataChanged() override; + private: util::ptr getSprite(); void updateTiles(); @@ -84,6 +88,7 @@ private: std::unique_ptr texturePool; std::unique_ptr painter; std::unique_ptr