summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/geometry_tile_worker.hpp
blob: 1df1ef43c462b2e4e49a08f976e9a8630a7ba789 (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
#pragma once

#include <mbgl/map/mode.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/sprite/sprite_atlas.hpp>
#include <mbgl/text/glyph.hpp>
#include <mbgl/text/placement_config.hpp>
#include <mbgl/actor/actor_ref.hpp>
#include <mbgl/util/optional.hpp>

#include <atomic>
#include <memory>

namespace mbgl {

class GeometryTile;
class GeometryTileData;
class GlyphAtlas;
class SymbolLayout;
class RenderLayer;

namespace style {
class Layer;
} // namespace style

class GeometryTileWorker {
public:
    GeometryTileWorker(ActorRef<GeometryTileWorker> self,
                       ActorRef<GeometryTile> parent,
                       OverscaledTileID,
                       const std::atomic<bool>&,
                       const MapMode);
    ~GeometryTileWorker();

    void setLayers(std::vector<std::unique_ptr<style::Layer>>, uint64_t correlationID);
    void setData(std::unique_ptr<const GeometryTileData>, uint64_t correlationID);
    void setPlacementConfig(PlacementConfig, uint64_t correlationID);
    
    void onGlyphsAvailable(GlyphPositionMap glyphs);
    void onIconsAvailable(IconMap icons);

private:
    void coalesced();
    void redoLayout();
    void attemptPlacement();
    
    void coalesce();

    void requestNewGlyphs(const GlyphDependencies&);
    void requestNewIcons(const IconDependencies&);
   
    void symbolDependenciesChanged();
    bool hasPendingSymbolDependencies() const;
    bool hasPendingSymbolLayouts() const;

    ActorRef<GeometryTileWorker> self;
    ActorRef<GeometryTile> parent;

    const OverscaledTileID id;
    const std::atomic<bool>& obsolete;
    const MapMode mode;

    enum State {
        Idle,
        Coalescing,
        NeedLayout,
        NeedPlacement
    };

    State state = Idle;
    uint64_t correlationID = 0;

    // Outer optional indicates whether we've received it or not.
    optional<std::vector<std::unique_ptr<style::Layer>>> layers;
    optional<std::unique_ptr<const GeometryTileData>> data;
    optional<PlacementConfig> placementConfig;

    std::vector<std::unique_ptr<SymbolLayout>> symbolLayouts;
    GlyphDependencies pendingGlyphDependencies;
    IconDependencies pendingIconDependencies;
    GlyphPositionMap glyphPositions;
    IconMap icons;
};

} // namespace mbgl