diff options
author | Juha Alanen <juha.alanen@mapbox.com> | 2019-09-13 11:15:21 +0300 |
---|---|---|
committer | Juha Alanen <19551460+jmalanen@users.noreply.github.com> | 2019-09-18 14:29:15 +0300 |
commit | 48f462bc7b09285c09c2a6f3cd07b555fcd21f43 (patch) | |
tree | dda1b1cbd4ddd2434ed701977fa611825a824212 /src/mbgl/renderer | |
parent | 7ce9b0d47d794411bdf1315e22b6b8234c4f1a9d (diff) | |
download | qtlocation-mapboxgl-48f462bc7b09285c09c2a6f3cd07b555fcd21f43.tar.gz |
[core] Add removeFeatureState API
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r-- | src/mbgl/renderer/render_orchestrator.cpp | 9 | ||||
-rw-r--r-- | src/mbgl/renderer/render_orchestrator.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/renderer/render_source.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/renderer/source_state.cpp | 54 | ||||
-rw-r--r-- | src/mbgl/renderer/source_state.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_tile_source.cpp | 6 | ||||
-rw-r--r-- | src/mbgl/renderer/sources/render_tile_source.hpp | 4 |
8 files changed, 91 insertions, 0 deletions
diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index fbf98500b4..6bccee7798 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -580,6 +580,15 @@ void RenderOrchestrator::getFeatureState(FeatureState& state, } } +void RenderOrchestrator::removeFeatureState(const std::string& sourceID, + const optional<std::string>& sourceLayerID, + const optional<std::string>& featureID, + const optional<std::string>& stateKey) { + if (RenderSource* renderSource = getRenderSource(sourceID)) { + renderSource->removeFeatureState(sourceLayerID, featureID, stateKey); + } +} + void RenderOrchestrator::reduceMemoryUse() { filteredLayersForSource.shrink_to_fit(); for (const auto& entry : renderSources) { diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index 7467e0c7dd..f42a40ec33 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -74,6 +74,11 @@ public: const optional<std::string>& layerID, const std::string& featureID) const; + void removeFeatureState(const std::string& sourceID, + const optional<std::string>& sourceLayerID, + const optional<std::string>& featureID, + const optional<std::string>& stateKey); + void reduceMemoryUse(); void dumpDebugLogs(); diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index c803c82c95..39ca97d563 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -101,6 +101,10 @@ public: const optional<std::string>&, const std::string&) const {} + virtual void removeFeatureState(const optional<std::string>&, + const optional<std::string>&, + const optional<std::string>&) {} + virtual void reduceMemoryUse() = 0; virtual void dumpDebugLogs() const = 0; diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index 40b342b1d4..a91a0098ca 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -123,6 +123,13 @@ void Renderer::getFeatureState(FeatureState& state, impl->orchestrator.getFeatureState(state, sourceID, sourceLayerID, featureID); } +void Renderer::removeFeatureState(const std::string& sourceID, + const optional<std::string>& sourceLayerID, + const optional<std::string>& featureID, + const optional<std::string>& stateKey) { + impl->orchestrator.removeFeatureState(sourceID, sourceLayerID, featureID, stateKey); +} + void Renderer::dumpDebugLogs() { impl->orchestrator.dumpDebugLogs(); } diff --git a/src/mbgl/renderer/source_state.cpp b/src/mbgl/renderer/source_state.cpp index 087e28b2bb..c1b95aca68 100644 --- a/src/mbgl/renderer/source_state.cpp +++ b/src/mbgl/renderer/source_state.cpp @@ -58,7 +58,37 @@ void SourceFeatureState::coalesceChanges(std::vector<RenderTile>& tiles) { } changes[sourceLayer] = std::move(layerStates); } + + for (const auto& layerStatesEntry : deletedStates) { + const auto& sourceLayer = layerStatesEntry.first; + FeatureStates layerStates = { {}, {} }; + + if (deletedStates[sourceLayer].empty()) { + for (const auto& featureStatesEntry : currentStates[sourceLayer]) { + const auto& featureID = featureStatesEntry.first; + layerStates[featureID] = {}; + currentStates[sourceLayer][featureID] = {}; + } + } else { + for (const auto& feature : deletedStates[sourceLayer]) { + const auto& featureID = feature.first; + bool deleteWholeFeatureState = deletedStates[sourceLayer][featureID].empty(); + if (deleteWholeFeatureState) { + currentStates[sourceLayer][featureID] = {}; + } else { + for (const auto& stateEntry : deletedStates[sourceLayer][featureID]) { + currentStates[sourceLayer][featureID].erase(stateEntry.first); + } + } + layerStates[featureID] = currentStates[sourceLayer][featureID]; + } + } + changes[sourceLayer] = std::move(layerStates); + } + stateChanges.clear(); + deletedStates.clear(); + if (changes.empty()) return; for (auto& tile : tiles) { @@ -66,4 +96,28 @@ void SourceFeatureState::coalesceChanges(std::vector<RenderTile>& tiles) { } } +void SourceFeatureState::removeState(const optional<std::string>& sourceLayerID, const optional<std::string>& featureID, const optional<std::string>& stateKey) { + std::string sourceLayer = sourceLayerID.value_or(std::string()); + + bool sourceLayerDeleted = (deletedStates.count(sourceLayer) > 0) && deletedStates[sourceLayer].empty(); + if (sourceLayerDeleted) return; + + if (stateKey && featureID) { + if ((deletedStates.count(sourceLayer) == 0) && (deletedStates[sourceLayer].count(*featureID)) == 0) { + deletedStates[sourceLayer][*featureID][*stateKey] = {}; + } + } else if (featureID) { + bool updateInQueue = stateChanges.count(sourceLayer) && stateChanges[sourceLayer].count(*featureID); + if (updateInQueue) { + for (const auto& changeEntry : stateChanges[sourceLayer][*featureID]) { + deletedStates[sourceLayer][*featureID][changeEntry.first] = {}; + } + } else { + deletedStates[sourceLayer][*featureID] = {}; + } + } else { + deletedStates[sourceLayer] = {}; + } +} + } // namespace mbgl diff --git a/src/mbgl/renderer/source_state.hpp b/src/mbgl/renderer/source_state.hpp index 9944709b0d..61546aff62 100644 --- a/src/mbgl/renderer/source_state.hpp +++ b/src/mbgl/renderer/source_state.hpp @@ -15,12 +15,14 @@ public: 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 removeState(const optional<std::string>& sourceLayerID, const optional<std::string>& featureID, const optional<std::string>& stateKey); void coalesceChanges(std::vector<RenderTile>& tiles); private: LayerFeatureStates currentStates; LayerFeatureStates stateChanges; + LayerFeatureStates deletedStates; }; } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index f2297f7ed4..3c6eff0855 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -146,6 +146,12 @@ void RenderTileSource::getFeatureState(FeatureState& state, featureState.getState(state, sourceLayerID, featureID); } +void RenderTileSource::removeFeatureState(const optional<std::string>& sourceLayerID, + const optional<std::string>& featureID, + const optional<std::string>& stateKey) { + featureState.removeState(sourceLayerID, featureID, stateKey); +} + void RenderTileSource::reduceMemoryUse() { tilePyramid.reduceMemoryUse(); } diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp index 822b2cac16..48eea8558c 100644 --- a/src/mbgl/renderer/sources/render_tile_source.hpp +++ b/src/mbgl/renderer/sources/render_tile_source.hpp @@ -43,6 +43,10 @@ public: const optional<std::string>&, const std::string&) const override; + virtual void removeFeatureState(const optional<std::string>&, + const optional<std::string>&, + const optional<std::string>&) override; + void reduceMemoryUse() override; void dumpDebugLogs() const override; |