diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-04-28 10:21:49 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-05-05 18:35:40 +0300 |
commit | f10839bac21a067bd4eff50a160223e5796a587e (patch) | |
tree | b5343d48c0227dfc34f85d232d9b4e0b21595c42 /src | |
parent | 1455e5e53c1795401bec1b88272e93ce326d1753 (diff) | |
download | qtlocation-mapboxgl-f10839bac21a067bd4eff50a160223e5796a587e.tar.gz |
Make GlyphStore observable
GlyphStore will notify observers when a glyph range is loaded. By now
the notification is generic, but could be fine grained, causing the
processing of buckets depending on this particular range.
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/map/resource_loader.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/map/resource_loader.hpp | 9 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/text/glyph_store.hpp | 14 |
4 files changed, 42 insertions, 2 deletions
diff --git a/src/mbgl/map/resource_loader.cpp b/src/mbgl/map/resource_loader.cpp index 00688911a9..5dc0ab9d62 100644 --- a/src/mbgl/map/resource_loader.cpp +++ b/src/mbgl/map/resource_loader.cpp @@ -73,6 +73,10 @@ void ResourceLoader::update(MapData& data, } } +void ResourceLoader::onGlyphRangeLoaded() { + emitTileDataChanged(); +} + void ResourceLoader::onSourceLoaded() { emitTileDataChanged(); } diff --git a/src/mbgl/map/resource_loader.hpp b/src/mbgl/map/resource_loader.hpp index af518a48a7..a4d10d038e 100644 --- a/src/mbgl/map/resource_loader.hpp +++ b/src/mbgl/map/resource_loader.hpp @@ -3,6 +3,7 @@ #include <mbgl/map/source.hpp> #include <mbgl/map/sprite.hpp> +#include <mbgl/text/glyph_store.hpp> #include <mbgl/util/noncopyable.hpp> #include <string> @@ -21,7 +22,10 @@ class TransformState; // by the Style. The Source object currently owns all the tiles, thus this // class will notify its observers of any change on these tiles which will // ultimately cause a new rendering to be triggered. -class ResourceLoader : public Source::Observer, public Sprite::Observer, private util::noncopyable { +class ResourceLoader : public GlyphStore::Observer, + public Source::Observer, + public Sprite::Observer, + private util::noncopyable { public: class Observer { public: @@ -52,6 +56,9 @@ public: return sprite_; } + // GlyphStore::Observer implementation. + void onGlyphRangeLoaded() override; + // Source::Observer implementation. void onSourceLoaded() override; void onTileLoaded() override; diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index 1871908b02..aed162ade2 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -226,7 +226,13 @@ void GlyphPBF::parse(FontStack &stack) { data.clear(); } -GlyphStore::GlyphStore(Environment& env_) : env(env_), mtx(util::make_unique<uv::mutex>()) {} +GlyphStore::GlyphStore(Environment& env_) + : env(env_), mtx(util::make_unique<uv::mutex>()), observer(nullptr) { +} + +GlyphStore::~GlyphStore() { + observer = nullptr; +} void GlyphStore::setURL(const std::string &url) { glyphURL = url; @@ -289,5 +295,14 @@ uv::exclusive<FontStack> GlyphStore::getFontStack(const std::string &fontStack) return stack; } +void GlyphStore::setObserver(Observer* observer_) { + observer = observer_; +} + +void GlyphStore::emitGlyphRangeLoaded() { + if (observer) { + observer->onGlyphRangeLoaded(); + } +} } diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index ee2097536c..f92161995a 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -75,7 +75,15 @@ private: // Manages Glyphrange PBF loading. class GlyphStore { public: + class Observer { + public: + virtual ~Observer() = default; + + virtual void onGlyphRangeLoaded() = 0; + }; + GlyphStore(Environment &); + ~GlyphStore(); // Block until all specified GlyphRanges of the specified font stack are loaded. void waitForGlyphRanges(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges); @@ -84,7 +92,11 @@ public: void setURL(const std::string &url); + void setObserver(Observer* observer); + private: + void emitGlyphRangeLoaded(); + // Loads an individual glyph range from the font stack and adds it to rangeSets std::shared_future<GlyphPBF &> loadGlyphRange(const std::string &fontStack, std::map<GlyphRange, std::unique_ptr<GlyphPBF>> &rangeSets, GlyphRange range); @@ -95,6 +107,8 @@ private: std::unordered_map<std::string, std::map<GlyphRange, std::unique_ptr<GlyphPBF>>> ranges; std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks; std::unique_ptr<uv::mutex> mtx; + + Observer* observer; }; |