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.
This commit is contained in:
@@ -73,6 +73,10 @@ void ResourceLoader::update(MapData& data,
|
||||
}
|
||||
}
|
||||
|
||||
void ResourceLoader::onGlyphRangeLoaded() {
|
||||
emitTileDataChanged();
|
||||
}
|
||||
|
||||
void ResourceLoader::onSourceLoaded() {
|
||||
emitTileDataChanged();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user