diff options
author | Molly Lloyd <molly@mapbox.com> | 2018-08-29 17:27:40 -0700 |
---|---|---|
committer | Molly Lloyd <mollymerp@users.noreply.github.com> | 2018-08-31 13:08:47 -0700 |
commit | d197fc7d8daf06cc2efc35a34fb45d86ea64d65b (patch) | |
tree | 365b09122531ef51b253417191368c14de171eb4 /src/mbgl/layout | |
parent | f7dcd5d7416f076c3553ccec9844fa77fe0e0ea5 (diff) | |
download | qtlocation-mapboxgl-d197fc7d8daf06cc2efc35a34fb45d86ea64d65b.tar.gz |
[core] simplify dependency layout process and refactor data structures
Diffstat (limited to 'src/mbgl/layout')
-rw-r--r-- | src/mbgl/layout/layout.hpp | 36 | ||||
-rw-r--r-- | src/mbgl/layout/pattern_layout.hpp | 20 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.cpp | 23 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.hpp | 16 |
4 files changed, 78 insertions, 17 deletions
diff --git a/src/mbgl/layout/layout.hpp b/src/mbgl/layout/layout.hpp new file mode 100644 index 0000000000..de2d28728f --- /dev/null +++ b/src/mbgl/layout/layout.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include <mbgl/style/layer_type.hpp> +#include <mbgl/renderer/image_atlas.hpp> +#include <mbgl/text/glyph_atlas.hpp> +#include <memory> + +namespace mbgl { + +class Bucket; +class BucketParameters; +class RenderLayer; +class FeatureIndex; + +class Layout { +public: + Layout() = default; + virtual ~Layout() = default; + + virtual void createBucket(const ImagePositions&, + std::unique_ptr<FeatureIndex>&, + std::unordered_map<std::string, std::shared_ptr<Bucket>>&, + const bool, + const bool) = 0; + + virtual void prepareSymbols(const GlyphMap&, const GlyphPositions&, + const ImageMap&, const ImagePositions&) {}; + + virtual bool hasSymbolInstances() const { + return true; + }; + + virtual bool hasDependencies() const = 0; +}; + +} // namespace mbgl diff --git a/src/mbgl/layout/pattern_layout.hpp b/src/mbgl/layout/pattern_layout.hpp index 9f4964ca6b..0ffac36b75 100644 --- a/src/mbgl/layout/pattern_layout.hpp +++ b/src/mbgl/layout/pattern_layout.hpp @@ -1,4 +1,5 @@ #pragma once +#include <mbgl/layout/layout.hpp> #include <mbgl/renderer/bucket_parameters.hpp> #include <mbgl/geometry/feature_index.hpp> #include <mbgl/renderer/render_layer.hpp> @@ -22,13 +23,14 @@ public: }; template <class B> -class PatternLayout { +class PatternLayout : public Layout { public: PatternLayout(const BucketParameters& parameters, const std::vector<const RenderLayer*>& layers, std::unique_ptr<GeometryTileLayer> sourceLayer_, ImageDependencies& patternDependencies) - : bucketLeaderID(layers.at(0)->getID()), + : Layout(), + bucketLeaderID(layers.at(0)->getID()), sourceLayer(std::move(sourceLayer_)), zoom(parameters.tileID.overscaledZ), overscaling(parameters.tileID.overscaleFactor()), @@ -90,12 +92,14 @@ public: } }; - bool pattern() { + ~PatternLayout() final = default; + + bool hasDependencies() const override { return hasPattern; } - std::unique_ptr<B> createBucket(const ImagePositions& patternPositions, std::unique_ptr<FeatureIndex>& featureIndex) { - auto bucket = std::make_unique<B>(layout, layerPaintProperties, zoom, overscaling); + void createBucket(const ImagePositions& patternPositions, std::unique_ptr<FeatureIndex>& featureIndex, std::unordered_map<std::string, std::shared_ptr<Bucket>>& buckets, const bool, const bool) override { + auto bucket = std::make_shared<B>(layout, layerPaintProperties, zoom, overscaling); for (auto & patternFeature : features) { const auto i = patternFeature.i; std::unique_ptr<GeometryTileFeature> feature = std::move(patternFeature.feature); @@ -105,7 +109,11 @@ public: bucket->addFeature(*feature, geometries, patternPositions, patterns); featureIndex->insert(geometries, i, sourceLayerID, groupID); } - return bucket; + if (bucket->hasData()) { + for (const auto& pair : layerPaintProperties) { + buckets.emplace(pair.first, bucket); + } + } }; std::map<std::string, typename B::PossiblyEvaluatedPaintProperties> layerPaintProperties; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index fd4dd2bedd..344a76bbe9 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -1,3 +1,4 @@ +#include <mbgl/layout/layout.hpp> #include <mbgl/layout/symbol_layout.hpp> #include <mbgl/layout/merge_lines.hpp> #include <mbgl/layout/clip_lines.hpp> @@ -40,7 +41,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, std::unique_ptr<GeometryTileLayer> sourceLayer_, ImageDependencies& imageDependencies, GlyphDependencies& glyphDependencies) - : bucketLeaderID(layers.at(0)->getID()), + : Layout(), + bucketLeaderID(layers.at(0)->getID()), sourceLayer(std::move(sourceLayer_)), overscaling(parameters.tileID.overscaleFactor()), zoom(parameters.tileID.overscaledZ), @@ -149,11 +151,15 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, } } +bool SymbolLayout::hasDependencies() const { + return features.size() != 0; +} + bool SymbolLayout::hasSymbolInstances() const { return !symbolInstances.empty(); } -void SymbolLayout::prepare(const GlyphMap& glyphMap, const GlyphPositions& glyphPositions, +void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap, const GlyphPositions& glyphPositions, const ImageMap& imageMap, const ImagePositions& imagePositions) { const bool textAlongLine = layout.get<TextRotationAlignment>() == AlignmentType::Map && layout.get<SymbolPlacement>() != SymbolPlacementType::Point; @@ -394,11 +400,11 @@ std::vector<float> CalculateTileDistances(const GeometryCoordinates& line, const return tileDistances; } -std::unique_ptr<SymbolBucket> SymbolLayout::place(const bool showCollisionBoxes) { +void SymbolLayout::createBucket(const ImagePositions&, std::unique_ptr<FeatureIndex>&, std::unordered_map<std::string, std::shared_ptr<Bucket>>& buckets, const bool firstLoad, const bool showCollisionBoxes) { const bool mayOverlap = layout.get<TextAllowOverlap>() || layout.get<IconAllowOverlap>() || layout.get<TextIgnorePlacement>() || layout.get<IconIgnorePlacement>(); - auto bucket = std::make_unique<SymbolBucket>(layout, layerPaintProperties, textSize, iconSize, zoom, sdfIcons, iconsNeedLinear, mayOverlap, bucketLeaderID, std::move(symbolInstances)); + auto bucket = std::make_shared<SymbolBucket>(layout, layerPaintProperties, textSize, iconSize, zoom, sdfIcons, iconsNeedLinear, mayOverlap, bucketLeaderID, std::move(symbolInstances)); for (SymbolInstance &symbolInstance : bucket->symbolInstances) { @@ -469,8 +475,15 @@ std::unique_ptr<SymbolBucket> SymbolLayout::place(const bool showCollisionBoxes) if (showCollisionBoxes) { addToDebugBuffers(*bucket); } + if (bucket->hasData()){ + for (const auto& pair : layerPaintProperties) { + if (!firstLoad) { + bucket->justReloaded = true; + } + buckets.emplace(pair.first, bucket); + } + } - return bucket; } template <typename Buffer> diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 43b577859f..b866703e6c 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -1,5 +1,6 @@ #pragma once +#include <mbgl/layout/layout.hpp> #include <mbgl/map/mode.hpp> #include <mbgl/style/layers/symbol_layer_properties.hpp> #include <mbgl/layout/symbol_feature.hpp> @@ -25,20 +26,23 @@ namespace style { class Filter; } // namespace style -class SymbolLayout { +class SymbolLayout : public Layout { public: SymbolLayout(const BucketParameters&, const std::vector<const RenderLayer*>&, std::unique_ptr<GeometryTileLayer>, ImageDependencies&, GlyphDependencies&); + + ~SymbolLayout() final = default; - void prepare(const GlyphMap&, const GlyphPositions&, - const ImageMap&, const ImagePositions&); + void prepareSymbols(const GlyphMap&, const GlyphPositions&, + const ImageMap&, const ImagePositions&) override; - std::unique_ptr<SymbolBucket> place(const bool showCollisionBoxes); + void createBucket(const ImagePositions&, std::unique_ptr<FeatureIndex>&, std::unordered_map<std::string, std::shared_ptr<Bucket>>&, const bool firstLoad, const bool showCollisionBoxes) override; - bool hasSymbolInstances() const; + bool hasSymbolInstances() const override; + bool hasDependencies() const override; std::map<std::string, std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>> layerPaintProperties; @@ -81,7 +85,7 @@ private: bool sdfIcons = false; bool iconsNeedLinear = false; - + style::TextSize::UnevaluatedType textSize; style::IconSize::UnevaluatedType iconSize; |