Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Convert GeometryTileWorker to "one-phase" loading
Browse files Browse the repository at this point in the history
Modest simplification refactoring (issue #10457).
Also, fixes issue #11538, which was caused in part by a hole in the vestigial two-phase loading.
  • Loading branch information
ChrisLoer committed Mar 30, 2018
1 parent cf5d2ca commit e4dda35
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 162 deletions.
46 changes: 11 additions & 35 deletions src/mbgl/tile/geometry_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,36 +125,17 @@ void GeometryTile::setShowCollisionBoxes(const bool showCollisionBoxes_) {
}

void GeometryTile::onLayout(LayoutResult result, const uint64_t resultCorrelationID) {
// Don't mark ourselves loaded or renderable until the first successful placement
// TODO: Ideally we'd render this tile without symbols as long as this tile wasn't
// replacing a tile at a different zoom that _did_ have symbols.
(void)resultCorrelationID;
nonSymbolBuckets = std::move(result.nonSymbolBuckets);
// It is possible for multiple onLayouts to be called before an onPlacement is called, in which
// case we will discard previous pending data
pendingFeatureIndex = {{ false, std::move(result.featureIndex) }};
pendingData = {{ false, std::move(result.tileData) }};
observer->onTileChanged(*this);
}

void GeometryTile::onPlacement(PlacementResult result, const uint64_t resultCorrelationID) {
loaded = true;
renderable = true;
if (resultCorrelationID == correlationID) {
pending = false;
}

nonSymbolBuckets = std::move(result.nonSymbolBuckets);
symbolBuckets = std::move(result.symbolBuckets);
// When symbolBuckets arrive, mark pendingData/FeatureIndex as "ready for commit" at the
// time of the next global placement. We are counting on these symbolBuckets being
// in sync with the data/index in the last `onLayout` call, even though the correlation IDs
// may not be the same (e.g. "setShowCollisionBoxes" could bump the correlation ID while
// waiting for glyph dependencies)
if (pendingData) {
pendingData->first = true;
}
if (pendingFeatureIndex) {
pendingFeatureIndex->first = true;
}

dataPendingCommit = {{ std::move(result.tileData), std::move(result.featureIndex) }};

if (result.glyphAtlasImage) {
glyphAtlasImage = std::move(*result.glyphAtlasImage);
}
Expand Down Expand Up @@ -227,17 +208,12 @@ Bucket* GeometryTile::getBucket(const Layer::Impl& layer) const {
}

void GeometryTile::commitFeatureIndex() {
// We commit our pending FeatureIndex and GeometryTileData when:
// 1) An `onPlacement` result has delivered us updated symbolBuckets since we received the pending data
// 2) A global placement has run, synchronizing the global CollisionIndex with the latest
// symbolBuckets (and thus with the latest FeatureIndex/GeometryTileData)
if (pendingFeatureIndex && pendingFeatureIndex->first) {
featureIndex = std::move(pendingFeatureIndex->second);
pendingFeatureIndex = nullopt;
}
if (pendingData && pendingData->first) {
data = std::move(pendingData->second);
pendingData = nullopt;
// We commit our pending FeatureIndex and GeometryTileData when a global placement has run,
// synchronizing the global CollisionIndex with the latest symbolBuckets/FeatureIndex/GeometryTileData
if (dataPendingCommit) {
data = std::move(dataPendingCommit->first);
featureIndex = std::move(dataPendingCommit->second);
dataPendingCommit = nullopt;
}
}

Expand Down
33 changes: 13 additions & 20 deletions src/mbgl/tile/geometry_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,24 @@ class GeometryTile : public Tile, public GlyphRequestor, ImageRequestor {
std::unordered_map<std::string, std::shared_ptr<Bucket>> nonSymbolBuckets;
std::unique_ptr<FeatureIndex> featureIndex;
std::unique_ptr<GeometryTileData> tileData;
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;
optional<AlphaImage> glyphAtlasImage;
optional<PremultipliedImage> iconAtlasImage;

LayoutResult(std::unordered_map<std::string, std::shared_ptr<Bucket>> nonSymbolBuckets_,
std::unique_ptr<FeatureIndex> featureIndex_,
std::unique_ptr<GeometryTileData> tileData_)
std::unique_ptr<GeometryTileData> tileData_,
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets_,
optional<AlphaImage> glyphAtlasImage_,
optional<PremultipliedImage> iconAtlasImage_)
: nonSymbolBuckets(std::move(nonSymbolBuckets_)),
featureIndex(std::move(featureIndex_)),
tileData(std::move(tileData_)) {}
};
void onLayout(LayoutResult, uint64_t correlationID);

class PlacementResult {
public:
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;
optional<AlphaImage> glyphAtlasImage;
optional<PremultipliedImage> iconAtlasImage;

PlacementResult(std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets_,
optional<AlphaImage> glyphAtlasImage_,
optional<PremultipliedImage> iconAtlasImage_)
: symbolBuckets(std::move(symbolBuckets_)),
tileData(std::move(tileData_)),
symbolBuckets(std::move(symbolBuckets_)),
glyphAtlasImage(std::move(glyphAtlasImage_)),
iconAtlasImage(std::move(iconAtlasImage_)) {}
};
void onPlacement(PlacementResult, uint64_t correlationID);
void onLayout(LayoutResult, uint64_t correlationID);

void onError(std::exception_ptr, uint64_t correlationID);

Expand Down Expand Up @@ -124,16 +118,15 @@ class GeometryTile : public Tile, public GlyphRequestor, ImageRequestor {
uint64_t correlationID = 0;

std::unordered_map<std::string, std::shared_ptr<Bucket>> nonSymbolBuckets;
std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;

optional<std::pair<std::unique_ptr<const GeometryTileData>, std::unique_ptr<FeatureIndex>>> dataPendingCommit;
std::unique_ptr<FeatureIndex> featureIndex;
optional<std::pair<bool,std::unique_ptr<FeatureIndex>>> pendingFeatureIndex;
std::unique_ptr<const GeometryTileData> data;
optional<std::pair<bool, std::unique_ptr<const GeometryTileData>>> pendingData;

optional<AlphaImage> glyphAtlasImage;
optional<PremultipliedImage> iconAtlasImage;

std::unordered_map<std::string, std::shared_ptr<Bucket>> symbolBuckets;

const MapMode mode;

bool showCollisionBoxes;
Expand Down
Loading

0 comments on commit e4dda35

Please sign in to comment.