diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp index ac05963ce..9043bd193 100644 --- a/src/mbgl/source/source.cpp +++ b/src/mbgl/source/source.cpp @@ -63,7 +63,7 @@ bool Source::isLoaded() const { if (!loaded) return false; for (const auto& pair : tileDataMap) { - if (pair.second->getState() != TileData::State::parsed) { + if (!pair.second->isComplete()) { return false; } } diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp index 6280c2a97..b47c3fed2 100644 --- a/src/mbgl/tile/raster_tile_data.cpp +++ b/src/mbgl/tile/raster_tile_data.cpp @@ -18,8 +18,6 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_, : TileData(id_), texturePool(texturePool_), worker(worker_) { - state = State::loading; - const Resource resource = Resource::tile(urlTemplate, pixelRatio, id.canonical.x, id.canonical.y, id.canonical.z); req = fileSource.request(resource, [callback, this](Response res) { @@ -39,17 +37,9 @@ RasterTileData::RasterTileData(const OverscaledTileID& id_, modified = res.modified; expires = res.expires; - // Only overwrite the state when we didn't have a previous tile. - if (state == State::loading) { - state = State::loaded; - } - workRequest.reset(); workRequest = worker.parseRasterTile(std::make_unique(texturePool), res.data, [this, callback] (RasterTileParseResult result) { workRequest.reset(); - if (state != State::loaded) { - return; - } std::exception_ptr error; if (result.is>()) { diff --git a/src/mbgl/tile/tile_data.cpp b/src/mbgl/tile/tile_data.cpp index 2198d2674..0e4237fc2 100644 --- a/src/mbgl/tile/tile_data.cpp +++ b/src/mbgl/tile/tile_data.cpp @@ -6,16 +6,14 @@ namespace mbgl { TileData::TileData(const OverscaledTileID& id_) : id(id_), - state(State::initial) { + state(State::loading) { } TileData::~TileData() = default; const char* TileData::StateToString(const State state) { switch (state) { - case TileData::State::initial: return "initial"; case TileData::State::loading : return "loading"; - case TileData::State::loaded : return "loaded"; case TileData::State::obsolete : return "obsolete"; case TileData::State::parsed : return "parsed"; case TileData::State::partial : return "partial"; diff --git a/src/mbgl/tile/tile_data.hpp b/src/mbgl/tile/tile_data.hpp index e223c12e0..8c93f787f 100644 --- a/src/mbgl/tile/tile_data.hpp +++ b/src/mbgl/tile/tile_data.hpp @@ -24,16 +24,10 @@ class TransformState; class TileData : private util::noncopyable { public: - // initial: - // Initial state, only used when the TileData object is created. - // // loading: // A request to the FileSource was made for the actual tile data and TileData // is waiting for it to arrive. // - // loaded: - // The actual tile data has arrived and the tile can be parsed. - // // partial: // 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, @@ -47,9 +41,7 @@ public: // The TileData can go to obsolete from any state, due to parsing or loading error, // request cancellation or because the tile is no longer in use. enum class State { - initial, loading, - loaded, partial, parsed, obsolete @@ -82,6 +74,10 @@ public: return state == State::partial || state == State::parsed; } + bool isComplete() const { + return state == State::parsed; + } + State getState() const { return state; } diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index 220290cbf..29aac5af3 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -29,7 +29,6 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_, mode_), monitor(std::move(monitor_)) { - state = State::loading; tileRequest = monitor->monitorTile([callback, this](std::exception_ptr err, std::unique_ptr tile, optional modified_, @@ -51,9 +50,9 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_, return; } - if (state == State::loading) { - state = State::loaded; - } else if (isRenderable()) { + // Mark the tile as pending again if it was complete before to prevent signaling a complete + // state despite pending parse operations. + if (isComplete()) { state = State::partial; } @@ -80,7 +79,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_, // existing buckets in case we got a refresh parse. buckets = std::move(resultBuckets.buckets); - if (state == State::parsed) { + if (isComplete()) { featureIndex = std::move(resultBuckets.featureIndex); geometryTile = std::move(resultBuckets.geometryTile); } @@ -127,7 +126,7 @@ bool VectorTileData::parsePending(std::function callba // place again in case the configuration has changed. placedConfig = config; - if (state == State::parsed) { + if (isComplete()) { featureIndex = std::move(resultBuckets.featureIndex); geometryTile = std::move(resultBuckets.geometryTile); }