Push TileMembers members down hierarchy

This commit is contained in:
John Firebaugh
2015-06-04 17:22:47 -07:00
parent 29a2cd908f
commit 217c376291
6 changed files with 131 additions and 138 deletions

View File

@@ -10,14 +10,15 @@
using namespace mbgl;
RasterTileData::RasterTileData(const TileID& id_, TexturePool &texturePool,
RasterTileData::RasterTileData(const TileID& id_,
TexturePool &texturePool,
const SourceInfo &source_)
: TileData(id_, source_), bucket(texturePool, layout) {
: TileData(id_),
source(source_),
bucket(texturePool, layout) {
}
RasterTileData::~RasterTileData() {
// Cancel in most derived class destructor so that worker tasks are joined before
// any member data goes away.
cancel();
}
@@ -34,7 +35,8 @@ void RasterTileData::request(Worker& worker,
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
setError(message.str());
error = message.str();
state = State::obsolete;
callback();
return;
}
@@ -42,32 +44,36 @@ void RasterTileData::request(Worker& worker,
state = State::loaded;
data = res.data;
// Schedule tile parsing in another thread
reparse(worker, callback);
workRequest = worker.send([this] {
if (getState() != State::loaded) {
return;
}
if (bucket.setImage(data)) {
state = State::parsed;
} else {
state = State::invalid;
}
}, callback);
});
}
bool RasterTileData::reparse(Worker& worker, std::function<void()> callback) {
if (!mayStartParsing()) {
return false;
}
workRequest = worker.send([this] { parse(); endParsing(); }, callback);
return true;
}
void RasterTileData::parse() {
if (getState() != State::loaded) {
return;
}
if (bucket.setImage(data)) {
setState(State::parsed);
} else {
setState(State::invalid);
}
bool RasterTileData::reparse(Worker&, std::function<void()>) {
assert(false);
return false;
}
Bucket* RasterTileData::getBucket(StyleLayer const&) {
return &bucket;
}
void RasterTileData::cancel() {
if (state != State::obsolete) {
state = State::obsolete;
}
if (req) {
util::ThreadContext::getFileSource()->cancel(req);
req = nullptr;
}
workRequest.reset();
}