diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 6f7c52cca..7a58f0546 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -77,9 +77,6 @@ public: // Notifies the Map thread that the state has changed and an update might be necessary. void triggerUpdate(Update = Update::Nothing); - // Triggers a render. Can be called from any thread. - void triggerRender(); - // Releases resources immediately void terminate(); @@ -215,7 +212,6 @@ private: std::unique_ptr asyncTerminate; std::unique_ptr asyncUpdate; std::unique_ptr asyncInvoke; - std::unique_ptr asyncRender; bool terminating = false; bool pausing = false; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 208ca92f1..fab3b775d 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -118,7 +118,7 @@ void Map::start(bool startPaused, Mode renderMode) { terminating = true; // Closes all open handles on the loop. This means that the loop will automatically terminate. - asyncRender.reset(); + context->asyncRender.reset(); asyncUpdate.reset(); asyncInvoke.reset(); asyncTerminate.reset(); @@ -136,7 +136,7 @@ void Map::start(bool startPaused, Mode renderMode) { processTasks(); }); - asyncRender = util::make_unique(env->loop, [this] { + context->asyncRender = util::make_unique(env->loop, [this] { // Must be called in Map thread. assert(Environment::currentlyOn(ThreadType::Map)); @@ -295,7 +295,7 @@ void Map::run() { asyncTerminate->ref(); asyncUpdate->ref(); asyncInvoke->ref(); - asyncRender->ref(); + context->asyncRender->ref(); } } } else { @@ -312,28 +312,13 @@ void Map::renderSync() { // Must be called in UI thread. assert(Environment::currentlyOn(ThreadType::Main)); - triggerRender(); + context->triggerRender(); std::unique_lock lock(mutexRendered); condRendered.wait(lock, [this] { return rendered; }); rendered = false; } -void Map::triggerUpdate(const Update u) { - updated |= static_cast(u); - - if (asyncUpdate) { - asyncUpdate->ref(); - asyncUpdate->send(); - } -} - -void Map::triggerRender() { - assert(mode == Mode::Continuous); - assert(asyncRender); - asyncRender->send(); -} - // Runs the function in the map thread. void Map::invokeTask(std::function&& fn) { { @@ -659,16 +644,6 @@ LatLngBounds Map::getBoundsForAnnotations(const std::vector& annotatio }); } -void Map::updateAnnotationTiles(const std::vector& ids) { - assert(Environment::currentlyOn(ThreadType::Main)); - if (!context->style) return; - for (const auto &source : context->style->sources) { - if (source->info.type == SourceType::Annotations) { - source->invalidateTiles(ids); - } - } - triggerUpdate(); -} #pragma mark - Toggles @@ -723,6 +698,28 @@ Duration Map::getDefaultTransitionDuration() { return data->getDefaultTransitionDuration(); } +#pragma mark - Private + +void Map::triggerUpdate(const Update u) { + updated |= static_cast(u); + + if (asyncUpdate) { + asyncUpdate->ref(); + asyncUpdate->send(); + } +} + +void Map::updateAnnotationTiles(const std::vector& ids) { + assert(Environment::currentlyOn(ThreadType::Main)); + if (!context->style) return; + for (const auto &source : context->style->sources) { + if (source->info.type == SourceType::Annotations) { + source->invalidateTiles(ids); + } + } + triggerUpdate(); +} + void Map::updateTiles() { assert(Environment::currentlyOn(ThreadType::Map)); if (!context->style) return; @@ -823,7 +820,7 @@ void Map::prepare() { asyncTerminate->unref(); asyncUpdate->unref(); asyncInvoke->unref(); - asyncRender->unref(); + context->asyncRender->unref(); } if (context->style) { diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 1380667ea..146a01cc0 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -47,4 +47,9 @@ util::ptr MapContext::getSprite() { return sprite; } +void MapContext::triggerRender() { + assert(asyncRender); + asyncRender->send(); +} + } diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index d1eadb045..9ef9a8769 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -5,6 +5,10 @@ #include +namespace uv { +class async; +} + namespace mbgl { class Environment; @@ -23,15 +27,19 @@ class MapContext { public: MapContext(Environment&, MapData&); + // These can only be called from the Map thread. Worker& getWorker(); util::ptr getSprite(); -public: - std::unique_ptr workers; + // Triggers a render. Can be called from any thread. + void triggerRender(); public: Environment& env; MapData& data; + + std::unique_ptr asyncRender; + std::unique_ptr workers; const std::unique_ptr glyphStore; const std::unique_ptr glyphAtlas; const std::unique_ptr spriteAtlas; @@ -43,4 +51,4 @@ public: }; } -#endif \ No newline at end of file +#endif