From f222efb939a6c6055d97fdae6ed36960948864e6 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Thu, 7 May 2015 16:56:04 +0300 Subject: [PATCH] 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. --- src/mbgl/map/map_context.cpp | 4 ++-- src/mbgl/map/resource_loader.cpp | 21 ++++++++++++++++++--- src/mbgl/map/resource_loader.hpp | 11 +++++++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 38a4104e7..5191293a0 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& ids) { diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp index fba61cc64..0f5c33abd 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 a4d10d038..6f63fe226 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 getSprite() const { @@ -71,7 +75,10 @@ private: std::string accessToken_; util::ptr sprite_; + + GlyphStore* glyphStore_ = nullptr; Style* style_ = nullptr; + Observer* observer_ = nullptr; };