summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/tile_data.hpp
blob: c7b878879dff9db1295c21875df5356f947dd4e5 (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
86
87
88
89
90
91
92
93
#pragma once

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/text/placement_config.hpp>
#include <mbgl/tile/geometry_tile.hpp>

#include <string>
#include <memory>
#include <functional>
#include <unordered_map>

namespace mbgl {

class Worker;
class DebugBucket;
class TransformState;
class TileSource;

namespace style {
class Layer;
}

class TileData : private util::noncopyable {
public:
    TileData(const OverscaledTileID&);
    virtual ~TileData();

    void setTileSource(std::unique_ptr<TileSource>);

    // Mark this tile as no longer needed and cancel any pending work.
    virtual void cancel() = 0;

    virtual Bucket* getBucket(const style::Layer&) = 0;

    virtual bool parsePending() { return true; }
    virtual void redoPlacement(PlacementConfig, const std::function<void()>&) {}
    virtual void redoPlacement(const std::function<void()>&) {}

    virtual void queryRenderedFeatures(
            std::unordered_map<std::string, std::vector<Feature>>& result,
            const GeometryCoordinates& queryGeometry,
            const TransformState&,
            const optional<std::vector<std::string>>& layerIDs);

    // Tile data considered "Renderable" can be used for rendering. Data in
    // partial state is still waiting for network resources but can also
    // be rendered, although layers will be missing.
    bool isRenderable() const {
        return availableData != DataAvailability::None;
    }

    bool isComplete() const {
        return availableData == DataAvailability::All;
    }
    bool isIncomplete() const {
        return availableData == DataAvailability::Some;
    }


    void dumpDebugLogs() const;

    const OverscaledTileID id;
    optional<Timestamp> modified;
    optional<Timestamp> expires;

    // Contains the tile ID string for painting debug information.
    std::unique_ptr<DebugBucket> debugBucket;

protected:
    enum class DataAvailability : uint8_t {
        // Still waiting for data to load or parse.
        None,

        // TileData is partially parsed, some buckets are still waiting for dependencies
        // to arrive, but it is good for rendering. Partial tiles can also be re-parsed,
        // but might remain in the same state if dependencies are still missing.
        Some,

        // TileData is fully parsed, and all buckets are available if they exist.
        All,
    };

    DataAvailability availableData = DataAvailability::None;

    std::unique_ptr<TileSource> tileSource;
};

} // namespace mbgl