summaryrefslogtreecommitdiff
path: root/src/mbgl/tile
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-01 21:44:15 +0300
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2019-07-04 16:56:43 +0300
commit63dd17e2bbdb2c956789865c1d517305f860a175 (patch)
tree6888c96f50df988e55b5722dd870db98fdd877b5 /src/mbgl/tile
parentb1cbc2f2451d6eea9a8ad2adde1c8087ab581192 (diff)
downloadqtlocation-mapboxgl-63dd17e2bbdb2c956789865c1d517305f860a175.tar.gz
[core] Introduce TileRenderData
Remove rendering functionality from Tile implementations.
Diffstat (limited to 'src/mbgl/tile')
-rw-r--r--src/mbgl/tile/geometry_tile.cpp165
-rw-r--r--src/mbgl/tile/geometry_tile.hpp14
-rw-r--r--src/mbgl/tile/raster_dem_tile.cpp16
-rw-r--r--src/mbgl/tile/raster_dem_tile.hpp8
-rw-r--r--src/mbgl/tile/raster_tile.cpp15
-rw-r--r--src/mbgl/tile/raster_tile.hpp8
-rw-r--r--src/mbgl/tile/tile.hpp13
7 files changed, 131 insertions, 108 deletions
diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp
index 7fe6343889..0b9ba263f5 100644
--- a/src/mbgl/tile/geometry_tile.cpp
+++ b/src/mbgl/tile/geometry_tile.cpp
@@ -18,11 +18,98 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/actor/scheduler.hpp>
+#include <mbgl/renderer/tile_render_data.hpp>
namespace mbgl {
+LayerRenderData* GeometryTile::LayoutResult::getLayerRenderData(const style::Layer::Impl& layerImpl) {
+ auto it = layerRenderData.find(layerImpl.id);
+ if (it == layerRenderData.end()) {
+ return nullptr;
+ }
+ LayerRenderData& result = it->second;
+ if (result.layerProperties->baseImpl->getTypeInfo() != layerImpl.getTypeInfo()) {
+ // Layer data might be outdated, see issue #12432.
+ return nullptr;
+ }
+ return &result;
+}
+
+class GeometryTileRenderData final : public TileRenderData {
+public:
+ GeometryTileRenderData(
+ std::shared_ptr<GeometryTile::LayoutResult> layoutResult_,
+ std::shared_ptr<TileAtlasTextures> atlasTextures_,
+ ImageManager& imageManager_)
+ : TileRenderData(std::move(atlasTextures_))
+ , layoutResult(std::move(layoutResult_))
+ , imageManager(imageManager_) {
+ }
+
+private:
+ // TileRenderData overrides.
+ optional<ImagePosition> getPattern(const std::string&) const override;
+ const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const override;
+ Bucket* getBucket(const style::Layer::Impl&) const override;
+ void upload(gfx::UploadPass&) override;
+
+ std::shared_ptr<GeometryTile::LayoutResult> layoutResult;
+ ImageManager& imageManager;
+};
+
using namespace style;
+optional<ImagePosition> GeometryTileRenderData::getPattern(const std::string& pattern) const {
+ if (layoutResult) {
+ const auto& iconAtlas = layoutResult->iconAtlas;
+ auto it = iconAtlas.patternPositions.find(pattern);
+ if (it != iconAtlas.patternPositions.end()) {
+ return it->second;
+ }
+ }
+ return nullopt;
+}
+
+void GeometryTileRenderData::upload(gfx::UploadPass& uploadPass) {
+ if (!layoutResult) return;
+
+ auto uploadFn = [&] (Bucket& bucket) {
+ if (bucket.needsUpload()) {
+ bucket.upload(uploadPass);
+ }
+ };
+
+ for (auto& entry : layoutResult->layerRenderData) {
+ uploadFn(*entry.second.bucket);
+ }
+
+ assert(atlasTextures);
+
+ if (layoutResult->glyphAtlasImage) {
+ atlasTextures->glyph = uploadPass.createTexture(*layoutResult->glyphAtlasImage);
+ layoutResult->glyphAtlasImage = {};
+ }
+
+ if (layoutResult->iconAtlas.image.valid()) {
+ atlasTextures->icon = uploadPass.createTexture(layoutResult->iconAtlas.image);
+ layoutResult->iconAtlas.image = {};
+ }
+
+ if (atlasTextures->icon) {
+ layoutResult->iconAtlas.patchUpdatedImages(uploadPass, *atlasTextures->icon, imageManager);
+ }
+}
+
+Bucket* GeometryTileRenderData::getBucket(const Layer::Impl& layer) const {
+ const LayerRenderData* data = getLayerRenderData(layer);
+ return data ? data->bucket.get() : nullptr;
+}
+
+const LayerRenderData* GeometryTileRenderData::getLayerRenderData(const style::Layer::Impl& layerImpl) const {
+ return layoutResult ? layoutResult->getLayerRenderData(layerImpl) : nullptr;
+}
+
+
/*
Correlation between GeometryTile and GeometryTileWorker is safeguarded by two
correlation schemes:
@@ -88,6 +175,9 @@ void GeometryTile::setData(std::unique_ptr<const GeometryTileData> data_) {
worker.self().invoke(&GeometryTileWorker::setData, std::move(data_), correlationID);
}
+std::unique_ptr<TileRenderData> GeometryTile::createRenderData() {
+ return std::make_unique<GeometryTileRenderData>(layoutResult, atlasTextures, imageManager);
+}
void GeometryTile::setLayers(const std::vector<Immutable<LayerProperties>>& layers) {
// Mark the tile as pending again if it was complete before to prevent signaling a complete
@@ -131,6 +221,9 @@ void GeometryTile::onLayout(std::shared_ptr<LayoutResult> result, const uint64_t
}
layoutResult = std::move(result);
+ if (!atlasTextures) {
+ atlasTextures = std::make_shared<TileAtlasTextures>();
+ }
observer->onTileChanged(*this);
}
@@ -159,61 +252,12 @@ void GeometryTile::getImages(ImageRequestPair pair) {
imageManager.getImages(*this, std::move(pair));
}
-const optional<ImagePosition> GeometryTile::getPattern(const std::string& pattern) const {
- 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 : layoutResult->layerRenderData) {
- uploadFn(*entry.second.bucket);
- }
-
- if (layoutResult->glyphAtlasImage) {
- glyphAtlasTexture = uploadPass.createTexture(*layoutResult->glyphAtlasImage);
- layoutResult->glyphAtlasImage = {};
- }
-
- if (layoutResult->iconAtlas.image.valid()) {
- iconAtlasTexture = uploadPass.createTexture(layoutResult->iconAtlas.image);
- layoutResult->iconAtlas.image = {};
- }
-
- if (iconAtlasTexture) {
- layoutResult->iconAtlas.patchUpdatedImages(uploadPass, *iconAtlasTexture, imageManager);
- }
-}
-
-Bucket* GeometryTile::getBucket(const Layer::Impl& layer) const {
- const LayerRenderData* data = getLayerRenderData(layer);
- return data ? data->bucket.get() : nullptr;
-}
-
-const LayerRenderData* GeometryTile::getLayerRenderData(const style::Layer::Impl& layerImpl) const {
- auto* that = const_cast<GeometryTile*>(this);
- return that->getMutableLayerRenderData(layerImpl);
-}
-
bool GeometryTile::layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) {
- LayerRenderData* renderData = getMutableLayerRenderData(*layerProperties->baseImpl);
+ LayerRenderData* renderData = getLayerRenderData(*layerProperties->baseImpl);
if (!renderData) {
return false;
}
@@ -233,27 +277,16 @@ const GeometryTileData* GeometryTile::getData() const {
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;
- }
- LayerRenderData& result = it->second;
- if (result.layerProperties->baseImpl->getTypeInfo() != layerImpl.getTypeInfo()) {
- // Layer data might be outdated, see issue #12432.
- return nullptr;
- }
- return &result;
+LayerRenderData* GeometryTile::getLayerRenderData(const style::Layer::Impl& layerImpl) {
+ return layoutResult ? layoutResult->getLayerRenderData(layerImpl) : nullptr;
}
float GeometryTile::getQueryPadding(const std::vector<const RenderLayer*>& layers) {
float queryPadding = 0;
for (const RenderLayer* layer : layers) {
- auto bucket = getBucket(*layer->baseImpl);
- if (bucket && bucket->hasData()) {
- queryPadding = std::max(queryPadding, bucket->getQueryRadius(*layer));
+ const LayerRenderData* data = getLayerRenderData(*layer->baseImpl);
+ if (data && data->bucket && data->bucket->hasData()) {
+ queryPadding = std::max(queryPadding, data->bucket->getQueryRadius(*layer));
}
}
return queryPadding;
diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp
index 0373161d10..3d75dfc456 100644
--- a/src/mbgl/tile/geometry_tile.hpp
+++ b/src/mbgl/tile/geometry_tile.hpp
@@ -23,6 +23,7 @@ class SourceQueryOptions;
class TileParameters;
class GlyphAtlas;
class ImageAtlas;
+class TileAtlasTextures;
class GeometryTile : public Tile, public GlyphRequestor, public ImageRequestor {
public:
@@ -35,6 +36,7 @@ public:
void setError(std::exception_ptr);
void setData(std::unique_ptr<const GeometryTileData>);
+ std::unique_ptr<TileRenderData> createRenderData() override;
void setLayers(const std::vector<Immutable<style::LayerProperties>>&) override;
void setShowCollisionBoxes(const bool showCollisionBoxes) override;
@@ -44,9 +46,6 @@ public:
void getGlyphs(GlyphDependencies);
void getImages(ImageRequestPair);
- void upload(gfx::UploadPass&) override;
- Bucket* getBucket(const style::Layer::Impl&) const override;
- const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const override;
bool layerPropertiesUpdated(const Immutable<style::LayerProperties>&) override;
void queryRenderedFeatures(
@@ -72,6 +71,8 @@ public:
optional<AlphaImage> glyphAtlasImage;
ImageAtlas iconAtlas;
+ LayerRenderData* getLayerRenderData(const style::Layer::Impl&);
+
LayoutResult(std::unordered_map<std::string, LayerRenderData> renderData_,
std::unique_ptr<FeatureIndex> featureIndex_,
optional<AlphaImage> glyphAtlasImage_,
@@ -89,14 +90,13 @@ public:
void markRenderedIdeal() override;
void markRenderedPreviously() override;
void performedFadePlacement() override;
- const optional<ImagePosition> getPattern(const std::string& pattern) const;
const std::shared_ptr<FeatureIndex> getFeatureIndex() const;
const std::string sourceID;
protected:
const GeometryTileData* getData() const;
- LayerRenderData* getMutableLayerRenderData(const style::Layer::Impl&);
+ LayerRenderData* getLayerRenderData(const style::Layer::Impl&);
private:
void markObsolete();
@@ -114,6 +114,7 @@ private:
uint64_t correlationID = 0;
std::shared_ptr<LayoutResult> layoutResult;
+ std::shared_ptr<TileAtlasTextures> atlasTextures;
const MapMode mode;
@@ -127,9 +128,6 @@ private:
};
FadeState fadeState = FadeState::Loaded;
-public:
- optional<gfx::Texture> glyphAtlasTexture;
- optional<gfx::Texture> iconAtlasTexture;
};
} // namespace mbgl
diff --git a/src/mbgl/tile/raster_dem_tile.cpp b/src/mbgl/tile/raster_dem_tile.cpp
index cf70687ffe..c092809130 100644
--- a/src/mbgl/tile/raster_dem_tile.cpp
+++ b/src/mbgl/tile/raster_dem_tile.cpp
@@ -7,6 +7,7 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
+#include <mbgl/renderer/tile_render_data.hpp>
#include <mbgl/renderer/buckets/hillshade_bucket.hpp>
#include <mbgl/actor/scheduler.hpp>
@@ -35,6 +36,10 @@ RasterDEMTile::RasterDEMTile(const OverscaledTileID& id_,
RasterDEMTile::~RasterDEMTile() = default;
+std::unique_ptr<TileRenderData> RasterDEMTile::createRenderData() {
+ return std::make_unique<SharedBucketTileRenderData<HillshadeBucket>>(bucket);
+}
+
void RasterDEMTile::setError(std::exception_ptr err) {
loaded = true;
observer->onTileError(*this, err);
@@ -69,15 +74,8 @@ void RasterDEMTile::onError(std::exception_ptr err, const uint64_t resultCorrela
observer->onTileError(*this, err);
}
-void RasterDEMTile::upload(gfx::UploadPass& uploadPass) {
- if (bucket) {
- bucket->upload(uploadPass);
- }
-}
-
-
-Bucket* RasterDEMTile::getBucket(const style::Layer::Impl&) const {
- return bucket.get();
+bool RasterDEMTile::layerPropertiesUpdated(const Immutable<style::LayerProperties>&) {
+ return bool(bucket);
}
HillshadeBucket* RasterDEMTile::getBucket() const {
diff --git a/src/mbgl/tile/raster_dem_tile.hpp b/src/mbgl/tile/raster_dem_tile.hpp
index 165a5b9d2b..e6a6b6f9f5 100644
--- a/src/mbgl/tile/raster_dem_tile.hpp
+++ b/src/mbgl/tile/raster_dem_tile.hpp
@@ -59,21 +59,21 @@ namespace style {
class Layer;
} // namespace style
-class RasterDEMTile : public Tile {
+class RasterDEMTile final : public Tile {
public:
RasterDEMTile(const OverscaledTileID&,
const TileParameters&,
const Tileset&);
~RasterDEMTile() override;
+ std::unique_ptr<TileRenderData> createRenderData() override;
void setNecessity(TileNecessity) final;
void setError(std::exception_ptr);
void setMetadata(optional<Timestamp> modified, optional<Timestamp> expires);
void setData(std::shared_ptr<const std::string> data);
- void upload(gfx::UploadPass&) override;
- Bucket* getBucket(const style::Layer::Impl&) const override;
+ bool layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) override;
HillshadeBucket* getBucket() const;
void backfillBorder(const RasterDEMTile& borderTile, const DEMTileNeighbors mask);
@@ -98,7 +98,7 @@ private:
// Contains the Bucket object for the tile. Buckets are render
// objects and they get added by tile parsing operations.
- std::unique_ptr<HillshadeBucket> bucket;
+ std::shared_ptr<HillshadeBucket> bucket;
};
diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp
index 1d8e7f3b3c..50a0d700b8 100644
--- a/src/mbgl/tile/raster_tile.cpp
+++ b/src/mbgl/tile/raster_tile.cpp
@@ -7,6 +7,7 @@
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/renderer/tile_parameters.hpp>
+#include <mbgl/renderer/tile_render_data.hpp>
#include <mbgl/renderer/buckets/raster_bucket.hpp>
#include <mbgl/actor/scheduler.hpp>
@@ -24,6 +25,10 @@ RasterTile::RasterTile(const OverscaledTileID& id_,
RasterTile::~RasterTile() = default;
+std::unique_ptr<TileRenderData> RasterTile::createRenderData() {
+ return std::make_unique<SharedBucketTileRenderData<RasterBucket>>(bucket);
+}
+
void RasterTile::setError(std::exception_ptr err) {
loaded = true;
observer->onTileError(*this, err);
@@ -58,14 +63,8 @@ void RasterTile::onError(std::exception_ptr err, const uint64_t resultCorrelatio
observer->onTileError(*this, err);
}
-void RasterTile::upload(gfx::UploadPass& uploadPass) {
- if (bucket) {
- bucket->upload(uploadPass);
- }
-}
-
-Bucket* RasterTile::getBucket(const style::Layer::Impl&) const {
- return bucket.get();
+bool RasterTile::layerPropertiesUpdated(const Immutable<style::LayerProperties>&) {
+ return bool(bucket);
}
void RasterTile::setMask(TileMask&& mask) {
diff --git a/src/mbgl/tile/raster_tile.hpp b/src/mbgl/tile/raster_tile.hpp
index f62ddebf57..49ca3239ef 100644
--- a/src/mbgl/tile/raster_tile.hpp
+++ b/src/mbgl/tile/raster_tile.hpp
@@ -15,21 +15,21 @@ namespace style {
class Layer;
} // namespace style
-class RasterTile : public Tile {
+class RasterTile final : public Tile {
public:
RasterTile(const OverscaledTileID&,
const TileParameters&,
const Tileset&);
~RasterTile() override;
+ std::unique_ptr<TileRenderData> createRenderData() override;
void setNecessity(TileNecessity) final;
void setError(std::exception_ptr);
void setMetadata(optional<Timestamp> modified, optional<Timestamp> expires);
void setData(std::shared_ptr<const std::string> data);
- void upload(gfx::UploadPass&) override;
- Bucket* getBucket(const style::Layer::Impl&) const override;
+ bool layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) override;
void setMask(TileMask&&) override;
@@ -46,7 +46,7 @@ private:
// Contains the Bucket object for the tile. Buckets are render
// objects and they get added by tile parsing operations.
- std::unique_ptr<RasterBucket> bucket;
+ std::shared_ptr<RasterBucket> bucket;
};
} // namespace mbgl
diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp
index 17a16b4666..4ba8bc1160 100644
--- a/src/mbgl/tile/tile.hpp
+++ b/src/mbgl/tile/tile.hpp
@@ -24,6 +24,7 @@ class LayerRenderData;
class TransformState;
class TileObserver;
class RenderLayer;
+class TileRenderData;
class RenderedQueryOptions;
class SourceQueryOptions;
class CollisionIndex;
@@ -45,6 +46,8 @@ public:
Tile(Kind, OverscaledTileID);
virtual ~Tile();
+ virtual std::unique_ptr<TileRenderData> createRenderData() = 0;
+
void setObserver(TileObserver* observer);
virtual void setNecessity(TileNecessity) {}
@@ -52,12 +55,6 @@ public:
// Mark this tile as no longer needed and cancel any pending work.
virtual void cancel();
- virtual void upload(gfx::UploadPass&) = 0;
- virtual Bucket* getBucket(const style::Layer::Impl&) const = 0;
- virtual const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const {
- assert(false);
- return nullptr;
- }
// Notifies this tile of the updated layer properties.
//
// Tile implementation should update the contained layer
@@ -65,9 +62,7 @@ public:
//
// Returns `true` if the corresponding render layer data is present in this tile (and i.e. it
// was succesfully updated); returns `false` otherwise.
- virtual bool layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) {
- return bool(getBucket(*layerProperties->baseImpl));
- }
+ virtual bool layerPropertiesUpdated(const Immutable<style::LayerProperties>& layerProperties) = 0;
virtual void setShowCollisionBoxes(const bool) {}
virtual void setLayers(const std::vector<Immutable<style::LayerProperties>>&) {}
virtual void setMask(TileMask&&) {}