Files
MapLibreParticleLab/src/mbgl/map/tile_data.hpp
Thiago Marcos P. Santos b7c63630a4 Initialize the atomic_flag in the class definition
ATOMIC_FLAG_INIT is often defined to { 0 } or { false } and some
compilers might complain about initializing as flag(ATOMIC_FLAG_INIT).
2015-05-11 15:43:55 +03:00

94 lines
2.2 KiB
C++

#ifndef MBGL_MAP_TILE_DATA
#define MBGL_MAP_TILE_DATA
#include <mbgl/map/tile_id.hpp>
#include <mbgl/renderer/debug_bucket.hpp>
#include <mbgl/geometry/debug_font_buffer.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/ptr.hpp>
#include <atomic>
#include <string>
#include <functional>
namespace mbgl {
class Environment;
class Painter;
class SourceInfo;
class StyleLayer;
class Request;
class Worker;
class WorkRequest;
class TileData : private util::noncopyable {
public:
enum class State {
invalid,
initial,
loading,
loaded,
partial,
parsed,
obsolete
};
// Tile data considered "Ready" 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.
inline static bool isReadyState(const State& state) {
return state == State::partial || state == State::parsed;
}
TileData(const TileID&, const SourceInfo&);
~TileData();
void request(Worker&, float pixelRatio, std::function<void ()> callback);
void reparse(Worker&, std::function<void ()> callback);
void cancel();
const std::string toString() const;
inline bool ready() const {
return isReadyState(state);
}
void endParsing();
// Override this in the child class.
virtual void parse() = 0;
virtual Bucket* getBucket(StyleLayer const &layer_desc) = 0;
const TileID id;
const std::string name;
std::atomic<State> state;
std::atomic_flag parsing = ATOMIC_FLAG_INIT;
protected:
// Set the internal parsing state to true so we prevent
// multiple workers to parse the same tile in parallel,
// which can happen if the tile is in the "partial" state.
// It will return true if is possible to start pasing the
// tile or false if not (so some other worker is already
// parsing the tile).
bool mayStartParsing();
const SourceInfo& source;
Environment& env;
Request *req = nullptr;
std::string data;
std::unique_ptr<WorkRequest> workRequest;
// Contains the tile ID string for painting debug information.
DebugFontBuffer debugFontBuffer;
public:
DebugBucket debugBucket;
};
}
#endif