Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] split TileData::State::obsolete into its own thing
Browse files Browse the repository at this point in the history
  • Loading branch information
kkaefer committed May 25, 2016
1 parent c91e4ee commit 6f1477f
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/mbgl/style/style_bucket_parameters.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <mbgl/map/mode.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/style/filter.hpp>
#include <mbgl/tile/tile_data.hpp>

#include <functional>

Expand All @@ -21,7 +21,7 @@ class StyleBucketParameters {
public:
StyleBucketParameters(const OverscaledTileID& tileID_,
const GeometryTileLayer& layer_,
const std::atomic<TileData::State>& state_,
const std::atomic<bool>& obsolete_,
uintptr_t tileUID_,
bool& partialParse_,
SpriteStore& spriteStore_,
Expand All @@ -31,7 +31,7 @@ class StyleBucketParameters {
const MapMode mode_)
: tileID(tileID_),
layer(layer_),
state(state_),
obsolete(obsolete_),
tileUID(tileUID_),
partialParse(partialParse_),
spriteStore(spriteStore_),
Expand All @@ -41,14 +41,14 @@ class StyleBucketParameters {
mode(mode_) {}

bool cancelled() const {
return state == TileData::State::obsolete;
return obsolete;
}

void eachFilteredFeature(const Filter&, std::function<void (const GeometryTileFeature&, std::size_t index, const std::string& layerName)>);

const OverscaledTileID& tileID;
const GeometryTileLayer& layer;
const std::atomic<TileData::State>& state;
const std::atomic<bool>& obsolete;
uintptr_t tileUID;
bool& partialParse;
SpriteStore& spriteStore;
Expand Down
1 change: 0 additions & 1 deletion src/mbgl/tile/raster_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ Bucket* RasterTileData::getBucket(StyleLayer const&) {
}

void RasterTileData::cancel() {
state = State::obsolete;
req = nullptr;
workRequest.reset();
}
1 change: 0 additions & 1 deletion src/mbgl/tile/tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<unknown>";
Expand Down
8 changes: 1 addition & 7 deletions src/mbgl/tile/tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <mbgl/text/placement_config.hpp>
#include <mbgl/tile/geometry_tile.hpp>

#include <atomic>
#include <string>
#include <memory>
#include <functional>
Expand All @@ -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);
Expand Down Expand Up @@ -92,7 +86,7 @@ class TileData : private util::noncopyable {
std::unique_ptr<DebugBucket> debugBucket;

protected:
std::atomic<State> state;
State state;
};

} // namespace mbgl
12 changes: 6 additions & 6 deletions src/mbgl/tile/tile_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ TileWorker::TileWorker(const OverscaledTileID& id_,
SpriteStore& spriteStore_,
GlyphAtlas& glyphAtlas_,
GlyphStore& glyphStore_,
const std::atomic<TileData::State>& state_,
const std::atomic<bool>& obsolete_,
const MapMode mode_)
: id(id_),
sourceID(std::move(sourceID_)),
spriteStore(spriteStore_),
glyphAtlas(glyphAtlas_),
glyphStore(glyphStore_),
state(state_),
obsolete(obsolete_),
mode(mode_) {
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -131,7 +131,7 @@ std::unique_ptr<CollisionTile> 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.
Expand All @@ -158,7 +158,7 @@ void TileWorker::parseLayer(const StyleLayer* layer) {

StyleBucketParameters parameters(id,
*geometryLayer,
state,
obsolete,
reinterpret_cast<uintptr_t>(this),
partialParse,
spriteStore,
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/tile/tile_worker.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <mbgl/map/mode.hpp>
#include <mbgl/tile/tile_data.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/noncopyable.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/ptr.hpp>
Expand Down Expand Up @@ -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<std::string, std::unique_ptr<Bucket>> buckets;
std::unique_ptr<FeatureIndex> featureIndex;
std::unique_ptr<const GeometryTile> geometryTile;
Expand All @@ -46,7 +46,7 @@ class TileWorker : public util::noncopyable {
SpriteStore&,
GlyphAtlas&,
GlyphStore&,
const std::atomic<TileData::State>&,
const std::atomic<bool>&,
const MapMode);
~TileWorker();

Expand All @@ -71,7 +71,7 @@ class TileWorker : public util::noncopyable {
SpriteStore& spriteStore;
GlyphAtlas& glyphAtlas;
GlyphStore& glyphStore;
const std::atomic<TileData::State>& state;
const std::atomic<bool>& obsolete;
const MapMode mode;

bool partialParse = false;
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/tile/vector_tile_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
*style_.spriteStore,
*style_.glyphAtlas,
*style_.glyphStore,
state,
obsolete,
mode_),
monitor(std::move(monitor_))
{
Expand Down Expand Up @@ -66,7 +66,7 @@ VectorTileData::VectorTileData(const OverscaledTileID& id_,
std::exception_ptr error;
if (result.is<TileParseResultData>()) {
auto& resultBuckets = result.get<TileParseResultData>();
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.
Expand Down Expand Up @@ -109,7 +109,7 @@ bool VectorTileData::parsePending(std::function<void(std::exception_ptr)> callba
std::exception_ptr error;
if (result.is<TileParseResultData>()) {
auto& resultBuckets = result.get<TileParseResultData>();
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.
Expand Down Expand Up @@ -205,7 +205,7 @@ void VectorTileData::queryRenderedFeatures(
}

void VectorTileData::cancel() {
state = State::obsolete;
obsolete = true;
tileRequest.reset();
workRequest.reset();
}
Expand Down
3 changes: 3 additions & 0 deletions src/mbgl/tile/vector_tile_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> obsolete { false };
};

} // namespace mbgl

0 comments on commit 6f1477f

Please sign in to comment.