[core] TilePyramid has sorted render tiles

Thus we obviate unneeded extra sorting of render tiles at each render layer.
This commit is contained in:
Mikhail Pozdnyakov
2019-01-16 14:35:13 +02:00
parent e0aeeba10f
commit ac3d59862a
8 changed files with 29 additions and 20 deletions

View File

@@ -43,7 +43,7 @@ RenderLayer::RenderTiles RenderLayer::filterRenderTiles(RenderTiles tiles) const
}
void RenderLayer::sortRenderTiles(const TransformState&) {
std::sort(renderTiles.begin(), renderTiles.end(), [](const auto& a, const auto& b) { return a.get().id < b.get().id; });
// no-op
}
const RenderLayerSymbolInterface* RenderLayer::getSymbolInterface() const {

View File

@@ -58,7 +58,7 @@ public:
virtual void startRender(PaintParameters&) = 0;
virtual void finishRender(PaintParameters&) = 0;
// Returns an unsorted list of RenderTiles.
// Returns a list of RenderTiles, sorted by tile id.
virtual std::vector<std::reference_wrapper<RenderTile>> getRenderTiles() = 0;
virtual std::unordered_map<std::string, std::vector<Feature>>

View File

@@ -96,11 +96,11 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
if (data.lock() != data_) {
data = data_;
tilePyramid.cache.clear();
tilePyramid.reduceMemoryUse();
if (data_) {
const uint8_t maxZ = impl().getZoomRange().max;
for (const auto& pair : tilePyramid.tiles) {
for (const auto& pair : tilePyramid.getTiles()) {
if (pair.first.canonical.z <= maxZ) {
static_cast<GeoJSONTile*>(pair.second.get())->updateData(data_->getTile(pair.first.canonical));
}
@@ -109,8 +109,7 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
}
if (!data_) {
tilePyramid.tiles.clear();
tilePyramid.renderTiles.clear();
tilePyramid.clearAll();
return;
}

View File

@@ -38,9 +38,7 @@ void RenderRasterDEMSource::update(Immutable<style::Source::Impl> baseImpl_,
maxzoom = tileset->zoomRange.max;
// TODO: this removes existing buckets, and will cause flickering.
// Should instead refresh tile data in place.
tilePyramid.tiles.clear();
tilePyramid.renderTiles.clear();
tilePyramid.cache.clear();
tilePyramid.clearAll();
}
// Allow clearing the tile pyramid first, before the early return in case
// the new tileset is not yet available or has an error in loading

View File

@@ -36,9 +36,7 @@ void RenderRasterSource::update(Immutable<style::Source::Impl> baseImpl_,
// TODO: this removes existing buckets, and will cause flickering.
// Should instead refresh tile data in place.
tilePyramid.tiles.clear();
tilePyramid.renderTiles.clear();
tilePyramid.cache.clear();
tilePyramid.clearAll();
}
// Allow clearing the tile pyramid first, before the early return in case
// the new tileset is not yet available or has an error in loading

View File

@@ -39,9 +39,7 @@ void RenderVectorSource::update(Immutable<style::Source::Impl> baseImpl_,
// TODO: this removes existing buckets, and will cause flickering.
// Should instead refresh tile data in place.
tilePyramid.tiles.clear();
tilePyramid.renderTiles.clear();
tilePyramid.cache.clear();
tilePyramid.clearAll();
}
// Allow clearing the tile pyramid first, before the early return in case
// the new tileset is not yet available or has an error in loading

View File

@@ -177,7 +177,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
}
auto renderTileFn = [&](const UnwrappedTileID& tileID, Tile& tile) {
renderTiles.emplace_back(tileID, tile);
addRenderTile(tileID, tile);
rendered.emplace(tileID);
previouslyRenderedTiles.erase(tileID); // Still rendering this tile, no need for special fading logic.
tile.markRenderedIdeal();
@@ -200,7 +200,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
// Since it was rendered in the last frame, we know we have it
// Don't mark the tile "Required" to avoid triggering a new network request
retainTileFn(tile, TileNecessity::Optional);
renderTiles.emplace_back(previouslyRenderedTile.first, tile);
addRenderTile(previouslyRenderedTile.first, tile);
rendered.emplace(previouslyRenderedTile.first);
}
}
@@ -296,7 +296,7 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered
}
mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);
// TODO: Find out why we need a special sorting algorithm here.
std::vector<std::reference_wrapper<const RenderTile>> sortedTiles{ renderTiles.begin(),
renderTiles.end() };
std::sort(sortedTiles.begin(), sortedTiles.end(), [](const RenderTile& a, const RenderTile& b) {
@@ -365,4 +365,16 @@ void TilePyramid::dumpDebugLogs() const {
}
}
void TilePyramid::clearAll() {
tiles.clear();
renderTiles.clear();
cache.clear();
}
void TilePyramid::addRenderTile(const UnwrappedTileID& tileID, Tile& tile) {
auto it = std::lower_bound(renderTiles.begin(), renderTiles.end(), tileID,
[](const RenderTile& a, const UnwrappedTileID& id) { return a.id < id; });
renderTiles.emplace(it, tileID, tile);
}
} // namespace mbgl

View File

@@ -66,12 +66,16 @@ public:
void setObserver(TileObserver*);
void dumpDebugLogs() const;
bool enabled = false;
const std::map<OverscaledTileID, std::unique_ptr<Tile>>& getTiles() const { return tiles; }
void clearAll();
private:
void addRenderTile(const UnwrappedTileID& tileID, Tile& tile);
std::map<OverscaledTileID, std::unique_ptr<Tile>> tiles;
TileCache cache;
std::vector<RenderTile> renderTiles;
std::list<RenderTile> renderTiles;
TileObserver* observer = nullptr;