summaryrefslogtreecommitdiff
path: root/src/mbgl/map/tile_worker.hpp
blob: ee94f756ed059a2f4e7d70fbfc463278560ec394 (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
#ifndef MBGL_MAP_TILE_WORKER
#define MBGL_MAP_TILE_WORKER

#include <mapbox/variant.hpp>

#include <mbgl/map/tile_data.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/text/placement_config.hpp>

#include <string>
#include <memory>
#include <mutex>
#include <list>
#include <unordered_map>

namespace mbgl {

class CollisionTile;
class GeometryTile;
class Style;
class Bucket;
class StyleLayer;

// We're using this class to shuttle the resulting buckets from the worker thread to the MapContext
// thread. This class is movable-only because the vector contains movable-only value elements.
class TileParseResultBuckets {
public:
    TileData::State state = TileData::State::invalid;
    std::unordered_map<std::string, std::unique_ptr<Bucket>> buckets;
};

using TileParseResult = mapbox::util::variant<TileParseResultBuckets, // success
                                              std::string>;           // error

class TileWorker : public util::noncopyable {
public:
    TileWorker(TileID,
               std::string sourceID,
               Style&,
               const std::atomic<TileData::State>&);
    ~TileWorker();

    TileParseResult parseAllLayers(std::vector<util::ptr<StyleLayer>>,
                                   const GeometryTile&,
                                   PlacementConfig);

    TileParseResult parsePendingLayers();

    void redoPlacement(std::vector<util::ptr<StyleLayer>>,
                       const std::unordered_map<std::string, std::unique_ptr<Bucket>>*,
                       PlacementConfig);

private:
    void parseLayer(const StyleLayer&, const GeometryTile&);
    void insertBucket(const std::string& name, std::unique_ptr<Bucket>);

    const TileID id;
    const std::string sourceID;

    Style& style;
    const std::atomic<TileData::State>& state;

    bool partialParse = false;

    std::unique_ptr<CollisionTile> collisionTile;

    // Contains buckets that we couldn't parse so far due to missing resources.
    // They will be attempted on subsequent parses.
    std::list<std::pair<const StyleLayer&, std::unique_ptr<Bucket>>> pending;

    // Temporary holder
    TileParseResultBuckets result;
};

} // namespace mbgl

#endif