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

[core] TilePyramid has sorted render tiles #13739

Merged
merged 1 commit into from
Jan 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function is a no-op, we can remove it entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderSymbolLayer still overrides it, however this is something I'd like to change in the following PR.

}

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
18 changes: 15 additions & 3 deletions src/mbgl/renderer/tile_pyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions 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:
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;

Expand Down