blob: fec19981f520ba6e453ffecb4057ac89a5190a42 (
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
|
#pragma once
#include <mbgl/style/image_impl.hpp>
#include <mbgl/util/immutable.hpp>
#include <map>
#include <string>
namespace mbgl {
template <class T>
class Actor;
namespace gfx {
class UploadPass;
} // namespace gfx
class ImageManagerObserver;
class ImageRequestor;
/**
* @brief tracks requests for icon images from tile workers and sends responses when the requests are fulfilled.
*/
class ImageManager {
public:
ImageManager();
ImageManager(const ImageManager&) = delete;
ImageManager& operator=(const ImageManager&) = delete;
~ImageManager();
void setObserver(ImageManagerObserver*);
void setLoaded(bool);
bool isLoaded() const;
void dumpDebugLogs() const;
const style::Image::Impl* getImage(const std::string&) const;
const Immutable<style::Image::Impl>* getSharedImage(const std::string&) const;
void addImage(Immutable<style::Image::Impl>);
bool updateImage(Immutable<style::Image::Impl>);
void removeImage(const std::string&);
void getImages(ImageRequestor&, ImageRequestPair&&);
void removeRequestor(ImageRequestor&);
void notifyIfMissingImageAdded();
void reduceMemoryUse();
void reduceMemoryUseIfCacheSizeExceedsLimit();
const std::set<std::string>& getAvailableImages() const;
ImageVersionMap updatedImageVersions;
void clear();
private:
void checkMissingAndNotify(ImageRequestor&, const ImageRequestPair&);
void notify(ImageRequestor&, const ImageRequestPair&) const;
void removePattern(const std::string&);
bool loaded = false;
std::map<ImageRequestor*, ImageRequestPair> requestors;
std::map<ImageRequestor*, ImageRequestPair> missingImageRequestors;
std::map<std::string, std::set<ImageRequestor*>> requestedImages;
std::size_t requestedImagesCacheSize = 0ul;
ImageMap images;
// Mirror of 'ImageMap images;' keys.
std::set<std::string> availableImages;
ImageManagerObserver* observer = nullptr;
};
class ImageRequestor {
public:
explicit ImageRequestor(ImageManager&);
virtual ~ImageRequestor();
virtual void onImagesAvailable(ImageMap icons, ImageMap patterns, ImageVersionMap versionMap, uint64_t imageCorrelationID) = 0;
void addPendingRequest(const std::string& imageId) { pendingRequests.insert(imageId); }
bool hasPendingRequest(const std::string& imageId) const { return pendingRequests.count(imageId); }
bool hasPendingRequests() const { return !pendingRequests.empty(); }
void removePendingRequest(const std::string& imageId) { pendingRequests.erase(imageId); }
private:
ImageManager& imageManager;
// Pending requests are image requests that are waiting to be dispatched to the client.
std::set<std::string> pendingRequests;
};
} // namespace mbgl
|