Emit the signal on the MapThread

We were previously emitting the signal on the thread parsing the
glyph, but signals can only be trigger from the MapThread
because the observers are living there.
This commit is contained in:
Thiago Marcos P. Santos
2015-05-07 21:00:20 +03:00
parent f222efb939
commit 41dc5e836a
3 changed files with 19 additions and 5 deletions

View File

@@ -36,7 +36,7 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map
envScope(env, ThreadType::Map, "Map"),
updated(static_cast<UpdateType>(Update::Nothing)),
asyncUpdate(util::make_unique<uv::async>(loop, [this] { update(); })),
glyphStore(util::make_unique<GlyphStore>(env)),
glyphStore(util::make_unique<GlyphStore>(loop, env)),
glyphAtlas(util::make_unique<GlyphAtlas>(1024, 1024)),
spriteAtlas(util::make_unique<SpriteAtlas>(512, 512)),
lineAtlas(util::make_unique<LineAtlas>(512, 512)),

View File

@@ -9,6 +9,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/token.hpp>
#include <mbgl/util/math.hpp>
#include <mbgl/util/uv_detail.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/platform/log.hpp>
#include <mbgl/platform/platform.hpp>
@@ -236,8 +237,11 @@ bool GlyphPBF::isParsed() const {
return parsed;
}
GlyphStore::GlyphStore(Environment& env_)
: env(env_), observer(nullptr) {
GlyphStore::GlyphStore(uv_loop_t* loop, Environment& env_)
: env(env_),
asyncEmitGlyphRangeLoaded(util::make_unique<uv::async>(loop, [this] { emitGlyphRangeLoaded(); })),
observer(nullptr) {
asyncEmitGlyphRangeLoaded->unref();
}
GlyphStore::~GlyphStore() {
@@ -258,7 +262,7 @@ bool GlyphStore::requestGlyphRangesIfNeeded(const std::string& fontStack,
auto callback = [this, fontStack](GlyphPBF* glyph) {
glyph->parse(*createFontStack(fontStack));
emitGlyphRangeLoaded();
asyncEmitGlyphRangeLoaded->send();
};
std::lock_guard<std::mutex> lock(rangesMutex);

View File

@@ -13,6 +13,14 @@
#include <string>
#include <unordered_map>
typedef struct uv_loop_s uv_loop_t;
namespace uv {
class async;
}
namespace mbgl {
class FileSource;
@@ -87,7 +95,7 @@ public:
virtual void onGlyphRangeLoaded() = 0;
};
GlyphStore(Environment &);
GlyphStore(uv_loop_t* loop, Environment &);
~GlyphStore();
// Asynchronously request for GlyphRanges and when it gets loaded, notifies the
@@ -116,6 +124,8 @@ private:
std::unordered_map<std::string, std::unique_ptr<FontStack>> stacks;
std::mutex stacksMutex;
std::unique_ptr<uv::async> asyncEmitGlyphRangeLoaded;
Observer* observer;
};