diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-22 15:37:09 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2018-11-27 18:10:21 +0200 |
commit | 361982fef83a145769da5c04d1c19731df89921c (patch) | |
tree | e6212cb782cf9df83ecc3e32cb52beaebeb73ab8 /src/mbgl/style/layers/layer.cpp.ejs | |
parent | cca37e765bf9b853262783a6f7cc3d1a4c72957d (diff) | |
download | qtlocation-mapboxgl-361982fef83a145769da5c04d1c19731df89921c.tar.gz |
[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`.
Diffstat (limited to 'src/mbgl/style/layers/layer.cpp.ejs')
-rw-r--r-- | src/mbgl/style/layers/layer.cpp.ejs | 40 |
1 files changed, 22 insertions, 18 deletions
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 <mbgl/style/conversion_impl.hpp> #include <mbgl/util/fnv_hash.hpp> +#include <mbgl/renderer/layers/render_<%- type.replace('-', '_') %>_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<Impl>(LayerType::<%- camelize(type) %>, layerID, std::string())) { + : Layer(makeMutable<Impl>(layerID, std::string())) { } <% } else { -%> <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID, const std::string& sourceID) - : Layer(makeMutable<Impl>(LayerType::<%- camelize(type) %>, layerID, sourceID)) { + : Layer(makeMutable<Impl>(layerID, sourceID)) { } <% } -%> @@ -106,10 +112,6 @@ void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjs } <% } -%> -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<Layer::Impl> <%- camelize(type) %>Layer::mutableBaseImpl() const { return staticMutableCast<Layer::Impl>(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<style::Layer> <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const conversion::Convertible& value) { +std::unique_ptr<style::Layer> <%- camelize(type) %>LayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { <% if (type === 'background') { -%> (void)value; - return std::unique_ptr<style::Layer>(new <%- camelize(type) %>Layer(id)); + return std::unique_ptr<style::Layer>(new style::<%- camelize(type) %>Layer(id)); <% } else { -%> optional<std::string> source = getSource(value); if (!source) { return nullptr; } - std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(new <%- camelize(type) %>Layer(id, *source)); + std::unique_ptr<style::Layer> layer = std::unique_ptr<style::Layer>(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<style::Layer> <%- camelize(type) %>LayerFactory::createLayer(con <% } -%> } -} // namespace style +std::unique_ptr<RenderLayer> <%- camelize(type) %>LayerFactory::createRenderLayer(Immutable<style::Layer::Impl> impl) noexcept { + assert(impl->getTypeInfo() == getTypeInfo()); + return std::make_unique<Render<%- camelize(type) %>Layer>(staticImmutableCast<style::<%- camelize(type) %>Layer::Impl>(std::move(impl))); +} + } // namespace mbgl |