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:
Thiago Marcos P. Santos
2015-04-28 10:21:49 +03:00
parent 1455e5e53c
commit f10839bac2
4 changed files with 42 additions and 2 deletions

View File

@@ -73,6 +73,10 @@ void ResourceLoader::update(MapData& data,
}
}
void ResourceLoader::onGlyphRangeLoaded() {
emitTileDataChanged();
}
void ResourceLoader::onSourceLoaded() {
emitTileDataChanged();
}

View File

@@ -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;

View File

@@ -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();
}
}
}

View File

@@ -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;
};