Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason

Conflicts:
	Makefile
	platform/default/headless_view.cpp
	src/mbgl/map/map.cpp
This commit is contained in:
Leith Bade
2014-12-21 15:02:47 +13:00
8 changed files with 277 additions and 175 deletions

View File

@@ -96,6 +96,7 @@ Map::Map(View& view_, FileSource& fileSource_)
view(view_),
#ifndef NDEBUG
mainThread(std::this_thread::get_id()),
mapThread(mainThread),
#endif
transform(view_),
fileSource(fileSource_),
@@ -113,7 +114,7 @@ Map::Map(View& view_, FileSource& fileSource_)
}
Map::~Map() {
if (async) {
if (mode == Mode::Continuous) {
stop();
}
@@ -137,11 +138,11 @@ uv::worker &Map::getWorker() {
void Map::start(bool startPaused) {
assert(std::this_thread::get_id() == mainThread);
assert(!async);
assert(mode == Mode::None);
// When starting map rendering in another thread, we perform async/continuously
// updated rendering. Only in these cases, we attach the async handlers.
async = true;
mode = Mode::Continuous;
// Reset the flag.
isStopped = false;
@@ -212,7 +213,7 @@ void Map::start(bool startPaused) {
void Map::stop(std::function<void ()> callback) {
assert(std::this_thread::get_id() == mainThread);
assert(mainThread != mapThread);
assert(async);
assert(mode == Mode::Continuous);
asyncTerminate->send();
@@ -234,12 +235,12 @@ void Map::stop(std::function<void ()> callback) {
// already finished executing.
thread.join();
async = false;
mode = Mode::None;
}
void Map::pause(bool waitForPause) {
assert(std::this_thread::get_id() == mainThread);
assert(async);
assert(mode == Mode::Continuous);
mutexRun.lock();
pausing = true;
mutexRun.unlock();
@@ -257,7 +258,7 @@ void Map::pause(bool waitForPause) {
void Map::resume() {
assert(std::this_thread::get_id() == mainThread);
assert(async);
assert(mode == Mode::Continuous);
mutexRun.lock();
pausing = false;
@@ -270,21 +271,22 @@ void Map::run() {
COFFEE_TRY() {
#endif
if (mode == Mode::None) {
#ifndef NDEBUG
if (!async) {
mapThread = mainThread;
}
#endif
mode = Mode::Static;
}
assert(std::this_thread::get_id() == mapThread);
if (async) {
if (mode == Mode::Continuous) {
checkForPause();
}
setup();
prepare();
if (async) {
if (mode == Mode::Continuous) {
terminating = false;
while(!terminating) {
uv_run(**loop, UV_RUN_DEFAULT);
@@ -299,11 +301,13 @@ void Map::run() {
// If the map rendering wasn't started asynchronously, we perform one render
// *after* all events have been processed.
if (!async) {
if (mode == Mode::Static) {
render();
#ifndef NDEBUG
mapThread = std::thread::id();
#endif
mode = Mode::None;
fileSource.clearLoop();
}
#ifdef __ANDROID__
} COFFEE_CATCH() {
@@ -334,9 +338,12 @@ void Map::checkForPause() {
}
void Map::rerender() {
// We only send render events if we want to continuously update the map
// (== async rendering).
if (async) {
if (mode == Mode::Static) {
prepare();
} else if (mode == Mode::Continuous) {
// We only send render events if we want to continuously update the map
// (== async rendering).
assert(asyncRender);
asyncRender->send();
}
}
@@ -373,7 +380,7 @@ void Map::setStyleURL(const std::string &url) {
// TODO: Make threadsafe.
styleURL = url;
if (async) {
if (mode == Mode::Continuous) {
stop();
start();
}