summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer/render_source.hpp
blob: 178ee92f93e96beb906fed0bb62121a7112a66e2 (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
#pragma once

#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/util/mat4.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/style/source_impl.hpp>

#include <unordered_map>
#include <vector>
#include <map>
#include <memory>

namespace mbgl {

class Painter;
class TransformState;
class RenderTile;
class RenderedQueryOptions;
class SourceQueryOptions;
class Tile;
class RenderSourceObserver;
class TileParameters;

namespace algorithm {
class ClipIDGenerator;
} // namespace algorithm

class RenderSource : protected TileObserver {
public:
    RenderSource(Immutable<style::Source::Impl>);
    ~RenderSource() override = default;

    virtual bool isLoaded() const = 0;

    // Called when the camera has changed. May load new tiles, unload obsolete tiles, or
    // trigger re-placement of existing complete tiles.
    virtual void updateTiles(const TileParameters&) = 0;

    // Removes all tiles (by putting them into the cache).
    virtual void removeTiles() = 0;

    // Remove all tiles and clear the cache.
    virtual void invalidateTiles() = 0;

    // Request that all loaded tiles re-run the layout operation on the existing source
    // data with fresh style information.
    virtual void reloadTiles() = 0;

    virtual void startRender(algorithm::ClipIDGenerator&,
                             const mat4& projMatrix,
                             const mat4& clipMatrix,
                             const TransformState&) = 0;
    virtual void finishRender(Painter&) = 0;

    virtual std::map<UnwrappedTileID, RenderTile>& getRenderTiles() = 0;

    virtual std::unordered_map<std::string, std::vector<Feature>>
    queryRenderedFeatures(const ScreenLineString& geometry,
                          const TransformState& transformState,
                          const RenderedQueryOptions& options) const = 0;

    virtual std::vector<Feature>
    querySourceFeatures(const SourceQueryOptions&) const = 0;

    virtual void setCacheSize(size_t) = 0;
    virtual void onLowMemory() = 0;

    virtual void dumpDebugLogs() const = 0;

    void setObserver(RenderSourceObserver*);

    Immutable<style::Source::Impl> baseImpl;
    void setImpl(Immutable<style::Source::Impl>);

    bool enabled = false;

protected:
    RenderSourceObserver* observer;

    void onTileChanged(Tile&) final;
    void onTileError(Tile&, std::exception_ptr) final;
};

} // namespace mbgl