diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index c36b4fc9d..bdbf1ff0b 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(util::RunLoop::getLoop(), [this] { update(); })), - texturePool(std::make_unique()), - viewInvalidated(false) { + asyncInvalidate(std::make_unique(util::RunLoop::getLoop(), [&view_] { view_.invalidate(); })), + texturePool(std::make_unique()) { 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 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 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 5964c6686..f1bfb01e4 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 asyncUpdate; + std::unique_ptr asyncInvalidate; std::unique_ptr texturePool; std::unique_ptr painter; @@ -97,7 +96,6 @@ private: size_t sourceCacheSize; TransformState transformState; FrameData frameData; - bool viewInvalidated; }; }