blob: 33949aa487fbcf0ed47f55ac4188ec698569b4ff (
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
|
#ifndef MBGL_MAP_RESOURCE_LOADER
#define MBGL_MAP_RESOURCE_LOADER
#include <mbgl/map/source.hpp>
#include <mbgl/map/sprite.hpp>
#include <mbgl/text/glyph_store.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <string>
namespace mbgl {
class GlyphAtlas;
class GlyphStore;
class MapData;
class SpriteAtlas;
class Style;
class TexturePool;
class TransformState;
// ResourceLoader is responsible for loading and updating the Source(s) owned
// by the Style. The Source object currently owns all the tiles, thus this
// class will notify its observers of any change on these tiles which will
// ultimately cause a new rendering to be triggered.
class ResourceLoader : public GlyphStore::Observer,
public Source::Observer,
public Sprite::Observer,
private util::noncopyable {
public:
class Observer {
public:
virtual ~Observer() = default;
virtual void onTileDataChanged() = 0;
virtual void onResourceLoadingFailed(std::exception_ptr error) = 0;
};
ResourceLoader();
~ResourceLoader();
void setObserver(Observer* observer);
// The style object currently owns all the sources. When setting
// a new style we will go through all of them and try to load.
void setStyle(Style* style);
// TODO: Move GlyphStore to ResourceLoader. We cannot do it now
// because we reset the ResourceLoader every time we change the
// style.
void setGlyphStore(GlyphStore* glyphStore);
// Set the access token to be used for loading the tile data.
void setAccessToken(const std::string& accessToken);
// 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&, GlyphAtlas&, SpriteAtlas&, TexturePool&);
// FIXME: There is probably a better place for this.
inline util::ptr<Sprite> getSprite() const {
return sprite_;
}
// 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;
private:
void emitTileDataChanged();
void emitResourceLoadingFailed(std::exception_ptr error);
bool shouldReparsePartialTiles_ = false;
std::string accessToken_;
util::ptr<Sprite> sprite_;
GlyphStore* glyphStore_ = nullptr;
Style* style_ = nullptr;
Observer* observer_ = nullptr;
};
}
#endif
|