diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-09-19 15:54:13 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-10-27 18:14:53 -0700 |
commit | ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb (patch) | |
tree | 66632219fe62c86edf9f8424004f99d1008dbc14 | |
parent | 91272992f3a7ca7baa124c3378f1c1e2b3e5bb76 (diff) | |
download | qtlocation-mapboxgl-ef8017198ce8f0bd79ba5a5ed31e35a16e3433bb.tar.gz |
[core] remove tiles for disabled sources
When no layer of a source is visible anymore, we are now evicting tiles that are still stored in that source and move them to the cache.
-rw-r--r-- | src/mbgl/style/source_impl.cpp | 24 | ||||
-rw-r--r-- | src/mbgl/style/source_impl.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/style.cpp | 9 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 1fb6d59f0e..68e2feed1b 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -146,6 +146,19 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { cache.setSize(conservativeCacheSize); } + removeStaleTiles(retain); + + const PlacementConfig config { parameters.transformState.getAngle(), + parameters.transformState.getPitch(), + parameters.debugOptions & MapDebugOptions::Collision }; + + for (auto& pair : tiles) { + pair.second->setPlacementConfig(config); + } +} + +// Moves all tiles to the cache except for those specified in the retain set. +void Source::Impl::removeStaleTiles(const std::set<OverscaledTileID>& retain) { // Remove stale tiles. This goes through the (sorted!) tiles map and retain set in lockstep // and removes items from tiles that don't have the corresponding key in the retain set. auto tilesIt = tiles.begin(); @@ -162,13 +175,12 @@ void Source::Impl::updateTiles(const UpdateParameters& parameters) { ++retainIt; } } +} - const PlacementConfig config { parameters.transformState.getAngle(), - parameters.transformState.getPitch(), - parameters.debugOptions & MapDebugOptions::Collision }; - - for (auto& pair : tiles) { - pair.second->setPlacementConfig(config); +void Source::Impl::removeTiles() { + renderTiles.clear(); + if (!tiles.empty()) { + removeStaleTiles({}); } } diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index 14ed9cd01c..9efe5205b3 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -48,6 +48,9 @@ public: // re-placement of existing complete tiles. void updateTiles(const UpdateParameters&); + // Removes all tiles (by putting them into the cache). + void removeTiles(); + // Request that all loaded tiles re-run the layout operation on the existing source // data with fresh style information. void reloadTiles(); @@ -82,6 +85,7 @@ public: protected: void invalidateTiles(); + void removeStaleTiles(const std::set<OverscaledTileID>&); Source& base; SourceObserver* observer = nullptr; diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 0605a66d80..cec922f45e 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -254,6 +254,8 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) { } void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { + // Disable all sources first. If we find an enabled layer that uses this source, we will + // re-enable it later. for (const auto& source : sources) { source->baseImpl->enabled = false; } @@ -287,6 +289,13 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { } } } + + // Remove the existing tiles if we didn't end up re-enabling the source. + for (const auto& source : sources) { + if (!source->baseImpl->enabled) { + source->baseImpl->removeTiles(); + } + } } Source* Style::getSource(const std::string& id) const { |