move asyncRender to MapContext

This commit is contained in:
Konstantin Käfer
2015-03-24 11:47:51 +01:00
committed by John Firebaugh
parent f8600d8d97
commit fa272b3aaa
4 changed files with 43 additions and 37 deletions

View File

@@ -118,7 +118,7 @@ void Map::start(bool startPaused, Mode renderMode) {
terminating = true;
// Closes all open handles on the loop. This means that the loop will automatically terminate.
asyncRender.reset();
context->asyncRender.reset();
asyncUpdate.reset();
asyncInvoke.reset();
asyncTerminate.reset();
@@ -136,7 +136,7 @@ void Map::start(bool startPaused, Mode renderMode) {
processTasks();
});
asyncRender = util::make_unique<uv::async>(env->loop, [this] {
context->asyncRender = util::make_unique<uv::async>(env->loop, [this] {
// Must be called in Map thread.
assert(Environment::currentlyOn(ThreadType::Map));
@@ -295,7 +295,7 @@ void Map::run() {
asyncTerminate->ref();
asyncUpdate->ref();
asyncInvoke->ref();
asyncRender->ref();
context->asyncRender->ref();
}
}
} else {
@@ -312,28 +312,13 @@ void Map::renderSync() {
// Must be called in UI thread.
assert(Environment::currentlyOn(ThreadType::Main));
triggerRender();
context->triggerRender();
std::unique_lock<std::mutex> lock(mutexRendered);
condRendered.wait(lock, [this] { return rendered; });
rendered = false;
}
void Map::triggerUpdate(const Update u) {
updated |= static_cast<UpdateType>(u);
if (asyncUpdate) {
asyncUpdate->ref();
asyncUpdate->send();
}
}
void Map::triggerRender() {
assert(mode == Mode::Continuous);
assert(asyncRender);
asyncRender->send();
}
// Runs the function in the map thread.
void Map::invokeTask(std::function<void()>&& fn) {
{
@@ -659,16 +644,6 @@ LatLngBounds Map::getBoundsForAnnotations(const std::vector<uint32_t>& annotatio
});
}
void Map::updateAnnotationTiles(const std::vector<TileID>& ids) {
assert(Environment::currentlyOn(ThreadType::Main));
if (!context->style) return;
for (const auto &source : context->style->sources) {
if (source->info.type == SourceType::Annotations) {
source->invalidateTiles(ids);
}
}
triggerUpdate();
}
#pragma mark - Toggles
@@ -723,6 +698,28 @@ Duration Map::getDefaultTransitionDuration() {
return data->getDefaultTransitionDuration();
}
#pragma mark - Private
void Map::triggerUpdate(const Update u) {
updated |= static_cast<UpdateType>(u);
if (asyncUpdate) {
asyncUpdate->ref();
asyncUpdate->send();
}
}
void Map::updateAnnotationTiles(const std::vector<TileID>& ids) {
assert(Environment::currentlyOn(ThreadType::Main));
if (!context->style) return;
for (const auto &source : context->style->sources) {
if (source->info.type == SourceType::Annotations) {
source->invalidateTiles(ids);
}
}
triggerUpdate();
}
void Map::updateTiles() {
assert(Environment::currentlyOn(ThreadType::Map));
if (!context->style) return;
@@ -823,7 +820,7 @@ void Map::prepare() {
asyncTerminate->unref();
asyncUpdate->unref();
asyncInvoke->unref();
asyncRender->unref();
context->asyncRender->unref();
}
if (context->style) {