diff options
Diffstat (limited to 'src/mbgl/map/tile_data.hpp')
-rw-r--r-- | src/mbgl/map/tile_data.hpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp index 3be10dc034..3945a32147 100644 --- a/src/mbgl/map/tile_data.hpp +++ b/src/mbgl/map/tile_data.hpp @@ -7,7 +7,6 @@ #include <mbgl/util/noncopyable.hpp> #include <mbgl/util/ptr.hpp> -#include <mbgl/util/work_request.hpp> #include <atomic> #include <string> @@ -21,6 +20,7 @@ class SourceInfo; class StyleLayer; class Request; class Worker; +class WorkRequest; class TileData : private util::noncopyable { public: @@ -45,14 +45,34 @@ public: ~TileData(); void request(Worker&, float pixelRatio, std::function<void ()> callback); - void reparse(Worker&, std::function<void ()> callback); + + // Schedule a tile reparse on a worker thread and call the callback on + // completion. It will return true if the work was schedule or false it was + // not, which can occur if the tile is already being parsed by another + // worker (see "mayStartParsing()"). + bool reparse(Worker&, std::function<void ()> callback); + void cancel(); const std::string toString() const; - inline bool ready() const { + inline bool isReady() const { return isReadyState(state); } + // Returns true if the TileData is in a final state and we cannot + // make changes to it anymore. + inline bool isImmutable() const { + return state == State::parsed || state == State::obsolete; + } + + // We let subclasses override setState() so they + // can intercept the state change and react accordingly. + virtual void setState(const State& state); + + inline State getState() const { + return state; + } + void endParsing(); // Override this in the child class. @@ -61,8 +81,7 @@ public: const TileID id; const std::string name; - std::atomic<State> state; - std::atomic_flag parsing; + std::atomic_flag parsing = ATOMIC_FLAG_INIT; protected: // Set the internal parsing state to true so we prevent @@ -79,8 +98,12 @@ protected: Request *req = nullptr; std::string data; - WorkRequest workRequest; + std::unique_ptr<WorkRequest> workRequest; +private: + std::atomic<State> state; + +protected: // Contains the tile ID string for painting debug information. DebugFontBuffer debugFontBuffer; |