Report errors when parsing raster tiles

Use the same API/pattern for parsing raster tiles as we use for vector
tiles. Forward the error as an exception that will ultimately reach the
StillImageCallback.

Also set the tile to State::obsolete on error like we do for vector
tiles.
This commit is contained in:
Thiago Marcos P. Santos
2015-07-02 16:04:30 +03:00
parent c357ce540a
commit 9cc986e758
8 changed files with 26 additions and 18 deletions

View File

@@ -25,8 +25,8 @@ bool Raster::isLoaded() const {
return loaded;
}
bool Raster::load(const std::string &data) {
img = std::make_unique<util::Image>(data);
bool Raster::load(std::unique_ptr<util::Image> image) {
img = std::move(image);
width = img->getWidth();
height = img->getHeight();

View File

@@ -6,7 +6,6 @@
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/chrono.hpp>
#include <string>
#include <mutex>
typedef struct uv_loop_s uv_loop_t;
@@ -20,7 +19,7 @@ public:
~Raster();
// load image data
bool load(const std::string &img);
bool load(std::unique_ptr<util::Image> image);
// bind current texture
void bind(bool linear = false);

View File

@@ -20,8 +20,17 @@ public:
util::ThreadContext::setFileSource(fs);
}
void parseRasterTile(RasterBucket* bucket, std::string data, std::function<void (bool)> callback) {
callback(bucket->setImage(data));
void parseRasterTile(RasterBucket* bucket, std::string data, std::function<void (TileParseResult)> callback) {
std::unique_ptr<util::Image> image(new util::Image(data));
if (!(*image)) {
callback(TileParseResult("error parsing raster image"));
}
if (!bucket->setImage(std::move(image))) {
callback(TileParseResult("error setting raster image to bucket"));
}
callback(TileParseResult(TileData::State::parsed));
}
void parseVectorTile(TileWorker* worker, std::string data, std::function<void (TileParseResult)> callback) {
@@ -56,7 +65,7 @@ Worker::Worker(std::size_t count) {
Worker::~Worker() = default;
std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function<void (bool)> callback) {
std::unique_ptr<WorkRequest> Worker::parseRasterTile(RasterBucket& bucket, std::string data, std::function<void (TileParseResult)> callback) {
current = (current + 1) % threads.size();
return threads[current]->invokeWithCallback(&Worker::Impl::parseRasterTile, callback, &bucket, data);
}

View File

@@ -34,7 +34,7 @@ public:
Request parseRasterTile(
RasterBucket&,
std::string data,
std::function<void (bool)> callback);
std::function<void (TileParseResult)> callback);
Request parseVectorTile(
TileWorker&,