summaryrefslogtreecommitdiff
path: root/src/mbgl/style/style.hpp
blob: c70f019c43325b7d36723589e4fc204d89832f70 (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
#ifndef MBGL_STYLE_STYLE
#define MBGL_STYLE_STYLE

#include <mbgl/style/property_transition.hpp>
#include <mbgl/style/zoom_history.hpp>

#include <mbgl/map/source.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/text/glyph_store.hpp>

#include <mbgl/util/uv.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/worker.hpp>

#include <cstdint>
#include <string>
#include <vector>

namespace mbgl {

class Environment;
class GlyphAtlas;
class GlyphStore;
class SpriteAtlas;
class LineAtlas;
class StyleLayer;

class Style : public GlyphStore::Observer,
              public Source::Observer,
              public Sprite::Observer,
              public util::noncopyable {
public:
    Style(const std::string& data,
          const std::string& base,
          uv_loop_t*, Environment&);
    ~Style();

    class Observer {
    public:
        virtual ~Observer() = default;

        virtual void onTileDataChanged() = 0;
        virtual void onResourceLoadingFailed(std::exception_ptr error) = 0;
    };

    void setObserver(Observer*);

    bool isLoaded() const;

    // Fetch the tiles needed by the current viewport and emit a signal when
    // a tile is ready so observers can render the tile.
    void update(MapData&, const TransformState&, TexturePool&);

    void cascade(const std::vector<std::string>&);
    void recalculate(float z, TimePoint now);

    void setDefaultTransitionDuration(Duration);
    bool hasTransitions() const;

    std::unique_ptr<GlyphStore> glyphStore;
    std::unique_ptr<GlyphAtlas> glyphAtlas;
    util::ptr<Sprite> sprite;
    std::unique_ptr<SpriteAtlas> spriteAtlas;
    std::unique_ptr<LineAtlas> lineAtlas;

    std::vector<util::ptr<Source>> sources;
    std::vector<util::ptr<StyleLayer>> layers;

private:
    // GlyphStore::Observer implementation.
    void onGlyphRangeLoaded() override;
    void onGlyphRangeLoadingFailed(std::exception_ptr error) override;

    // Source::Observer implementation.
    void onSourceLoaded() override;
    void onSourceLoadingFailed(std::exception_ptr error) override;
    void onTileLoaded(bool isNewTile) override;
    void onTileLoadingFailed(std::exception_ptr error) override;

    // Sprite::Observer implementation.
    void onSpriteLoaded() override;
    void onSpriteLoadingFailed(std::exception_ptr error) override;

    void emitTileDataChanged();
    void emitResourceLoadingFailed(std::exception_ptr error);

    bool shouldReparsePartialTiles = false;

    Observer* observer = nullptr;

    std::string spriteURL;
    PropertyTransition defaultTransition;
    std::unique_ptr<uv::rwlock> mtx;
    ZoomHistory zoomHistory;

public:
    Worker workers;
};

}

#endif