From f10839bac21a067bd4eff50a160223e5796a587e Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 28 Apr 2015 10:21:49 +0300 Subject: [PATCH] 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. --- src/mbgl/map/resource_loader.cpp | 4 ++++ src/mbgl/map/resource_loader.hpp | 9 ++++++++- src/mbgl/text/glyph_store.cpp | 17 ++++++++++++++++- 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 00688911a..5dc0ab9d6 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 af518a48a..a4d10d038 100644 --- a/src/mbgl/map/resource_loader.hpp +++ b/src/mbgl/map/resource_loader.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -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 1871908b0..aed162ade 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()) {} +GlyphStore::GlyphStore(Environment& env_) + : env(env_), mtx(util::make_unique()), observer(nullptr) { +} + +GlyphStore::~GlyphStore() { + observer = nullptr; +} void GlyphStore::setURL(const std::string &url) { glyphURL = url; @@ -289,5 +295,14 @@ uv::exclusive 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 ee2097536..f92161995 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 &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 loadGlyphRange(const std::string &fontStack, std::map> &rangeSets, GlyphRange range); @@ -95,6 +107,8 @@ private: std::unordered_map>> ranges; std::unordered_map> stacks; std::unique_ptr mtx; + + Observer* observer; };