diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2014-11-25 14:18:47 -0500 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2014-12-03 12:25:11 -0500 |
commit | dac76a0f9269a580706e52b730a98f9b1430bcdf (patch) | |
tree | b7c592b648a443ef456479ddd2e21fe66d22abad /src/map/map.cpp | |
parent | d3ab8951530b760afb19e685078b1480babc2209 (diff) | |
download | qtlocation-mapboxgl-dac76a0f9269a580706e52b730a98f9b1430bcdf.tar.gz |
break out FileSource as an abstract class
add CachingHTTPFileSource implementation
Diffstat (limited to 'src/map/map.cpp')
-rw-r--r-- | src/map/map.cpp | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/src/map/map.cpp b/src/map/map.cpp index cc22e048f7..a33200fe0b 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -85,13 +85,14 @@ const static bool sqlite_version_check = []() { using namespace mbgl; -Map::Map(View& view_) +Map::Map(View& view_, FileSource& fileSource_) : loop(util::make_unique<uv::loop>()), view(view_), #ifndef NDEBUG mainThread(uv_thread_self()), #endif transform(view_), + fileSource(fileSource_), glyphAtlas(1024, 1024), spriteAtlas(512, 512), texturePool(std::make_shared<TexturePool>()), @@ -115,7 +116,6 @@ Map::~Map() { glyphStore.reset(); style.reset(); texturePool.reset(); - fileSource.reset(); workers.reset(); uv_run(**loop, UV_RUN_DEFAULT); @@ -145,7 +145,6 @@ void Map::start() { // Remove all of these to make sure they are destructed in the correct thread. glyphStore.reset(); - fileSource.reset(); style.reset(); workers.reset(); activeSources.clear(); @@ -286,11 +285,9 @@ void Map::terminate() { void Map::setReachability(bool reachable) { // Note: This function may be called from *any* thread. if (reachable) { - if (fileSource) { - fileSource->prepare([&]() { - fileSource->retryAllPending(); - }); - } + fileSource.prepare([&]() { + fileSource.retryAllPending(); + }); } } @@ -317,11 +314,11 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) { style = std::make_shared<Style>(); } style->loadJSON((const uint8_t *)styleJSON.c_str()); - if (!fileSource) { - fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared<GlyphStore>(*fileSource); + if (!fileSource.hasLoop()) { + fileSource.setLoop(**loop); + glyphStore = std::make_shared<GlyphStore>(fileSource); } - fileSource->setBase(base); + fileSource.setBase(base); glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken())); update(); } @@ -343,7 +340,7 @@ util::ptr<Sprite> Map::getSprite() { const float pixelRatio = state.getPixelRatio(); const std::string &sprite_url = style->getSpriteURL(); if (!sprite || sprite->pixelRatio != pixelRatio) { - sprite = Sprite::Create(sprite_url, pixelRatio, *fileSource); + sprite = Sprite::Create(sprite_url, pixelRatio, fileSource); } return sprite; @@ -554,7 +551,7 @@ void Map::updateSources() { if (source->enabled) { if (!source->source) { source->source = std::make_shared<Source>(source->info); - source->source->load(*this, *fileSource); + source->source->load(*this, fileSource); } } else { source->source.reset(); @@ -588,20 +585,20 @@ void Map::updateTiles() { source->source->update(*this, getWorker(), style, glyphAtlas, *glyphStore, spriteAtlas, getSprite(), - *texturePool, *fileSource, [this](){ update(); }); + *texturePool, fileSource, [this](){ update(); }); } } void Map::prepare() { - if (!fileSource) { - fileSource = std::make_shared<FileSource>(**loop, platform::defaultCacheDatabase()); - glyphStore = std::make_shared<GlyphStore>(*fileSource); + if (!fileSource.hasLoop()) { + fileSource.setLoop(**loop); + glyphStore = std::make_shared<GlyphStore>(fileSource); } if (!style) { style = std::make_shared<Style>(); - fileSource->request(ResourceType::JSON, styleURL)->onload([&](const Response &res) { + fileSource.request(ResourceType::JSON, styleURL)->onload([&](const Response &res) { if (res.code == 200) { // Calculate the base const size_t pos = styleURL.rfind('/'); |