summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/renderer.cpp
blob: 5e92bd4b79ae7d246b53a51f72a13bc4f3665c2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <mbgl/renderer/renderer.hpp>

#include <mbgl/layermanager/layer_manager.hpp>
#include <mbgl/renderer/renderer_impl.hpp>
#include <mbgl/renderer/render_tree.hpp>
#include <mbgl/gfx/backend_scope.hpp>
#include <mbgl/annotation/annotation_manager.hpp>

namespace mbgl {

Renderer::Renderer(gfx::RendererBackend& backend, float pixelRatio_, const optional<std::string> localFontFamily_)
    : impl(std::make_unique<Impl>(backend, pixelRatio_, localFontFamily_)) {}

Renderer::~Renderer() {
    gfx::BackendScope guard { impl->backend };
    impl.reset();
}

void Renderer::markContextLost() {
    impl->orchestrator.markContextLost();
}

void Renderer::setObserver(RendererObserver* observer) {
    impl->setObserver(observer);
    impl->orchestrator.setObserver(observer);
}

void Renderer::render(const std::shared_ptr<UpdateParameters>& updateParameters) {
    assert(updateParameters);
    auto frame_start = Clock::now();
    if (auto renderTree = impl->orchestrator.createRenderTree(updateParameters)) {
        renderTree->prepare();
        impl->render(*renderTree, frame_start);
    }
}

std::vector<Feature> Renderer::queryRenderedFeatures(const ScreenLineString& geometry, const RenderedQueryOptions& options) const {
    return impl->orchestrator.queryRenderedFeatures(geometry, options);
}

std::vector<Feature> Renderer::queryRenderedFeatures(const ScreenCoordinate& point, const RenderedQueryOptions& options) const {
    return impl->orchestrator.queryRenderedFeatures({ point }, options);
}

std::vector<Feature> Renderer::queryRenderedFeatures(const ScreenBox& box, const RenderedQueryOptions& options) const {
    return impl->orchestrator.queryRenderedFeatures(
            {
                    box.min,
                    {box.max.x, box.min.y},
                    box.max,
                    {box.min.x, box.max.y},
                    box.min
            },
            options
    );
}

AnnotationIDs Renderer::queryPointAnnotations(const ScreenBox& box) const {
    if (!LayerManager::annotationsEnabled) {
        return {};
    }
    RenderedQueryOptions options;
    options.layerIDs = {{ AnnotationManager::PointLayerID }};
    auto features = queryRenderedFeatures(box, options);
    return getAnnotationIDs(features);
}

AnnotationIDs Renderer::queryShapeAnnotations(const ScreenBox& box) const {
    if (!LayerManager::annotationsEnabled) {
        return {};
    }
    auto features = impl->orchestrator.queryShapeAnnotations({
        box.min,
        {box.max.x, box.min.y},
        box.max,
        {box.min.x, box.max.y},
        box.min
    });
    return getAnnotationIDs(features);
}
    
AnnotationIDs Renderer::getAnnotationIDs(const std::vector<Feature>& features) const {
    if (!LayerManager::annotationsEnabled) {
        return {};
    }
    std::set<AnnotationID> set;
    for (auto &feature : features) {
        assert(feature.id.is<uint64_t>());
        assert(feature.id.get<uint64_t>() <= std::numeric_limits<AnnotationID>::max());
        set.insert(static_cast<AnnotationID>(feature.id.get<uint64_t>()));
    }
    AnnotationIDs ids;
    ids.reserve(set.size());
    std::move(set.begin(), set.end(), std::back_inserter(ids));
    return ids;
}

std::vector<Feature> Renderer::querySourceFeatures(const std::string& sourceID, const SourceQueryOptions& options) const {
    return impl->orchestrator.querySourceFeatures(sourceID, options);
}

FeatureExtensionValue Renderer::queryFeatureExtensions(const std::string& sourceID,
                                                       const Feature& feature,
                                                       const std::string& extension,
                                                       const std::string& extensionField,
                                                       const optional<std::map<std::string, Value>>& args) const {
    return impl->orchestrator.queryFeatureExtensions(sourceID, feature, extension, extensionField, args);
}

void Renderer::setFeatureState(const std::string& sourceID, const optional<std::string>& sourceLayerID,
                               const std::string& featureID, const FeatureState& state) {
    impl->orchestrator.setFeatureState(sourceID, sourceLayerID, featureID, state);
}

void Renderer::getFeatureState(FeatureState& state, const std::string& sourceID,
                               const optional<std::string>& sourceLayerID, const std::string& featureID) const {
    impl->orchestrator.getFeatureState(state, sourceID, sourceLayerID, featureID);
}

void Renderer::removeFeatureState(const std::string& sourceID, const optional<std::string>& sourceLayerID,
                                  const optional<std::string>& featureID, const optional<std::string>& stateKey) {
    impl->orchestrator.removeFeatureState(sourceID, sourceLayerID, featureID, stateKey);
}

void Renderer::dumpDebugLogs() {
    impl->orchestrator.dumpDebugLogs();
}

void Renderer::reduceMemoryUse() {
    gfx::BackendScope guard { impl->backend };
    impl->reduceMemoryUse();
    impl->orchestrator.reduceMemoryUse();
}

} // namespace mbgl