summaryrefslogtreecommitdiff
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 13:03:10 +0200
commite0a2e36d290f5fd8d97319dfbb40cbb3ebd29fac (patch)
tree15bd74db4faee778b481c3bae0aeaf8cbf46d530
parentc01c8282fe6e3de1cb65223efc50d36bad4d591f (diff)
downloadqtlocation-mapboxgl-upstream/mikhail_mac_core_layers.tar.gz
[mac, ios] Enable core-only layersupstream/mikhail_mac_core_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.
-rw-r--r--platform/android/src/style/layers/layer_manager.hpp2
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.h16
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.mm38
3 files changed, 45 insertions, 11 deletions
diff --git a/platform/android/src/style/layers/layer_manager.hpp b/platform/android/src/style/layers/layer_manager.hpp
index fb87721dd2..807ded1737 100644
--- a/platform/android/src/style/layers/layer_manager.hpp
+++ b/platform/android/src/style/layers/layer_manager.hpp
@@ -30,7 +30,7 @@ public:
private:
LayerManagerAndroid();
/**
- * @brief Enables a layer type for both JSON style an runtime API.
+ * @brief Enables a layer type for both JSON style and runtime API.
*/
void addLayerType(std::unique_ptr<JavaLayerPeerFactory>);
/**
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