diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-03-25 17:03:52 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-04-02 11:50:52 +0300 |
commit | 5f4e33b1a3d14cdbebbfe724e51bdcba11f44437 (patch) | |
tree | 1c0d6fee60ad678f398196d2a7d7d47ab0ca167b | |
parent | 4bdb3ce200e1b6c7d1838d6ebabf18debd331e04 (diff) | |
download | qtlocation-mapboxgl-5f4e33b1a3d14cdbebbfe724e51bdcba11f44437.tar.gz |
[core] Introduce API to collect placed symbols data
The following methods are added to the `Renderer` class:
- `collectPlacedSymbolData()`
enables or disables collecting of the placed symbols data
- `getPlacedSymbolsData()`
if collecting of the placed symbols data is enabled, returns the
reference to the `PlacedSymbolData` vector holding the collected data.
-rw-r--r-- | include/mbgl/renderer/renderer.hpp | 39 | ||||
-rw-r--r-- | src/mbgl/renderer/render_orchestrator.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/renderer/render_orchestrator.hpp | 3 | ||||
-rw-r--r-- | src/mbgl/renderer/renderer.cpp | 8 | ||||
-rw-r--r-- | src/mbgl/text/placement.cpp | 5 | ||||
-rw-r--r-- | src/mbgl/text/placement.hpp | 11 |
6 files changed, 70 insertions, 6 deletions
diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp index 79782839ee..c7514054e4 100644 --- a/include/mbgl/renderer/renderer.hpp +++ b/include/mbgl/renderer/renderer.hpp @@ -21,6 +21,21 @@ namespace gfx { class RendererBackend; } // namespace gfx +struct PlacedSymbolData { + // Contents of the label + std::u16string key; + // If symbol contains text, text collision box in viewport coordinates + optional<mapbox::geometry::box<float>> textCollisionBox; + // If symbol contains icon, icon collision box in viewport coordinates + optional<mapbox::geometry::box<float>> iconCollisionBox; + // Symbol text was placed + bool textPlaced; + // Symbol icon was placed + bool iconPlaced; + // Symbol text or icon collision box intersects tile borders + bool intersectsTileBorder; +}; + class Renderer { public: Renderer(gfx::RendererBackend&, float pixelRatio_, const optional<std::string>& localFontFamily = {}); @@ -54,12 +69,32 @@ public: void getFeatureState(FeatureState& state, const std::string& sourceID, const optional<std::string>& sourceLayerID, const std::string& featureID) const; - void removeFeatureState(const std::string& sourceID, const optional<std::string>& sourceLayerID, - const optional<std::string>& featureID, const optional<std::string>& stateKey); + void removeFeatureState(const std::string& sourceID, + const optional<std::string>& sourceLayerID, + const optional<std::string>& featureID, + const optional<std::string>& stateKey); // Debug void dumpDebugLogs(); + /** + * @brief In Tile map mode, enables or disables collecting of the placed symbols data, + * which can be obtained with `getPlacedSymbolsData()`. + * + * The placed symbols data collecting is disabled by default. + */ + void collectPlacedSymbolData(bool enable); + + /** + * @brief If collecting of the placed symbols data is enabled, returns the reference + * to the `PlacedSymbolData` vector holding the collected data. + * + * Note: the returned vector gets re-populated at every `render()` call. + * + * @return collected placed symbols data + */ + const std::vector<PlacedSymbolData>& getPlacedSymbolsData() const; + // Memory void reduceMemoryUse(); void clearData(); diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index ae66e4ab42..ac62b71828 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -378,6 +378,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree( } } // Symbol placement. + assert((updateParameters->mode == MapMode::Tile) || !placedSymbolDataCollected); bool symbolBucketsChanged = false; bool symbolBucketsAdded = false; std::set<std::string> usedSymbolLayers; @@ -425,6 +426,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree( renderTreeParameters->placementChanged = symbolBucketsChanged = !layersNeedPlacement.empty(); if (renderTreeParameters->placementChanged) { Mutable<Placement> placement = Placement::create(updateParameters); + placement->collectPlacedSymbolData(placedSymbolDataCollected); placement->placeLayers(layersNeedPlacement); placementController.setPlacement(std::move(placement)); } @@ -635,6 +637,14 @@ void RenderOrchestrator::dumpDebugLogs() { imageManager->dumpDebugLogs(); } +void RenderOrchestrator::collectPlacedSymbolData(bool enable) { + placedSymbolDataCollected = enable; +} + +const std::vector<PlacedSymbolData>& RenderOrchestrator::getPlacedSymbolsData() const { + return placementController.getPlacement()->getPlacedSymbolsData(); +} + RenderLayer* RenderOrchestrator::getRenderLayer(const std::string& id) { auto it = renderLayers.find(id); return it != renderLayers.end() ? it->second.get() : nullptr; diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index 19632c3218..08904e7e5a 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -72,6 +72,8 @@ public: void reduceMemoryUse(); void dumpDebugLogs(); + void collectPlacedSymbolData(bool); + const std::vector<PlacedSymbolData>& getPlacedSymbolsData() const; void clearData(); private: @@ -124,6 +126,7 @@ private: const bool backgroundLayerAsColor; bool contextLost = false; + bool placedSymbolDataCollected = false; // Vectors with reserved capacity of layerImpls->size() to avoid reallocation // on each frame. diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index 0ec73671d1..ac9fac8990 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -125,6 +125,14 @@ void Renderer::dumpDebugLogs() { impl->orchestrator.dumpDebugLogs(); } +void Renderer::collectPlacedSymbolData(bool enable) { + impl->orchestrator.collectPlacedSymbolData(enable); +} + +const std::vector<PlacedSymbolData>& Renderer::getPlacedSymbolsData() const { + return impl->orchestrator.getPlacedSymbolsData(); +} + void Renderer::reduceMemoryUse() { gfx::BackendScope guard { impl->backend }; impl->reduceMemoryUse(); diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 0436a3ccd5..eaea1114d6 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -1142,6 +1142,11 @@ bool Placement::hasTransitions(TimePoint now) const { transitionOptions.duration.value_or(util::DEFAULT_TRANSITION_DURATION); } +const std::vector<PlacedSymbolData>& Placement::getPlacedSymbolsData() const { + const static std::vector<PlacedSymbolData> data; + return data; +} + const CollisionIndex& Placement::getCollisionIndex() const { return collisionIndex; } diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp index add0aa004a..af60f1a66b 100644 --- a/src/mbgl/text/placement.hpp +++ b/src/mbgl/text/placement.hpp @@ -1,11 +1,12 @@ #pragma once -#include <string> -#include <unordered_map> -#include <mbgl/util/chrono.hpp> -#include <mbgl/text/collision_index.hpp> #include <mbgl/layout/symbol_projection.hpp> +#include <mbgl/renderer/renderer.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/text/collision_index.hpp> +#include <mbgl/util/chrono.hpp> +#include <string> +#include <unordered_map> #include <unordered_set> namespace mbgl { @@ -122,6 +123,8 @@ public: virtual float symbolFadeChange(TimePoint now) const; virtual bool hasTransitions(TimePoint now) const; virtual bool transitionsEnabled() const; + virtual void collectPlacedSymbolData(bool /*enable*/) {} + virtual const std::vector<PlacedSymbolData>& getPlacedSymbolsData() const; const CollisionIndex& getCollisionIndex() const; TimePoint getCommitTime() const { return commitTime; } |