Coalesce view invalidation calls
Do not call for view invalidation until painter has rendered a new frame.
This commit is contained in:
@@ -35,7 +35,8 @@ MapContext::MapContext(View& view_, FileSource& fileSource, MapData& data_)
|
||||
data(data_),
|
||||
updated(static_cast<UpdateType>(Update::Nothing)),
|
||||
asyncUpdate(std::make_unique<uv::async>(util::RunLoop::getLoop(), [this] { update(); })),
|
||||
texturePool(std::make_unique<TexturePool>()) {
|
||||
texturePool(std::make_unique<TexturePool>()),
|
||||
viewInvalidated(false) {
|
||||
assert(util::ThreadContext::currentlyOn(util::ThreadType::Map));
|
||||
|
||||
util::ThreadContext::setFileSource(&fileSource);
|
||||
@@ -272,8 +273,8 @@ void MapContext::update() {
|
||||
style->update(transformState, *texturePool);
|
||||
|
||||
if (data.mode == MapMode::Continuous) {
|
||||
view.invalidate();
|
||||
} else if (callback && style->isLoaded()) {
|
||||
invalidateView();
|
||||
} else if (callback && isLoaded()) {
|
||||
renderSync(transformState, frameData);
|
||||
}
|
||||
|
||||
@@ -342,8 +343,10 @@ MapContext::RenderResult MapContext::renderSync(const TransformState& state, con
|
||||
|
||||
view.swap();
|
||||
|
||||
viewInvalidated = false;
|
||||
|
||||
return RenderResult {
|
||||
style->isLoaded(),
|
||||
isLoaded(),
|
||||
style->hasTransitions() || painter->needsAnimation()
|
||||
};
|
||||
}
|
||||
@@ -370,7 +373,7 @@ void MapContext::setSourceTileCacheSize(size_t size) {
|
||||
for (const auto &source : style->sources) {
|
||||
source->setCacheSize(sourceCacheSize);
|
||||
}
|
||||
view.invalidate();
|
||||
invalidateView();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,7 +383,7 @@ void MapContext::onLowMemory() {
|
||||
for (const auto &source : style->sources) {
|
||||
source->onLowMemory();
|
||||
}
|
||||
view.invalidate();
|
||||
invalidateView();
|
||||
}
|
||||
|
||||
void MapContext::setSprite(const std::string& name, std::shared_ptr<const SpriteImage> sprite) {
|
||||
@@ -410,4 +413,11 @@ void MapContext::onResourceLoadingFailed(std::exception_ptr error) {
|
||||
}
|
||||
}
|
||||
|
||||
void MapContext::invalidateView() {
|
||||
if (!viewInvalidated) {
|
||||
viewInvalidated = true;
|
||||
view.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,6 +77,8 @@ 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;
|
||||
|
||||
@@ -98,6 +100,7 @@ private:
|
||||
size_t sourceCacheSize;
|
||||
TransformState transformState;
|
||||
FrameData frameData;
|
||||
bool viewInvalidated;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user