From 207104426b37e9cb9c453a142124deaf5eb9d3c5 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Fri, 30 Nov 2018 12:10:33 +0200 Subject: [core] layermanager folder Move `LayerManager` and `LayerFactory` abstract classes to a dedicated folder. --- cmake/core-files.txt | 6 ++ include/mbgl/layermanager/layer_factory.hpp | 29 +++++++++ include/mbgl/layermanager/layer_manager.hpp | 56 +++++++++++++++++ include/mbgl/style/layer.hpp | 70 ---------------------- include/mbgl/style/layers/background_layer.hpp | 2 +- include/mbgl/style/layers/circle_layer.hpp | 2 +- include/mbgl/style/layers/custom_layer.hpp | 1 + include/mbgl/style/layers/fill_extrusion_layer.hpp | 2 +- include/mbgl/style/layers/fill_layer.hpp | 2 +- include/mbgl/style/layers/heatmap_layer.hpp | 2 +- include/mbgl/style/layers/hillshade_layer.hpp | 2 +- include/mbgl/style/layers/layer.hpp.ejs | 2 +- include/mbgl/style/layers/line_layer.hpp | 2 +- include/mbgl/style/layers/raster_layer.hpp | 2 +- include/mbgl/style/layers/symbol_layer.hpp | 2 +- platform/android/src/style/layers/layer.hpp | 1 + .../android/src/style/layers/layer_manager.hpp | 3 +- platform/darwin/src/MGLStyleLayerManager.h | 1 + platform/darwin/src/MGLStyleLayer_Private.h | 1 + platform/default/layer_manager.cpp | 22 +++---- src/mbgl/annotation/annotation_manager.cpp | 1 + src/mbgl/layermanager/layer_factory.cpp | 47 +++++++++++++++ src/mbgl/layermanager/layer_manager.cpp | 31 ++++++++++ src/mbgl/map/map.cpp | 1 + src/mbgl/renderer/renderer.cpp | 2 + src/mbgl/renderer/renderer_impl.cpp | 1 + src/mbgl/style/conversion/layer.cpp | 2 + src/mbgl/style/layer.cpp | 59 ------------------ src/mbgl/tile/geometry_tile_worker.cpp | 1 + test/renderer/group_by_layout.test.cpp | 1 + 30 files changed, 204 insertions(+), 152 deletions(-) create mode 100644 include/mbgl/layermanager/layer_factory.hpp create mode 100644 include/mbgl/layermanager/layer_manager.hpp create mode 100644 src/mbgl/layermanager/layer_factory.cpp create mode 100644 src/mbgl/layermanager/layer_manager.cpp diff --git a/cmake/core-files.txt b/cmake/core-files.txt index 2d55807ee8..bccdc27066 100644 --- a/cmake/core-files.txt +++ b/cmake/core-files.txt @@ -94,6 +94,12 @@ src/mbgl/gl/vertex_array.hpp src/mbgl/gl/vertex_array_extension.hpp src/mbgl/gl/vertex_buffer.hpp +# layermanager +include/mbgl/layermanager/layer_factory.hpp +include/mbgl/layermanager/layer_manager.hpp +src/mbgl/layermanager/layer_factory.cpp +src/mbgl/layermanager/layer_manager.cpp + # layout src/mbgl/layout/clip_lines.cpp src/mbgl/layout/clip_lines.hpp diff --git a/include/mbgl/layermanager/layer_factory.hpp b/include/mbgl/layermanager/layer_factory.hpp new file mode 100644 index 0000000000..3e2b2c3ddd --- /dev/null +++ b/include/mbgl/layermanager/layer_factory.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace mbgl { + +class RenderLayer; + +/** + * @brief The LayerFactory abstract class + * + * This class is responsible for creation of the layer objects that belong to a concrete layer type. + */ +class LayerFactory { +public: + virtual ~LayerFactory() = default; + /// Returns the layer type data. + virtual const style::LayerTypeInfo* getTypeInfo() const noexcept = 0; + /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. + virtual std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept = 0; + /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. + virtual std::unique_ptr createRenderLayer(Immutable) noexcept = 0; + +protected: + optional getSource(const style::conversion::Convertible& value) const noexcept; + bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept; +}; + +} // namespace mbgl diff --git a/include/mbgl/layermanager/layer_manager.hpp b/include/mbgl/layermanager/layer_manager.hpp new file mode 100644 index 0000000000..038a6dcb04 --- /dev/null +++ b/include/mbgl/layermanager/layer_manager.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include + +namespace mbgl { + +class LayerFactory; +class RenderLayer; + +/** + * @brief A singleton class responsible for creating layer instances. + * + * The LayerManager has implementation per platform. The LayerManager implementation + * defines what layer types are available and it can also disable annotations. + * + * Linker excludes the unreachable code for the disabled annotations and layers + * from the binaries, significantly reducing their size. + */ +class LayerManager { +public: + /** + * @brief A singleton getter. + * + * @return LayerManager* + */ + static LayerManager* get() noexcept; + + /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. + std::unique_ptr createLayer(const std::string& type, const std::string& id, + const style::conversion::Convertible& value, style::conversion::Error& error) noexcept; + /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. + std::unique_ptr createRenderLayer(Immutable) noexcept; + + /** + * @brief a build-time flag to enable/disable annotations in mapbox-gl-native core. + * + * At the moment, the annotations implementation in core is creating concrete + * layer instances apart from LayerManager/LayerFactory code path. + * + * So, annotations must be disabled if the LayerManager implementation does + * not provide line, fill or symbol layers (those, used by the annotations + * implementation). + * + * Note: in future, annotations implemantation will be moved from the core to platform + * SDK (see https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation) + * and this flag won't be needed any more. + */ + static const bool annotationsEnabled; + +protected: + virtual ~LayerManager() = default; + virtual LayerFactory* getFactory(const std::string& type) noexcept = 0; + virtual LayerFactory* getFactory(const style::LayerTypeInfo*) noexcept = 0; +}; + +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index d85f459815..bd0905cd6d 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -126,74 +126,4 @@ protected: }; } // namespace style - -class RenderLayer; -// TODO: The following classes shall not be here. Move layer factories and manager to a dedicated folder. - -/** - * @brief The LayerFactory abstract class - * - * This class is responsible for creation of the layer objects that belong to a concrete layer type. - */ -class LayerFactory { -public: - virtual ~LayerFactory() = default; - /// Returns the layer type data. - virtual const style::LayerTypeInfo* getTypeInfo() const noexcept = 0; - /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. - virtual std::unique_ptr createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept = 0; - /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. - virtual std::unique_ptr createRenderLayer(Immutable) noexcept = 0; - -protected: - optional getSource(const style::conversion::Convertible& value) const noexcept; - bool initSourceLayerAndFilter(style::Layer*, const style::conversion::Convertible& value) const noexcept; -}; - -/** - * @brief A singleton class responsible for creating layer instances. - * - * The LayerManager has implementation per platform. The LayerManager implementation - * defines what layer types are available and it can also disable annotations. - * - * Linker excludes the unreachable code for the disabled annotations and layers - * from the binaries, significantly reducing their size. - */ -class LayerManager { -public: - /** - * @brief A singleton getter. - * - * @return LayerManager* - */ - static LayerManager* get() noexcept; - - /// Returns a new Layer instance on success call; returns `nulltptr` otherwise. - std::unique_ptr createLayer(const std::string& type, const std::string& id, - const style::conversion::Convertible& value, style::conversion::Error& error) noexcept; - /// Returns a new RenderLayer instance on success call; returns `nulltptr` otherwise. - std::unique_ptr createRenderLayer(Immutable) noexcept; - - /** - * @brief a build-time flag to enable/disable annotations in mapbox-gl-native core. - * - * At the moment, the annotations implementation in core is creating concrete - * layer instances apart from LayerManager/LayerFactory code path. - * - * So, annotations must be disabled if the LayerManager implementation does - * not provide line, fill or symbol layers (those, used by the annotations - * implementation). - * - * Note: in future, annotations implemantation will be moved from the core to platform - * SDK (see https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation) - * and this flag won't be needed any more. - */ - static const bool annotationsEnabled; - -protected: - virtual ~LayerManager() = default; - virtual LayerFactory* getFactory(const std::string& type) noexcept = 0; - virtual LayerFactory* getFactory(const style::LayerTypeInfo*) noexcept = 0; -}; - } // namespace mbgl diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index b471d8613e..e501954620 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index 46951653b7..6d8969e834 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp index d204a782f2..27c16fbbc5 100644 --- a/include/mbgl/style/layers/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index 059b8f8996..78906d8f1b 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index 222142daf3..6c235b6ab7 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index 004d77c487..6ff377cf8f 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -2,12 +2,12 @@ #pragma once +#include #include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index f840386907..0c1843af75 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 84a8edd9de..e4c9d69dbf 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -7,6 +7,7 @@ #pragma once +#include <% if (type === 'heatmap' || type === 'line') { -%> #include <% } -%> @@ -14,7 +15,6 @@ #include #include #include - #include <% if (type === 'line' || type === 'symbol') { -%> diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index bbc0213c53..083bac6b9c 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -2,12 +2,12 @@ #pragma once +#include #include #include #include #include #include - #include #include diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 0def2faacd..ef84ee569a 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include namespace mbgl { diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index e17df295f3..3d23120559 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -2,11 +2,11 @@ #pragma once +#include #include #include #include #include - #include #include diff --git a/platform/android/src/style/layers/layer.hpp b/platform/android/src/style/layers/layer.hpp index c405bc17c1..0fb679152b 100644 --- a/platform/android/src/style/layers/layer.hpp +++ b/platform/android/src/style/layers/layer.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include "../../gson/json_array.hpp" diff --git a/platform/android/src/style/layers/layer_manager.hpp b/platform/android/src/style/layers/layer_manager.hpp index 1521645cce..ff7e48027e 100644 --- a/platform/android/src/style/layers/layer_manager.hpp +++ b/platform/android/src/style/layers/layer_manager.hpp @@ -1,10 +1,9 @@ #pragma once +#include #include #include -#include - #include "layer.hpp" #include diff --git a/platform/darwin/src/MGLStyleLayerManager.h b/platform/darwin/src/MGLStyleLayerManager.h index 2fa34991a1..cdd30f4fff 100644 --- a/platform/darwin/src/MGLStyleLayerManager.h +++ b/platform/darwin/src/MGLStyleLayerManager.h @@ -2,6 +2,7 @@ #import "MGLStyleLayer_Private.h" +#include #include #include diff --git a/platform/darwin/src/MGLStyleLayer_Private.h b/platform/darwin/src/MGLStyleLayer_Private.h index 656f74ca42..314f61f680 100644 --- a/platform/darwin/src/MGLStyleLayer_Private.h +++ b/platform/darwin/src/MGLStyleLayer_Private.h @@ -3,6 +3,7 @@ #import "MGLStyleLayer.h" #import "MGLStyleValue_Private.h" +#include #include NS_ASSUME_NONNULL_BEGIN diff --git a/platform/default/layer_manager.cpp b/platform/default/layer_manager.cpp index 32d5cbc0fc..86343369b4 100644 --- a/platform/default/layer_manager.cpp +++ b/platform/default/layer_manager.cpp @@ -1,14 +1,14 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 17cf77865c..ab22404c15 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/src/mbgl/layermanager/layer_factory.cpp b/src/mbgl/layermanager/layer_factory.cpp new file mode 100644 index 0000000000..c7f63b8699 --- /dev/null +++ b/src/mbgl/layermanager/layer_factory.cpp @@ -0,0 +1,47 @@ +#include + +#include +#include +#include +#include + +namespace mbgl { + +optional LayerFactory::getSource(const style::conversion::Convertible& value) const noexcept { + auto sourceValue = objectMember(value, "source"); + if (!sourceValue) { + return nullopt; + } + + optional source = toString(*sourceValue); + if (!source) { + return nullopt; + } + + return source; +} + +bool LayerFactory::initSourceLayerAndFilter(style::Layer* layer, const style::conversion::Convertible& value) const noexcept { + auto sourceLayerValue = objectMember(value, "source-layer"); + if (sourceLayerValue) { + optional sourceLayer = toString(*sourceLayerValue); + if (!sourceLayer) { + return false; + } + layer->setSourceLayer(*sourceLayer); + } + + auto filterValue = objectMember(value, "filter"); + if (filterValue) { + style::conversion::Error error; + optional filter = style::conversion::convert(*filterValue, error); + if (!filter) { + return false; + } + layer->setFilter(*filter); + } + + return true; +} + +} // namespace mbgl diff --git a/src/mbgl/layermanager/layer_manager.cpp b/src/mbgl/layermanager/layer_manager.cpp new file mode 100644 index 0000000000..8f42bc9218 --- /dev/null +++ b/src/mbgl/layermanager/layer_manager.cpp @@ -0,0 +1,31 @@ +#include + +#include +#include +#include +#include +#include + +namespace mbgl { + +std::unique_ptr LayerManager::createLayer( + const std::string& type, const std::string& id, + const style::conversion::Convertible& value, style::conversion::Error& error) noexcept { + if (LayerFactory* factory = getFactory(type)) { + auto layer = factory->createLayer(id, value); + if (!layer) { + error.message = "Error parsing a layer of type: " + type; + } + return layer; + } + error.message = "Unsupported layer type: " + type; + return nullptr; +} + +std::unique_ptr LayerManager::createRenderLayer(Immutable impl) noexcept { + LayerFactory* factory = getFactory(impl->getTypeInfo()); + assert(factory); + return factory->createRenderLayer(std::move(impl)); +} + +} // namespace mbgl diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index b8d5186729..c3bebae837 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index 9976c1b6dc..6b73e568fc 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -1,4 +1,6 @@ #include + +#include #include #include #include diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index 7d1653cdbd..c844d1f87c 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp index b551f1bfb2..e8f94a1064 100644 --- a/src/mbgl/style/conversion/layer.cpp +++ b/src/mbgl/style/conversion/layer.cpp @@ -3,6 +3,8 @@ #include #include +#include + namespace mbgl { namespace style { namespace conversion { diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index abe6444701..328cd47555 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -110,63 +110,4 @@ const LayerTypeInfo* Layer::getTypeInfo() const noexcept { } } // namespace style - -optional LayerFactory::getSource(const style::conversion::Convertible& value) const noexcept { - auto sourceValue = objectMember(value, "source"); - if (!sourceValue) { - return nullopt; - } - - optional source = toString(*sourceValue); - if (!source) { - return nullopt; - } - - return source; -} - -bool LayerFactory::initSourceLayerAndFilter(style::Layer* layer, const style::conversion::Convertible& value) const noexcept { - auto sourceLayerValue = objectMember(value, "source-layer"); - if (sourceLayerValue) { - optional sourceLayer = toString(*sourceLayerValue); - if (!sourceLayer) { - return false; - } - layer->setSourceLayer(*sourceLayer); - } - - auto filterValue = objectMember(value, "filter"); - if (filterValue) { - style::conversion::Error error; - optional filter = style::conversion::convert(*filterValue, error); - if (!filter) { - return false; - } - layer->setFilter(*filter); - } - - return true; -} - -std::unique_ptr LayerManager::createLayer( - const std::string& type, const std::string& id, - const style::conversion::Convertible& value, style::conversion::Error& error) noexcept { - if (LayerFactory* factory = getFactory(type)) { - auto layer = factory->createLayer(id, value); - if (!layer) { - error.message = "Error parsing a layer of type: " + type; - } - return layer; - } - error.message = "Unsupported layer type: " + type; - return nullptr; -} - -std::unique_ptr LayerManager::createRenderLayer(Immutable impl) noexcept { - LayerFactory* factory = getFactory(impl->getTypeInfo()); - assert(factory); - return factory->createRenderLayer(std::move(impl)); -} - - } // namespace mbgl diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index 9e4c045ce5..854bfcf1a4 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/test/renderer/group_by_layout.test.cpp b/test/renderer/group_by_layout.test.cpp index deaa30b9f4..d1a7a0bf5f 100644 --- a/test/renderer/group_by_layout.test.cpp +++ b/test/renderer/group_by_layout.test.cpp @@ -1,5 +1,6 @@ #include +#include #include #include #include -- cgit v1.2.1