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 /platform/darwin/src | |
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 'platform/darwin/src')
-rw-r--r-- | platform/darwin/src/MGLBackgroundStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLCircleStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLFillStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLHeatmapStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLHillshadeStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLLineStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLOpenGLStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLRasterStyleLayer_Private.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayerManager.h | 12 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayerManager.mm | 39 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer_Private.h | 2 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleLayer_Private.h.ejs | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLSymbolStyleLayer_Private.h | 4 |
14 files changed, 48 insertions, 49 deletions
diff --git a/platform/darwin/src/MGLBackgroundStyleLayer_Private.h b/platform/darwin/src/MGLBackgroundStyleLayer_Private.h index 07021669dc..a6295a7c5a 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer_Private.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class BackgroundStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::BackgroundLayerFactory { +class BackgroundStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::BackgroundLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLCircleStyleLayer_Private.h b/platform/darwin/src/MGLCircleStyleLayer_Private.h index 3813a9a068..a023e2a88b 100644 --- a/platform/darwin/src/MGLCircleStyleLayer_Private.h +++ b/platform/darwin/src/MGLCircleStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class CircleStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::CircleLayerFactory { +class CircleStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::CircleLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h b/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h index 2b9a53f59f..fdd99d74f4 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class FillExtrusionStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::FillExtrusionLayerFactory { +class FillExtrusionStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::FillExtrusionLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLFillStyleLayer_Private.h b/platform/darwin/src/MGLFillStyleLayer_Private.h index f31d397434..28f24f056d 100644 --- a/platform/darwin/src/MGLFillStyleLayer_Private.h +++ b/platform/darwin/src/MGLFillStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class FillStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::FillLayerFactory { +class FillStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::FillLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLHeatmapStyleLayer_Private.h b/platform/darwin/src/MGLHeatmapStyleLayer_Private.h index 16ad816be4..e81920ae39 100644 --- a/platform/darwin/src/MGLHeatmapStyleLayer_Private.h +++ b/platform/darwin/src/MGLHeatmapStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class HeatmapStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::HeatmapLayerFactory { +class HeatmapStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::HeatmapLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLHillshadeStyleLayer_Private.h b/platform/darwin/src/MGLHillshadeStyleLayer_Private.h index 28958512d7..e92cc7f3ec 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer_Private.h +++ b/platform/darwin/src/MGLHillshadeStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class HillshadeStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::HillshadeLayerFactory { +class HillshadeStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::HillshadeLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLLineStyleLayer_Private.h b/platform/darwin/src/MGLLineStyleLayer_Private.h index ba50ebbc0d..85dbffb8ca 100644 --- a/platform/darwin/src/MGLLineStyleLayer_Private.h +++ b/platform/darwin/src/MGLLineStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class LineStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::LineLayerFactory { +class LineStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::LineLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLOpenGLStyleLayer_Private.h b/platform/darwin/src/MGLOpenGLStyleLayer_Private.h index 1188c50cd5..cce062b53d 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLOpenGLStyleLayer_Private.h @@ -6,9 +6,9 @@ namespace mbgl { -class OpenGLStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::CustomLayerFactory { +class OpenGLStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::CustomLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLRasterStyleLayer_Private.h b/platform/darwin/src/MGLRasterStyleLayer_Private.h index 1070751a61..5388d64302 100644 --- a/platform/darwin/src/MGLRasterStyleLayer_Private.h +++ b/platform/darwin/src/MGLRasterStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class RasterStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::RasterLayerFactory { +class RasterStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::RasterLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLStyleLayerManager.h b/platform/darwin/src/MGLStyleLayerManager.h index 0f7fab00ed..2fa34991a1 100644 --- a/platform/darwin/src/MGLStyleLayerManager.h +++ b/platform/darwin/src/MGLStyleLayerManager.h @@ -10,7 +10,7 @@ namespace mbgl { -class LayerManagerDarwin : public style::LayerManager { +class LayerManagerDarwin : public LayerManager { public: static LayerManagerDarwin* get() noexcept; ~LayerManagerDarwin(); @@ -20,11 +20,13 @@ public: private: LayerManagerDarwin(); void addLayerType(std::unique_ptr<LayerPeerFactory>); - // LayerManager overrides. - std::unique_ptr<style::Layer> createLayer(const std::string& type, const std::string& id, const style::conversion::Convertible& value, style::conversion::Error& error) noexcept final; - + LayerPeerFactory* getPeerFactory(const style::LayerTypeInfo* typeInfo); + // mbgl::LayerManager overrides. + LayerFactory* getFactory(const std::string& type) noexcept final; + LayerFactory* getFactory(const mbgl::style::LayerTypeInfo* info) noexcept final; + std::vector<std::unique_ptr<LayerPeerFactory>> factories; - std::map<std::string, style::LayerFactory*> typeToFactory; + std::map<std::string, LayerFactory*> typeToFactory; }; } // namespace mbgl diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm index 2cb919dd9d..90272851c3 100644 --- a/platform/darwin/src/MGLStyleLayerManager.mm +++ b/platform/darwin/src/MGLStyleLayerManager.mm @@ -31,14 +31,9 @@ LayerManagerDarwin::LayerManagerDarwin() { LayerManagerDarwin::~LayerManagerDarwin() = default; MGLStyleLayer* LayerManagerDarwin::createPeer(style::Layer* layer) { - auto* typeInfo = layer->getTypeInfo(); - assert(typeInfo); - for (const auto& factory: factories) { - if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) { - return factory->createPeer(layer); - } + if (auto* factory = getPeerFactory(layer->getTypeInfo())) { + return factory->createPeer(layer); } - assert(false); return nullptr; } @@ -51,34 +46,36 @@ void LayerManagerDarwin::addLayerType(std::unique_ptr<LayerPeerFactory> factory) factories.emplace_back(std::move(factory)); } -std::unique_ptr<style::Layer> LayerManagerDarwin::createLayer(const std::string& type, - const std::string& id, - const style::conversion::Convertible& value, - style::conversion::Error& error) noexcept { - auto search = typeToFactory.find(type); - if (search != typeToFactory.end()) { - auto layer = search->second->createLayer(id, value); - if (!layer) { - error.message = "Error parsing a layer of type: " + type; +LayerPeerFactory* LayerManagerDarwin::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) { + assert(typeInfo); + for (const auto& factory: factories) { + if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) { + return factory.get(); } - return layer; } - error.message = "Unsupported layer type: " + type; + assert(false); return nullptr; } +LayerFactory* LayerManagerDarwin::getFactory(const std::string& type) noexcept { + auto search = typeToFactory.find(type); + return (search != typeToFactory.end()) ? search->second : nullptr; +} + +LayerFactory* LayerManagerDarwin::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept { + LayerPeerFactory* peerFactory = getPeerFactory(info); + return (peerFactory != nullptr) ? peerFactory->getCoreLayerFactory() : nullptr; +} + // static LayerManagerDarwin* LayerManagerDarwin::get() noexcept { static LayerManagerDarwin impl; return &impl; } -namespace style { - // static LayerManager* LayerManager::get() noexcept { return LayerManagerDarwin::get(); } -} // namespace style } // namespace mbgl diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index 0d6e4094bd..656f74ca42 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -90,7 +90,7 @@ public: /** Get the corresponding core layer factory. */ - virtual style::LayerFactory* getCoreLayerFactory() = 0; + virtual LayerFactory* getCoreLayerFactory() = 0; /** Creates an MGLStyleLayer instance with a raw pointer to the backing store. */ diff --git a/platform/darwin/src/MGLStyleLayer_Private.h.ejs b/platform/darwin/src/MGLStyleLayer_Private.h.ejs index 245eeec29e..8cb8d6281a 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h.ejs +++ b/platform/darwin/src/MGLStyleLayer_Private.h.ejs @@ -15,9 +15,9 @@ namespace mbgl { -class <%- camelize(type) %>StyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::<%- camelize(type) %>LayerFactory { +class <%- camelize(type) %>StyleLayerPeerFactory : public LayerPeerFactory, public mbgl::<%- camelize(type) %>LayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; diff --git a/platform/darwin/src/MGLSymbolStyleLayer_Private.h b/platform/darwin/src/MGLSymbolStyleLayer_Private.h index 6ba7c7bfd0..5e5755ad67 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer_Private.h +++ b/platform/darwin/src/MGLSymbolStyleLayer_Private.h @@ -8,9 +8,9 @@ namespace mbgl { -class SymbolStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::SymbolLayerFactory { +class SymbolStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::SymbolLayerFactory { // LayerPeerFactory overrides. - style::LayerFactory* getCoreLayerFactory() final { return this; } + LayerFactory* getCoreLayerFactory() final { return this; } virtual MGLStyleLayer* createPeer(style::Layer*) final; }; |