blob: 98b43ac8e4ec85a08d6fa0f9795d14858989ec1a (
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
|
#ifndef MBGL_SPRITE_STORE
#define MBGL_SPRITE_STORE
#include <mbgl/sprite/sprite_image.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <map>
#include <memory>
#include <mutex>
namespace mbgl {
class SpriteStore : private util::noncopyable {
public:
using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;
class Observer {
public:
virtual ~Observer() = default;
virtual void onSpriteLoaded() = 0;
virtual void onSpriteLoadingFailed(std::exception_ptr) = 0;
};
SpriteStore(float pixelRatio);
~SpriteStore();
void setURL(const std::string&);
bool isLoaded() const {
return loaded;
}
void dumpDebugLogs() const;
void setObserver(Observer* observer);
// Adds/replaces a Sprite image.
void setSprite(const std::string&, std::shared_ptr<const SpriteImage> = nullptr);
// Adds/replaces mutliple Sprite images.
void setSprites(const Sprites& sprites);
// Removes a Sprite.
void removeSprite(const std::string&);
// Obtains a Sprite image.
std::shared_ptr<const SpriteImage> getSprite(const std::string&);
// Returns Sprite images that changed since the last invocation of this function.
Sprites getDirty();
const float pixelRatio;
private:
void _setSprite(const std::string&, const std::shared_ptr<const SpriteImage>& = nullptr);
void emitSpriteLoadedIfComplete();
void emitSpriteLoadingFailed(const std::string& message);
struct Loader;
std::unique_ptr<Loader> loader;
bool loaded = false;
Observer* observer = nullptr;
// Lock for sprites and dirty maps.
std::mutex mutex;
// Stores all current sprites.
Sprites sprites;
// Stores all Sprite IDs that changed since the last invocation.
Sprites dirty;
};
} // namespace mbgl
#endif
|