Don't pass Worker& around so much
This commit is contained in:
@@ -24,7 +24,7 @@ LiveTileData::~LiveTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
bool LiveTileData::reparse(Worker& worker, std::function<void()> callback) {
|
||||
bool LiveTileData::reparse(std::function<void()> callback) {
|
||||
if (parsing || (state != State::loaded && state != State::partial)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
bool collisionDebug_);
|
||||
~LiveTileData();
|
||||
|
||||
bool reparse(Worker&, std::function<void ()> callback) override;
|
||||
bool reparse(std::function<void ()> callback) override;
|
||||
|
||||
private:
|
||||
AnnotationManager& annotationManager;
|
||||
|
||||
@@ -12,9 +12,11 @@ using namespace mbgl;
|
||||
|
||||
RasterTileData::RasterTileData(const TileID& id_,
|
||||
TexturePool &texturePool,
|
||||
const SourceInfo &source_)
|
||||
const SourceInfo &source_,
|
||||
Worker& worker_)
|
||||
: TileData(id_),
|
||||
source(source_),
|
||||
worker(worker_),
|
||||
bucket(texturePool, layout) {
|
||||
}
|
||||
|
||||
@@ -22,14 +24,13 @@ RasterTileData::~RasterTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
void RasterTileData::request(Worker& worker,
|
||||
float pixelRatio,
|
||||
const std::function<void()>& callback) {
|
||||
void RasterTileData::request(float pixelRatio,
|
||||
const std::function<void()>& callback) {
|
||||
std::string url = source.tileURL(id, pixelRatio);
|
||||
state = State::loading;
|
||||
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::current.get()->get(), [url, callback, &worker, this](const Response &res) {
|
||||
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::current.get()->get(), [url, callback, this](const Response &res) {
|
||||
req = nullptr;
|
||||
|
||||
if (res.status != Response::Successful) {
|
||||
@@ -59,7 +60,7 @@ void RasterTileData::request(Worker& worker,
|
||||
});
|
||||
}
|
||||
|
||||
bool RasterTileData::reparse(Worker&, std::function<void()>) {
|
||||
bool RasterTileData::reparse(std::function<void()>) {
|
||||
assert(false);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,14 +15,13 @@ class WorkRequest;
|
||||
|
||||
class RasterTileData : public TileData {
|
||||
public:
|
||||
RasterTileData(const TileID&, TexturePool&, const SourceInfo&);
|
||||
RasterTileData(const TileID&, TexturePool&, const SourceInfo&, Worker&);
|
||||
~RasterTileData();
|
||||
|
||||
void request(Worker&,
|
||||
float pixelRatio,
|
||||
void request(float pixelRatio,
|
||||
const std::function<void()>& callback) override;
|
||||
|
||||
bool reparse(Worker&, std::function<void ()> callback) override;
|
||||
bool reparse(std::function<void ()> callback) override;
|
||||
|
||||
void cancel() override;
|
||||
|
||||
@@ -30,6 +29,7 @@ public:
|
||||
|
||||
private:
|
||||
const SourceInfo& source;
|
||||
Worker& worker;
|
||||
Request* req = nullptr;
|
||||
|
||||
StyleLayoutRaster layout;
|
||||
|
||||
@@ -225,7 +225,7 @@ TileData::State Source::hasTile(const TileID& id) {
|
||||
return TileData::State::invalid;
|
||||
}
|
||||
|
||||
bool Source::handlePartialTile(const TileID& id, Worker& worker) {
|
||||
bool Source::handlePartialTile(const TileID& id, Worker&) {
|
||||
const TileID normalized_id = id.normalized();
|
||||
|
||||
auto it = tile_data.find(normalized_id);
|
||||
@@ -248,7 +248,7 @@ bool Source::handlePartialTile(const TileID& id, Worker& worker) {
|
||||
}
|
||||
};
|
||||
|
||||
return data->reparse(worker, callback);
|
||||
return data->reparse(callback);
|
||||
}
|
||||
|
||||
TileData::State Source::addTile(MapData& data,
|
||||
@@ -293,16 +293,15 @@ TileData::State Source::addTile(MapData& data,
|
||||
new_tile.data =
|
||||
std::make_shared<VectorTileData>(normalized_id, style, info,
|
||||
transformState.getAngle(), data.getCollisionDebug());
|
||||
new_tile.data->request(style.workers, transformState.getPixelRatio(), callback);
|
||||
new_tile.data->request(transformState.getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Raster) {
|
||||
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info);
|
||||
new_tile.data->request(
|
||||
style.workers, transformState.getPixelRatio(), callback);
|
||||
new_tile.data = std::make_shared<RasterTileData>(normalized_id, texturePool, info, style.workers);
|
||||
new_tile.data->request(transformState.getPixelRatio(), callback);
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
new_tile.data = std::make_shared<LiveTileData>(normalized_id, data.annotationManager,
|
||||
style, info,
|
||||
transformState.getAngle(), data.getCollisionDebug());
|
||||
new_tile.data->reparse(style.workers, callback);
|
||||
new_tile.data->reparse(callback);
|
||||
} else {
|
||||
throw std::runtime_error("source type not implemented");
|
||||
}
|
||||
|
||||
@@ -70,16 +70,14 @@ public:
|
||||
TileData(const TileID&);
|
||||
virtual ~TileData() = default;
|
||||
|
||||
virtual void request(Worker&,
|
||||
float pixelRatio,
|
||||
virtual void request(float pixelRatio,
|
||||
const std::function<void()>& callback) = 0;
|
||||
|
||||
// Schedule a tile reparse on a worker thread and call the callback on
|
||||
// completion. It will return true if the work was schedule or false it was
|
||||
// not, which can occur if the tile is already being parsed by another
|
||||
// worker.
|
||||
virtual bool reparse(Worker&,
|
||||
std::function<void ()> callback) = 0;
|
||||
virtual bool reparse(std::function<void ()> callback) = 0;
|
||||
|
||||
// Mark this tile as no longer needed and cancel any pending work.
|
||||
virtual void cancel() = 0;
|
||||
|
||||
@@ -18,6 +18,7 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
float angle,
|
||||
bool collisionDebug)
|
||||
: TileData(id_),
|
||||
worker(style_.workers),
|
||||
tileWorker(id_,
|
||||
style_,
|
||||
source_.max_zoom,
|
||||
@@ -26,7 +27,6 @@ VectorTileData::VectorTileData(const TileID& id_,
|
||||
source_.tile_size * id.overscaling,
|
||||
angle, collisionDebug)),
|
||||
source(source_),
|
||||
worker(style_.workers),
|
||||
lastAngle(angle),
|
||||
currentAngle(angle) {
|
||||
}
|
||||
@@ -35,7 +35,7 @@ VectorTileData::~VectorTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
void VectorTileData::request(Worker&, float pixelRatio, const std::function<void()>& callback) {
|
||||
void VectorTileData::request(float pixelRatio, const std::function<void()>& callback) {
|
||||
std::string url = source.tileURL(id, pixelRatio);
|
||||
state = State::loading;
|
||||
|
||||
@@ -55,11 +55,11 @@ void VectorTileData::request(Worker&, float pixelRatio, const std::function<void
|
||||
state = State::loaded;
|
||||
data = res.data;
|
||||
|
||||
reparse(worker, callback);
|
||||
reparse(callback);
|
||||
});
|
||||
}
|
||||
|
||||
bool VectorTileData::reparse(Worker&, std::function<void()> callback) {
|
||||
bool VectorTileData::reparse(std::function<void()> callback) {
|
||||
if (parsing || (state != State::loaded && state != State::partial)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,20 +25,20 @@ public:
|
||||
bool collisionDebug_);
|
||||
~VectorTileData();
|
||||
|
||||
void redoPlacement(float angle, bool collisionDebug) override;
|
||||
|
||||
Bucket* getBucket(const StyleLayer&) override;
|
||||
size_t countBuckets() const;
|
||||
|
||||
void request(Worker&,
|
||||
float pixelRatio,
|
||||
void request(float pixelRatio,
|
||||
const std::function<void()>& callback) override;
|
||||
|
||||
bool reparse(Worker&, std::function<void ()> callback) override;
|
||||
bool reparse(std::function<void ()> callback) override;
|
||||
|
||||
void redoPlacement(float angle, bool collisionDebug) override;
|
||||
|
||||
void cancel() override;
|
||||
|
||||
protected:
|
||||
Worker& worker;
|
||||
TileWorker tileWorker;
|
||||
std::unique_ptr<WorkRequest> workRequest;
|
||||
bool parsing = false;
|
||||
@@ -47,7 +47,6 @@ private:
|
||||
const SourceInfo& source;
|
||||
Request* req = nullptr;
|
||||
std::string data;
|
||||
Worker& worker;
|
||||
|
||||
float lastAngle = 0;
|
||||
float currentAngle;
|
||||
|
||||
Reference in New Issue
Block a user