From 361982fef83a145769da5c04d1c19731df89921c Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Thu, 22 Nov 2018 15:37:09 +0200 Subject: [core][Android][Darwin] LayerManager creates RenderLayer instances `LayerManager` is now responsible for `RenderLayer` instances creation, so that there is a single entry point for creating of objects, which correspond to a certain layer type. The `LayerType type` field is dropped from `Layer::Impl`. --- src/mbgl/annotation/fill_annotation_impl.cpp | 1 - src/mbgl/annotation/line_annotation_impl.cpp | 1 - src/mbgl/renderer/group_by_layout.cpp | 2 +- .../renderer/layers/render_background_layer.cpp | 2 +- src/mbgl/renderer/layers/render_circle_layer.cpp | 2 +- src/mbgl/renderer/layers/render_custom_layer.cpp | 2 +- .../layers/render_fill_extrusion_layer.cpp | 2 +- src/mbgl/renderer/layers/render_fill_layer.cpp | 2 +- src/mbgl/renderer/layers/render_heatmap_layer.cpp | 2 +- .../renderer/layers/render_hillshade_layer.cpp | 2 +- src/mbgl/renderer/layers/render_line_layer.cpp | 2 +- src/mbgl/renderer/layers/render_raster_layer.cpp | 2 +- src/mbgl/renderer/layers/render_symbol_layer.cpp | 2 +- src/mbgl/renderer/render_layer.cpp | 46 ++-------------------- src/mbgl/renderer/render_layer.hpp | 8 +--- src/mbgl/renderer/renderer_impl.cpp | 2 +- src/mbgl/renderer/style_diff.cpp | 3 +- src/mbgl/style/layer.cpp | 38 +++++++++++++----- src/mbgl/style/layer_impl.cpp | 5 +-- src/mbgl/style/layer_impl.hpp | 11 ++++-- src/mbgl/style/layers/background_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/background_layer_impl.hpp | 3 +- src/mbgl/style/layers/circle_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/circle_layer_impl.cpp | 2 +- src/mbgl/style/layers/circle_layer_impl.hpp | 3 +- src/mbgl/style/layers/custom_layer.cpp | 20 ++++++---- src/mbgl/style/layers/custom_layer_impl.cpp | 2 +- src/mbgl/style/layers/custom_layer_impl.hpp | 3 +- src/mbgl/style/layers/fill_extrusion_layer.cpp | 36 +++++++++-------- .../style/layers/fill_extrusion_layer_impl.cpp | 2 +- .../style/layers/fill_extrusion_layer_impl.hpp | 3 +- src/mbgl/style/layers/fill_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/fill_layer_impl.cpp | 2 +- src/mbgl/style/layers/fill_layer_impl.hpp | 3 +- src/mbgl/style/layers/heatmap_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/heatmap_layer_impl.cpp | 2 +- src/mbgl/style/layers/heatmap_layer_impl.hpp | 3 +- src/mbgl/style/layers/hillshade_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/hillshade_layer_impl.hpp | 3 +- src/mbgl/style/layers/layer.cpp.ejs | 40 ++++++++++--------- src/mbgl/style/layers/line_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/line_layer_impl.cpp | 2 +- src/mbgl/style/layers/line_layer_impl.hpp | 3 +- src/mbgl/style/layers/raster_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/raster_layer_impl.hpp | 3 +- src/mbgl/style/layers/symbol_layer.cpp | 36 +++++++++-------- src/mbgl/style/layers/symbol_layer_impl.cpp | 2 +- src/mbgl/style/layers/symbol_layer_impl.hpp | 3 +- src/mbgl/tile/geometry_tile.cpp | 3 +- src/mbgl/tile/geometry_tile_worker.cpp | 2 +- 50 files changed, 298 insertions(+), 272 deletions(-) (limited to 'src') diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp index 7ac1932f32..59b8133cf7 100644 --- a/src/mbgl/annotation/fill_annotation_impl.cpp +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -21,7 +21,6 @@ void FillAnnotationImpl::updateStyle(Style::Impl& style) const { layer = style.addLayer(std::move(newLayer), AnnotationManager::PointLayerID); } - assert(layer->getType() == LayerType::Fill); auto* fillLayer = static_cast(layer); fillLayer->setFillOpacity(annotation.opacity); fillLayer->setFillColor(annotation.color); diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp index b4dc10049f..315a36954b 100644 --- a/src/mbgl/annotation/line_annotation_impl.cpp +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -22,7 +22,6 @@ void LineAnnotationImpl::updateStyle(Style::Impl& style) const { layer = style.addLayer(std::move(newLayer), AnnotationManager::PointLayerID); } - assert(layer->getType() == LayerType::Line); LineLayer* lineLayer = static_cast(layer); lineLayer->setLineOpacity(annotation.opacity); lineLayer->setLineWidth(annotation.width); diff --git a/src/mbgl/renderer/group_by_layout.cpp b/src/mbgl/renderer/group_by_layout.cpp index 3b02727ff8..41a895902c 100644 --- a/src/mbgl/renderer/group_by_layout.cpp +++ b/src/mbgl/renderer/group_by_layout.cpp @@ -18,7 +18,7 @@ std::string layoutKey(const RenderLayer& layer) { rapidjson::Writer writer(s); writer.StartArray(); - writer.Uint(static_cast(layer.type)); + writer.Uint64(reinterpret_cast(layer.baseImpl->getTypeInfo())); writer.String(layer.baseImpl->source); writer.String(layer.baseImpl->sourceLayer); writer.Double(layer.baseImpl->minZoom); diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index 3e510ef352..d7bf0dc6bd 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -14,7 +14,7 @@ namespace mbgl { using namespace style; RenderBackgroundLayer::RenderBackgroundLayer(Immutable _impl) - : RenderLayer(style::LayerType::Background, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_circle_layer.cpp b/src/mbgl/renderer/layers/render_circle_layer.cpp index 46db06416d..b984c596d3 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.cpp +++ b/src/mbgl/renderer/layers/render_circle_layer.cpp @@ -15,7 +15,7 @@ namespace mbgl { using namespace style; RenderCircleLayer::RenderCircleLayer(Immutable _impl) - : RenderLayer(style::LayerType::Circle, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_custom_layer.cpp b/src/mbgl/renderer/layers/render_custom_layer.cpp index e80ceda6c7..9e65830faf 100644 --- a/src/mbgl/renderer/layers/render_custom_layer.cpp +++ b/src/mbgl/renderer/layers/render_custom_layer.cpp @@ -13,7 +13,7 @@ namespace mbgl { using namespace style; RenderCustomLayer::RenderCustomLayer(Immutable _impl) - : RenderLayer(LayerType::Custom, _impl), host(_impl->host) { + : RenderLayer(std::move(_impl)), host(impl().host) { assert(BackendScope::exists()); host->initialize(); } diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 8f1b961d1a..91d58bf8d6 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -19,7 +19,7 @@ namespace mbgl { using namespace style; RenderFillExtrusionLayer::RenderFillExtrusionLayer(Immutable _impl) - : RenderLayer(style::LayerType::FillExtrusion, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index 83be3ccd57..391c2d5b0f 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -17,7 +17,7 @@ namespace mbgl { using namespace style; RenderFillLayer::RenderFillLayer(Immutable _impl) - : RenderLayer(style::LayerType::Fill, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 4e5e890358..1842cdac93 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -17,7 +17,7 @@ namespace mbgl { using namespace style; RenderHeatmapLayer::RenderHeatmapLayer(Immutable _impl) - : RenderLayer(style::LayerType::Heatmap, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()), colorRamp({256, 1}) { } diff --git a/src/mbgl/renderer/layers/render_hillshade_layer.cpp b/src/mbgl/renderer/layers/render_hillshade_layer.cpp index 835cb3f9f9..ba7e782f16 100644 --- a/src/mbgl/renderer/layers/render_hillshade_layer.cpp +++ b/src/mbgl/renderer/layers/render_hillshade_layer.cpp @@ -16,7 +16,7 @@ namespace mbgl { using namespace style; RenderHillshadeLayer::RenderHillshadeLayer(Immutable _impl) - : RenderLayer(style::LayerType::Hillshade, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 94081b5f09..fcdbc0b47a 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -18,7 +18,7 @@ namespace mbgl { using namespace style; RenderLineLayer::RenderLineLayer(Immutable _impl) - : RenderLayer(style::LayerType::Line, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()), colorRamp({256, 1}) { } diff --git a/src/mbgl/renderer/layers/render_raster_layer.cpp b/src/mbgl/renderer/layers/render_raster_layer.cpp index 8e0651b65b..e0a7e427ad 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.cpp +++ b/src/mbgl/renderer/layers/render_raster_layer.cpp @@ -14,7 +14,7 @@ namespace mbgl { using namespace style; RenderRasterLayer::RenderRasterLayer(Immutable _impl) - : RenderLayer(style::LayerType::Raster, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 2b3a7195c5..11ffd74b10 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -23,7 +23,7 @@ namespace mbgl { using namespace style; RenderSymbolLayer::RenderSymbolLayer(Immutable _impl) - : RenderLayer(style::LayerType::Symbol, _impl), + : RenderLayer(std::move(_impl)), unevaluated(impl().paint.untransitioned()) { } diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index 3e9a7caf24..033df02282 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -1,14 +1,4 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -19,42 +9,12 @@ namespace mbgl { using namespace style; -std::unique_ptr RenderLayer::create(Immutable impl) { - switch (impl->type) { - case LayerType::Fill: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Line: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Circle: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Symbol: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Raster: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Hillshade: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Background: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Custom: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::FillExtrusion: - return std::make_unique(staticImmutableCast(impl)); - case LayerType::Heatmap: - return std::make_unique(staticImmutableCast(impl)); - } - - // Not reachable, but placate GCC. - assert(false); - return nullptr; -} - -RenderLayer::RenderLayer(style::LayerType type_, Immutable baseImpl_) - : type(type_), - baseImpl(baseImpl_) { +RenderLayer::RenderLayer(Immutable baseImpl_) + : baseImpl(std::move(baseImpl_)) { } void RenderLayer::setImpl(Immutable impl) { - baseImpl = impl; + baseImpl = std::move(impl); } const std::string& RenderLayer::getID() const { diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index a92d8f5aff..4e0e1913b6 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -23,13 +23,9 @@ class TransformState; class RenderLayer { protected: - RenderLayer(style::LayerType, Immutable); - - const style::LayerType type; + RenderLayer(Immutable); public: - static std::unique_ptr create(Immutable); - virtual ~RenderLayer() = default; // Begin transitions for any properties that have changed since the last frame. @@ -93,8 +89,6 @@ public: // TODO: Only for background layers. virtual optional getSolidBackground() const; - friend std::string layoutKey(const RenderLayer&); - protected: // Checks whether the current hardware can render this layer. If it can't, we'll show a warning // in the console to inform the developer. diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 32fcd57332..c4c4851345 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -164,7 +164,7 @@ void Renderer::Impl::render(const UpdateParameters& updateParameters) { // Create render layers for newly added layers. for (const auto& entry : layerDiff.added) { - renderLayers.emplace(entry.first, RenderLayer::create(entry.second)); + renderLayers.emplace(entry.first, LayerManager::get()->createRenderLayer(entry.second)); } // Update render layers for changed layers. diff --git a/src/mbgl/renderer/style_diff.cpp b/src/mbgl/renderer/style_diff.cpp index 0017280310..270c4483cd 100644 --- a/src/mbgl/renderer/style_diff.cpp +++ b/src/mbgl/renderer/style_diff.cpp @@ -62,8 +62,7 @@ SourceDifference diffSources(const Immutable>& a, LayerDifference diffLayers(const Immutable>& a, const Immutable>& b) { return diff(a, b, [] (const ImmutableLayer& lhs, const ImmutableLayer& rhs) { - return std::tie(lhs->id, lhs->type) - == std::tie(rhs->id, rhs->type); + return (lhs->id == rhs->id) && (lhs->getTypeInfo() == rhs->getTypeInfo()); }); } diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index 56b825760b..abe6444701 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -5,6 +5,8 @@ #include #include +#include + namespace mbgl { namespace style { @@ -17,10 +19,6 @@ Layer::Layer(Immutable impl) Layer::~Layer() = default; -LayerType Layer::getType() const { - return baseImpl->type; -} - std::string Layer::getID() const { return baseImpl->id; } @@ -111,7 +109,9 @@ const LayerTypeInfo* Layer::getTypeInfo() const noexcept { return baseImpl->getTypeInfo(); } -optional LayerFactory::getSource(const conversion::Convertible& value) const noexcept { +} // namespace style + +optional LayerFactory::getSource(const style::conversion::Convertible& value) const noexcept { auto sourceValue = objectMember(value, "source"); if (!sourceValue) { return nullopt; @@ -125,7 +125,7 @@ optional LayerFactory::getSource(const conversion::Convertible& val return source; } -bool LayerFactory::initSourceLayerAndFilter(Layer* layer, const conversion::Convertible& value) const noexcept { +bool LayerFactory::initSourceLayerAndFilter(style::Layer* layer, const style::conversion::Convertible& value) const noexcept { auto sourceLayerValue = objectMember(value, "source-layer"); if (sourceLayerValue) { optional sourceLayer = toString(*sourceLayerValue); @@ -137,8 +137,8 @@ bool LayerFactory::initSourceLayerAndFilter(Layer* layer, const conversion::Conv auto filterValue = objectMember(value, "filter"); if (filterValue) { - conversion::Error error; - optional filter = conversion::convert(*filterValue, error); + style::conversion::Error error; + optional filter = style::conversion::convert(*filterValue, error); if (!filter) { return false; } @@ -148,5 +148,25 @@ bool LayerFactory::initSourceLayerAndFilter(Layer* layer, const conversion::Conv return true; } -} // namespace style +std::unique_ptr LayerManager::createLayer( + const std::string& type, const std::string& id, + const style::conversion::Convertible& value, style::conversion::Error& error) noexcept { + if (LayerFactory* factory = getFactory(type)) { + auto layer = factory->createLayer(id, value); + if (!layer) { + error.message = "Error parsing a layer of type: " + type; + } + return layer; + } + error.message = "Unsupported layer type: " + type; + return nullptr; +} + +std::unique_ptr LayerManager::createRenderLayer(Immutable impl) noexcept { + LayerFactory* factory = getFactory(impl->getTypeInfo()); + assert(factory); + return factory->createRenderLayer(std::move(impl)); +} + + } // namespace mbgl diff --git a/src/mbgl/style/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp index c6a248de90..b6ab145012 100644 --- a/src/mbgl/style/layer_impl.cpp +++ b/src/mbgl/style/layer_impl.cpp @@ -3,9 +3,8 @@ namespace mbgl { namespace style { -Layer::Impl::Impl(LayerType type_, std::string layerID, std::string sourceID) - : type(type_), - id(std::move(layerID)), +Layer::Impl::Impl(std::string layerID, std::string sourceID) + : id(std::move(layerID)), source(std::move(sourceID)) { } diff --git a/src/mbgl/style/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp index 948bbab619..c64173600e 100644 --- a/src/mbgl/style/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -29,7 +29,7 @@ namespace style { */ class Layer::Impl { public: - Impl(LayerType, std::string layerID, std::string sourceID); + Impl(std::string layerID, std::string sourceID); virtual ~Impl() = default; Impl& operator=(const Impl&) = delete; @@ -47,8 +47,6 @@ public: // Populates the given \a fontStack with fonts being used by the layer. virtual void populateFontStack(std::set& fontStack) const; - // Note: LayerType is deprecated, do not use it. - const LayerType type; std::string id; std::string source; std::string sourceLayer; @@ -61,5 +59,10 @@ protected: Impl(const Impl&) = default; }; +// To be used in the inherited classes. +#define DECLARE_LAYER_TYPE_INFO \ +const LayerTypeInfo* getTypeInfo() const noexcept final { return staticTypeInfo(); } \ +static const LayerTypeInfo* staticTypeInfo() noexcept + } // namespace style -} // namespace mbgl +} // namespace mbgl \ No newline at end of file diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 1342afd7b1..8beafb0278 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoBackground + +// static +const LayerTypeInfo* BackgroundLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"background", LayerTypeInfo::Source::NotRequired, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::NotRequired, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + BackgroundLayer::BackgroundLayer(const std::string& layerID) - : Layer(makeMutable(LayerType::Background, layerID, std::string())) { + : Layer(makeMutable(layerID, std::string())) { } BackgroundLayer::BackgroundLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr BackgroundLayer::cloneRef(const std::string& id_) const { void BackgroundLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* BackgroundLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoBackground; -} - // Layout properties @@ -284,18 +286,20 @@ Mutable BackgroundLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -BackgroundLayerFactory::BackgroundLayerFactory() = default; - -BackgroundLayerFactory::~BackgroundLayerFactory() = default; +} // namespace style -const LayerTypeInfo* BackgroundLayerFactory::getTypeInfo() const noexcept { - return &typeInfoBackground; +const style::LayerTypeInfo* BackgroundLayerFactory::getTypeInfo() const noexcept { + return style::BackgroundLayer::Impl::staticTypeInfo(); } -std::unique_ptr BackgroundLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr BackgroundLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { (void)value; - return std::unique_ptr(new BackgroundLayer(id)); + return std::unique_ptr(new style::BackgroundLayer(id)); +} + +std::unique_ptr BackgroundLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); } -} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp index 5407c4c065..0c68610c62 100644 --- a/src/mbgl/style/layers/background_layer_impl.hpp +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -13,9 +13,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; BackgroundPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index c04d40083a..1e6200e4d2 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoCircle + +// static +const LayerTypeInfo* CircleLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"circle", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::NotRequired, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + CircleLayer::CircleLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Circle, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } CircleLayer::CircleLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr CircleLayer::cloneRef(const std::string& id_) const { void CircleLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* CircleLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoCircle; -} - // Layout properties @@ -701,26 +703,28 @@ Mutable CircleLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -CircleLayerFactory::CircleLayerFactory() = default; - -CircleLayerFactory::~CircleLayerFactory() = default; +} // namespace style -const LayerTypeInfo* CircleLayerFactory::getTypeInfo() const noexcept { - return &typeInfoCircle; +const style::LayerTypeInfo* CircleLayerFactory::getTypeInfo() const noexcept { + return style::CircleLayer::Impl::staticTypeInfo(); } -std::unique_ptr CircleLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr CircleLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new CircleLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::CircleLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr CircleLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp index 358598e09c..bf0688ac8b 100644 --- a/src/mbgl/style/layers/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { bool CircleLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::Circle); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp index 5cd56b630c..9b3ce48706 100644 --- a/src/mbgl/style/layers/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -13,9 +13,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; CirclePaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp index bff55a7a52..abea5d2d31 100644 --- a/src/mbgl/style/layers/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace mbgl { namespace style { @@ -48,22 +50,24 @@ Mutable CustomLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -const LayerTypeInfo* CustomLayer::Impl::getTypeInfo() const noexcept { +// static +const LayerTypeInfo* CustomLayer::Impl::staticTypeInfo() noexcept { return &typeInfoCustom; } -CustomLayerFactory::CustomLayerFactory() = default; - -CustomLayerFactory::~CustomLayerFactory() = default; +} // namespace style -const LayerTypeInfo* CustomLayerFactory::getTypeInfo() const noexcept { - return &typeInfoCustom; +const style::LayerTypeInfo* CustomLayerFactory::getTypeInfo() const noexcept { + return &style::typeInfoCustom; } -std::unique_ptr CustomLayerFactory::createLayer(const std::string&, const conversion::Convertible&) { +std::unique_ptr CustomLayerFactory::createLayer(const std::string&, const style::conversion::Convertible&) noexcept { assert(false); return nullptr; } -} // namespace style +std::unique_ptr CustomLayerFactory::createRenderLayer(Immutable impl) noexcept { + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp index 05c41623c4..f82cb1ea2c 100644 --- a/src/mbgl/style/layers/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -5,7 +5,7 @@ namespace style { CustomLayer::Impl::Impl(const std::string& id_, std::unique_ptr host_) - : Layer::Impl(LayerType::Custom, id_, std::string()) { + : Layer::Impl(id_, std::string()) { host = std::move(host_); } diff --git a/src/mbgl/style/layers/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp index 6c7a9078a5..1ebf1b53f1 100644 --- a/src/mbgl/style/layers/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -18,9 +18,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; std::shared_ptr host; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index 9a5cc02df4..7ca9d6ed6f 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoFillExtrusion + +// static +const LayerTypeInfo* FillExtrusionLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"fill-extrusion", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::Required, LayerTypeInfo::Layout::Required, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + FillExtrusionLayer::FillExtrusionLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::FillExtrusion, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } FillExtrusionLayer::FillExtrusionLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr FillExtrusionLayer::cloneRef(const std::string& id_) cons void FillExtrusionLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* FillExtrusionLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoFillExtrusion; -} - // Layout properties @@ -503,26 +505,28 @@ Mutable FillExtrusionLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -FillExtrusionLayerFactory::FillExtrusionLayerFactory() = default; - -FillExtrusionLayerFactory::~FillExtrusionLayerFactory() = default; +} // namespace style -const LayerTypeInfo* FillExtrusionLayerFactory::getTypeInfo() const noexcept { - return &typeInfoFillExtrusion; +const style::LayerTypeInfo* FillExtrusionLayerFactory::getTypeInfo() const noexcept { + return style::FillExtrusionLayer::Impl::staticTypeInfo(); } -std::unique_ptr FillExtrusionLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr FillExtrusionLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new FillExtrusionLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::FillExtrusionLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr FillExtrusionLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp index 357ea3e973..18eea1f7fc 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { bool FillExtrusionLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::FillExtrusion); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp index 6758320c2b..dcb6de1d8c 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_impl.hpp @@ -13,10 +13,11 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; Properties<>::Unevaluated layout; FillExtrusionPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 17a5eaf3b1..480fc597dd 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoFill + +// static +const LayerTypeInfo* FillLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"fill", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::Required, LayerTypeInfo::Clipping::Required }; -} // namespace + return &typeInfo; +} + FillLayer::FillLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Fill, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } FillLayer::FillLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr FillLayer::cloneRef(const std::string& id_) const { void FillLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* FillLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoFill; -} - // Layout properties @@ -503,26 +505,28 @@ Mutable FillLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -FillLayerFactory::FillLayerFactory() = default; - -FillLayerFactory::~FillLayerFactory() = default; +} // namespace style -const LayerTypeInfo* FillLayerFactory::getTypeInfo() const noexcept { - return &typeInfoFill; +const style::LayerTypeInfo* FillLayerFactory::getTypeInfo() const noexcept { + return style::FillLayer::Impl::staticTypeInfo(); } -std::unique_ptr FillLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr FillLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new FillLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::FillLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr FillLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp index a8ba1b693b..4df32e02fa 100644 --- a/src/mbgl/style/layers/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { bool FillLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::Fill); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp index 5b0592d062..92f3c97284 100644 --- a/src/mbgl/style/layers/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -13,10 +13,11 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; Properties<>::Unevaluated layout; FillPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index 113f158f51..92477615b2 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoHeatmap + +// static +const LayerTypeInfo* HeatmapLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"heatmap", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::Required, LayerTypeInfo::Layout::NotRequired, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + HeatmapLayer::HeatmapLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Heatmap, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } HeatmapLayer::HeatmapLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr HeatmapLayer::cloneRef(const std::string& id_) const { void HeatmapLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* HeatmapLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoHeatmap; -} - // Layout properties @@ -388,26 +390,28 @@ Mutable HeatmapLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -HeatmapLayerFactory::HeatmapLayerFactory() = default; - -HeatmapLayerFactory::~HeatmapLayerFactory() = default; +} // namespace style -const LayerTypeInfo* HeatmapLayerFactory::getTypeInfo() const noexcept { - return &typeInfoHeatmap; +const style::LayerTypeInfo* HeatmapLayerFactory::getTypeInfo() const noexcept { + return style::HeatmapLayer::Impl::staticTypeInfo(); } -std::unique_ptr HeatmapLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr HeatmapLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new HeatmapLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::HeatmapLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr HeatmapLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/heatmap_layer_impl.cpp b/src/mbgl/style/layers/heatmap_layer_impl.cpp index 8fd0cf72b2..dd5baaeb44 100644 --- a/src/mbgl/style/layers/heatmap_layer_impl.cpp +++ b/src/mbgl/style/layers/heatmap_layer_impl.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { bool HeatmapLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::Heatmap); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/heatmap_layer_impl.hpp b/src/mbgl/style/layers/heatmap_layer_impl.hpp index 7645fa0cc1..3022293860 100644 --- a/src/mbgl/style/layers/heatmap_layer_impl.hpp +++ b/src/mbgl/style/layers/heatmap_layer_impl.hpp @@ -13,9 +13,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; HeatmapPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 81d2c32f6f..d914d0cdea 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoHillshade + +// static +const LayerTypeInfo* HillshadeLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"hillshade", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::Required, LayerTypeInfo::Layout::NotRequired, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + HillshadeLayer::HillshadeLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Hillshade, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } HillshadeLayer::HillshadeLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr HillshadeLayer::cloneRef(const std::string& id_) const { void HillshadeLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* HillshadeLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoHillshade; -} - // Layout properties @@ -435,23 +437,25 @@ Mutable HillshadeLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -HillshadeLayerFactory::HillshadeLayerFactory() = default; - -HillshadeLayerFactory::~HillshadeLayerFactory() = default; +} // namespace style -const LayerTypeInfo* HillshadeLayerFactory::getTypeInfo() const noexcept { - return &typeInfoHillshade; +const style::LayerTypeInfo* HillshadeLayerFactory::getTypeInfo() const noexcept { + return style::HillshadeLayer::Impl::staticTypeInfo(); } -std::unique_ptr HillshadeLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr HillshadeLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new HillshadeLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::HillshadeLayer(id, *source)); return layer; } -} // namespace style +std::unique_ptr HillshadeLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/hillshade_layer_impl.hpp b/src/mbgl/style/layers/hillshade_layer_impl.hpp index 520b18cc84..86409fa542 100644 --- a/src/mbgl/style/layers/hillshade_layer_impl.hpp +++ b/src/mbgl/style/layers/hillshade_layer_impl.hpp @@ -13,9 +13,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; HillshadePaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 0971e1af5b..d03e41da76 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -16,10 +16,12 @@ #include #include +#include _layer.hpp> + namespace mbgl { namespace style { -namespace {<% +<% let layerCapabilities = {}; let defaults = { caps: { 'Source': 'NotRequired', 'Pass3D': 'NotRequired', @@ -60,19 +62,23 @@ layerCapabilities['line'] = layerCapabilities['fill']; layerCapabilities['heatmap'] = layerCapabilities['hillshade']; layerCapabilities['raster'] = layerCapabilities['circle']; %> - const LayerTypeInfo typeInfo<%- `${camelize(type)}`%> +// static +const LayerTypeInfo* <%- camelize(type) %>Layer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"<%- type %>", <%-`${layerCapabilities[type].map(cap => `LayerTypeInfo::${cap}`).join(',\n ')}` %> }; -} // namespace + return &typeInfo; +} + <% if (type === 'background') { -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID) - : Layer(makeMutable(LayerType::<%- camelize(type) %>, layerID, std::string())) { + : Layer(makeMutable(layerID, std::string())) { } <% } else { -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::<%- camelize(type) %>, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } <% } -%> @@ -106,10 +112,6 @@ void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer -const LayerTypeInfo* <%- camelize(type) %>Layer::Impl::getTypeInfo() const noexcept { - return &typeInfo<%- camelize(type) %>; -} - // Layout properties <% for (const property of layoutProperties) { -%> @@ -311,25 +313,23 @@ Mutable <%- camelize(type) %>Layer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -<%- camelize(type) %>LayerFactory::<%- camelize(type) %>LayerFactory() = default; - -<%- camelize(type) %>LayerFactory::~<%- camelize(type) %>LayerFactory() = default; +} // namespace style -const LayerTypeInfo* <%- camelize(type) %>LayerFactory::getTypeInfo() const noexcept { - return &typeInfo<%- camelize(type) %>; +const style::LayerTypeInfo* <%- camelize(type) %>LayerFactory::getTypeInfo() const noexcept { + return style::<%- camelize(type) %>Layer::Impl::staticTypeInfo(); } -std::unique_ptr <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { <% if (type === 'background') { -%> (void)value; - return std::unique_ptr(new <%- camelize(type) %>Layer(id)); + return std::unique_ptr(new style::<%- camelize(type) %>Layer(id)); <% } else { -%> optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new <%- camelize(type) %>Layer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::<%- camelize(type) %>Layer(id, *source)); <% if (type !== 'raster' && type !== 'hillshade') { -%> if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; @@ -339,5 +339,9 @@ std::unique_ptr <%- camelize(type) %>LayerFactory::createLayer(con <% } -%> } -} // namespace style +std::unique_ptr <%- camelize(type) %>LayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_uniqueLayer>(staticImmutableCastLayer::Impl>(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index aeb0635254..f021a5fd73 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoLine + +// static +const LayerTypeInfo* LineLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"line", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::Required, LayerTypeInfo::Clipping::Required }; -} // namespace + return &typeInfo; +} + LineLayer::LineLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Line, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } LineLayer::LineLayer(Immutable impl_) @@ -53,10 +59,6 @@ void LineLayer::Impl::stringifyLayout(rapidjson::Writer layout.stringify(writer); } -const LayerTypeInfo* LineLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoLine; -} - // Layout properties PropertyValue LineLayer::getDefaultLineCap() { @@ -842,26 +844,28 @@ Mutable LineLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -LineLayerFactory::LineLayerFactory() = default; - -LineLayerFactory::~LineLayerFactory() = default; +} // namespace style -const LayerTypeInfo* LineLayerFactory::getTypeInfo() const noexcept { - return &typeInfoLine; +const style::LayerTypeInfo* LineLayerFactory::getTypeInfo() const noexcept { + return style::LineLayer::Impl::staticTypeInfo(); } -std::unique_ptr LineLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr LineLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new LineLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::LineLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr LineLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp index 68cd3a8f49..b5183ba9ae 100644 --- a/src/mbgl/style/layers/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { bool LineLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::Line); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index cd56a18fa8..af6c13dfd3 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -13,10 +13,11 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; LineLayoutProperties::Unevaluated layout; LinePaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 0356c2f75c..40224a0b6d 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoRaster + +// static +const LayerTypeInfo* RasterLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"raster", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::NotRequired, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + RasterLayer::RasterLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Raster, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } RasterLayer::RasterLayer(Immutable impl_) @@ -52,10 +58,6 @@ std::unique_ptr RasterLayer::cloneRef(const std::string& id_) const { void RasterLayer::Impl::stringifyLayout(rapidjson::Writer&) const { } -const LayerTypeInfo* RasterLayer::Impl::getTypeInfo() const noexcept { - return &typeInfoRaster; -} - // Layout properties @@ -524,23 +526,25 @@ Mutable RasterLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -RasterLayerFactory::RasterLayerFactory() = default; - -RasterLayerFactory::~RasterLayerFactory() = default; +} // namespace style -const LayerTypeInfo* RasterLayerFactory::getTypeInfo() const noexcept { - return &typeInfoRaster; +const style::LayerTypeInfo* RasterLayerFactory::getTypeInfo() const noexcept { + return style::RasterLayer::Impl::staticTypeInfo(); } -std::unique_ptr RasterLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr RasterLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new RasterLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::RasterLayer(id, *source)); return layer; } -} // namespace style +std::unique_ptr RasterLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp index 2e93ecec80..740efff322 100644 --- a/src/mbgl/style/layers/raster_layer_impl.hpp +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -13,9 +13,10 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; RasterPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 65a81c1071..f4fbf550f2 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -11,21 +11,27 @@ #include #include +#include + namespace mbgl { namespace style { -namespace { - const LayerTypeInfo typeInfoSymbol + +// static +const LayerTypeInfo* SymbolLayer::Impl::staticTypeInfo() noexcept { + const static LayerTypeInfo typeInfo {"symbol", LayerTypeInfo::Source::Required, LayerTypeInfo::Pass3D::NotRequired, LayerTypeInfo::Layout::Required, LayerTypeInfo::Clipping::NotRequired }; -} // namespace + return &typeInfo; +} + SymbolLayer::SymbolLayer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable(LayerType::Symbol, layerID, sourceID)) { + : Layer(makeMutable(layerID, sourceID)) { } SymbolLayer::SymbolLayer(Immutable impl_) @@ -53,10 +59,6 @@ void SymbolLayer::Impl::stringifyLayout(rapidjson::Writer SymbolLayer::getDefaultSymbolPlacement() { @@ -1992,26 +1994,28 @@ Mutable SymbolLayer::mutableBaseImpl() const { return staticMutableCast(mutableImpl()); } -SymbolLayerFactory::SymbolLayerFactory() = default; - -SymbolLayerFactory::~SymbolLayerFactory() = default; +} // namespace style -const LayerTypeInfo* SymbolLayerFactory::getTypeInfo() const noexcept { - return &typeInfoSymbol; +const style::LayerTypeInfo* SymbolLayerFactory::getTypeInfo() const noexcept { + return style::SymbolLayer::Impl::staticTypeInfo(); } -std::unique_ptr SymbolLayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr SymbolLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { optional source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr layer = std::unique_ptr(new SymbolLayer(id, *source)); + std::unique_ptr layer = std::unique_ptr(new style::SymbolLayer(id, *source)); if (!initSourceLayerAndFilter(layer.get(), value)) { return nullptr; } return layer; } -} // namespace style +std::unique_ptr SymbolLayerFactory::createRenderLayer(Immutable impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique(staticImmutableCast(std::move(impl))); +} + } // namespace mbgl diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index e177391686..3dd1da1136 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -6,7 +6,7 @@ namespace mbgl { namespace style { bool SymbolLayer::Impl::hasLayoutDifference(const Layer::Impl& other) const { - assert(other.type == LayerType::Symbol); + assert(other.getTypeInfo() == getTypeInfo()); const auto& impl = static_cast(other); return filter != impl.filter || visibility != impl.visibility || diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 01ff9772b8..a5b0332f6c 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -13,11 +13,12 @@ public: bool hasLayoutDifference(const Layer::Impl&) const override; void stringifyLayout(rapidjson::Writer&) const override; - const LayerTypeInfo* getTypeInfo() const noexcept final; void populateFontStack(std::set& fontStack) const final; SymbolLayoutProperties::Unevaluated layout; SymbolPaintProperties::Transitionable paint; + + DECLARE_LAYER_TYPE_INFO; }; } // namespace style diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index 80b3e970bd..c85f9ef713 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -97,8 +97,7 @@ void GeometryTile::setLayers(const std::vector>& layers) for (const auto& layer : layers) { // Skip irrelevant layers. - if (layer->type == LayerType::Background || - layer->type == LayerType::Custom || + if (layer->getTypeInfo()->source == LayerTypeInfo::Source::NotRequired || layer->source != sourceID || id.overscaledZ < std::floor(layer->minZoom) || id.overscaledZ >= std::ceil(layer->maxZoom) || diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index 89592e12be..9e4c045ce5 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -312,7 +312,7 @@ static std::vector> toRenderLayers(const std::vecto std::vector> renderLayers; renderLayers.reserve(layers.size()); for (auto& layer : layers) { - renderLayers.push_back(RenderLayer::create(layer)); + renderLayers.push_back(LayerManager::get()->createRenderLayer(layer)); renderLayers.back()->transition(TransitionParameters { Clock::time_point::max(), -- cgit v1.2.1