From 8077055b1ad5bb7324b81c9b199176124240237b Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 12 Nov 2018 17:22:54 +0200 Subject: [ios, macos] Layer manager for Darwin platforms The newly introduced `MGLStyleLayerManager` is now responsible for creating both style layer objects and their obj C peers on Darwin. --- platform/darwin/scripts/generate-style-code.js | 2 + platform/darwin/src/MGLBackgroundStyleLayer.mm | 11 ++- .../darwin/src/MGLBackgroundStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLCircleStyleLayer.mm | 11 ++- platform/darwin/src/MGLCircleStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLFillExtrusionStyleLayer.mm | 11 ++- .../src/MGLFillExtrusionStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLFillStyleLayer.mm | 11 ++- platform/darwin/src/MGLFillStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLHeatmapStyleLayer.mm | 11 ++- platform/darwin/src/MGLHeatmapStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLHillshadeStyleLayer.mm | 11 ++- .../darwin/src/MGLHillshadeStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLLineStyleLayer.mm | 11 ++- platform/darwin/src/MGLLineStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLOpenGLStyleLayer.mm | 10 +++ platform/darwin/src/MGLOpenGLStyleLayer_Private.h | 15 ++++ platform/darwin/src/MGLRasterStyleLayer.mm | 11 ++- platform/darwin/src/MGLRasterStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLStyle.mm | 38 +--------- platform/darwin/src/MGLStyleLayer.mm.ejs | 11 ++- platform/darwin/src/MGLStyleLayerManager.h | 30 ++++++++ platform/darwin/src/MGLStyleLayerManager.mm | 84 ++++++++++++++++++++++ platform/darwin/src/MGLStyleLayer_Private.h | 17 +++++ platform/darwin/src/MGLStyleLayer_Private.h.ejs | 24 +++++++ platform/darwin/src/MGLSymbolStyleLayer.mm | 11 ++- platform/darwin/src/MGLSymbolStyleLayer_Private.h | 17 +++++ 27 files changed, 438 insertions(+), 45 deletions(-) create mode 100644 platform/darwin/src/MGLBackgroundStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLCircleStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLFillStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLHeatmapStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLHillshadeStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLLineStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLOpenGLStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLRasterStyleLayer_Private.h create mode 100644 platform/darwin/src/MGLStyleLayerManager.h create mode 100644 platform/darwin/src/MGLStyleLayerManager.mm create mode 100644 platform/darwin/src/MGLStyleLayer_Private.h.ejs create mode 100644 platform/darwin/src/MGLSymbolStyleLayer_Private.h (limited to 'platform/darwin') diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index a372943060..704b0a29f4 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -669,6 +669,7 @@ const lightDoc = spec['light-cocoa-doc']; const lightType = 'light'; const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); +const layerPrivateH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer_Private.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.mm.ejs', 'utf8'), { strict: true}); const forStyleAuthorsMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/For Style Authors.md.ejs', 'utf8'), { strict: true }); @@ -755,6 +756,7 @@ for (var layer of layers) { } writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer))); + writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}_Private.h`, duplicatePlatformDecls(layerPrivateH(layer))); writeIfModified(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer)); writeIfModified(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.mm`, testLayers(layer)); } diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index ceaf2ce475..5ddfff5534 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLBackgroundStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLBackgroundStyleLayer_Private.h" #include -#include + @interface MGLBackgroundStyleLayer () @@ -146,3 +147,11 @@ } @end + +namespace mbgl { + +MGLStyleLayer* BackgroundStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLBackgroundStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLBackgroundStyleLayer_Private.h b/platform/darwin/src/MGLBackgroundStyleLayer_Private.h new file mode 100644 index 0000000000..07021669dc --- /dev/null +++ b/platform/darwin/src/MGLBackgroundStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class BackgroundStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::BackgroundLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index dd3729829c..0562414b05 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLCircleStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLCircleStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -497,3 +498,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* CircleStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLCircleStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLCircleStyleLayer_Private.h b/platform/darwin/src/MGLCircleStyleLayer_Private.h new file mode 100644 index 0000000000..3813a9a068 --- /dev/null +++ b/platform/darwin/src/MGLCircleStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class CircleStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::CircleLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm index 09a58e37bb..03676a4ed5 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLFillExtrusionStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLFillExtrusionStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -350,3 +351,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* FillExtrusionStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLFillExtrusionStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h b/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h new file mode 100644 index 0000000000..2b9a53f59f --- /dev/null +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class FillExtrusionStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::FillExtrusionLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 1d4882edd3..f5dc62cd5b 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLFillStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLFillStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -338,3 +339,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* FillStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLFillStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLFillStyleLayer_Private.h b/platform/darwin/src/MGLFillStyleLayer_Private.h new file mode 100644 index 0000000000..f31d397434 --- /dev/null +++ b/platform/darwin/src/MGLFillStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class FillStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::FillLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.mm b/platform/darwin/src/MGLHeatmapStyleLayer.mm index 76675585f3..a3816c0fdd 100644 --- a/platform/darwin/src/MGLHeatmapStyleLayer.mm +++ b/platform/darwin/src/MGLHeatmapStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLHeatmapStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLHeatmapStyleLayer_Private.h" #include -#include + @interface MGLHeatmapStyleLayer () @@ -220,3 +221,11 @@ } @end + +namespace mbgl { + +MGLStyleLayer* HeatmapStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLHeatmapStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLHeatmapStyleLayer_Private.h b/platform/darwin/src/MGLHeatmapStyleLayer_Private.h new file mode 100644 index 0000000000..16ad816be4 --- /dev/null +++ b/platform/darwin/src/MGLHeatmapStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class HeatmapStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::HeatmapLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm index dcc18ba54d..c1f47b0b68 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.mm +++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLHillshadeStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLHillshadeStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -249,3 +250,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* HillshadeStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLHillshadeStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLHillshadeStyleLayer_Private.h b/platform/darwin/src/MGLHillshadeStyleLayer_Private.h new file mode 100644 index 0000000000..28958512d7 --- /dev/null +++ b/platform/darwin/src/MGLHillshadeStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class HillshadeStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::HillshadeLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 1409a4608d..8fdd9a0bcc 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLLineStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLLineStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -592,3 +593,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* LineStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLLineStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLLineStyleLayer_Private.h b/platform/darwin/src/MGLLineStyleLayer_Private.h new file mode 100644 index 0000000000..ba50ebbc0d --- /dev/null +++ b/platform/darwin/src/MGLLineStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class LineStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::LineLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLOpenGLStyleLayer.mm b/platform/darwin/src/MGLOpenGLStyleLayer.mm index d89fbc80c3..678bf15bfc 100644 --- a/platform/darwin/src/MGLOpenGLStyleLayer.mm +++ b/platform/darwin/src/MGLOpenGLStyleLayer.mm @@ -1,4 +1,5 @@ #import "MGLOpenGLStyleLayer.h" +#import "MGLOpenGLStyleLayer_Private.h" #import "MGLMapView_Private.h" #import "MGLStyle_Private.h" @@ -184,3 +185,12 @@ private: } @end + +namespace mbgl { + +MGLStyleLayer* OpenGLStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLOpenGLStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl + diff --git a/platform/darwin/src/MGLOpenGLStyleLayer_Private.h b/platform/darwin/src/MGLOpenGLStyleLayer_Private.h new file mode 100644 index 0000000000..1188c50cd5 --- /dev/null +++ b/platform/darwin/src/MGLOpenGLStyleLayer_Private.h @@ -0,0 +1,15 @@ +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class OpenGLStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::CustomLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 7416400b2e..bcaffe1c4a 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLRasterStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLRasterStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -351,3 +352,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* RasterStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLRasterStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLRasterStyleLayer_Private.h b/platform/darwin/src/MGLRasterStyleLayer_Private.h new file mode 100644 index 0000000000..1070751a61 --- /dev/null +++ b/platform/darwin/src/MGLRasterStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class RasterStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::RasterLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index c023ed80f4..4c98fd332b 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -13,6 +13,7 @@ #import "MGLRasterStyleLayer.h" #import "MGLBackgroundStyleLayer.h" #import "MGLOpenGLStyleLayer.h" +#import "MGLStyleLayerManager.h" #import "MGLSource.h" #import "MGLSource_Private.h" @@ -32,16 +33,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -358,31 +349,8 @@ static_assert(6 == mbgl::util::default_styles::numOrderedStyles, if (MGLStyleLayer *layer = rawLayer->peer.has_value() ? rawLayer->peer.get().layer : nil) { return layer; } - switch (rawLayer->getType()) { - case mbgl::style::LayerType::Fill: - return [[MGLFillStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::FillExtrusion: - return [[MGLFillExtrusionStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Line: - return [[MGLLineStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Symbol: - return [[MGLSymbolStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Raster: - return [[MGLRasterStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Heatmap: - return [[MGLHeatmapStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Hillshade: - return [[MGLHillshadeStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Circle: - return [[MGLCircleStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Background: - return [[MGLBackgroundStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - case mbgl::style::LayerType::Custom: - return [[MGLOpenGLStyleLayer alloc] initWithRawLayer:static_cast(rawLayer)]; - default: - MGLAssert(NO, @"Unrecognized layer type"); - return nil;; - } + + return mbgl::LayerManagerDarwin::get()->createPeer(rawLayer); } - (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index b7be5fb9be..0cccd16a40 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -14,9 +14,10 @@ #import "MGLStyleValue_Private.h" #import "MGL<%- camelize(type) %>StyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGL<%- camelize(type) %>StyleLayer_Private.h" #include -#include _layer.hpp> + <% if (enumProperties) { -%> namespace mbgl { @@ -254,3 +255,11 @@ namespace mbgl { <% } -%> @end <% } -%> + +namespace mbgl { + +MGLStyleLayer* <%- camelize(type) %>StyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGL<%- camelize(type) %>StyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLStyleLayerManager.h b/platform/darwin/src/MGLStyleLayerManager.h new file mode 100644 index 0000000000..0f7fab00ed --- /dev/null +++ b/platform/darwin/src/MGLStyleLayerManager.h @@ -0,0 +1,30 @@ +#pragma once + +#import "MGLStyleLayer_Private.h" + +#include + +#include +#include +#include + +namespace mbgl { + +class LayerManagerDarwin : public style::LayerManager { +public: + static LayerManagerDarwin* get() noexcept; + ~LayerManagerDarwin(); + + MGLStyleLayer* createPeer(style::Layer*); + +private: + LayerManagerDarwin(); + void addLayerType(std::unique_ptr); + // LayerManager overrides. + std::unique_ptr createLayer(const std::string& type, const std::string& id, const style::conversion::Convertible& value, style::conversion::Error& error) noexcept final; + + std::vector> factories; + std::map typeToFactory; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm new file mode 100644 index 0000000000..2cb919dd9d --- /dev/null +++ b/platform/darwin/src/MGLStyleLayerManager.mm @@ -0,0 +1,84 @@ +#import "MGLStyleLayerManager.h" + +#import "MGLBackgroundStyleLayer_Private.h" +#import "MGLCircleStyleLayer_Private.h" +#import "MGLFillExtrusionStyleLayer_Private.h" +#import "MGLFillStyleLayer_Private.h" +#import "MGLHeatmapStyleLayer_Private.h" +#import "MGLHillshadeStyleLayer_Private.h" +#import "MGLLineStyleLayer_Private.h" +#import "MGLRasterStyleLayer_Private.h" +#import "MGLSymbolStyleLayer_Private.h" +#import "MGLOpenGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +LayerManagerDarwin::LayerManagerDarwin() { + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); + addLayerType(std::make_unique()); +} + +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); + } + } + assert(false); + return nullptr; +} + +void LayerManagerDarwin::addLayerType(std::unique_ptr factory) { + auto* coreFactory = factory->getCoreLayerFactory(); + std::string type{coreFactory->getTypeInfo()->type}; + if (!type.empty()) { + typeToFactory.emplace(std::make_pair(std::move(type), coreFactory)); + } + factories.emplace_back(std::move(factory)); +} + +std::unique_ptr 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; + } + return layer; + } + error.message = "Unsupported layer type: " + type; + return 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 ea43c680e0..0d6e4094bd 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -82,4 +82,21 @@ struct LayerWrapper { @end +namespace mbgl { + +class LayerPeerFactory { +public: + virtual ~LayerPeerFactory() = default; + /** + Get the corresponding core layer factory. + */ + virtual style::LayerFactory* getCoreLayerFactory() = 0; + /** + Creates an MGLStyleLayer instance with a raw pointer to the backing store. + */ + virtual MGLStyleLayer* createPeer(style::Layer*) = 0; +}; + +} // namespace mbgl + NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/MGLStyleLayer_Private.h.ejs b/platform/darwin/src/MGLStyleLayer_Private.h.ejs new file mode 100644 index 0000000000..245eeec29e --- /dev/null +++ b/platform/darwin/src/MGLStyleLayer_Private.h.ejs @@ -0,0 +1,24 @@ +<% + const doc = locals.doc; + const type = locals.type; + const layoutProperties = locals.layoutProperties; + const paintProperties = locals.paintProperties; + const enumProperties = locals.enumProperties; +-%> +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include _layer.hpp> + +namespace mbgl { + +class <%- camelize(type) %>StyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::<%- camelize(type) %>LayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index cd293481fe..481570fdeb 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -8,9 +8,10 @@ #import "MGLStyleValue_Private.h" #import "MGLSymbolStyleLayer.h" #import "MGLLoggingConfiguration_Private.h" +#import "MGLSymbolStyleLayer_Private.h" #include -#include + namespace mbgl { @@ -1610,3 +1611,11 @@ namespace mbgl { } @end + +namespace mbgl { + +MGLStyleLayer* SymbolStyleLayerPeerFactory::createPeer(style::Layer* rawLayer) { + return [[MGLSymbolStyleLayer alloc] initWithRawLayer:rawLayer]; +} + +} // namespace mbgl diff --git a/platform/darwin/src/MGLSymbolStyleLayer_Private.h b/platform/darwin/src/MGLSymbolStyleLayer_Private.h new file mode 100644 index 0000000000..6ba7c7bfd0 --- /dev/null +++ b/platform/darwin/src/MGLSymbolStyleLayer_Private.h @@ -0,0 +1,17 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. +#pragma once + +#include "MGLStyleLayer_Private.h" + +#include + +namespace mbgl { + +class SymbolStyleLayerPeerFactory : public LayerPeerFactory, public mbgl::style::SymbolLayerFactory { + // LayerPeerFactory overrides. + style::LayerFactory* getCoreLayerFactory() final { return this; } + virtual MGLStyleLayer* createPeer(style::Layer*) final; +}; + +} // namespace mbgl -- cgit v1.2.1