summaryrefslogtreecommitdiff
path: root/src/mbgl/annotation/sprite_store.hpp
blob: 3e81a4daf04cf15a99edc820cba74a1b4bb8b4fb (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
#ifndef MBGL_ANNOTATION_SPRITE_STORE
#define MBGL_ANNOTATION_SPRITE_STORE

#include <mbgl/annotation/sprite_image.hpp>

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/geo.hpp>

#include <map>
#include <set>
#include <vector>
#include <memory>
#include <mutex>
#include <cstdint>

namespace mbgl {

// The SpriteStore object holds Sprite images.
class SpriteStore : private util::noncopyable {
    using Sprites = std::map<std::string, std::shared_ptr<const SpriteImage>>;

public:
    SpriteStore(const float ratio);

    // Adds/replaces a Sprite image.
    void setSprite(const std::string&, std::shared_ptr<const SpriteImage> = nullptr);

    // 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();

private:
    const float ratio;

    // 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