summaryrefslogtreecommitdiff
path: root/src/mbgl/tile/tile.hpp
blob: 800752f8c9f880e508f5a75f22f5cfe10ebbaeda (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once

#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/tile_coordinate.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/renderer/tile_mask.hpp>
#include <mbgl/renderer/bucket.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/style/layer_impl.hpp>

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

namespace mbgl {

class DebugBucket;
class TransformState;
class TileObserver;
class PlacementConfig;
class RenderStyle;
class RenderedQueryOptions;
class SourceQueryOptions;

namespace gl {
class Context;
} // namespace gl

class Tile : private util::noncopyable {
public:
    Tile(OverscaledTileID);
    virtual ~Tile();

    void setObserver(TileObserver* observer);

    // Tiles can have two states: optional or required.
    // - optional means that only low-cost actions should be taken to obtain the data
    //   (e.g. load from cache, but accept stale data)
    // - required means that every effort should be taken to obtain the data (e.g. load
    //   from internet and keep the data fresh if it expires)
    using Necessity = Resource::Necessity;

    virtual void setNecessity(Necessity) = 0;

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

    virtual void upload(gl::Context&) = 0;
    virtual Bucket* getBucket(const style::Layer::Impl&) const = 0;

    virtual void setPlacementConfig(const PlacementConfig&) {}
    virtual void setLayers(const std::vector<Immutable<style::Layer::Impl>>&) {}
    virtual void setMask(TileMask&&) {}

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

    virtual void querySourceFeatures(
            std::vector<Feature>& result,
            const SourceQueryOptions&);

    // Tile data considered "Renderable" can be used for rendering. It doesn't necessarily mean that
    // there is anything to render, since tiles can be empty. Tiles that are still waiting for
    // network resources but can also be rendered, although layers will be missing.
    bool isRenderable() const {
        return renderable;
    }

    // A tile is "loaded" when we have received a response from a FileSource, and have attempted
    // to parse the tile (if applicable), and there are no further operations in progress to acquire
    // more, newer, or better data. Furthermore, it means that there are no pending layout/placement
    // or parsing operations going on. Completeness doesn't mean that the tile can be rendered, but
    // merely that we have exhausted all options to get this tile to a renderable state. Some tiles
    // may not be renderable, but complete, e.g. when a raster tile couldn't be loaded, or parsing
    // failed.
    bool isLoaded() const {
        return (loaded ? parsed : failed) && !pending;
    }

    void dumpDebugLogs() const;

    void logDebug(const char*) const;

    // This information is only used for displaying debugging information.
    const OverscaledTileID id;
    optional<Timestamp> modified;
    optional<Timestamp> expires;

    // Contains the tile ID string for painting debug information.
    std::unique_ptr<DebugBucket> debugBucket;
    
    virtual float yStretch() const { return 1.0f; }

protected:
    // A tile is loaded when we acquired data for it, and no further operations to acquire more,
    // newer, or better data are in progress.
    bool loaded = false;

    // A tile is marked as failed when we tried to acquire data, but couldn't, and no further
    // operations to acquire more, newer, or better data are in progress.
    bool failed = false;

    // A tile is marked as parsed when we attempted to parse its contents. It doesn't necessairly
    // mean that we *successfully* parsed it, just that there's been an attempt.
    bool parsed = false;

    // Renderability means that we successfully parsed a tile. Note that it doesn't mean there's
    // anything to render (e.g. vector tiles may be empty).
    bool renderable = false;

    // A tile is pending while parsing or placement operations are going on.
    bool pending = false;

    TileObserver* observer = nullptr;
};

} // namespace mbgl