summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-01 14:07:53 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-04 16:56:43 +0300
commitb1cbc2f2451d6eea9a8ad2adde1c8087ab581192 (patch)
tree2daf3ff070899e14c645df51241bc5ec4f57dee2 /src
parentd57083497509a1918fcccfb3005be2ba532e0266 (diff)
downloadqtlocation-mapboxgl-b1cbc2f2451d6eea9a8ad2adde1c8087ab581192.tar.gz
[core] Geometry tile keeps layout result as a shared pointer
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/tile/geometry_tile.cpp57
-rw-r--r--src/mbgl/tile/geometry_tile.hpp22
-rw-r--r--src/mbgl/tile/geometry_tile_worker.cpp4
3 files changed, 42 insertions, 41 deletions
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 1bc7646d1e..7fe6343889 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -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,
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index c206dd1157..0373161d10 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -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;
diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp
index ad9de2c07b..a69825d346 100644
--- a/src/mbgl/tile/geometry_tile_worker.cpp
+++ b/src/mbgl/tile/geometry_tile_worker.cpp
@@ -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