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

@@ -77,9 +77,6 @@ public:
// Notifies the Map thread that the state has changed and an update might be necessary.
void triggerUpdate(Update = Update::Nothing);
// Triggers a render. Can be called from any thread.
void triggerRender();
// Releases resources immediately
void terminate();
@@ -215,7 +212,6 @@ private:
std::unique_ptr<uv::async> asyncTerminate;
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<uv::async> asyncInvoke;
std::unique_ptr<uv::async> asyncRender;
bool terminating = false;
bool pausing = false;

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) {

View File

@@ -47,4 +47,9 @@ util::ptr<Sprite> MapContext::getSprite() {
return sprite;
}
void MapContext::triggerRender() {
assert(asyncRender);
asyncRender->send();
}
}

View File

@@ -5,6 +5,10 @@
#include <set>
namespace uv {
class async;
}
namespace mbgl {
class Environment;
@@ -23,15 +27,19 @@ class MapContext {
public:
MapContext(Environment&, MapData&);
// These can only be called from the Map thread.
Worker& getWorker();
util::ptr<Sprite> getSprite();
public:
std::unique_ptr<Worker> workers;
// Triggers a render. Can be called from any thread.
void triggerRender();
public:
Environment& env;
MapData& data;
std::unique_ptr<uv::async> asyncRender;
std::unique_ptr<Worker> workers;
const std::unique_ptr<GlyphStore> glyphStore;
const std::unique_ptr<GlyphAtlas> glyphAtlas;
const std::unique_ptr<SpriteAtlas> spriteAtlas;
@@ -43,4 +51,4 @@ public:
};
}
#endif
#endif