summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-files.json2
-rw-r--r--src/mbgl/renderer/source_state.cpp69
-rw-r--r--src/mbgl/renderer/source_state.hpp26
3 files changed, 97 insertions, 0 deletions
diff --git a/src/core-files.json b/src/core-files.json
index f4f2dd2c40..4867bd3dc4 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -134,6 +134,7 @@
"src/mbgl/renderer/renderer.cpp",
"src/mbgl/renderer/renderer_impl.cpp",
"src/mbgl/renderer/renderer_state.cpp",
+ "src/mbgl/renderer/source_state.cpp",
"src/mbgl/renderer/sources/render_custom_geometry_source.cpp",
"src/mbgl/renderer/sources/render_geojson_source.cpp",
"src/mbgl/renderer/sources/render_image_source.cpp",
@@ -656,6 +657,7 @@
"mbgl/renderer/render_tile.hpp": "src/mbgl/renderer/render_tile.hpp",
"mbgl/renderer/render_tree.hpp": "src/mbgl/renderer/render_tree.hpp",
"mbgl/renderer/renderer_impl.hpp": "src/mbgl/renderer/renderer_impl.hpp",
+ "mbgl/renderer/source_state.hpp": "src/mbgl/renderer/source_state.hpp",
"mbgl/renderer/sources/render_custom_geometry_source.hpp": "src/mbgl/renderer/sources/render_custom_geometry_source.hpp",
"mbgl/renderer/sources/render_geojson_source.hpp": "src/mbgl/renderer/sources/render_geojson_source.hpp",
"mbgl/renderer/sources/render_image_source.hpp": "src/mbgl/renderer/sources/render_image_source.hpp",
diff --git a/src/mbgl/renderer/source_state.cpp b/src/mbgl/renderer/source_state.cpp
new file mode 100644
index 0000000000..087e28b2bb
--- /dev/null
+++ b/src/mbgl/renderer/source_state.cpp
@@ -0,0 +1,69 @@
+#include <mbgl/renderer/source_state.hpp>
+#include <mbgl/style/conversion_impl.hpp>
+#include <mbgl/renderer/render_tile.hpp>
+#include <mbgl/util/logging.hpp>
+
+namespace mbgl {
+
+void SourceFeatureState::updateState(const optional<std::string>& sourceLayerID, const std::string& featureID, const FeatureState& newState) {
+ std::string sourceLayer = sourceLayerID.value_or(std::string());
+ for (const auto& state : newState) {
+ auto& layerStates = stateChanges[sourceLayer];
+ auto& featureStates = layerStates[featureID];
+ featureStates[state.first] = state.second;
+ }
+}
+
+void SourceFeatureState::getState(FeatureState& result, const optional<std::string>& sourceLayerID, const std::string& featureID) const {
+ std::string sourceLayer = sourceLayerID.value_or(std::string());
+ FeatureState current, changes;
+ auto layerStates = currentStates.find(sourceLayer);
+ if (layerStates != currentStates.end()) {
+ const auto currentStateEntry = layerStates->second.find(featureID);
+ if (currentStateEntry != layerStates->second.end()) {
+ current = currentStateEntry->second;
+ }
+ }
+
+ layerStates = stateChanges.find(sourceLayer);
+ if (layerStates != stateChanges.end()) {
+ const auto stateChangesEntry = layerStates->second.find(featureID);
+ if (stateChangesEntry != layerStates->second.end()) {
+ changes = stateChangesEntry->second;
+ }
+ }
+ result = std::move(changes);
+ result.insert(current.begin(), current.end());
+}
+
+void SourceFeatureState::coalesceChanges(std::vector<RenderTile>& tiles) {
+ LayerFeatureStates changes;
+ for (const auto& layerStatesEntry : stateChanges) {
+ const auto& sourceLayer = layerStatesEntry.first;
+ FeatureStates layerStates;
+ for (const auto& featureStatesEntry : stateChanges[sourceLayer]) {
+ const auto& featureID = featureStatesEntry.first;
+ for (const auto& stateEntry : stateChanges[sourceLayer][featureID]) {
+ const auto& stateKey = stateEntry.first;
+ const auto& stateVal = stateEntry.second;
+
+ auto currentState = currentStates[sourceLayer][featureID].find(stateKey);
+ if (currentState != currentStates[sourceLayer][featureID].end()) {
+ currentState->second = stateVal;
+ } else {
+ currentStates[sourceLayer][featureID].insert(std::make_pair(stateKey, stateVal));
+ }
+ }
+ layerStates[featureID] = currentStates[sourceLayer][featureID];
+ }
+ changes[sourceLayer] = std::move(layerStates);
+ }
+ stateChanges.clear();
+ if (changes.empty()) return;
+
+ for (auto& tile : tiles) {
+ tile.setFeatureState(changes);
+ }
+}
+
+} // namespace mbgl
diff --git a/src/mbgl/renderer/source_state.hpp b/src/mbgl/renderer/source_state.hpp
new file mode 100644
index 0000000000..9944709b0d
--- /dev/null
+++ b/src/mbgl/renderer/source_state.hpp
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <mbgl/style/conversion.hpp>
+#include <mbgl/util/feature.hpp>
+
+namespace mbgl {
+
+class RenderTile;
+using namespace style::conversion;
+
+class SourceFeatureState {
+public:
+ SourceFeatureState() = default;
+ ~SourceFeatureState() = default;
+
+ void updateState(const optional<std::string>& sourceLayerID, const std::string& featureID, const FeatureState& newState);
+ void getState(FeatureState& result, const optional<std::string>& sourceLayerID, const std::string& featureID) const;
+
+ void coalesceChanges(std::vector<RenderTile>& tiles);
+
+private:
+ LayerFeatureStates currentStates;
+ LayerFeatureStates stateChanges;
+};
+
+} // namespace mbgl