summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-04 17:52:00 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-03-18 01:26:22 +0200
commitaa530d2bea565cc2a3ae4ac020d091fd4cca04a2 (patch)
treed3c52c9ae170c6a191879b553121ac7b9363a3cb
parent01edd4503c5b78a73ac8ce1ee1de8b403d76d4fc (diff)
downloadqtlocation-mapboxgl-aa530d2bea565cc2a3ae4ac020d091fd4cca04a2.tar.gz
[core] Cleaned up duplicate code in MapContext
-rw-r--r--src/mbgl/map/map_context.cpp43
-rw-r--r--src/mbgl/map/map_context.hpp3
2 files changed, 19 insertions, 27 deletions
diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp
index bf2ffc546f..5c6f568b2f 100644
--- a/src/mbgl/map/map_context.cpp
+++ b/src/mbgl/map/map_context.cpp
@@ -78,13 +78,16 @@ void MapContext::pause() {
asyncInvalidate.send();
}
-void MapContext::triggerUpdate(const TransformState& state, const Update flags) {
- transformState = state;
+void MapContext::updateAsync(Update flags) {
updateFlags |= flags;
-
asyncUpdate.send();
}
+void MapContext::triggerUpdate(const TransformState& state, Update flags) {
+ transformState = state;
+ updateAsync(flags);
+}
+
void MapContext::setStyleURL(const std::string& url) {
if (styleURL == url) {
return;
@@ -146,8 +149,7 @@ void MapContext::loadStyleJSON(const std::string& json, const std::string& base)
// created but before a style is loaded
data.loading = true;
- updateFlags |= Update::DefaultTransition | Update::Classes | Update::Zoom | Update::Annotations;
- asyncUpdate.send();
+ updateAsync(Update::DefaultTransition | Update::Classes | Update::Zoom | Update::Annotations);
}
void MapContext::update() {
@@ -217,8 +219,7 @@ void MapContext::renderStill(const TransformState& state, const FrameData& frame
transformState = state;
frameData = frame;
- updateFlags |= Update::RenderStill;
- asyncUpdate.send();
+ updateAsync(Update::RenderStill);
}
bool MapContext::renderSync(const TransformState& state, const FrameData& frame) {
@@ -247,11 +248,9 @@ bool MapContext::renderSync(const TransformState& state, const FrameData& frame)
view.afterRender();
if (style->hasTransitions()) {
- updateFlags |= Update::Zoom;
- asyncUpdate.send();
+ updateAsync(Update::Zoom);
} else if (painter->needsAnimation()) {
- updateFlags |= Update::Repaint;
- asyncUpdate.send();
+ updateAsync(Update::Repaint);
}
return isLoaded();
@@ -278,14 +277,12 @@ double MapContext::getTopOffsetPixelsForAnnotationIcon(const std::string& name)
void MapContext::addLayer(std::unique_ptr<StyleLayer> layer, optional<std::string> after) {
style->addLayer(std::move(layer), after);
- updateFlags |= Update::Classes;
- asyncUpdate.send();
+ updateAsync(Update::Classes);
}
void MapContext::removeLayer(const std::string& id) {
style->removeLayer(id);
- updateFlags |= Update::Classes;
- asyncUpdate.send();
+ updateAsync(Update::Classes);
}
std::vector<std::string> MapContext::getClasses() const {
@@ -297,23 +294,16 @@ bool MapContext::hasClass(const std::string& className) const {
}
void MapContext::addClass(const std::string& className) {
- if (style->addClass(className)) {
- updateFlags |= Update::Classes;
- asyncUpdate.send();
- }
+ if (style->addClass(className)) updateAsync(Update::Classes);
}
void MapContext::removeClass(const std::string& className) {
- if (style->removeClass(className)) {
- updateFlags |= Update::Classes;
- asyncUpdate.send();
- }
+ if (style->removeClass(className)) updateAsync(Update::Classes);
}
void MapContext::setClasses(const std::vector<std::string>& classNames) {
style->setClasses(classNames);
- updateFlags |= Update::Classes;
- asyncUpdate.send();
+ updateAsync(Update::Classes);
}
void MapContext::setSourceTileCacheSize(size_t size) {
@@ -334,8 +324,7 @@ void MapContext::onLowMemory() {
}
void MapContext::onResourceLoaded() {
- updateFlags |= Update::Repaint;
- asyncUpdate.send();
+ updateAsync(Update::Repaint);
}
void MapContext::onResourceError(std::exception_ptr error) {
diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp
index 0a76d6179a..11e50cdf0b 100644
--- a/src/mbgl/map/map_context.hpp
+++ b/src/mbgl/map/map_context.hpp
@@ -80,6 +80,9 @@ private:
// Update the state indicated by the accumulated Update flags, then render.
void update();
+ // Helper function for triggering asynchronous updates.
+ void updateAsync(Update);
+
// Loads the actual JSON object an creates a new Style object.
void loadStyleJSON(const std::string& json, const std::string& base);