From 6f1477f2d4aee46f41215d16dcc0a2755e4ae721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Wed, 25 May 2016 20:28:18 +0200 Subject: [PATCH] [core] split TileData::State::obsolete into its own thing --- src/mbgl/style/style_bucket_parameters.hpp | 10 +++++----- src/mbgl/tile/raster_tile_data.cpp | 1 - src/mbgl/tile/tile_data.cpp | 1 - src/mbgl/tile/tile_data.hpp | 8 +------- src/mbgl/tile/tile_worker.cpp | 12 ++++++------ src/mbgl/tile/tile_worker.hpp | 8 ++++---- src/mbgl/tile/vector_tile_data.cpp | 8 ++++---- src/mbgl/tile/vector_tile_data.hpp | 3 +++ 8 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/mbgl/style/style_bucket_parameters.hpp b/src/mbgl/style/style_bucket_parameters.hpp index ab63f8fe555..6234d5c3019 100644 --- a/src/mbgl/style/style_bucket_parameters.hpp +++ b/src/mbgl/style/style_bucket_parameters.hpp @@ -1,8 +1,8 @@ #pragma once #include +#include #include -#include #include @@ -21,7 +21,7 @@ class StyleBucketParameters { public: StyleBucketParameters(const OverscaledTileID& tileID_, const GeometryTileLayer& layer_, - const std::atomic& state_, + const std::atomic& obsolete_, uintptr_t tileUID_, bool& partialParse_, SpriteStore& spriteStore_, @@ -31,7 +31,7 @@ class StyleBucketParameters { const MapMode mode_) : tileID(tileID_), layer(layer_), - state(state_), + obsolete(obsolete_), tileUID(tileUID_), partialParse(partialParse_), spriteStore(spriteStore_), @@ -41,14 +41,14 @@ class StyleBucketParameters { mode(mode_) {} bool cancelled() const { - return state == TileData::State::obsolete; + return obsolete; } void eachFilteredFeature(const Filter&, std::function); const OverscaledTileID& tileID; const GeometryTileLayer& layer; - const std::atomic& state; + const std::atomic& obsolete; uintptr_t tileUID; bool& partialParse; SpriteStore& spriteStore; diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp index aab166807ff..b70cd1d8364 100644 --- a/src/mbgl/tile/raster_tile_data.cpp +++ b/src/mbgl/tile/raster_tile_data.cpp @@ -66,7 +66,6 @@ Bucket* RasterTileData::getBucket(StyleLayer const&) { } void RasterTileData::cancel() { - state = State::obsolete; req = nullptr; workRequest.reset(); } diff --git a/src/mbgl/tile/tile_data.cpp b/src/mbgl/tile/tile_data.cpp index 0e4237fc25e..00cd0731975 100644 --- a/src/mbgl/tile/tile_data.cpp +++ b/src/mbgl/tile/tile_data.cpp @@ -14,7 +14,6 @@ TileData::~TileData() = default; const char* TileData::StateToString(const State state) { switch (state) { case TileData::State::loading : return "loading"; - case TileData::State::obsolete : return "obsolete"; case TileData::State::parsed : return "parsed"; case TileData::State::partial : return "partial"; default: return ""; diff --git a/src/mbgl/tile/tile_data.hpp b/src/mbgl/tile/tile_data.hpp index 8c93f787fbb..d6d9f6289f4 100644 --- a/src/mbgl/tile/tile_data.hpp +++ b/src/mbgl/tile/tile_data.hpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -36,15 +35,10 @@ class TileData : private util::noncopyable { // parsed: // TileData is fully parsed and its contents won't change from this point. This // is the only state which is safe to cache this object. - // - // obsolete: - // 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 { loading, partial, parsed, - obsolete }; static const char* StateToString(State); @@ -92,7 +86,7 @@ class TileData : private util::noncopyable { std::unique_ptr debugBucket; protected: - std::atomic state; + State state; }; } // namespace mbgl diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp index 0a9ab35779b..fdebe912296 100644 --- a/src/mbgl/tile/tile_worker.cpp +++ b/src/mbgl/tile/tile_worker.cpp @@ -22,14 +22,14 @@ TileWorker::TileWorker(const OverscaledTileID& id_, SpriteStore& spriteStore_, GlyphAtlas& glyphAtlas_, GlyphStore& glyphStore_, - const std::atomic& state_, + const std::atomic& obsolete_, const MapMode mode_) : id(id_), sourceID(std::move(sourceID_)), spriteStore(spriteStore_), glyphAtlas(glyphAtlas_), glyphStore(glyphStore_), - state(state_), + obsolete(obsolete_), mode(mode_) { } @@ -92,9 +92,9 @@ TileParseResult TileWorker::parsePendingLayers(const PlacementConfig config) { } TileParseResult TileWorker::prepareResult(const PlacementConfig& config) { - result.state = pending.empty() ? TileData::State::parsed : TileData::State::partial; + result.complete = pending.empty(); - if (result.state == TileData::State::parsed) { + if (result.complete) { featureIndex->setCollisionTile(placeLayers(config)); result.featureIndex = std::move(featureIndex); result.geometryTile = std::move(geometryTile); @@ -131,7 +131,7 @@ std::unique_ptr TileWorker::redoPlacement( void TileWorker::parseLayer(const StyleLayer* layer) { // Cancel early when parsing. - if (state == TileData::State::obsolete) + if (obsolete) return; // Background and custom layers are special cases. @@ -158,7 +158,7 @@ void TileWorker::parseLayer(const StyleLayer* layer) { StyleBucketParameters parameters(id, *geometryLayer, - state, + obsolete, reinterpret_cast(this), partialParse, spriteStore, diff --git a/src/mbgl/tile/tile_worker.hpp b/src/mbgl/tile/tile_worker.hpp index 8183b9d554f..6a60a17b079 100644 --- a/src/mbgl/tile/tile_worker.hpp +++ b/src/mbgl/tile/tile_worker.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -29,7 +29,7 @@ class SymbolLayer; // thread. This class is movable-only because the vector contains movable-only value elements. class TileParseResultData { public: - TileData::State state; + bool complete = false; std::unordered_map> buckets; std::unique_ptr featureIndex; std::unique_ptr geometryTile; @@ -46,7 +46,7 @@ class TileWorker : public util::noncopyable { SpriteStore&, GlyphAtlas&, GlyphStore&, - const std::atomic&, + const std::atomic&, const MapMode); ~TileWorker(); @@ -71,7 +71,7 @@ class TileWorker : public util::noncopyable { SpriteStore& spriteStore; GlyphAtlas& glyphAtlas; GlyphStore& glyphStore; - const std::atomic& state; + const std::atomic& obsolete; const MapMode mode; bool partialParse = false; diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index afca67e78ee..c4df292d9f7 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -25,7 +25,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_, *style_.spriteStore, *style_.glyphAtlas, *style_.glyphStore, - state, + obsolete, mode_), monitor(std::move(monitor_)) { @@ -66,7 +66,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_, std::exception_ptr error; if (result.is()) { auto& resultBuckets = result.get(); - state = resultBuckets.state; + state = resultBuckets.complete ? State::parsed : State::partial; // Persist the configuration we just placed so that we can later check whether we need to // place again in case the configuration has changed. @@ -109,7 +109,7 @@ bool VectorTileData::parsePending(std::function callba std::exception_ptr error; if (result.is()) { auto& resultBuckets = result.get(); - state = resultBuckets.state; + state = resultBuckets.complete ? State::parsed : State::partial; // Move over all buckets we received in this parse request, potentially overwriting // existing buckets in case we got a refresh parse. @@ -205,7 +205,7 @@ void VectorTileData::queryRenderedFeatures( } void VectorTileData::cancel() { - state = State::obsolete; + obsolete = true; tileRequest.reset(); workRequest.reset(); } diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp index b38fe3828bf..2545df801ba 100644 --- a/src/mbgl/tile/vector_tile_data.hpp +++ b/src/mbgl/tile/vector_tile_data.hpp @@ -64,6 +64,9 @@ class VectorTileData : public TileData { // Stores the placement configuration of how the text should be placed. This isn't necessarily // the one that is being displayed. PlacementConfig targetConfig; + + // Used to signal the worker that it should abandon parsing this tile as soon as possible. + std::atomic obsolete { false }; }; } // namespace mbgl