From 9dc51e7f80f4ee1406be9743d671b28710274f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 24 Mar 2015 11:55:20 +0100 Subject: [PATCH] move rendering mode enum to MapData object --- include/mbgl/map/map.hpp | 13 +++---------- include/mbgl/map/mode.hpp | 16 ++++++++++++++++ src/mbgl/map/map.cpp | 32 +++++++++++++++----------------- src/mbgl/map/map_context.cpp | 1 + src/mbgl/map/map_data.hpp | 2 ++ 5 files changed, 37 insertions(+), 27 deletions(-) create mode 100644 include/mbgl/map/mode.hpp diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 7a58f0546..bbf6dea92 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -39,18 +40,12 @@ class Map : private util::noncopyable { friend class View; public: - enum class Mode : uint8_t { - None, // we're not doing any processing - Continuous, // continually updating map - Still, // a once-off still image. - }; - explicit Map(View&, FileSource&); ~Map(); // Start the map render thread. It is asynchronous. - void start(bool startPaused = false, Mode mode = Mode::Continuous); - inline void start(Mode renderMode) { start(false, renderMode); } + void start(bool startPaused = false, MapMode mode = MapMode::Continuous); + inline void start(MapMode renderMode) { start(false, renderMode); } // Stop the map render thread. This call will block until the map rendering thread stopped. // The optional callback function will be invoked repeatedly until the map thread is stopped. @@ -199,8 +194,6 @@ private: size_t sourceCacheSize; - Mode mode = Mode::None; - const std::unique_ptr env; std::unique_ptr scope; View &view; diff --git a/include/mbgl/map/mode.hpp b/include/mbgl/map/mode.hpp new file mode 100644 index 000000000..f8c4eb1e0 --- /dev/null +++ b/include/mbgl/map/mode.hpp @@ -0,0 +1,16 @@ +#ifndef MBGL_MAP_MODE +#define MBGL_MAP_MODE + +#include + +namespace mbgl { + +enum class MapMode : uint8_t { + None, // we're not doing any processing + Continuous, // continually updating map + Still, // a once-off still image +}; + +} + +#endif \ No newline at end of file diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index fab3b775d..c13cce73b 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -73,7 +73,7 @@ Map::Map(View& view_, FileSource& fileSource_) } Map::~Map() { - if (mode != Mode::None) { + if (data->mode != MapMode::None) { stop(); } @@ -93,13 +93,13 @@ Map::~Map() { env->performCleanup(); } -void Map::start(bool startPaused, Mode renderMode) { +void Map::start(bool startPaused, MapMode renderMode) { assert(Environment::currentlyOn(ThreadType::Main)); - assert(mode == Mode::None); + assert(data->mode == MapMode::None); // When starting map rendering in another thread, we perform async/continuously // updated rendering. Only in these cases, we attach the async handlers. - mode = renderMode; + data->mode = renderMode; // Reset the flag. isStopped = false; @@ -172,7 +172,7 @@ void Map::start(bool startPaused, Mode renderMode) { void Map::stop(std::function cb) { assert(Environment::currentlyOn(ThreadType::Main)); - assert(mode != Mode::None); + assert(data->mode != MapMode::None); asyncTerminate->send(); @@ -194,12 +194,12 @@ void Map::stop(std::function cb) { // already finished executing. thread.join(); - mode = Mode::None; + data->mode = MapMode::None; } void Map::pause(bool waitForPause) { assert(Environment::currentlyOn(ThreadType::Main)); - assert(mode == Mode::Continuous); + assert(data->mode == MapMode::Continuous); mutexRun.lock(); pausing = true; mutexRun.unlock(); @@ -217,7 +217,7 @@ void Map::pause(bool waitForPause) { void Map::resume() { assert(Environment::currentlyOn(ThreadType::Main)); - assert(mode != Mode::None); + assert(data->mode != MapMode::None); mutexRun.lock(); pausing = false; @@ -228,7 +228,7 @@ void Map::resume() { void Map::renderStill(StillImageCallback fn) { assert(Environment::currentlyOn(ThreadType::Main)); - if (mode != Mode::Still) { + if (data->mode != MapMode::Still) { throw util::Exception("Map is not in still image render mode"); } @@ -236,7 +236,7 @@ void Map::renderStill(StillImageCallback fn) { throw util::Exception("Map is currently rendering an image"); } - assert(mode == Mode::Still); + assert(data->mode == MapMode::Still); callback = std::move(fn); @@ -246,14 +246,12 @@ void Map::renderStill(StillImageCallback fn) { void Map::run() { EnvironmentScope mapScope(*env, ThreadType::Map, "Map"); assert(Environment::currentlyOn(ThreadType::Map)); - assert(mode != Mode::None); + assert(data->mode != MapMode::None); - if (mode == Mode::Continuous) { + if (data->mode == MapMode::Continuous) { checkForPause(); } - auto styleInfo = data->getStyleInfo(); - view.activate(); view.discard(); @@ -262,13 +260,13 @@ void Map::run() { setup(); prepare(); - if (mode == Mode::Continuous) { + if (data->mode == MapMode::Continuous) { terminating = false; while (!terminating) { uv_run(env->loop, UV_RUN_DEFAULT); checkForPause(); } - } else if (mode == Mode::Still) { + } else if (data->mode == MapMode::Still) { terminating = false; while (!terminating) { uv_run(env->loop, UV_RUN_DEFAULT); @@ -845,7 +843,7 @@ void Map::prepare() { updateTiles(); } - if (mode == Mode::Continuous) { + if (data->mode == MapMode::Continuous) { view.invalidate(); } } diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 146a01cc0..2e9f50d4a 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -48,6 +48,7 @@ util::ptr MapContext::getSprite() { } void MapContext::triggerRender() { + assert(data.mode == MapMode::Continuous); assert(asyncRender); asyncRender->send(); } diff --git a/src/mbgl/map/map_data.hpp b/src/mbgl/map/map_data.hpp index d37ef781f..78ecc9e5a 100644 --- a/src/mbgl/map/map_data.hpp +++ b/src/mbgl/map/map_data.hpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -106,6 +107,7 @@ public: public: Transform transform; AnnotationManager annotationManager; + MapMode mode = MapMode::None; private: mutable std::mutex mtx;