Provide view invalidation call coalescion via uv_async_t
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user