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

Commit

Permalink
[core] Introduce API to collect placed symbols data
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pozdnyakov committed Mar 25, 2020
1 parent d4db3b1 commit d838256
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
28 changes: 28 additions & 0 deletions include/mbgl/renderer/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ namespace gfx {
class RendererBackend;
} // namespace gfx

struct PlacedSymbolData {
std::u16string key;
std::size_t dataFeatureIndex;
optional<mapbox::geometry::box<float>> textCollisionBox;
optional<mapbox::geometry::box<float>> iconCollisionBox;
bool textPlaced;
bool iconPlaced;
bool intersectsTileBorder;
};

class Renderer {
public:
Renderer(gfx::RendererBackend&, float pixelRatio_, const optional<std::string>& localFontFamily = {});
Expand Down Expand Up @@ -60,6 +70,24 @@ class Renderer {
// 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();
Expand Down
12 changes: 11 additions & 1 deletion src/mbgl/renderer/render_orchestrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -410,7 +411,7 @@ std::unique_ptr<RenderTree> RenderOrchestrator::createRenderTree(
if (renderTreeParameters->placementChanged) {
Mutable<Placement> placement = Placement::create(updateParameters, placementController.getPlacement());
placement->placeLayers(layersNeedPlacement);
placementController.setPlacement(std::move(placement));
if (updateParameters->mode == MapMode::Tile) placementController.setPlacement(std::move(placement));
crossTileSymbolIndex.pruneUnusedLayers(usedSymbolLayers);
for (const auto& entry : renderSources) {
entry.second->updateFadingTiles();
Expand All @@ -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));
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/renderer/render_orchestrator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class RenderOrchestrator final : public GlyphManagerObserver,

void reduceMemoryUse();
void dumpDebugLogs();
void collectPlacedSymbolData(bool);
const std::vector<PlacedSymbolData>& getPlacedSymbolsData() const;
void clearData();

private:
Expand Down Expand Up @@ -124,6 +126,7 @@ class RenderOrchestrator final : public GlyphManagerObserver,

const bool backgroundLayerAsColor;
bool contextLost = false;
bool placedSymbolDataCollected = false;

// Vectors with reserved capacity of layerImpls->size() to avoid reallocation
// on each frame.
Expand Down
8 changes: 8 additions & 0 deletions src/mbgl/renderer/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/text/placement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 7 additions & 4 deletions src/mbgl/text/placement.hpp
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -122,6 +123,8 @@ class Placement {
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; }
Expand Down

0 comments on commit d838256

Please sign in to comment.