summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/tile_loader.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/tile/tile_loader.hpp')
-rw-r--r--src/mbgl/tile/tile_loader.hpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/mbgl/tile/tile_loader.hpp b/src/mbgl/tile/tile_loader.hpp
new file mode 100644
index 0000000000..cab1907741
--- /dev/null
+++ b/src/mbgl/tile/tile_loader.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <mbgl/util/noncopyable.hpp>
+#include <mbgl/storage/resource.hpp>
+
+namespace mbgl {
+
+class FileSource;
+class AsyncRequest;
+class Response;
+class Tileset;
+
+namespace style {
+class UpdateParameters;
+} // namespace style
+
+template <typename T>
+class TileLoader : private util::noncopyable {
+public:
+ // TileSources can have two states: optional or required.
+ // - optional means that only low-cost actions should be taken to obtain the data
+ // (e.g. load from cache, but accept stale data)
+ // - required means that every effort should be taken to obtain the data (e.g. load
+ // from internet and keep the data fresh if it expires)
+ enum class Necessity : bool {
+ Optional = false,
+ Required = true,
+ };
+
+ TileLoader(T&,
+ const OverscaledTileID&,
+ const style::UpdateParameters&,
+ const Tileset&);
+
+ void setNecessity(Necessity newNecessity) {
+ if (newNecessity != necessity) {
+ necessity = newNecessity;
+ if (necessity == Necessity::Required) {
+ makeRequired();
+ } else {
+ makeOptional();
+ }
+ }
+ }
+
+private:
+ // called when the tile is one of the ideal tiles that we want to show definitely. the tile source
+ // should try to make every effort (e.g. fetch from internet, or revalidate existing resources).
+ void makeRequired();
+
+ // called when the zoom level no longer corresponds to the displayed one, but
+ // we're still interested in retaining the tile, e.g. for backfill.
+ // subclassed TileSources should cancel actions they are taking to provide
+ // an up-to-date version or load new data
+ void makeOptional();
+
+ void loadOptional();
+ void loadedData(const Response&);
+ void loadRequired();
+
+ T& tile;
+ Necessity necessity;
+ Resource resource;
+ FileSource& fileSource;
+ std::unique_ptr<AsyncRequest> request;
+};
+
+} // namespace mbgl