[core] Use current copy of style layers when reparsing tiles

This fixes adding shape annotations after VectorTileData objects have
been created for annotations already, and will also be necessary for
the dynamic Style API.
This commit is contained in:
John Firebaugh
2015-10-29 14:26:34 -07:00
parent 7669e02062
commit 8c3b3cb792
6 changed files with 27 additions and 18 deletions

View File

@@ -18,10 +18,8 @@ using namespace mbgl;
TileWorker::TileWorker(TileID id_,
std::string sourceID_,
Style& style_,
std::vector<util::ptr<StyleLayer>> layers_,
const std::atomic<TileData::State>& state_)
: layers(std::move(layers_)),
id(id_),
: id(id_),
sourceID(sourceID_),
parameters(id.z),
style(style_),
@@ -33,7 +31,8 @@ TileWorker::~TileWorker() {
style.glyphAtlas->removeGlyphs(reinterpret_cast<uintptr_t>(this));
}
TileParseResult TileWorker::parseAllLayers(const GeometryTile& geometryTile,
TileParseResult TileWorker::parseAllLayers(std::vector<util::ptr<StyleLayer>> layers,
const GeometryTile& geometryTile,
PlacementConfig config) {
// We're doing a fresh parse of the tile, because the underlying data has changed.
pending.clear();
@@ -85,6 +84,7 @@ TileParseResult TileWorker::parsePendingLayers() {
}
void TileWorker::redoPlacement(
std::vector<util::ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>* buckets,
PlacementConfig config) {

View File

@@ -42,16 +42,18 @@ public:
TileWorker(TileID,
std::string sourceID,
Style&,
std::vector<util::ptr<StyleLayer>>,
const std::atomic<TileData::State>&);
~TileWorker();
TileParseResult parseAllLayers(const GeometryTile&, PlacementConfig);
TileParseResult parsePendingLayers();
void redoPlacement(const std::unordered_map<std::string, std::unique_ptr<Bucket>>*,
PlacementConfig);
TileParseResult parseAllLayers(std::vector<util::ptr<StyleLayer>>,
const GeometryTile&,
PlacementConfig);
std::vector<util::ptr<StyleLayer>> layers;
TileParseResult parsePendingLayers();
void redoPlacement(std::vector<util::ptr<StyleLayer>>,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>*,
PlacementConfig);
private:
void parseLayer(const StyleLayer&, const GeometryTile&);

View File

@@ -16,16 +16,16 @@ VectorTileData::VectorTileData(const TileID& id_,
Style& style_,
const std::function<void()>& callback)
: TileData(id_),
style(style_),
worker(style_.workers),
tileWorker(id_,
sourceID,
style_,
style_.layers,
state),
monitor(std::move(monitor_))
{
state = State::loading;
req = monitor->monitorTile([callback, sourceID, this](std::exception_ptr err, std::unique_ptr<GeometryTile> tile) {
req = monitor->monitorTile([callback, this](std::exception_ptr err, std::unique_ptr<GeometryTile> tile) {
if (err) {
try {
std::rethrow_exception(err);
@@ -54,7 +54,7 @@ VectorTileData::VectorTileData(const TileID& id_,
// when tile data changed. Replacing the workdRequest will cancel a pending work
// request in case there is one.
workRequest.reset();
workRequest = worker.parseGeometryTile(tileWorker, std::move(tile), targetConfig, [callback, sourceID, this, config = targetConfig] (TileParseResult result) {
workRequest = worker.parseGeometryTile(tileWorker, style.layers, std::move(tile), targetConfig, [callback, this, config = targetConfig] (TileParseResult result) {
workRequest.reset();
if (state == State::obsolete) {
return;
@@ -162,7 +162,7 @@ void VectorTileData::redoPlacement(const PlacementConfig newConfig) {
void VectorTileData::redoPlacement() {
workRequest.reset();
workRequest = worker.redoPlacement(tileWorker, buckets, targetConfig, [this, config = targetConfig] {
workRequest = worker.redoPlacement(tileWorker, style.layers, buckets, targetConfig, [this, config = targetConfig] {
workRequest.reset();
// Persist the configuration we just placed so that we can later check whether we need to

View File

@@ -36,6 +36,7 @@ public:
void cancel() override;
private:
Style& style;
Worker& worker;
TileWorker tileWorker;

View File

@@ -30,11 +30,12 @@ public:
}
void parseGeometryTile(TileWorker* worker,
std::vector<util::ptr<StyleLayer>> layers,
std::unique_ptr<GeometryTile> tile,
PlacementConfig config,
std::function<void(TileParseResult)> callback) {
try {
callback(worker->parseAllLayers(*tile, config));
callback(worker->parseAllLayers(layers, *tile, config));
} catch (const std::exception& ex) {
callback(TileParseResult(ex.what()));
}
@@ -50,10 +51,11 @@ public:
}
void redoPlacement(TileWorker* worker,
std::vector<util::ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>* buckets,
PlacementConfig config,
std::function<void()> callback) {
worker->redoPlacement(buckets, config);
worker->redoPlacement(layers, buckets, config);
callback();
}
};
@@ -78,12 +80,13 @@ Worker::parseRasterTile(std::unique_ptr<RasterBucket> bucket,
std::unique_ptr<WorkRequest>
Worker::parseGeometryTile(TileWorker& worker,
std::vector<util::ptr<StyleLayer>> layers,
std::unique_ptr<GeometryTile> tile,
PlacementConfig config,
std::function<void(TileParseResult)> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::parseGeometryTile, callback, &worker,
std::move(tile), config);
std::move(layers), std::move(tile), config);
}
std::unique_ptr<WorkRequest>
@@ -96,12 +99,13 @@ Worker::parsePendingGeometryTileLayers(TileWorker& worker,
std::unique_ptr<WorkRequest>
Worker::redoPlacement(TileWorker& worker,
std::vector<util::ptr<StyleLayer>> layers,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>& buckets,
PlacementConfig config,
std::function<void()> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::redoPlacement, callback, &worker,
&buckets, config);
layers, &buckets, config);
}
} // end namespace mbgl

View File

@@ -40,6 +40,7 @@ public:
std::function<void(RasterTileParseResult)> callback);
Request parseGeometryTile(TileWorker&,
std::vector<util::ptr<StyleLayer>>,
std::unique_ptr<GeometryTile>,
PlacementConfig,
std::function<void(TileParseResult)> callback);
@@ -48,6 +49,7 @@ public:
std::function<void(TileParseResult)> callback);
Request redoPlacement(TileWorker&,
std::vector<util::ptr<StyleLayer>>,
const std::unordered_map<std::string, std::unique_ptr<Bucket>>&,
PlacementConfig config,
std::function<void()> callback);