[core] Geometry tile keeps layout result as a shared pointer
This commit is contained in:
@@ -123,24 +123,15 @@ void GeometryTile::setShowCollisionBoxes(const bool showCollisionBoxes_) {
|
||||
}
|
||||
}
|
||||
|
||||
void GeometryTile::onLayout(LayoutResult result, const uint64_t resultCorrelationID) {
|
||||
void GeometryTile::onLayout(std::shared_ptr<LayoutResult> result, const uint64_t resultCorrelationID) {
|
||||
loaded = true;
|
||||
renderable = true;
|
||||
if (resultCorrelationID == correlationID) {
|
||||
pending = false;
|
||||
}
|
||||
|
||||
layerIdToLayerRenderData = std::move(result.renderData);
|
||||
|
||||
latestFeatureIndex = std::move(result.featureIndex);
|
||||
|
||||
if (result.glyphAtlasImage) {
|
||||
glyphAtlasImage = std::move(*result.glyphAtlasImage);
|
||||
}
|
||||
if (result.iconAtlas.image.valid()) {
|
||||
iconAtlas = std::move(result.iconAtlas);
|
||||
}
|
||||
|
||||
layoutResult = std::move(result);
|
||||
|
||||
observer->onTileChanged(*this);
|
||||
}
|
||||
|
||||
@@ -169,36 +160,45 @@ void GeometryTile::getImages(ImageRequestPair pair) {
|
||||
}
|
||||
|
||||
const optional<ImagePosition> GeometryTile::getPattern(const std::string& pattern) const {
|
||||
auto it = iconAtlas.patternPositions.find(pattern);
|
||||
if (it != iconAtlas.patternPositions.end()) {
|
||||
return it->second;
|
||||
if (layoutResult) {
|
||||
const auto& iconAtlas = layoutResult->iconAtlas;
|
||||
auto it = iconAtlas.patternPositions.find(pattern);
|
||||
if (it != iconAtlas.patternPositions.end()) {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
const std::shared_ptr<FeatureIndex> GeometryTile::getFeatureIndex() const {
|
||||
return layoutResult ? layoutResult->featureIndex : nullptr;
|
||||
}
|
||||
|
||||
void GeometryTile::upload(gfx::UploadPass& uploadPass) {
|
||||
if (!layoutResult) return;
|
||||
|
||||
auto uploadFn = [&] (Bucket& bucket) {
|
||||
if (bucket.needsUpload()) {
|
||||
bucket.upload(uploadPass);
|
||||
}
|
||||
};
|
||||
|
||||
for (auto& entry : layerIdToLayerRenderData) {
|
||||
for (auto& entry : layoutResult->layerRenderData) {
|
||||
uploadFn(*entry.second.bucket);
|
||||
}
|
||||
|
||||
if (glyphAtlasImage) {
|
||||
glyphAtlasTexture = uploadPass.createTexture(*glyphAtlasImage);
|
||||
glyphAtlasImage = {};
|
||||
if (layoutResult->glyphAtlasImage) {
|
||||
glyphAtlasTexture = uploadPass.createTexture(*layoutResult->glyphAtlasImage);
|
||||
layoutResult->glyphAtlasImage = {};
|
||||
}
|
||||
|
||||
if (iconAtlas.image.valid()) {
|
||||
iconAtlasTexture = uploadPass.createTexture(iconAtlas.image);
|
||||
iconAtlas.image = {};
|
||||
if (layoutResult->iconAtlas.image.valid()) {
|
||||
iconAtlasTexture = uploadPass.createTexture(layoutResult->iconAtlas.image);
|
||||
layoutResult->iconAtlas.image = {};
|
||||
}
|
||||
|
||||
if (iconAtlasTexture) {
|
||||
iconAtlas.patchUpdatedImages(uploadPass, *iconAtlasTexture, imageManager);
|
||||
layoutResult->iconAtlas.patchUpdatedImages(uploadPass, *iconAtlasTexture, imageManager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,16 @@ bool GeometryTile::layerPropertiesUpdated(const Immutable<style::LayerProperties
|
||||
return true;
|
||||
}
|
||||
|
||||
const GeometryTileData* GeometryTile::getData() const {
|
||||
if (!layoutResult || !layoutResult->featureIndex) {
|
||||
return nullptr;
|
||||
}
|
||||
return layoutResult->featureIndex->getData();
|
||||
}
|
||||
|
||||
LayerRenderData* GeometryTile::getMutableLayerRenderData(const style::Layer::Impl& layerImpl) {
|
||||
if (!layoutResult) return nullptr;
|
||||
auto& layerIdToLayerRenderData = layoutResult->layerRenderData;
|
||||
auto it = layerIdToLayerRenderData.find(layerImpl.id);
|
||||
if (it == layerIdToLayerRenderData.end()) {
|
||||
return nullptr;
|
||||
@@ -266,7 +275,7 @@ void GeometryTile::queryRenderedFeatures(
|
||||
transformState.matrixFor(posMatrix, id.toUnwrapped());
|
||||
matrix::multiply(posMatrix, projMatrix, posMatrix);
|
||||
|
||||
latestFeatureIndex->query(result,
|
||||
layoutResult->featureIndex->query(result,
|
||||
queryGeometry,
|
||||
transformState,
|
||||
posMatrix,
|
||||
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
|
||||
class LayoutResult {
|
||||
public:
|
||||
std::unordered_map<std::string, LayerRenderData> renderData;
|
||||
std::unique_ptr<FeatureIndex> featureIndex;
|
||||
std::unordered_map<std::string, LayerRenderData> layerRenderData;
|
||||
std::shared_ptr<FeatureIndex> featureIndex;
|
||||
optional<AlphaImage> glyphAtlasImage;
|
||||
ImageAtlas iconAtlas;
|
||||
|
||||
@@ -76,12 +76,12 @@ public:
|
||||
std::unique_ptr<FeatureIndex> featureIndex_,
|
||||
optional<AlphaImage> glyphAtlasImage_,
|
||||
ImageAtlas iconAtlas_)
|
||||
: renderData(std::move(renderData_)),
|
||||
: layerRenderData(std::move(renderData_)),
|
||||
featureIndex(std::move(featureIndex_)),
|
||||
glyphAtlasImage(std::move(glyphAtlasImage_)),
|
||||
iconAtlas(std::move(iconAtlas_)) {}
|
||||
};
|
||||
void onLayout(LayoutResult, uint64_t correlationID);
|
||||
void onLayout(std::shared_ptr<LayoutResult>, uint64_t correlationID);
|
||||
|
||||
void onError(std::exception_ptr, uint64_t correlationID);
|
||||
|
||||
@@ -90,15 +90,12 @@ public:
|
||||
void markRenderedPreviously() override;
|
||||
void performedFadePlacement() override;
|
||||
const optional<ImagePosition> getPattern(const std::string& pattern) const;
|
||||
const std::shared_ptr<FeatureIndex> getFeatureIndex() const { return latestFeatureIndex; }
|
||||
const std::shared_ptr<FeatureIndex> getFeatureIndex() const;
|
||||
|
||||
const std::string sourceID;
|
||||
|
||||
protected:
|
||||
const GeometryTileData* getData() {
|
||||
return latestFeatureIndex ? latestFeatureIndex->getData() : nullptr;
|
||||
}
|
||||
|
||||
const GeometryTileData* getData() const;
|
||||
LayerRenderData* getMutableLayerRenderData(const style::Layer::Impl&);
|
||||
|
||||
private:
|
||||
@@ -116,12 +113,7 @@ private:
|
||||
|
||||
uint64_t correlationID = 0;
|
||||
|
||||
std::unordered_map<std::string, LayerRenderData> layerIdToLayerRenderData;
|
||||
|
||||
std::shared_ptr<FeatureIndex> latestFeatureIndex;
|
||||
|
||||
optional<AlphaImage> glyphAtlasImage;
|
||||
ImageAtlas iconAtlas;
|
||||
std::shared_ptr<LayoutResult> layoutResult;
|
||||
|
||||
const MapMode mode;
|
||||
|
||||
|
||||
@@ -460,12 +460,12 @@ void GeometryTileWorker::finalizeLayout() {
|
||||
" Canonical: " << static_cast<int>(id.canonical.z) << "/" << id.canonical.x << "/" << id.canonical.y <<
|
||||
" Time");
|
||||
|
||||
parent.invoke(&GeometryTile::onLayout, GeometryTile::LayoutResult {
|
||||
parent.invoke(&GeometryTile::onLayout, std::make_shared<GeometryTile::LayoutResult>(
|
||||
std::move(renderData),
|
||||
std::move(featureIndex),
|
||||
std::move(glyphAtlasImage),
|
||||
std::move(iconAtlas)
|
||||
}, correlationID);
|
||||
), correlationID);
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
Reference in New Issue
Block a user