summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-09 19:03:17 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-10-22 15:13:21 +0300
commit148cfe9e554e065a2a6e56f0ce4e7d19971e6902 (patch)
tree28fe71ecc2211bfb56599259257a06bc8e66688a
parent0ca96fd8a402ae530da72e3955196007a2ec365f (diff)
downloadqtlocation-mapboxgl-upstream/mikhail_decouple_map_change_and_transition_updates.tar.gz
[core] Decouple style change and transitions updateupstream/mikhail_decouple_map_change_and_transition_updates
Update transitions in a separate call chain in order to avoid infinite loop, in case map is modified from within the transitions update callback.
-rw-r--r--src/mbgl/map/map_impl.cpp33
-rw-r--r--src/mbgl/map/map_impl.hpp6
2 files changed, 26 insertions, 13 deletions
diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp
index 69c3de9783..fd4a1e6f83 100644
--- a/src/mbgl/map/map_impl.cpp
+++ b/src/mbgl/map/map_impl.cpp
@@ -1,3 +1,4 @@
+#include <mbgl/actor/scheduler.hpp>
#include <mbgl/layermanager/layer_manager.hpp>
#include <mbgl/map/map_impl.hpp>
#include <mbgl/renderer/update_parameters.hpp>
@@ -11,15 +12,17 @@ Map::Impl::Impl(RendererFrontend& frontend_,
MapObserver& observer_,
std::shared_ptr<FileSource> fileSource_,
const MapOptions& mapOptions)
- : observer(observer_),
- rendererFrontend(frontend_),
- transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()),
- mode(mapOptions.mapMode()),
- pixelRatio(mapOptions.pixelRatio()),
- crossSourceCollisions(mapOptions.crossSourceCollisions()),
- fileSource(std::move(fileSource_)),
- style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
- annotationManager(*style) {
+ : observer(observer_),
+ rendererFrontend(frontend_),
+ transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()),
+ mode(mapOptions.mapMode()),
+ pixelRatio(mapOptions.pixelRatio()),
+ crossSourceCollisions(mapOptions.crossSourceCollisions()),
+ fileSource(std::move(fileSource_)),
+ style(std::make_unique<style::Style>(*fileSource, pixelRatio)),
+ annotationManager(*style),
+ mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
+ actor(*this, mailbox) {
transform.setNorthOrientation(mapOptions.northOrientation());
style->impl->setObserver(this);
rendererFrontend.setObserver(*this);
@@ -39,12 +42,16 @@ void Map::Impl::onSourceChanged(style::Source& source) {
}
void Map::Impl::onUpdate() {
- // Don't load/render anything in still mode until explicitly requested.
- if (mode != MapMode::Continuous && !stillImageRequest) {
- return;
+ if (mode == MapMode::Continuous) {
+ actor.invoke(&Map::Impl::updateInternal, Clock::now());
+ } else if (stillImageRequest) {
+ updateInternal(Clock::time_point::max());
}
+}
- TimePoint timePoint = mode == MapMode::Continuous ? Clock::now() : Clock::time_point::max();
+void Map::Impl::updateInternal(TimePoint timePoint) {
+ // Don't load/render anything in still mode until explicitly requested.
+ assert(mode == MapMode::Continuous || stillImageRequest);
transform.updateTransitions(timePoint);
diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp
index 416662f9e5..aaa9a1d7cd 100644
--- a/src/mbgl/map/map_impl.hpp
+++ b/src/mbgl/map/map_impl.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/annotation/annotation_manager.hpp>
#include <mbgl/map/map.hpp>
#include <mbgl/map/map_observer.hpp>
@@ -51,6 +52,9 @@ public:
// Map
void jumpTo(const CameraOptions&);
+ // Internal
+ void updateInternal(TimePoint timePoint);
+
MapObserver& observer;
RendererFrontend& rendererFrontend;
@@ -74,6 +78,8 @@ public:
bool loading = false;
bool rendererFullyLoaded;
std::unique_ptr<StillImageRequest> stillImageRequest;
+ std::shared_ptr<Mailbox> mailbox;
+ ActorRef<Map::Impl> actor;
};
} // namespace mbgl