Provide view invalidation call coalescion via uv_async_t

This commit is contained in:
Bruno de Oliveira Abinader
2015-08-30 22:04:26 +03:00
parent 227776dee0
commit e920328223
2 changed files with 10 additions and 20 deletions

View File

@@ -34,14 +34,15 @@ MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_)
: view(view_),
data(data_),
asyncUpdate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [this] { update(); })),
texturePool(std::make_unique<TexturePool>()),
viewInvalidated(false) {
asyncInvalidate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [&view_] { view_.invalidate(); })),
texturePool(std::make_unique<TexturePool>()) {
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
util::ThreadContext::setFileSource(&fileSource);
util::ThreadContext::setGLObjectStore(&glObjectStore);
asyncUpdate->unref();
asyncInvalidate->unref();
view.activate();
}
@@ -74,8 +75,6 @@ void MapContext::cleanup() {
void MapContext::pause() {
MBGL_CHECK_ERROR(glFinish());
viewInvalidated = false;
view.deactivate();
std::unique_lock<std::mutex> lockPause(data.mutexPause);
@@ -84,7 +83,7 @@ void MapContext::pause() {
view.activate();
invalidateView();
asyncInvalidate->send();
}
void MapContext::triggerUpdate(const TransformState& state, const Update flags) {
@@ -276,8 +275,8 @@ void MapContext::update() {
style->update(transformState, *texturePool);
if (data.mode == MapMode::Continuous) {
invalidateView();
} else if (callback && isLoaded()) {
asyncInvalidate->send();
} else if (callback && style->isLoaded()) {
renderSync(transformState, frameData);
}
@@ -347,7 +346,7 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
}
view.afterRender();
viewInvalidated = false;
data.setNeedsRepaint(style->hasTransitions() || painter->needsAnimation());
return isLoaded();
@@ -375,7 +374,7 @@ void MapContext::setSourceTileCacheSize(size_t size) {
for (const auto &source : style->sources) {
source->setCacheSize(sourceCacheSize);
}
invalidateView();
asyncInvalidate->send();
}
}
@@ -385,7 +384,7 @@ void MapContext::onLowMemory() {
for (const auto &source : style->sources) {
source->onLowMemory();
}
invalidateView();
asyncInvalidate->send();
}
void MapContext::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
@@ -415,11 +414,4 @@ void MapContext::onResourceLoadingFailed(std::exception_ptr error) {
}
}
void MapContext::invalidateView() {
if (!viewInvalidated) {
viewInvalidated = true;
view.invalidate();
}
}
}

View File

@@ -74,8 +74,6 @@ private:
// Loads the actual JSON object an creates a new Style object.
void loadStyleJSON(const std::string& json, const std::string& base);
void invalidateView();
View& view;
MapData& data;
@@ -83,6 +81,7 @@ private:
Update updateFlags = Update::Nothing;
std::unique_ptr<uv::async> asyncUpdate;
std::unique_ptr<uv::async> asyncInvalidate;
std::unique_ptr<TexturePool> texturePool;
std::unique_ptr<Painter> painter;
@@ -97,7 +96,6 @@ private:
size_t sourceCacheSize;
TransformState transformState;
FrameData frameData;
bool viewInvalidated;
};
}