diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp index 123a7767540..903825d5f57 100644 --- a/src/mbgl/annotation/render_annotation_source.cpp +++ b/src/mbgl/annotation/render_annotation_source.cpp @@ -46,7 +46,7 @@ void RenderAnnotationSource::update(Immutable baseImpl_, std::unordered_map> RenderAnnotationSource::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const { return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); diff --git a/src/mbgl/annotation/render_annotation_source.hpp b/src/mbgl/annotation/render_annotation_source.hpp index e5d5130446a..d748455a7bd 100644 --- a/src/mbgl/annotation/render_annotation_source.hpp +++ b/src/mbgl/annotation/render_annotation_source.hpp @@ -18,7 +18,7 @@ class RenderAnnotationSource final : public RenderTileSource { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const final; diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index f61f89b8e7f..3675e8bc6ed 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -47,7 +47,7 @@ void FeatureIndex::query( const double scale, const RenderedQueryOptions& queryOptions, const UnwrappedTileID& tileID, - const std::vector& layers, + const std::unordered_map& layers, const float additionalQueryPadding) const { if (!tileData) { @@ -81,7 +81,7 @@ void FeatureIndex::query( std::unordered_map> FeatureIndex::lookupSymbolFeatures(const std::vector& symbolFeatures, const RenderedQueryOptions& queryOptions, - const std::vector& layers, + const std::unordered_map& layers, const OverscaledTileID& tileID, const std::shared_ptr>& featureSortOrder) const { std::unordered_map> result; @@ -123,31 +123,24 @@ void FeatureIndex::addFeature( const IndexedSubfeature& indexedFeature, const RenderedQueryOptions& options, const CanonicalTileID& tileID, - const std::vector& layers, + const std::unordered_map& layers, const GeometryCoordinates& queryGeometry, const TransformState& transformState, const float pixelsToTileUnits, const mat4& posMatrix) const { - auto getRenderLayer = [&] (const std::string& layerID) -> const RenderLayer* { - for (const auto& layer : layers) { - if (layer->getID() == layerID) { - return layer; - } - } - return nullptr; - }; - // Lazily calculated. std::unique_ptr sourceLayer; std::unique_ptr geometryTileFeature; for (const std::string& layerID : bucketLayerIDs.at(indexedFeature.bucketLeaderID)) { - const RenderLayer* renderLayer = getRenderLayer(layerID); - if (!renderLayer) { + const auto it = layers.find(layerID); + if (it == layers.end()) { continue; } + const RenderLayer* renderLayer = it->second; + if (!geometryTileFeature) { sourceLayer = tileData->getLayer(indexedFeature.sourceLayerName); assert(sourceLayer); diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index cd041a7fdba..1a212761fa2 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -67,7 +67,7 @@ class FeatureIndex { const double scale, const RenderedQueryOptions& options, const UnwrappedTileID&, - const std::vector&, + const std::unordered_map&, const float additionalQueryPadding) const; static optional translateQueryGeometry( @@ -82,7 +82,7 @@ class FeatureIndex { std::unordered_map> lookupSymbolFeatures( const std::vector& symbolFeatures, const RenderedQueryOptions& options, - const std::vector& layers, + const std::unordered_map& layers, const OverscaledTileID& tileID, const std::shared_ptr>& featureSortOrder) const; @@ -92,7 +92,7 @@ class FeatureIndex { const IndexedSubfeature&, const RenderedQueryOptions& options, const CanonicalTileID&, - const std::vector&, + const std::unordered_map&, const GeometryCoordinates& queryGeometry, const TransformState& transformState, const float pixelsToTileUnits, diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index 71e38f2afd2..01e6dd53655 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -79,7 +79,7 @@ class RenderSource : protected TileObserver { virtual std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const = 0; diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index e1e8430df11..78681e06f2a 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -173,6 +173,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { } // Create render layers for newly added layers. + renderLayers.reserve(renderLayers.size() + layerDiff.added.size()); for (const auto& entry : layerDiff.added) { auto renderLayer = LayerManager::get()->createRenderLayer(entry.second); renderLayer->transition(transitionParameters); @@ -550,16 +551,16 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { } std::vector Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options) const { - std::vector layers; + std::unordered_map layers; if (options.layerIDs) { for (const auto& layerID : *options.layerIDs) { if (const RenderLayer* layer = getRenderLayer(layerID)) { - layers.emplace_back(layer); + layers.emplace(layer->getID(), layer); } } } else { for (const auto& entry : renderLayers) { - layers.emplace_back(entry.second.get()); + layers.emplace(entry.second->getID(), entry.second.get()); } } @@ -568,9 +569,22 @@ std::vector Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin void Renderer::Impl::queryRenderedSymbols(std::unordered_map>& resultsByLayer, const ScreenLineString& geometry, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options) const { - + const auto hasCrossTileIndex = [] (const auto& pair) { + return pair.second->baseImpl->getTypeInfo()->crossTileIndex == style::LayerTypeInfo::CrossTileIndex::Required; + }; + + std::unordered_map crossTileSymbolIndexLayers; + std::copy_if(layers.begin(), + layers.end(), + std::inserter(crossTileSymbolIndexLayers, crossTileSymbolIndexLayers.begin()), + hasCrossTileIndex); + + if (crossTileSymbolIndexLayers.empty()) { + return; + } + auto renderedSymbols = placement->getCollisionIndex().queryRenderedSymbols(geometry); std::vector> bucketQueryData; for (auto entry : renderedSymbols) { @@ -588,7 +602,7 @@ void Renderer::Impl::queryRenderedSymbols(std::unordered_maplookupSymbolFeatures(renderedSymbols[queryData.bucketInstanceId], options, - layers, + crossTileSymbolIndexLayers, queryData.tileID, queryData.featureSortOrder); @@ -599,10 +613,10 @@ void Renderer::Impl::queryRenderedSymbols(std::unordered_map Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options, const std::vector& layers) const { +std::vector Renderer::Impl::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options, const std::unordered_map& layers) const { std::unordered_set sourceIDs; - for (const RenderLayer* layer : layers) { - sourceIDs.emplace(layer->baseImpl->source); + for (const auto& pair : layers) { + sourceIDs.emplace(pair.second->baseImpl->source); } mat4 projMatrix; @@ -625,13 +639,12 @@ std::vector Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin } // Combine all results based on the style layer renderItems. - for (const auto& layerImpl : *layerImpls) { - const RenderLayer* layer = getRenderLayer(layerImpl->id); - if (!layer->needsRendering() || !layer->supportsZoom(zoomHistory.lastZoom)) { + for (const auto& pair : layers) { + if (!pair.second->needsRendering() || !pair.second->supportsZoom(zoomHistory.lastZoom)) { continue; } - auto it = resultsByLayer.find(layer->baseImpl->id); + auto it = resultsByLayer.find(pair.second->baseImpl->id); if (it != resultsByLayer.end()) { std::move(it->second.begin(), it->second.end(), std::back_inserter(result)); } @@ -642,13 +655,13 @@ std::vector Renderer::Impl::queryRenderedFeatures(const ScreenLineStrin std::vector Renderer::Impl::queryShapeAnnotations(const ScreenLineString& geometry) const { assert(LayerManager::annotationsEnabled); - std::vector shapeAnnotationLayers; + std::unordered_map shapeAnnotationLayers; RenderedQueryOptions options; for (const auto& layerImpl : *layerImpls) { if (std::mismatch(layerImpl->id.begin(), layerImpl->id.end(), AnnotationManager::ShapeLayerID.begin(), AnnotationManager::ShapeLayerID.end()).second == AnnotationManager::ShapeLayerID.end()) { if (const RenderLayer* layer = getRenderLayer(layerImpl->id)) { - shapeAnnotationLayers.emplace_back(layer); + shapeAnnotationLayers.emplace(layer->getID(), layer); } } } diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp index 51fc50b5747..75098fac66b 100644 --- a/src/mbgl/renderer/renderer_impl.hpp +++ b/src/mbgl/renderer/renderer_impl.hpp @@ -78,10 +78,10 @@ class Renderer::Impl : public GlyphManagerObserver, void queryRenderedSymbols(std::unordered_map>& resultsByLayer, const ScreenLineString& geometry, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options) const; - std::vector queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&, const std::vector&) const; + std::vector queryRenderedFeatures(const ScreenLineString&, const RenderedQueryOptions&, const std::unordered_map&) const; // GlyphManagerObserver implementation. void onGlyphsError(const FontStack&, const GlyphRange&, std::exception_ptr) override; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index db5ba75ffcc..206799ce4c5 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -96,7 +96,7 @@ void RenderImageSource::finishRender(PaintParameters& parameters) { std::unordered_map> RenderImageSource::queryRenderedFeatures(const ScreenLineString&, const TransformState&, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions&, const mat4&) const { return std::unordered_map> {}; diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp index a656ccd5390..e8dfcf658b5 100644 --- a/src/mbgl/renderer/sources/render_image_source.hpp +++ b/src/mbgl/renderer/sources/render_image_source.hpp @@ -40,7 +40,7 @@ class RenderImageSource : public RenderSource { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const final; diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp index 9854b4fdc39..841124fa4a2 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp @@ -125,7 +125,7 @@ void RenderRasterDEMSource::onTileChanged(Tile& tile){ std::unordered_map> RenderRasterDEMSource::queryRenderedFeatures(const ScreenLineString&, const TransformState&, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions&, const mat4&) const { return std::unordered_map>{}; diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp index d1e7f03e10a..e5148eb4cf8 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp @@ -19,7 +19,7 @@ class RenderRasterDEMSource final : public RenderTileSource { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const override; diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp index 827ffb9759c..06eb36795bf 100644 --- a/src/mbgl/renderer/sources/render_raster_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_source.cpp @@ -60,7 +60,7 @@ void RenderRasterSource::prepare(const SourcePrepareParameters& parameters) { std::unordered_map> RenderRasterSource::queryRenderedFeatures(const ScreenLineString&, const TransformState&, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions&, const mat4&) const { return std::unordered_map>{}; diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp index ec6d7f24743..e6424657dd0 100644 --- a/src/mbgl/renderer/sources/render_raster_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_source.hpp @@ -19,7 +19,7 @@ class RenderRasterSource final : public RenderTileSource { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const override; diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index 1037a2f78ec..706806dd871 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -56,7 +56,7 @@ std::vector> RenderTileSource::getRenderedTil std::unordered_map> RenderTileSource::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const { return tilePyramid.queryRenderedFeatures(geometry, transformState, layers, options, projMatrix); diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp index 5501e260f57..41e28bf13fb 100644 --- a/src/mbgl/renderer/sources/render_tile_source.hpp +++ b/src/mbgl/renderer/sources/render_tile_source.hpp @@ -27,7 +27,7 @@ class RenderTileSource : public RenderSource { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const override; diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index dee84c4e320..2b6c5f0c99f 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -284,7 +284,7 @@ void TilePyramid::handleWrapJump(float lng) { std::unordered_map> TilePyramid::queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) const { std::unordered_map> result; diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp index 610828bdb37..9615f146eee 100644 --- a/src/mbgl/renderer/tile_pyramid.hpp +++ b/src/mbgl/renderer/tile_pyramid.hpp @@ -51,7 +51,7 @@ class TilePyramid { std::unordered_map> queryRenderedFeatures(const ScreenLineString& geometry, const TransformState& transformState, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions& options, const mat4& projMatrix) const; diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 7a7b7cb7708..bda4129f3a2 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -238,12 +238,12 @@ LayerRenderData* GeometryTile::getMutableLayerRenderData(const style::Layer::Imp return &result; } -float GeometryTile::getQueryPadding(const std::vector& layers) { +float GeometryTile::getQueryPadding(const std::unordered_map& layers) { float queryPadding = 0; - for (const RenderLayer* layer : layers) { - auto bucket = getBucket(*layer->baseImpl); + for (const auto& pair : layers) { + auto bucket = getBucket(*pair.second->baseImpl); if (bucket && bucket->hasData()) { - queryPadding = std::max(queryPadding, bucket->getQueryRadius(*layer)); + queryPadding = std::max(queryPadding, bucket->getQueryRadius(*pair.second)); } } return queryPadding; @@ -253,7 +253,7 @@ void GeometryTile::queryRenderedFeatures( std::unordered_map>& result, const GeometryCoordinates& queryGeometry, const TransformState& transformState, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) { diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index cbc94deed08..8920f81e5a5 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -53,7 +53,7 @@ class GeometryTile : public Tile, public GlyphRequestor, public ImageRequestor { std::unordered_map>& result, const GeometryCoordinates& queryGeometry, const TransformState&, - const std::vector& layers, + const std::unordered_map& layers, const RenderedQueryOptions& options, const mat4& projMatrix) override; @@ -61,7 +61,7 @@ class GeometryTile : public Tile, public GlyphRequestor, public ImageRequestor { std::vector& result, const SourceQueryOptions&) override; - float getQueryPadding(const std::vector&) override; + float getQueryPadding(const std::unordered_map&) override; void cancel() override; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index 5e31898cafd..2f342c092d7 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -43,11 +43,11 @@ void Tile::queryRenderedFeatures( std::unordered_map>&, const GeometryCoordinates&, const TransformState&, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions&, const mat4&) {} -float Tile::getQueryPadding(const std::vector&) { +float Tile::getQueryPadding(const std::unordered_map&) { return 0; } diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 95ee0bc37eb..7a7cb9423c6 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -70,7 +70,7 @@ class Tile { std::unordered_map>& result, const GeometryCoordinates& queryGeometry, const TransformState&, - const std::vector&, + const std::unordered_map&, const RenderedQueryOptions& options, const mat4& projMatrix); @@ -78,7 +78,7 @@ class Tile { std::vector& result, const SourceQueryOptions&); - virtual float getQueryPadding(const std::vector&); + virtual float getQueryPadding(const std::unordered_map&); void setTriedCache();