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/android | |
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/android')
14 files changed, 44 insertions, 62 deletions
diff --git a/platform/android/src/style/layers/background_layer.hpp b/platform/android/src/style/layers/background_layer.hpp index efe882d531..c1b25b41bd 100644 --- a/platform/android/src/style/layers/background_layer.hpp +++ b/platform/android/src/style/layers/background_layer.hpp @@ -39,7 +39,7 @@ public: }; // class BackgroundLayer -class BackgroundJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::BackgroundLayerFactory { +class BackgroundJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::BackgroundLayerFactory { public: ~BackgroundJavaLayerPeerFactory() override; @@ -49,7 +49,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class BackgroundJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/circle_layer.hpp b/platform/android/src/style/layers/circle_layer.hpp index 5c53f6c191..6db97127c0 100644 --- a/platform/android/src/style/layers/circle_layer.hpp +++ b/platform/android/src/style/layers/circle_layer.hpp @@ -65,7 +65,7 @@ public: }; // class CircleLayer -class CircleJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::CircleLayerFactory { +class CircleJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::CircleLayerFactory { public: ~CircleJavaLayerPeerFactory() override; @@ -75,7 +75,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class CircleJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/custom_layer.hpp b/platform/android/src/style/layers/custom_layer.hpp index ea4a3d79a5..814cfea3ca 100644 --- a/platform/android/src/style/layers/custom_layer.hpp +++ b/platform/android/src/style/layers/custom_layer.hpp @@ -25,7 +25,7 @@ public: }; // class CustomLayer -class CustomJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::CustomLayerFactory { +class CustomJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::CustomLayerFactory { public: ~CustomJavaLayerPeerFactory() override; @@ -35,7 +35,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class CustomJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/fill_extrusion_layer.hpp b/platform/android/src/style/layers/fill_extrusion_layer.hpp index ace8cd1357..fe7204985c 100644 --- a/platform/android/src/style/layers/fill_extrusion_layer.hpp +++ b/platform/android/src/style/layers/fill_extrusion_layer.hpp @@ -53,7 +53,7 @@ public: }; // class FillExtrusionLayer -class FillExtrusionJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::FillExtrusionLayerFactory { +class FillExtrusionJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::FillExtrusionLayerFactory { public: ~FillExtrusionJavaLayerPeerFactory() override; @@ -63,7 +63,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class FillExtrusionJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/fill_layer.hpp b/platform/android/src/style/layers/fill_layer.hpp index c7b469ac90..776f2c3a88 100644 --- a/platform/android/src/style/layers/fill_layer.hpp +++ b/platform/android/src/style/layers/fill_layer.hpp @@ -51,7 +51,7 @@ public: }; // class FillLayer -class FillJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::FillLayerFactory { +class FillJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::FillLayerFactory { public: ~FillJavaLayerPeerFactory() override; @@ -61,7 +61,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class FillJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/heatmap_layer.hpp b/platform/android/src/style/layers/heatmap_layer.hpp index 45c194b0f0..51966ec93e 100644 --- a/platform/android/src/style/layers/heatmap_layer.hpp +++ b/platform/android/src/style/layers/heatmap_layer.hpp @@ -43,7 +43,7 @@ public: }; // class HeatmapLayer -class HeatmapJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::HeatmapLayerFactory { +class HeatmapJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::HeatmapLayerFactory { public: ~HeatmapJavaLayerPeerFactory() override; @@ -53,7 +53,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class HeatmapJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/hillshade_layer.hpp b/platform/android/src/style/layers/hillshade_layer.hpp index db0ea736b4..b63f85e36c 100644 --- a/platform/android/src/style/layers/hillshade_layer.hpp +++ b/platform/android/src/style/layers/hillshade_layer.hpp @@ -47,7 +47,7 @@ public: }; // class HillshadeLayer -class HillshadeJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::HillshadeLayerFactory { +class HillshadeJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::HillshadeLayerFactory { public: ~HillshadeJavaLayerPeerFactory() override; @@ -57,7 +57,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class HillshadeJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/layer.hpp b/platform/android/src/style/layers/layer.hpp index 633630b891..c405bc17c1 100644 --- a/platform/android/src/style/layers/layer.hpp +++ b/platform/android/src/style/layers/layer.hpp @@ -117,7 +117,7 @@ public: * * @return style::LayerFactory* must not be \c nullptr. */ - virtual style::LayerFactory* getLayerFactory() = 0; + virtual LayerFactory* getLayerFactory() = 0; }; diff --git a/platform/android/src/style/layers/layer.hpp.ejs b/platform/android/src/style/layers/layer.hpp.ejs index 5791c16501..e82470e270 100644 --- a/platform/android/src/style/layers/layer.hpp.ejs +++ b/platform/android/src/style/layers/layer.hpp.ejs @@ -43,7 +43,7 @@ public: }; // class <%- camelize(type) %>Layer -class <%- camelize(type) %>JavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::<%- camelize(type) %>LayerFactory { +class <%- camelize(type) %>JavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::<%- camelize(type) %>LayerFactory { public: ~<%- camelize(type) %>JavaLayerPeerFactory() override; @@ -53,7 +53,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class <%- camelize(type) %>JavaLayerPeerFactory diff --git a/platform/android/src/style/layers/layer_manager.cpp b/platform/android/src/style/layers/layer_manager.cpp index 9ad62121e6..9f13fa0640 100644 --- a/platform/android/src/style/layers/layer_manager.cpp +++ b/platform/android/src/style/layers/layer_manager.cpp @@ -1,17 +1,6 @@ #include "layer_manager.hpp" -#include <mbgl/style/layer.hpp> #include <mbgl/style/layer_impl.hpp> -#include <mbgl/style/layers/background_layer.hpp> -#include <mbgl/style/layers/circle_layer.hpp> -#include <mbgl/style/layers/fill_extrusion_layer.hpp> -#include <mbgl/style/layers/fill_layer.hpp> -#include <mbgl/style/layers/heatmap_layer.hpp> -#include <mbgl/style/layers/hillshade_layer.hpp> -#include <mbgl/style/layers/line_layer.hpp> -#include <mbgl/style/layers/raster_layer.hpp> -#include <mbgl/style/layers/symbol_layer.hpp> -#include <mbgl/style/layers/custom_layer.hpp> #include <mbgl/style/conversion/constant.hpp> #include <mbgl/style/conversion/filter.hpp> @@ -49,14 +38,14 @@ LayerManagerAndroid::LayerManagerAndroid() { LayerManagerAndroid::~LayerManagerAndroid() = default; jni::Local<jni::Object<Layer>> LayerManagerAndroid::createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, mbgl::style::Layer& layer) { - if (JavaLayerPeerFactory* factory = getPeerFactory(&layer)) { + if (JavaLayerPeerFactory* factory = getPeerFactory(layer.getTypeInfo())) { return factory->createJavaLayerPeer(env, map, layer); } return jni::Local<jni::Object<Layer>>(); } jni::Local<jni::Object<Layer>> LayerManagerAndroid::createJavaLayerPeer(jni::JNIEnv& env, mbgl::Map& map, std::unique_ptr<mbgl::style::Layer> layer) { - if (JavaLayerPeerFactory* factory = getPeerFactory(layer.get())) { + if (JavaLayerPeerFactory* factory = getPeerFactory(layer->getTypeInfo())) { return factory->createJavaLayerPeer(env, map, std::move(layer)); } return jni::Local<jni::Object<Layer>>(); @@ -78,8 +67,7 @@ void LayerManagerAndroid::addLayerType(std::unique_ptr<JavaLayerPeerFactory> fac factories.emplace_back(std::move(factory)); } -JavaLayerPeerFactory* LayerManagerAndroid::getPeerFactory(mbgl::style::Layer* layer) { - auto* typeInfo = layer->baseImpl->getTypeInfo(); +JavaLayerPeerFactory* LayerManagerAndroid::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) { assert(typeInfo); for (const auto& factory: factories) { if (factory->getLayerFactory()->getTypeInfo() == typeInfo) { @@ -90,20 +78,14 @@ JavaLayerPeerFactory* LayerManagerAndroid::getPeerFactory(mbgl::style::Layer* la return nullptr; } -std::unique_ptr<style::Layer> LayerManagerAndroid::createLayer(const std::string& type, - const std::string& id, - const style::conversion::Convertible& value, - style::conversion::Error& error) noexcept { +LayerFactory* LayerManagerAndroid::getFactory(const std::string& type) 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; + return (search != typeToFactory.end()) ? search->second : nullptr; +} + +LayerFactory* LayerManagerAndroid::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept { + JavaLayerPeerFactory* peerFactory = getPeerFactory(info); + return (peerFactory != nullptr) ? peerFactory->getLayerFactory() : nullptr; } // static @@ -114,11 +96,8 @@ LayerManagerAndroid* LayerManagerAndroid::get() noexcept { } // namespace android -namespace style { -// static LayerManager* LayerManager::get() noexcept { return android::LayerManagerAndroid::get(); } -} // style } // namespace mbgl diff --git a/platform/android/src/style/layers/layer_manager.hpp b/platform/android/src/style/layers/layer_manager.hpp index 396521cc4a..1521645cce 100644 --- a/platform/android/src/style/layers/layer_manager.hpp +++ b/platform/android/src/style/layers/layer_manager.hpp @@ -3,6 +3,8 @@ #include <mbgl/map/map.hpp> #include <mbgl/style/layer.hpp> +#include <mbgl/renderer/render_layer.hpp> + #include "layer.hpp" #include <jni/jni.hpp> @@ -16,9 +18,9 @@ namespace android { /** * @brief A singleton class forwarding calls to the corresponding \c JavaLayerPeerFactory instance. */ -class LayerManagerAndroid : public mbgl::style::LayerManager { +class LayerManagerAndroid final : public mbgl::LayerManager { public: - ~LayerManagerAndroid() override; + ~LayerManagerAndroid() final; static LayerManagerAndroid* get() noexcept; jni::Local<jni::Object<Layer>> createJavaLayerPeer(jni::JNIEnv&, mbgl::Map&, mbgl::style::Layer&); @@ -29,13 +31,14 @@ public: private: LayerManagerAndroid(); void addLayerType(std::unique_ptr<JavaLayerPeerFactory>); - JavaLayerPeerFactory* getPeerFactory(mbgl::style::Layer*); - // mbgl:style::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; + 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::map<std::string, style::LayerFactory*> typeToFactory; + std::map<std::string, mbgl::LayerFactory*> typeToFactory; }; -} -} +} // namespace android +} // namespace mbgl diff --git a/platform/android/src/style/layers/line_layer.hpp b/platform/android/src/style/layers/line_layer.hpp index 4dbc855ca9..7c16822ef8 100644 --- a/platform/android/src/style/layers/line_layer.hpp +++ b/platform/android/src/style/layers/line_layer.hpp @@ -75,7 +75,7 @@ public: }; // class LineLayer -class LineJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::LineLayerFactory { +class LineJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::LineLayerFactory { public: ~LineJavaLayerPeerFactory() override; @@ -85,7 +85,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class LineJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/raster_layer.hpp b/platform/android/src/style/layers/raster_layer.hpp index 492b3562fc..6be6792776 100644 --- a/platform/android/src/style/layers/raster_layer.hpp +++ b/platform/android/src/style/layers/raster_layer.hpp @@ -55,7 +55,7 @@ public: }; // class RasterLayer -class RasterJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::RasterLayerFactory { +class RasterJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::RasterLayerFactory { public: ~RasterJavaLayerPeerFactory() override; @@ -65,7 +65,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class RasterJavaLayerPeerFactory diff --git a/platform/android/src/style/layers/symbol_layer.hpp b/platform/android/src/style/layers/symbol_layer.hpp index 5df7ac3687..b38a659b06 100644 --- a/platform/android/src/style/layers/symbol_layer.hpp +++ b/platform/android/src/style/layers/symbol_layer.hpp @@ -153,7 +153,7 @@ public: }; // class SymbolLayer -class SymbolJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::style::SymbolLayerFactory { +class SymbolJavaLayerPeerFactory final : public JavaLayerPeerFactory, public mbgl::SymbolLayerFactory { public: ~SymbolJavaLayerPeerFactory() override; @@ -163,7 +163,7 @@ public: void registerNative(jni::JNIEnv&) final; - style::LayerFactory* getLayerFactory() final { return this; } + LayerFactory* getLayerFactory() final { return this; } }; // class SymbolJavaLayerPeerFactory |