[core] Add removeFeatureState API
This commit is contained in:
@@ -59,7 +59,10 @@ public:
|
||||
const optional<std::string>& sourceLayerID,
|
||||
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);
|
||||
|
||||
// Debug
|
||||
void dumpDebugLogs();
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user