| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <mbgl/util/noncopyable.hpp> |
| 4 | #include <mbgl/storage/resource.hpp> |
| 5 | #include <mbgl/tile/tile.hpp> |
| 6 | |
| 7 | namespace mbgl { |
| 8 | |
| 9 | class FileSource; |
| 10 | class AsyncRequest; |
| 11 | class Response; |
| 12 | class Tileset; |
| 13 | class TileParameters; |
| 14 | |
| 15 | template <typename T> |
| 16 | class TileLoader : private util::noncopyable { |
| 17 | public: |
| 18 | TileLoader(T&, |
| 19 | const OverscaledTileID&, |
| 20 | const TileParameters&, |
| 21 | const Tileset&); |
| 22 | ~TileLoader(); |
| 23 | |
| 24 | void setNecessity(TileNecessity newNecessity) { |
| 25 | if (newNecessity != necessity) { |
| 26 | necessity = newNecessity; |
| 27 | if (necessity == TileNecessity::Required) { |
| 28 | makeRequired(); |
| 29 | } else { |
| 30 | makeOptional(); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | private: |
| 36 | // called when the tile is one of the ideal tiles that we want to show definitely. the tile source |
| 37 | // should try to make every effort (e.g. fetch from internet, or revalidate existing resources). |
| 38 | void makeRequired(); |
| 39 | |
| 40 | // called when the zoom level no longer corresponds to the displayed one, but |
| 41 | // we're still interested in retaining the tile, e.g. for backfill. |
| 42 | // subclassed TileSources should cancel actions they are taking to provide |
| 43 | // an up-to-date version or load new data |
| 44 | void makeOptional(); |
| 45 | |
| 46 | void loadFromCache(); |
| 47 | void loadedData(const Response&); |
| 48 | void loadFromNetwork(); |
| 49 | |
| 50 | T& tile; |
| 51 | TileNecessity necessity; |
| 52 | Resource resource; |
| 53 | FileSource& fileSource; |
| 54 | std::unique_ptr<AsyncRequest> request; |
| 55 | }; |
| 56 | |
| 57 | } // namespace mbgl |
| 58 |
