From f272d13dead2b2cccc58d9c55697b9cac3c71e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 24 Mar 2015 10:59:31 +0100 Subject: [PATCH] move worker to MapContext --- include/mbgl/map/map.hpp | 2 -- src/mbgl/map/map.cpp | 12 +++--------- src/mbgl/map/map_context.cpp | 6 ++++++ src/mbgl/map/map_context.hpp | 4 ++++ 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 582eb430a..1ec12eb25 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -175,7 +175,6 @@ private: void resize(uint16_t width, uint16_t height, float ratio, uint16_t fbWidth, uint16_t fbHeight); util::ptr getSprite(); - Worker& getWorker(); // Checks if render thread needs to pause void checkForPause(); @@ -215,7 +214,6 @@ private: std::unique_ptr context; private: - std::unique_ptr workers; std::thread thread; std::unique_ptr asyncTerminate; std::unique_ptr asyncUpdate; diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 62ed60f3b..da16f2d8d 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -86,7 +86,6 @@ Map::~Map() { // Explicitly reset all pointers. style.reset(); - workers.reset(); context.reset(); uv_run(env->loop, UV_RUN_DEFAULT); @@ -94,11 +93,6 @@ Map::~Map() { env->performCleanup(); } -Worker& Map::getWorker() { - assert(workers); - return *workers; -} - void Map::start(bool startPaused, Mode renderMode) { assert(Environment::currentlyOn(ThreadType::Main)); assert(mode == Mode::None); @@ -119,7 +113,7 @@ void Map::start(bool startPaused, Mode renderMode) { // It's now safe to destroy/join the workers since there won't be any more callbacks that // could dispatch to the worker pool. - workers.reset(); + context->workers.reset(); terminating = true; @@ -263,7 +257,7 @@ void Map::run() { view.activate(); view.discard(); - workers = util::make_unique(env->loop, 4); + context->workers = util::make_unique(env->loop, 4); setup(); prepare(); @@ -744,7 +738,7 @@ void Map::updateTiles() { assert(Environment::currentlyOn(ThreadType::Map)); if (!style) return; for (const auto& source : style->sources) { - source->update(*data, getWorker(), style, *context->glyphAtlas, *context->glyphStore, + source->update(*data, context->getWorker(), style, *context->glyphAtlas, *context->glyphStore, *context->spriteAtlas, getSprite(), *context->texturePool, [this]() { assert(Environment::currentlyOn(ThreadType::Map)); triggerUpdate(); diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 258c4ab4c..cad2bd899 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -11,6 +11,7 @@ #include #include +#include #include namespace mbgl { @@ -24,4 +25,9 @@ MapContext::MapContext(Environment& env) painter(util::make_unique(*spriteAtlas, *glyphAtlas, *lineAtlas)) { } +Worker& MapContext::getWorker() { + assert(workers); + return *workers; +} + } \ No newline at end of file diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 694b82f43..cbe5994ae 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -17,12 +17,16 @@ class Painter; class Sprite; class StyleSource; class StyleLayerGroup; +class Worker; class MapContext { public: MapContext(Environment&); + Worker& getWorker(); + public: + std::unique_ptr workers; const std::unique_ptr glyphStore; const std::unique_ptr glyphAtlas; const std::unique_ptr spriteAtlas;