This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
TileData + Worker refactor #1691
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
4eff674
Revert "Do not hold a reference to the Style at the [Live|Vector]Tile…
jfirebaugh ee46378
Reduce number of arguments in Source::update pathway
jfirebaugh 7e71145
Make request and reparse pure virtual
jfirebaugh 29a2cd9
Introduce TileWorker
jfirebaugh 217c376
Push TileMembers members down hierarchy
jfirebaugh 875ef97
Remove indirection
jfirebaugh 4676553
Merge TileParser into TileWorker
jfirebaugh 9e0b241
reset partialParse when starting a new parsing run
kkaefer 24f50fd
Remove indirection
jfirebaugh d596d9d
Clean up bucket creation loop
jfirebaugh 5fadda5
Move WorkerTask functionality into RunLoop core
jfirebaugh f14e4c6
Add comment about a subtlety
jfirebaugh eee0242
Single-purpose Worker functions
jfirebaugh 3670a78
Convert Worker tests to Thread tests
jfirebaugh d30fce5
Catch exceptions when parsing tile PBFs
tmpsantos abdf205
Rename workerData ⇢ tileWorker
jfirebaugh db1202e
Don't pass Worker& around so much
jfirebaugh 3ab682e
Fix name shadowing
jfirebaugh fc64e97
Simplify RunLoop
jfirebaugh c0af683
Reapply style layer copy technique
jfirebaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,58 @@ | ||
#include <mbgl/map/annotation.hpp> | ||
#include <mbgl/map/live_tile_data.hpp> | ||
#include <mbgl/map/live_tile.hpp> | ||
#include <mbgl/map/tile_parser.hpp> | ||
#include <mbgl/map/source.hpp> | ||
#include <mbgl/map/vector_tile.hpp> | ||
#include <mbgl/platform/log.hpp> | ||
#include <mbgl/util/worker.hpp> | ||
#include <mbgl/util/work_request.hpp> | ||
|
||
#include <sstream> | ||
|
||
using namespace mbgl; | ||
|
||
LiveTileData::LiveTileData(const TileID& id_, | ||
AnnotationManager& annotationManager_, | ||
const std::vector<util::ptr<StyleLayer>>& layers_, | ||
Worker& workers_, | ||
GlyphAtlas& glyphAtlas_, | ||
GlyphStore& glyphStore_, | ||
SpriteAtlas& spriteAtlas_, | ||
util::ptr<Sprite> sprite_, | ||
Style& style_, | ||
const SourceInfo& source_, | ||
float angle_, | ||
bool collisionDebug_) | ||
: VectorTileData::VectorTileData(id_, layers_, workers_, glyphAtlas_, glyphStore_, | ||
spriteAtlas_, sprite_, source_, angle_, collisionDebug_), | ||
: VectorTileData(id_, style_, source_, angle_, collisionDebug_), | ||
annotationManager(annotationManager_) { | ||
// live features are always ready | ||
setState(State::loaded); | ||
// live features are always loaded | ||
state = State::loaded; | ||
} | ||
|
||
LiveTileData::~LiveTileData() { | ||
// Cancel in most derived class destructor so that worker tasks are joined before | ||
// any member data goes away. | ||
cancel(); | ||
} | ||
|
||
void LiveTileData::parse() { | ||
if (getState() != State::loaded) { | ||
return; | ||
bool LiveTileData::reparse(std::function<void()> callback) { | ||
if (parsing || (state != State::loaded && state != State::partial)) { | ||
return false; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These comments are very helpful. Any reason to remove them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My eventual plan was to have a flat hierarchy, with |
||
|
||
const LiveTile* tile = annotationManager.getTile(id); | ||
if (!tile) { | ||
state = State::parsed; | ||
return true; | ||
} | ||
|
||
parsing = true; | ||
|
||
if (tile) { | ||
try { | ||
// Parsing creates state that is encapsulated in TileParser. While parsing, | ||
// the TileParser object writes results into this objects. All other state | ||
// is going to be discarded afterwards. | ||
TileParser parser(*tile, *this, layers, glyphAtlas, glyphStore, spriteAtlas, sprite); | ||
parser.parse(); | ||
} catch (const std::exception& ex) { | ||
Log::Error(Event::ParseTile, "Live-parsing [%d/%d/%d] failed: %s", id.z, id.x, id.y, ex.what()); | ||
setState(State::obsolete); | ||
workRequest = worker.parseLiveTile(tileWorker, *tile, [this, callback] (TileParseResult result) { | ||
parsing = false; | ||
|
||
if (state == State::obsolete) { | ||
return; | ||
} | ||
} | ||
|
||
if (getState() != State::obsolete) { | ||
setState(State::parsed); | ||
} | ||
if (result.is<State>()) { | ||
state = result.get<State>(); | ||
} else { | ||
error = result.get<std::string>(); | ||
state = State::obsolete; | ||
} | ||
|
||
callback(); | ||
}); | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,81 @@ | ||
#include <mbgl/map/raster_tile_data.hpp> | ||
#include <mbgl/style/style.hpp> | ||
#include <mbgl/map/source.hpp> | ||
#include <mbgl/storage/resource.hpp> | ||
#include <mbgl/storage/response.hpp> | ||
#include <mbgl/storage/file_source.hpp> | ||
#include <mbgl/util/worker.hpp> | ||
#include <mbgl/util/work_request.hpp> | ||
|
||
#include <sstream> | ||
|
||
using namespace mbgl; | ||
|
||
RasterTileData::RasterTileData(const TileID& id_, TexturePool &texturePool, | ||
const SourceInfo &source_) | ||
: TileData(id_, source_), bucket(texturePool, layout) { | ||
RasterTileData::RasterTileData(const TileID& id_, | ||
TexturePool &texturePool, | ||
const SourceInfo &source_, | ||
Worker& worker_) | ||
: TileData(id_), | ||
source(source_), | ||
worker(worker_), | ||
bucket(texturePool, layout) { | ||
} | ||
|
||
RasterTileData::~RasterTileData() { | ||
// Cancel in most derived class destructor so that worker tasks are joined before | ||
// any member data goes away. | ||
cancel(); | ||
} | ||
|
||
void RasterTileData::parse() { | ||
if (getState() != State::loaded) { | ||
return; | ||
} | ||
void RasterTileData::request(float pixelRatio, | ||
const std::function<void()>& callback) { | ||
std::string url = source.tileURL(id, pixelRatio); | ||
state = State::loading; | ||
|
||
if (bucket.setImage(data)) { | ||
setState(State::parsed); | ||
} else { | ||
setState(State::invalid); | ||
} | ||
FileSource* fs = util::ThreadContext::getFileSource(); | ||
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) { | ||
std::stringstream message; | ||
message << "Failed to load [" << url << "]: " << res.message; | ||
error = message.str(); | ||
state = State::obsolete; | ||
callback(); | ||
return; | ||
} | ||
|
||
state = State::loaded; | ||
|
||
workRequest = worker.parseRasterTile(bucket, res.data, [this, callback] (bool result) { | ||
if (state != State::loaded) { | ||
return; | ||
} | ||
|
||
if (result) { | ||
state = State::parsed; | ||
} else { | ||
state = State::invalid; | ||
} | ||
|
||
callback(); | ||
}); | ||
}); | ||
} | ||
|
||
bool RasterTileData::reparse(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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we store this as a
dirty
flag so we know that we weren't able to start parsing and have to try again some time later?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand partial parsing yet but I assume this is handled by the return value here and the code in
Style::handlePartialTile
.