summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-06-09 10:08:20 -0400
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-07-01 15:21:11 -0700
commitdb1202e8e335be540ded48029216ad9884fc5bb9 (patch)
treeb52c47b6a6dd63176884a1a14e5b2d3f81ab12a9
parentabdf205510b1f2d7b3e0c9b432f17c8c4d71e895 (diff)
downloadqtlocation-mapboxgl-db1202e8e335be540ded48029216ad9884fc5bb9.tar.gz
Don't pass Worker& around so much
-rw-r--r--src/mbgl/map/live_tile_data.cpp2
-rw-r--r--src/mbgl/map/live_tile_data.hpp2
-rw-r--r--src/mbgl/map/raster_tile_data.cpp13
-rw-r--r--src/mbgl/map/raster_tile_data.hpp8
-rw-r--r--src/mbgl/map/source.cpp13
-rw-r--r--src/mbgl/map/tile_data.hpp6
-rw-r--r--src/mbgl/map/vector_tile_data.cpp8
-rw-r--r--src/mbgl/map/vector_tile_data.hpp11
8 files changed, 30 insertions, 33 deletions
diff --git a/src/mbgl/map/live_tile_data.cpp b/src/mbgl/map/live_tile_data.cpp
index 22f9a54b4a..ad28c6c628 100644
--- a/src/mbgl/map/live_tile_data.cpp
+++ b/src/mbgl/map/live_tile_data.cpp
@@ -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;
}
diff --git a/src/mbgl/map/live_tile_data.hpp b/src/mbgl/map/live_tile_data.hpp
index c837057e82..2d6b010614 100644
--- a/src/mbgl/map/live_tile_data.hpp
+++ b/src/mbgl/map/live_tile_data.hpp
@@ -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;
diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp
index e5a2626035..837f4c0f1b 100644
--- a/src/mbgl/map/raster_tile_data.cpp
+++ b/src/mbgl/map/raster_tile_data.cpp
@@ -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;
}
diff --git a/src/mbgl/map/raster_tile_data.hpp b/src/mbgl/map/raster_tile_data.hpp
index e519874c03..ce0286f5a0 100644
--- a/src/mbgl/map/raster_tile_data.hpp
+++ b/src/mbgl/map/raster_tile_data.hpp
@@ -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;
diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp
index 0bac4c3c7f..55761eb26d 100644
--- a/src/mbgl/map/source.cpp
+++ b/src/mbgl/map/source.cpp
@@ -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");
}
diff --git a/src/mbgl/map/tile_data.hpp b/src/mbgl/map/tile_data.hpp
index 5ed4ef4fd4..5525256957 100644
--- a/src/mbgl/map/tile_data.hpp
+++ b/src/mbgl/map/tile_data.hpp
@@ -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;
diff --git a/src/mbgl/map/vector_tile_data.cpp b/src/mbgl/map/vector_tile_data.cpp
index d0f4b131f9..9b04ab371a 100644
--- a/src/mbgl/map/vector_tile_data.cpp
+++ b/src/mbgl/map/vector_tile_data.cpp
@@ -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;
}
diff --git a/src/mbgl/map/vector_tile_data.hpp b/src/mbgl/map/vector_tile_data.hpp
index 6b866de376..a035015f4d 100644
--- a/src/mbgl/map/vector_tile_data.hpp
+++ b/src/mbgl/map/vector_tile_data.hpp
@@ -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;