summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-08-30 12:43:46 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-09-06 14:29:22 -0700
commit8e2170c8855456258de8ffd49d22a621b95e9fb2 (patch)
tree505c4eba02f5b9e237cf44984d8078c3a13e8414
parent6c23a6a095097c457c896dfeb1a3005a4f618f41 (diff)
downloadqtlocation-mapboxgl-8e2170c8855456258de8ffd49d22a621b95e9fb2.tar.gz
[core] Batch source updates
-rw-r--r--include/mbgl/map/update.hpp5
-rw-r--r--src/mbgl/map/map.cpp4
-rw-r--r--src/mbgl/style/style.cpp35
-rw-r--r--src/mbgl/style/style.hpp3
-rw-r--r--src/mbgl/style/update_batch.hpp15
5 files changed, 46 insertions, 16 deletions
diff --git a/include/mbgl/map/update.hpp b/include/mbgl/map/update.hpp
index 36ce59c01d..1da7e3ac92 100644
--- a/include/mbgl/map/update.hpp
+++ b/include/mbgl/map/update.hpp
@@ -2,11 +2,9 @@
#include <mbgl/util/traits.hpp>
-#include <cstdint>
-
namespace mbgl {
-enum class Update : uint8_t {
+enum class Update {
Nothing = 0,
Dimensions = 1 << 1,
Classes = 1 << 2,
@@ -15,6 +13,7 @@ enum class Update : uint8_t {
Repaint = 1 << 5,
AnnotationStyle = 1 << 6,
AnnotationData = 1 << 7,
+ Layout = 1 << 8
};
constexpr Update operator|(Update lhs, Update rhs) {
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index fe0be15b87..9e18e67f3a 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -212,6 +212,10 @@ void Map::Impl::update() {
annotationManager->updateData();
}
+ if (updateFlags & Update::Layout) {
+ style->relayout();
+ }
+
if (updateFlags & Update::Classes) {
style->cascade(timePoint, mode);
}
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index e797ec7a5b..1009654fc4 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -92,6 +92,7 @@ void Style::setJSON(const std::string& json) {
sources.clear();
layers.clear();
classes.clear();
+ updateBatch = {};
Parser parser;
auto error = parser.parse(json);
@@ -133,9 +134,13 @@ void Style::removeSource(const std::string& id) {
auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
return source->getID() == id;
});
- if (it == sources.end())
+
+ if (it == sources.end()) {
throw std::runtime_error("no such source");
+ }
+
sources.erase(it);
+ updateBatch.sourceIDs.erase(id);
}
std::vector<const Layer*> Style::getLayers() const {
@@ -220,6 +225,15 @@ void Style::updateTiles(const UpdateParameters& parameters) {
}
}
+void Style::relayout() {
+ for (const auto& sourceID : updateBatch.sourceIDs) {
+ Source* source = getSource(sourceID);
+ if (!source) continue;
+ source->baseImpl->reload();
+ }
+ updateBatch.sourceIDs.clear();
+}
+
void Style::cascade(const TimePoint& timePoint, MapMode mode) {
// When in continuous mode, we can either have user- or style-defined
// transitions. Still mode is always immediate.
@@ -487,8 +501,8 @@ void Style::onSpriteError(std::exception_ptr error) {
observer->onResourceError(error);
}
-struct LayerSourceReloadVisitor {
- Style& style;
+struct QueueSourceReloadVisitor {
+ UpdateBatch& updateBatch;
void operator()(CustomLayer&) { assert(false); }
void operator()(RasterLayer&) { assert(false); }
@@ -496,18 +510,13 @@ struct LayerSourceReloadVisitor {
template <class VectorLayer>
void operator()(VectorLayer& layer) {
- Source* source = style.getSource(layer.getSourceID());
- if (!source) return;
- source->baseImpl->reload();
+ updateBatch.sourceIDs.insert(layer.getSourceID());
}
};
-void Style::reloadLayerSource(Layer& layer) {
- layer.accept(LayerSourceReloadVisitor { *this });
-}
-
void Style::onLayerFilterChanged(Layer& layer) {
- reloadLayerSource(layer);
+ layer.accept(QueueSourceReloadVisitor { updateBatch });
+ observer->onUpdate(Update::Layout);
}
void Style::onLayerPaintPropertyChanged(Layer&) {
@@ -515,8 +524,8 @@ void Style::onLayerPaintPropertyChanged(Layer&) {
}
void Style::onLayerLayoutPropertyChanged(Layer& layer) {
- observer->onUpdate(Update::RecalculateStyle);
- reloadLayerSource(layer);
+ layer.accept(QueueSourceReloadVisitor { updateBatch });
+ observer->onUpdate(Update::Layout);
}
void Style::dumpDebugLogs() const {
diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp
index 26b96fba22..b3f70e1eb2 100644
--- a/src/mbgl/style/style.hpp
+++ b/src/mbgl/style/style.hpp
@@ -4,6 +4,7 @@
#include <mbgl/style/observer.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/layer_observer.hpp>
+#include <mbgl/style/update_batch.hpp>
#include <mbgl/text/glyph_store_observer.hpp>
#include <mbgl/sprite/sprite_store_observer.hpp>
#include <mbgl/map/mode.hpp>
@@ -52,6 +53,7 @@ public:
// a tile is ready so observers can render the tile.
void updateTiles(const UpdateParameters&);
+ void relayout();
void cascade(const TimePoint&, MapMode);
void recalculate(float z, const TimePoint&, MapMode);
@@ -142,6 +144,7 @@ private:
std::exception_ptr lastError;
+ UpdateBatch updateBatch;
ZoomHistory zoomHistory;
bool hasPendingTransitions = false;
diff --git a/src/mbgl/style/update_batch.hpp b/src/mbgl/style/update_batch.hpp
new file mode 100644
index 0000000000..ee82c98fda
--- /dev/null
+++ b/src/mbgl/style/update_batch.hpp
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <set>
+#include <string>
+
+namespace mbgl {
+namespace style {
+
+class UpdateBatch {
+public:
+ std::set<std::string> sourceIDs;
+};
+
+} // namespace style
+} // namespace mbgl