summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2015-08-30 22:04:26 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2015-09-02 23:20:46 +0300
commite92032822327d31656ebec3bd43dfd8654da68fa (patch)
tree7e5f14eccb81d84e8a0da7f2bada52fb2a165c27
parent227776dee04d440c0b6082def2bf5e40da65ecbc (diff)
downloadqtlocation-mapboxgl-e92032822327d31656ebec3bd43dfd8654da68fa.tar.gz
Provide view invalidation call coalescion via uv_async_t
-rw-r--r--src/mbgl/map/map_context.cpp26
-rw-r--r--src/mbgl/map/map_context.hpp4
2 files changed, 10 insertions, 20 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index c36b4fc9d6..bdbf1ff0b6 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -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();
- }
-}
-
}
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 5964c6686e..f1bfb01e44 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -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;
};
}