summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2015-05-07 16:56:04 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2015-05-18 10:42:05 +0300
commitf222efb939a6c6055d97fdae6ed36960948864e6 (patch)
treecadb2b21736966dcb188777028bec192f48470d2 /src
parent27e5d18c42dbb17e63b334a092ad548e282e287c (diff)
downloadqtlocation-mapboxgl-f222efb939a6c6055d97fdae6ed36960948864e6.tar.gz
Keep a pointer to GlyphStore on ResourceLoader
For now, keep a pointer so we can subscribe/unsubscribe to events. In the future, we should move this object completely to ResourceLoader, but we can't do it now because we delete the ResourceLoader when changing the style.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/map/map_context.cpp4
-rw-r--r--src/mbgl/map/resource_loader.cpp21
-rw-r--r--src/mbgl/map/resource_loader.hpp11
3 files changed, 29 insertions, 7 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index 38a4104e72..5191293a08 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -134,6 +134,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
resourceLoader->setAccessToken(data.getAccessToken());
resourceLoader->setObserver(this);
resourceLoader->setStyle(style.get());
+ resourceLoader->setGlyphStore(glyphStore.get());
triggerUpdate(Update::Zoom);
}
@@ -141,8 +142,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
void MapContext::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
- resourceLoader->update(data, transformState, *glyphAtlas, *glyphStore,
- *spriteAtlas, *texturePool);
+ resourceLoader->update(data, transformState, *glyphAtlas, *spriteAtlas, *texturePool);
}
void MapContext::updateAnnotationTiles(const std::vector<TileID>& ids) {
diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp
index fba61cc649..0f5c33abd2 100644
--- a/src/mbgl/map/resource_loader.cpp
+++ b/src/mbgl/map/resource_loader.cpp
@@ -25,6 +25,10 @@ ResourceLoader::~ResourceLoader() {
if (sprite_) {
sprite_->setObserver(nullptr);
}
+
+ if (glyphStore_) {
+ glyphStore_->setObserver(nullptr);
+ }
}
void ResourceLoader::setObserver(Observer* observer) {
@@ -45,6 +49,18 @@ void ResourceLoader::setStyle(Style* style) {
}
}
+void ResourceLoader::setGlyphStore(GlyphStore* glyphStore) {
+ assert(glyphStore);
+
+ if (glyphStore_) {
+ glyphStore_->setObserver(nullptr);
+ }
+
+ glyphStore_ = glyphStore;
+ glyphStore_->setObserver(this);
+}
+
+
void ResourceLoader::setAccessToken(const std::string& accessToken) {
accessToken_ = accessToken;
}
@@ -52,7 +68,6 @@ void ResourceLoader::setAccessToken(const std::string& accessToken) {
void ResourceLoader::update(MapData& data,
const TransformState& transform,
GlyphAtlas& glyphAtlas,
- GlyphStore& glyphStore,
SpriteAtlas& spriteAtlas,
TexturePool& texturePool) {
if (!style_) {
@@ -69,8 +84,8 @@ void ResourceLoader::update(MapData& data,
}
for (const auto& source : style_->sources) {
- source->update(
- data, transform, *style_, glyphAtlas, glyphStore, spriteAtlas, sprite_, texturePool);
+ source->update(data, transform, *style_, glyphAtlas, *glyphStore_,
+ spriteAtlas, sprite_, texturePool);
}
}
diff --git a/src/mbgl/map/resource_loader.hpp b/src/mbgl/map/resource_loader.hpp
index a4d10d038e..6f63fe2260 100644
--- a/src/mbgl/map/resource_loader.hpp
+++ b/src/mbgl/map/resource_loader.hpp
@@ -43,13 +43,17 @@ public:
// a new style we will go through all of them and try to load.
void setStyle(Style* style);
+ // TODO: Move GlyphStore to ResourceLoader. We cannot do it now
+ // because we reset the ResourceLoader every time we change the
+ // style.
+ void setGlyphStore(GlyphStore* glyphStore);
+
// Set the access token to be used for loading the tile data.
void setAccessToken(const std::string& accessToken);
// Fetch the tiles needed by the current viewport and emit a signal when
// a tile is ready so observers can render the tile.
- void update(MapData&, const TransformState&, GlyphAtlas&, GlyphStore&,
- SpriteAtlas&, TexturePool&);
+ void update(MapData&, const TransformState&, GlyphAtlas&, SpriteAtlas&, TexturePool&);
// FIXME: There is probably a better place for this.
inline util::ptr<Sprite> getSprite() const {
@@ -71,7 +75,10 @@ private:
std::string accessToken_;
util::ptr<Sprite> sprite_;
+
+ GlyphStore* glyphStore_ = nullptr;
Style* style_ = nullptr;
+
Observer* observer_ = nullptr;
};