summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-20 21:05:45 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-11-29 11:12:55 +0200
commit6419cd0ab2ba877bbae51ae7590ddba47765dac7 (patch)
treeb167f864db677365d281423e1df755f7fd383989 /src/mbgl/style
parentab5572b0bc3d386893592b842ad58b356b227a5d (diff)
downloadqtlocation-mapboxgl-6419cd0ab2ba877bbae51ae7590ddba47765dac7.tar.gz
[core] Calculate GeoJSON tile geometries in a background thread
Call `mapbox::geojsonvt::GeoJSONVT::getTile()` in a background thread, so that the rendering thread is not blocked.
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp43
1 files changed, 18 insertions, 25 deletions
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index 962d6bd060..e4b48223f4 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -3,6 +3,7 @@
#include <mbgl/util/constants.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/util/thread_pool.hpp>
#include <mapbox/geojsonvt.hpp>
#include <supercluster.hpp>
@@ -18,18 +19,16 @@ public:
: impl(geoJSON, options) {
}
- mapbox::feature::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final {
- return impl.getTile(tileID.z, tileID.x, tileID.y).features;
+ 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);
}
- mapbox::feature::feature_collection<double> getChildren(const std::uint32_t) final {
- return {};
- }
+ Features getChildren(const std::uint32_t) final { return {}; }
- mapbox::feature::feature_collection<double>
- getLeaves(const std::uint32_t, const std::uint32_t, const std::uint32_t) final {
- return {};
- }
+ Features getLeaves(const std::uint32_t, const std::uint32_t, const std::uint32_t) final { return {}; }
std::uint8_t getClusterExpansionZoom(std::uint32_t) final {
return 0;
@@ -37,26 +36,22 @@ public:
private:
mapbox::geojsonvt::GeoJSONVT impl;
+ SequencedScheduler scheduler;
};
class SuperclusterData : public GeoJSONData {
public:
- SuperclusterData(const mapbox::feature::feature_collection<double>& features,
- const mapbox::supercluster::Options& options)
- : impl(features, options) {
- }
+ SuperclusterData(const Features& features, const mapbox::supercluster::Options& options)
+ : impl(features, options) {}
- mapbox::feature::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final {
- return impl.getTile(tileID.z, tileID.x, tileID.y);
+ void getTile(const CanonicalTileID& id, const std::function<void(TileFeatures)>& fn) final {
+ assert(fn);
+ fn(impl.getTile(id.z, id.x, id.y));
}
- mapbox::feature::feature_collection<double> getChildren(const std::uint32_t cluster_id) final {
- return impl.getChildren(cluster_id);
- }
+ Features getChildren(const std::uint32_t cluster_id) final { return impl.getChildren(cluster_id); }
- mapbox::feature::feature_collection<double> getLeaves(const std::uint32_t cluster_id,
- const std::uint32_t limit,
- const std::uint32_t offset) final {
+ Features getLeaves(const std::uint32_t cluster_id, const std::uint32_t limit, const std::uint32_t offset) final {
return impl.getLeaves(cluster_id, limit, offset);
}
@@ -85,8 +80,7 @@ T evaluateFeature(const mapbox::feature::feature<double>& f,
// static
std::shared_ptr<GeoJSONData> GeoJSONData::create(const GeoJSON& geoJSON, Immutable<GeoJSONOptions> options) {
constexpr double scale = util::EXTENT / util::tileSize;
- if (options->cluster && geoJSON.is<mapbox::feature::feature_collection<double>>() &&
- !geoJSON.get<mapbox::feature::feature_collection<double>>().empty()) {
+ if (options->cluster && geoJSON.is<Features>() && !geoJSON.get<Features>().empty()) {
mapbox::supercluster::Options clusterOptions;
clusterOptions.maxZoom = options->clusterMaxZoom;
clusterOptions.extent = util::EXTENT;
@@ -111,8 +105,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<mapbox::feature::feature_collection<double>>(),
- clusterOptions);
+ return std::make_shared<SuperclusterData>(geoJSON.get<Features>(), clusterOptions);
}
mapbox::geojsonvt::Options vtOptions;