summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-28 14:54:54 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-29 11:12:55 +0200
commit597757df6aba1ae8c4477706142823303f020de7 (patch)
treec6cc9d3534de229ba99414f9fb9a30340094bd78
parent06c80cae3c36b196fab6adc1320c11444a52a26e (diff)
downloadqtlocation-mapboxgl-597757df6aba1ae8c4477706142823303f020de7.tar.gz
[core] GeoJSONVTData uses Scheduler::GetSequenced()
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index e4b48223f4..9a883ba96d 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -13,17 +13,19 @@
namespace mbgl {
namespace style {
-class GeoJSONVTData : public GeoJSONData {
+class GeoJSONVTData : public GeoJSONData, public std::enable_shared_from_this<GeoJSONVTData> {
public:
- GeoJSONVTData(const GeoJSON& geoJSON, const mapbox::geojsonvt::Options& options)
- : impl(geoJSON, options) {
- }
-
void getTile(const CanonicalTileID& id, const std::function<void(TileFeatures)>& fn) final {
assert(fn);
- // It's safe to pass `this` as scheduler will die earlier.
- scheduler.scheduleAndReplyValue(
- [id, this]() -> TileFeatures { return impl.getTile(id.z, id.x, id.y).features; }, fn);
+ std::weak_ptr<GeoJSONVTData> weak = shared_from_this();
+ scheduler->scheduleAndReplyValue(
+ [id, weak, this]() -> TileFeatures {
+ if (auto self = weak.lock()) {
+ return impl.getTile(id.z, id.x, id.y).features;
+ }
+ return {};
+ },
+ fn);
}
Features getChildren(const std::uint32_t) final { return {}; }
@@ -35,15 +37,15 @@ public:
}
private:
+ friend GeoJSONData;
+ GeoJSONVTData(const GeoJSON& geoJSON, const mapbox::geojsonvt::Options& options)
+ : impl(geoJSON, options), scheduler(Scheduler::GetSequenced()) {}
mapbox::geojsonvt::GeoJSONVT impl;
- SequencedScheduler scheduler;
+ std::shared_ptr<Scheduler> scheduler;
};
class SuperclusterData : public GeoJSONData {
public:
- SuperclusterData(const Features& features, const mapbox::supercluster::Options& options)
- : impl(features, options) {}
-
void getTile(const CanonicalTileID& id, const std::function<void(TileFeatures)>& fn) final {
assert(fn);
fn(impl.getTile(id.z, id.x, id.y));
@@ -60,6 +62,9 @@ public:
}
private:
+ friend GeoJSONData;
+ SuperclusterData(const Features& features, const mapbox::supercluster::Options& options)
+ : impl(features, options) {}
mapbox::supercluster::Supercluster impl;
};
@@ -105,7 +110,7 @@ std::shared_ptr<GeoJSONData> GeoJSONData::create(const GeoJSON& geoJSON, Immutab
toReturn[p.first] = evaluateFeature<Value>(*feature, p.second.second, accumulated);
}
};
- return std::make_shared<SuperclusterData>(geoJSON.get<Features>(), clusterOptions);
+ return std::shared_ptr<GeoJSONData>(new SuperclusterData(geoJSON.get<Features>(), clusterOptions));
}
mapbox::geojsonvt::Options vtOptions;
@@ -114,7 +119,7 @@ std::shared_ptr<GeoJSONData> GeoJSONData::create(const GeoJSON& geoJSON, Immutab
vtOptions.buffer = ::round(scale * options->buffer);
vtOptions.tolerance = scale * options->tolerance;
vtOptions.lineMetrics = options->lineMetrics;
- return std::make_shared<GeoJSONVTData>(geoJSON, vtOptions);
+ return std::shared_ptr<GeoJSONData>(new GeoJSONVTData(geoJSON, vtOptions));
}
GeoJSONSource::Impl::Impl(std::string id_, Immutable<GeoJSONOptions> options_)