From 24468956fc49ba1495e4dba7363a15b6f07f25e7 Mon Sep 17 00:00:00 2001 From: Michael Muesch Date: Thu, 10 Jan 2019 15:25:19 -0500 Subject: Ability to disable any layer using pre-processing flags. --- .../android/src/style/layers/layer_manager.cpp | 46 +++++++++++++++++++++- platform/darwin/src/MGLStyleLayerManager.mm | 44 +++++++++++++++++++++ .../src/mbgl/layermanager/layer_manager.cpp | 28 ++++++++++++- 3 files changed, 115 insertions(+), 3 deletions(-) diff --git a/platform/android/src/style/layers/layer_manager.cpp b/platform/android/src/style/layers/layer_manager.cpp index 2f023bd3ae..7822502cfa 100644 --- a/platform/android/src/style/layers/layer_manager.cpp +++ b/platform/android/src/style/layers/layer_manager.cpp @@ -23,16 +23,56 @@ namespace mbgl { namespace android { LayerManagerAndroid::LayerManagerAndroid() { +#if defined(MBGL_LAYER_FILL_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_FILL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_LINE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_LINE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_CIRCLE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_CIRCLE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_SYMBOL_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_RASTER_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_RASTER_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_BACKGROUND_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_BACKGROUND_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_HILLSHADE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_HILLSHADE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_HEATMAP_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_HEATMAP_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_CUSTOM_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) addLayerType(std::make_unique()); +#endif } LayerManagerAndroid::~LayerManagerAndroid() = default; @@ -111,7 +151,7 @@ LayerFactory* LayerManagerAndroid::getFactory(const mbgl::style::LayerTypeInfo* return nullptr; } -// static +// static LayerManagerAndroid* LayerManagerAndroid::get() noexcept { static LayerManagerAndroid impl; return &impl; @@ -123,6 +163,10 @@ LayerManager* LayerManager::get() noexcept { return android::LayerManagerAndroid::get(); } +#if defined(MBGL_LAYER_LINE_DISABLE_ALL) || defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) || defined(MBGL_LAYER_FILL_DISABLE_ALL) +const bool LayerManager::annotationsEnabled = false; +#else const bool LayerManager::annotationsEnabled = true; +#endif } // namespace mbgl diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm index a05e24bd9d..c0b72e4451 100644 --- a/platform/darwin/src/MGLStyleLayerManager.mm +++ b/platform/darwin/src/MGLStyleLayerManager.mm @@ -16,16 +16,56 @@ namespace mbgl { LayerManagerDarwin::LayerManagerDarwin() { +#if defined(MBGL_LAYER_FILL_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_FILL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_LINE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_LINE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_CIRCLE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_CIRCLE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_SYMBOL_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_RASTER_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_RASTER_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_BACKGROUND_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_BACKGROUND_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_HILLSHADE_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_HILLSHADE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_HEATMAP_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_HEATMAP_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if defined(MBGL_LAYER_CUSTOM_DISABLE_RUNTIME) + addLayerTypeCoreOnly(std::make_unique()); +#elif !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) addLayerType(std::make_unique()); +#endif } LayerManagerDarwin::~LayerManagerDarwin() = default; @@ -98,6 +138,10 @@ LayerManager* LayerManager::get() noexcept { return LayerManagerDarwin::get(); } +#if defined(MBGL_LAYER_LINE_DISABLE_ALL) || defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) || defined(MBGL_LAYER_FILL_DISABLE_ALL) +const bool LayerManager::annotationsEnabled = false; +#else const bool LayerManager::annotationsEnabled = true; +#endif } // namespace mbgl diff --git a/platform/default/src/mbgl/layermanager/layer_manager.cpp b/platform/default/src/mbgl/layermanager/layer_manager.cpp index 05d0f4d1ae..b8abf794fc 100644 --- a/platform/default/src/mbgl/layermanager/layer_manager.cpp +++ b/platform/default/src/mbgl/layermanager/layer_manager.cpp @@ -16,7 +16,7 @@ #include namespace mbgl { - + class LayerManagerDefault final : public LayerManager { public: LayerManagerDefault(); @@ -32,16 +32,36 @@ private: }; LayerManagerDefault::LayerManagerDefault() { +#if !defined(MBGL_LAYER_FILL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_LINE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_CIRCLE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_RASTER_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_BACKGROUND_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_HILLSHADE_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_FILL_EXTRUSION_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_HEATMAP_DISABLE_ALL) addLayerType(std::make_unique()); +#endif +#if !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) addLayerType(std::make_unique()); +#endif } void LayerManagerDefault::addLayerType(std::unique_ptr factory) { @@ -68,12 +88,16 @@ LayerFactory* LayerManagerDefault::getFactory(const std::string& type) noexcept return (search != typeToFactory.end()) ? search->second : nullptr; } -// static +// static LayerManager* LayerManager::get() noexcept { static LayerManagerDefault instance; return &instance; } +#if defined(MBGL_LAYER_LINE_DISABLE_ALL) || defined(MBGL_LAYER_SYMBOL_DISABLE_ALL) || defined(MBGL_LAYER_FILL_DISABLE_ALL) +const bool LayerManager::annotationsEnabled = false; +#else const bool LayerManager::annotationsEnabled = true; +#endif } // namespace mbgl -- cgit v1.2.1