summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-12-17 16:03:38 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-12-18 18:57:16 +0200
commita408b2f5d5708e4b9fb7a870b4b58cd96eee9609 (patch)
tree1da7cfcda6c695a30bf00bb67d7b22655df2f991 /platform/darwin
parentfbe7874db50e343740f3d065a8c06e7ceb07002e (diff)
downloadqtlocation-mapboxgl-a408b2f5d5708e4b9fb7a870b4b58cd96eee9609.tar.gz
[mac, ios] Enable core-only layers
`LayerManagerDarwin` can add layer types that are enabled only for JSON style. It allows to exclude the SDK wrappers for these layers from the project and decrease binary size.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.h16
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.mm38
2 files changed, 44 insertions, 10 deletions
diff --git a/platform/darwin/src/MGLStyleLayerManager.h b/platform/darwin/src/MGLStyleLayerManager.h
index cdd30f4fff..95fecd0252 100644
--- a/platform/darwin/src/MGLStyleLayerManager.h
+++ b/platform/darwin/src/MGLStyleLayerManager.h
@@ -20,13 +20,27 @@ public:
private:
LayerManagerDarwin();
+ /**
+ * Enables a layer type for both JSON style and runtime API.
+ */
void addLayerType(std::unique_ptr<LayerPeerFactory>);
+ /**
+ * Enables a layer type for JSON style only.
+ *
+ * We might not want to expose runtime API for some layer types
+ * in order to save binary size (the corresponding SDK layer wrappers
+ * should be excluded from the project build).
+ */
+ void addLayerTypeCoreOnly(std::unique_ptr<mbgl::LayerFactory>);
+
+ void registerCoreFactory(LayerFactory*);
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::vector<std::unique_ptr<LayerPeerFactory>> peerFactories;
+ std::vector<std::unique_ptr<LayerFactory>> coreFactories;
std::map<std::string, LayerFactory*> typeToFactory;
};
diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm
index bdcc303de5..a05e24bd9d 100644
--- a/platform/darwin/src/MGLStyleLayerManager.mm
+++ b/platform/darwin/src/MGLStyleLayerManager.mm
@@ -38,22 +38,33 @@ MGLStyleLayer* LayerManagerDarwin::createPeer(style::Layer* layer) {
}
void LayerManagerDarwin::addLayerType(std::unique_ptr<LayerPeerFactory> factory) {
- auto* coreFactory = factory->getCoreLayerFactory();
- std::string type{coreFactory->getTypeInfo()->type};
+ NSCAssert(getFactory(factory->getCoreLayerFactory()->getTypeInfo()) == nullptr,
+ @"A layer factory with the given info is already added.");
+ registerCoreFactory(factory->getCoreLayerFactory());
+ peerFactories.emplace_back(std::move(factory));
+}
+
+void LayerManagerDarwin::addLayerTypeCoreOnly(std::unique_ptr<LayerFactory> factory) {
+ NSCAssert(getFactory(factory->getTypeInfo()) == nullptr,
+ @"A layer factory with the given info is already added.");
+ registerCoreFactory(factory.get());
+ coreFactories.emplace_back(std::move(factory));
+}
+
+void LayerManagerDarwin::registerCoreFactory(LayerFactory* factory) {
+ std::string type{factory->getTypeInfo()->type};
if (!type.empty()) {
- typeToFactory.emplace(std::make_pair(std::move(type), coreFactory));
+ NSCAssert(typeToFactory.find(type) == typeToFactory.end(), @"A layer type can be registered only once.");
+ typeToFactory.emplace(std::make_pair(std::move(type), factory));
}
- factories.emplace_back(std::move(factory));
}
LayerPeerFactory* LayerManagerDarwin::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) {
- assert(typeInfo);
- for (const auto& factory: factories) {
+ for (const auto& factory: peerFactories) {
if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) {
return factory.get();
}
}
- assert(false);
return nullptr;
}
@@ -63,8 +74,17 @@ LayerFactory* LayerManagerDarwin::getFactory(const std::string& type) noexcept {
}
LayerFactory* LayerManagerDarwin::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept {
- LayerPeerFactory* peerFactory = getPeerFactory(info);
- return (peerFactory != nullptr) ? peerFactory->getCoreLayerFactory() : nullptr;
+ if (LayerPeerFactory* peerFactory = getPeerFactory(info)) {
+ return peerFactory->getCoreLayerFactory();
+ }
+
+ for (const auto& factory: coreFactories) {
+ if (factory->getTypeInfo() == info) {
+ return factory.get();
+ }
+ }
+
+ return nullptr;
}
// static