diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 5191293a0..f373274eb 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -36,7 +36,7 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map envScope(env, ThreadType::Map, "Map"), updated(static_cast(Update::Nothing)), asyncUpdate(util::make_unique(loop, [this] { update(); })), - glyphStore(util::make_unique(env)), + glyphStore(util::make_unique(loop, env)), glyphAtlas(util::make_unique(1024, 1024)), spriteAtlas(util::make_unique(512, 512)), lineAtlas(util::make_unique(512, 512)), diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index 71c1be6d9..853191218 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -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(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 lock(rangesMutex); diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index a41eec533..efa848dd0 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -13,6 +13,14 @@ #include #include +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> stacks; std::mutex stacksMutex; + std::unique_ptr asyncEmitGlyphRangeLoaded; + Observer* observer; };