diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index f91a24c35..07e6b65e1 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -131,7 +131,6 @@ public: // Memory void setSourceTileCacheSize(size_t); - size_t getSourceTileCacheSize() const { return sourceCacheSize; } void onLowMemory(); // Debug @@ -149,7 +148,6 @@ private: void resize(uint16_t width, uint16_t height, float ratio = 1); void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); - size_t sourceCacheSize; const std::unique_ptr env; std::unique_ptr scope; View &view; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index fc2b180a8..b6ca3b62c 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -54,8 +54,6 @@ Map::~Map() { static_cast(ThreadType::Map)), "MapandMain"); - // Explicitly reset all pointers. - context->style.reset(); context.reset(); uv_run(env->loop, UV_RUN_DEFAULT); @@ -162,7 +160,7 @@ void Map::renderSync() { context->triggerRender(); - context->rendered.wait(); + data->rendered.wait(); } void Map::update() { @@ -383,9 +381,7 @@ void Map::setDefaultPointAnnotationSymbol(const std::string& symbol) { double Map::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) { assert(Environment::currentlyOn(ThreadType::Main)); return context->invokeSyncTask([&] { - assert(context->sprite); - const SpritePosition pos = context->sprite->getSpritePosition(symbol); - return -pos.height / pos.pixelRatio / 2; + return context->getTopOffsetPixelsForAnnotationSymbol(symbol); }); } @@ -487,25 +483,14 @@ Duration Map::getDefaultTransitionDuration() { void Map::setSourceTileCacheSize(size_t size) { - if (size != getSourceTileCacheSize()) { - context->invokeTask([=] { - sourceCacheSize = size; - if (!context->style) return; - for (const auto &source : context->style->sources) { - source->setCacheSize(sourceCacheSize); - } - env->performCleanup(); - }); - } + context->invokeTask([=] { + context->setSourceTileCacheSize(size); + }); } void Map::onLowMemory() { context->invokeTask([=] { - if (!context->style) return; - for (const auto &source : context->style->sources) { - source->onLowMemory(); - } - env->performCleanup(); + context->onLowMemory(); }); } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 81bc8c645..1fd6f89df 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -42,6 +42,11 @@ MapContext::MapContext(Environment& env_, View& view_, MapData& data_) painter(util::make_unique(*spriteAtlas, *glyphAtlas, *lineAtlas)) { } +MapContext::~MapContext() { + // TODO: does this need to happen first for some reason? + style.reset(); +} + void MapContext::start() { // Setup async notifications assert(!asyncTerminate); @@ -85,7 +90,7 @@ void MapContext::start() { render(); // Finally, notify all listeners that we have finished rendering this frame. - rendered.notify(); + data.rendered.notify(); }); data.thread = std::thread([this]() { @@ -410,4 +415,32 @@ void MapContext::processTasks() { } } +double MapContext::getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol) { + assert(Environment::currentlyOn(ThreadType::Map)); + assert(sprite); + const SpritePosition pos = sprite->getSpritePosition(symbol); + return -pos.height / pos.pixelRatio / 2; +} + +void MapContext::setSourceTileCacheSize(size_t size) { + assert(Environment::currentlyOn(ThreadType::Map)); + if (size != sourceCacheSize) { + sourceCacheSize = size; + if (!style) return; + for (const auto &source : style->sources) { + source->setCacheSize(sourceCacheSize); + } + env.performCleanup(); + } +} + +void MapContext::onLowMemory() { + assert(Environment::currentlyOn(ThreadType::Map)); + if (!style) return; + for (const auto &source : style->sources) { + source->onLowMemory(); + } + env.performCleanup(); +} + } diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 3f2dbe725..e9e61844c 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -33,6 +32,7 @@ class Worker; class MapContext { public: MapContext(Environment&, View&, MapData&); + ~MapContext(); // Starts the map thread. void start(); @@ -57,6 +57,13 @@ public: return promise.get_future().get(); } + double getTopOffsetPixelsForAnnotationSymbol(const std::string& symbol); + void setSourceTileCacheSize(size_t size); + void onLowMemory(); + + // TODO: Make this private + public: void updateAnnotationTiles(const std::vector& ids); + // These can only be called from the Map thread. private: // Checks if render thread needs to pause @@ -66,58 +73,52 @@ private: util::ptr getSprite(); void updateTiles(); - // TODO: Make these private - public: void updateAnnotationTiles(const std::vector& ids); - // Triggered by triggerUpdate(); - private: void update(); + void update(); // Prepares a map render by updating the tiles we need for the current view, as well as updating // the stylesheet. - public: void prepare(); + void prepare(); // Unconditionally performs a render with the current map state. - public: void render(); + void render(); // Runs the enqueued tasks. - private: void processTasks(); + void processTasks(); -private: // Loads the style set in the data object. Called by Update::StyleInfo - private: void reloadStyle(); + void reloadStyle(); // Loads the actual JSON object an creates a new Style object. - private: void loadStyleJSON(const std::string& json, const std::string& base); + void loadStyleJSON(const std::string& json, const std::string& base); - // TODO: Make all of these private -public: - private: Environment& env; - private: View& view; - private: MapData& data; + Environment& env; + View& view; + MapData& data; - private: std::atomic updated { static_cast(Update::Nothing) }; + std::atomic updated { static_cast(Update::Nothing) }; - private: std::mutex mutexTask; - private: std::queue> tasks; + std::mutex mutexTask; + std::queue> tasks; - public: std::unique_ptr asyncUpdate; - public: std::unique_ptr asyncRender; - public: std::unique_ptr asyncInvoke; - public: std::unique_ptr asyncTerminate; + std::unique_ptr asyncUpdate; + std::unique_ptr asyncRender; + std::unique_ptr asyncInvoke; + std::unique_ptr asyncTerminate; - public: std::unique_ptr workers; - private: const std::unique_ptr glyphStore; - private: const std::unique_ptr glyphAtlas; - private: const std::unique_ptr spriteAtlas; - private: const std::unique_ptr lineAtlas; - private: const std::unique_ptr texturePool; - public: const std::unique_ptr painter; - public: util::ptr sprite; - public: util::ptr