summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/android/src/style/layers/layer_manager.cpp41
-rw-r--r--platform/android/src/style/layers/layer_manager.hpp18
2 files changed, 48 insertions, 11 deletions
diff --git a/platform/android/src/style/layers/layer_manager.cpp b/platform/android/src/style/layers/layer_manager.cpp
index 706c5a76a1..2f023bd3ae 100644
--- a/platform/android/src/style/layers/layer_manager.cpp
+++ b/platform/android/src/style/layers/layer_manager.cpp
@@ -52,29 +52,43 @@ jni::Local<jni::Object<Layer>> LayerManagerAndroid::createJavaLayerPeer(jni::JNI
}
void LayerManagerAndroid::registerNative(jni::JNIEnv& env) {
+ if (peerFactories.empty()) {
+ return;
+ }
+
Layer::registerNative(env);
- for (const auto& factory: factories) {
+ for (const auto& factory: peerFactories) {
factory->registerNative(env);
}
}
void LayerManagerAndroid::addLayerType(std::unique_ptr<JavaLayerPeerFactory> factory) {
- auto* coreFactory = factory->getLayerFactory();
- std::string type{coreFactory->getTypeInfo()->type};
+ assert(getFactory(factory->getLayerFactory()->getTypeInfo()) == nullptr);
+ registerCoreFactory(factory->getLayerFactory());
+ peerFactories.emplace_back(std::move(factory));
+}
+
+void LayerManagerAndroid::addLayerTypeCoreOnly(std::unique_ptr<LayerFactory> factory) {
+ assert(getFactory(factory->getTypeInfo()) == nullptr);
+ registerCoreFactory(factory.get());
+ coreFactories.emplace_back(std::move(factory));
+}
+
+void LayerManagerAndroid::registerCoreFactory(mbgl::LayerFactory* factory) {
+ std::string type{factory->getTypeInfo()->type};
if (!type.empty()) {
- typeToFactory.emplace(std::make_pair(std::move(type), coreFactory));
+ assert(typeToFactory.find(type) == typeToFactory.end());
+ typeToFactory.emplace(std::make_pair(std::move(type), factory));
}
- factories.emplace_back(std::move(factory));
}
JavaLayerPeerFactory* LayerManagerAndroid::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) {
assert(typeInfo);
- for (const auto& factory: factories) {
+ for (const auto& factory: peerFactories) {
if (factory->getLayerFactory()->getTypeInfo() == typeInfo) {
return factory.get();
}
}
- assert(false);
return nullptr;
}
@@ -84,8 +98,17 @@ LayerFactory* LayerManagerAndroid::getFactory(const std::string& type) noexcept
}
LayerFactory* LayerManagerAndroid::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept {
- JavaLayerPeerFactory* peerFactory = getPeerFactory(info);
- return (peerFactory != nullptr) ? peerFactory->getLayerFactory() : nullptr;
+ if (JavaLayerPeerFactory* peerFactory = getPeerFactory(info)) {
+ return peerFactory->getLayerFactory();
+ }
+
+ for (const auto& factory: coreFactories) {
+ if (factory->getTypeInfo() == info) {
+ return factory.get();
+ }
+ }
+
+ return nullptr;
}
// static
diff --git a/platform/android/src/style/layers/layer_manager.hpp b/platform/android/src/style/layers/layer_manager.hpp
index ff7e48027e..fb87721dd2 100644
--- a/platform/android/src/style/layers/layer_manager.hpp
+++ b/platform/android/src/style/layers/layer_manager.hpp
@@ -29,13 +29,27 @@ public:
private:
LayerManagerAndroid();
- void addLayerType(std::unique_ptr<JavaLayerPeerFactory>);
+ /**
+ * @brief Enables a layer type for both JSON style an runtime API.
+ */
+ void addLayerType(std::unique_ptr<JavaLayerPeerFactory>);
+ /**
+ * @brief 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 - JNI glue code for these layer types
+ * won't be added to the binary.
+ */
+ void addLayerTypeCoreOnly(std::unique_ptr<mbgl::LayerFactory>);
+
+ void registerCoreFactory(mbgl::LayerFactory*);
JavaLayerPeerFactory* getPeerFactory(const mbgl::style::LayerTypeInfo*);
// 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<JavaLayerPeerFactory>> factories;
+ std::vector<std::unique_ptr<JavaLayerPeerFactory>> peerFactories;
+ std::vector<std::unique_ptr<mbgl::LayerFactory>> coreFactories;
std::map<std::string, mbgl::LayerFactory*> typeToFactory;
};