diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-04-20 17:34:22 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-04-28 14:32:21 -0400 |
commit | 025eb013d79e2a33d90386e898d4daf20aabc489 (patch) | |
tree | e385e089f4db5f130ead6df0a61d09ba450e99d5 | |
parent | 424dae0a2c9e5ebe1c0230e5468f481273c98d0b (diff) | |
download | qtlocation-mapboxgl-025eb013d79e2a33d90386e898d4daf20aabc489.tar.gz |
Privatize remaining MapContext members
-rw-r--r-- | include/mbgl/map/map.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/map/map.cpp | 27 | ||||
-rw-r--r-- | src/mbgl/map/map_context.cpp | 35 | ||||
-rw-r--r-- | src/mbgl/map/map_context.hpp | 69 | ||||
-rw-r--r-- | src/mbgl/map/map_data.hpp | 7 |
5 files changed, 81 insertions, 59 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index f91a24c35a..07e6b65e16 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<Environment> env; std::unique_ptr<EnvironmentScope> scope; View &view; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index fc2b180a87..b6ca3b62cc 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -54,8 +54,6 @@ Map::~Map() { static_cast<uint8_t>(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 81bc8c6457..1fd6f89df4 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<Painter>(*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 3f2dbe725e..e9e61844ce 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -4,7 +4,6 @@ #include <mbgl/map/tile_id.hpp> #include <mbgl/map/update.hpp> #include <mbgl/util/ptr.hpp> -#include <mbgl/util/signal.hpp> #include <vector> #include <queue> @@ -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<TileID>& 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<Sprite> getSprite(); void updateTiles(); - // TODO: Make these private - public: void updateAnnotationTiles(const std::vector<TileID>& 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; + + std::atomic<UpdateType> updated { static_cast<UpdateType>(Update::Nothing) }; - private: std::atomic<UpdateType> updated { static_cast<UpdateType>(Update::Nothing) }; + std::mutex mutexTask; + std::queue<std::function<void()>> tasks; - private: std::mutex mutexTask; - private: std::queue<std::function<void()>> tasks; + std::unique_ptr<uv::async> asyncUpdate; + std::unique_ptr<uv::async> asyncRender; + std::unique_ptr<uv::async> asyncInvoke; + std::unique_ptr<uv::async> asyncTerminate; - public: std::unique_ptr<uv::async> asyncUpdate; - public: std::unique_ptr<uv::async> asyncRender; - public: std::unique_ptr<uv::async> asyncInvoke; - public: std::unique_ptr<uv::async> asyncTerminate; + std::unique_ptr<Worker> workers; + const std::unique_ptr<GlyphStore> glyphStore; + const std::unique_ptr<GlyphAtlas> glyphAtlas; + const std::unique_ptr<SpriteAtlas> spriteAtlas; + const std::unique_ptr<LineAtlas> lineAtlas; + const std::unique_ptr<TexturePool> texturePool; + const std::unique_ptr<Painter> painter; - public: std::unique_ptr<Worker> workers; - private: const std::unique_ptr<GlyphStore> glyphStore; - private: const std::unique_ptr<GlyphAtlas> glyphAtlas; - private: const std::unique_ptr<SpriteAtlas> spriteAtlas; - private: const std::unique_ptr<LineAtlas> lineAtlas; - private: const std::unique_ptr<TexturePool> texturePool; - public: const std::unique_ptr<Painter> painter; - public: util::ptr<Sprite> sprite; - public: util::ptr<Style> style; + util::ptr<Sprite> sprite; + util::ptr<Style> style; - // Used to signal that rendering completed. - public: util::Signal rendered; + size_t sourceCacheSize; }; } diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index 63373428d2..c2aa222463 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -2,6 +2,7 @@ #define MBGL_MAP_MAP_DATA #include <mbgl/util/chrono.hpp> +#include <mbgl/util/signal.hpp> #include <string> #include <mutex> @@ -122,8 +123,12 @@ private: std::atomic<Duration> animationTime; std::atomic<Duration> defaultTransitionDuration; +// TODO: make private public: - // TODO: make private + // Used to signal that rendering completed. + public: util::Signal rendered; + + // TODO: document bool terminating = false; std::thread thread; |