Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] TylePyramid has sorted render tiles
Browse files Browse the repository at this point in the history
Thus we obviate unneeded extra sorting of render tiles at each rener layer.
  • Loading branch information
pozdnyakov committed Jan 15, 2019
1 parent 59cfce3 commit 1ae224e
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/mbgl/renderer/render_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/renderer/render_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RenderSource : protected TileObserver {
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>>
Expand Down
7 changes: 3 additions & 4 deletions src/mbgl/renderer/sources/render_geojson_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -109,8 +109,7 @@ void RenderGeoJSONSource::update(Immutable<style::Source::Impl> baseImpl_,
}

if (!data_) {
tilePyramid.tiles.clear();
tilePyramid.renderTiles.clear();
tilePyramid.clearAll();
return;
}

Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/renderer/sources/render_raster_dem_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/renderer/sources/render_raster_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/mbgl/renderer/sources/render_vector_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 17 additions & 10 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void TilePyramid::finishRender(PaintParameters& parameters) {
}

std::vector<std::reference_wrapper<RenderTile>> TilePyramid::getRenderTiles() {
return { renderTiles.begin(), renderTiles.end() };
return sortedTiles;
}

Tile* TilePyramid::getTile(const OverscaledTileID& tileID){
Expand Down Expand Up @@ -85,7 +85,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
}

tiles.clear();
renderTiles.clear();
clearRenderTiles();

return;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
tile.markRenderedIdeal();
};

renderTiles.clear();
clearRenderTiles();

if (!panTiles.empty()) {
algorithm::updateRenderables(getTileFn, createTileFn, retainTileFn,
Expand All @@ -205,6 +205,9 @@ void TilePyramid::update(const std::vector<Immutable<style::Layer::Impl>>& layer
}
}

sortedTiles = std::vector<std::reference_wrapper<RenderTile>>(renderTiles.begin(), renderTiles.end());
std::sort(sortedTiles.begin(), sortedTiles.end(), [](const RenderTile& a, const RenderTile& b) { return a.id < b.id; });

if (type != SourceType::Annotations) {
size_t conservativeCacheSize =
std::max((float)parameters.transformState.getSize().width / tileSize, 1.0f) *
Expand Down Expand Up @@ -297,13 +300,6 @@ std::unordered_map<std::string, std::vector<Feature>> TilePyramid::queryRendered

mapbox::geometry::box<double> box = mapbox::geometry::envelope(queryGeometry);

std::vector<std::reference_wrapper<const RenderTile>> sortedTiles{ renderTiles.begin(),
renderTiles.end() };
std::sort(sortedTiles.begin(), sortedTiles.end(), [](const RenderTile& a, const RenderTile& b) {
return std::tie(a.id.canonical.z, a.id.canonical.y, a.id.wrap, a.id.canonical.x) <
std::tie(b.id.canonical.z, b.id.canonical.y, b.id.wrap, b.id.canonical.x);
});

auto maxPitchScaleFactor = transformState.maxPitchScaleFactor();

for (const RenderTile& renderTile : sortedTiles) {
Expand Down Expand Up @@ -365,4 +361,15 @@ void TilePyramid::dumpDebugLogs() const {
}
}

void TilePyramid::clearAll() {
tiles.clear();
clearRenderTiles();
cache.clear();
}

void TilePyramid::clearRenderTiles() {
renderTiles.clear();
sortedTiles.clear();
}

} // namespace mbgl
6 changes: 5 additions & 1 deletion src/mbgl/renderer/tile_pyramid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ class TilePyramid {
void setObserver(TileObserver*);
void dumpDebugLogs() const;

bool enabled = false;
const std::map<OverscaledTileID, std::unique_ptr<Tile>>& getTiles() const { return tiles; }
void clearAll();

private:
std::map<OverscaledTileID, std::unique_ptr<Tile>> tiles;
TileCache cache;

std::vector<RenderTile> renderTiles;
std::vector<std::reference_wrapper<RenderTile>> sortedTiles;
void clearRenderTiles();

TileObserver* observer = nullptr;

Expand Down

0 comments on commit 1ae224e

Please sign in to comment.