1 #pragma once
2 
3 #include <mbgl/tile/tile.hpp>
4 #include <mbgl/tile/tile_loader.hpp>
5 #include <mbgl/tile/raster_dem_tile_worker.hpp>
6 #include <mbgl/actor/actor.hpp>
7 
8 namespace mbgl {
9 
10 class Tileset;
11 class TileParameters;
12 class HillshadeBucket;
13 
14 enum class DEMTileNeighbors : uint8_t {
15   // 0b00000000
16   Empty = 0 << 1,
17 
18   // 0b00000001
19   Left = 1 << 0,
20   // 0b00000010
21   Right = 1 << 1,
22   // 0b00000100
23   TopLeft = 1 << 2,
24   // 0b00001000
25   TopCenter = 1 << 3,
26   // 0b00010000
27   TopRight = 1 << 4,
28   // 0b00100000
29   BottomLeft = 1 << 5,
30   // 0b01000000
31   BottomCenter = 1 << 6,
32   // 0b10000000
33   BottomRight = 1 << 7,
34 
35   // helper enums for tiles with no upper/lower neighbors
36   // and completely backfilled tiles
37 
38   // 0b00011100
39   NoUpper = 0b00011100,
40   // 0b11100000
41   NoLower = 0b11100000,
42   // 0b11111111
43   Complete = 0b11111111
44 };
45 
operator |(DEMTileNeighbors a,DEMTileNeighbors b)46 inline DEMTileNeighbors operator|(DEMTileNeighbors a, DEMTileNeighbors b) {
47     return static_cast<DEMTileNeighbors>(int(a) | int(b));
48 };
49 
operator &(DEMTileNeighbors a,DEMTileNeighbors b)50 inline DEMTileNeighbors operator&(DEMTileNeighbors a, DEMTileNeighbors b) {
51     return static_cast<DEMTileNeighbors>(int(a) & int(b));
52 }
53 
operator !=(DEMTileNeighbors a,DEMTileNeighbors b)54 inline bool operator!=(DEMTileNeighbors a, DEMTileNeighbors b) {
55     return static_cast<unsigned char>(a) != static_cast<unsigned char>(b);
56 }
57 
58 namespace style {
59 class Layer;
60 } // namespace style
61 
62 class RasterDEMTile : public Tile {
63 public:
64     RasterDEMTile(const OverscaledTileID&,
65                    const TileParameters&,
66                    const Tileset&);
67     ~RasterDEMTile() override;
68 
69     void setNecessity(TileNecessity) final;
70 
71     void setError(std::exception_ptr);
72     void setMetadata(optional<Timestamp> modified, optional<Timestamp> expires);
73     void setData(std::shared_ptr<const std::string> data);
74 
75     void upload(gl::Context&) override;
76     Bucket* getBucket(const style::Layer::Impl&) const override;
77 
78     HillshadeBucket* getBucket() const;
79     void backfillBorder(const RasterDEMTile& borderTile, const DEMTileNeighbors mask);
80 
81     // neighboringTiles is a bitmask for which neighboring tiles have been backfilled
82     // there are max 8 possible neighboring tiles, so each bit represents one neighbor
83     DEMTileNeighbors neighboringTiles = DEMTileNeighbors::Empty;
84 
85     void setMask(TileMask&&) override;
86 
87     void onParsed(std::unique_ptr<HillshadeBucket> result, uint64_t correlationID);
88     void onError(std::exception_ptr, uint64_t correlationID);
89 
90 private:
91     TileLoader<RasterDEMTile> loader;
92 
93     std::shared_ptr<Mailbox> mailbox;
94     Actor<RasterDEMTileWorker> worker;
95 
96     uint64_t correlationID = 0;
97     Tileset::DEMEncoding encoding;
98 
99     // Contains the Bucket object for the tile. Buckets are render
100     // objects and they get added by tile parsing operations.
101     std::unique_ptr<HillshadeBucket> bucket;
102 
103 };
104 
105 } // namespace mbgl
106