move rendering mode enum to MapData object

This commit is contained in:
Konstantin Käfer
2015-03-24 11:55:20 +01:00
committed by John Firebaugh
parent fa272b3aaa
commit 9dc51e7f80
5 changed files with 37 additions and 27 deletions

View File

@@ -3,6 +3,7 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/update.hpp>
#include <mbgl/map/mode.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/projection.hpp>
#include <mbgl/util/noncopyable.hpp>
@@ -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<Environment> env;
std::unique_ptr<EnvironmentScope> scope;
View &view;

16
include/mbgl/map/mode.hpp Normal file
View File

@@ -0,0 +1,16 @@
#ifndef MBGL_MAP_MODE
#define MBGL_MAP_MODE
#include <cstdint>
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

View File

@@ -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<void ()> 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<void ()> 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();
}
}

View File

@@ -48,6 +48,7 @@ util::ptr<Sprite> MapContext::getSprite() {
}
void MapContext::triggerRender() {
assert(data.mode == MapMode::Continuous);
assert(asyncRender);
asyncRender->send();
}

View File

@@ -9,6 +9,7 @@
#include <vector>
#include <cassert>
#include <mbgl/map/mode.hpp>
#include <mbgl/map/environment.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/map/transform_state.hpp>
@@ -106,6 +107,7 @@ public:
public:
Transform transform;
AnnotationManager annotationManager;
MapMode mode = MapMode::None;
private:
mutable std::mutex mtx;