diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-30 15:56:35 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2017-03-31 13:26:27 -0700 |
commit | d7a55a4be1300d79da0c63aefdf5d48d0c45a404 (patch) | |
tree | e50f42cdf87fa59c0f71d15892652c0e3424703a /src/mbgl | |
parent | 939526bac4aff734be4e6382b64c43214eb0bc9b (diff) | |
download | qtlocation-mapboxgl-d7a55a4be1300d79da0c63aefdf5d48d0c45a404.tar.gz |
[core] Introduce a fully-evaluated tuple type for layout properties
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/layout/symbol_instance.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_instance.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/layout/symbol_layout.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/line_bucket.hpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/renderer/symbol_bucket.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_impl.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layers/symbol_layer_impl.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/style/layout_property.hpp | 66 | ||||
-rw-r--r-- | src/mbgl/text/quads.cpp | 4 | ||||
-rw-r--r-- | src/mbgl/text/quads.hpp | 4 |
11 files changed, 69 insertions, 27 deletions
diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp index 8bdc528bbb..2264bfdc92 100644 --- a/src/mbgl/layout/symbol_instance.cpp +++ b/src/mbgl/layout/symbol_instance.cpp @@ -9,7 +9,7 @@ SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line, const std::pair<Shaping, Shaping>& shapedTextOrientations, const PositionedIcon& shapedIcon, - const SymbolLayoutProperties::Evaluated& layout, + const SymbolLayoutProperties::PossiblyEvaluated& layout, const bool addToBuffers, const uint32_t index_, const float textBoxScale, diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp index 70ebfeefa2..0980eb492b 100644 --- a/src/mbgl/layout/symbol_instance.hpp +++ b/src/mbgl/layout/symbol_instance.hpp @@ -16,7 +16,7 @@ public: const GeometryCoordinates& line, const std::pair<Shaping, Shaping>& shapedTextOrientations, const PositionedIcon& shapedIcon, - const style::SymbolLayoutProperties::Evaluated&, + const style::SymbolLayoutProperties::PossiblyEvaluated&, const bool inside, const uint32_t index, const float textBoxScale, diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 5b14090d97..bd72d3cd3f 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -78,7 +78,7 @@ private: const float zoom; const MapMode mode; - style::SymbolLayoutProperties::Evaluated layout; + style::SymbolLayoutProperties::PossiblyEvaluated layout; float textMaxSize; SpriteAtlas& spriteAtlas; diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 8d1ff2a3f2..5a126ba18e 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -29,7 +29,7 @@ public: void upload(gl::Context&) override; void render(Painter&, PaintParameters&, const style::Layer&, const RenderTile&) override; - style::LineLayoutProperties::Evaluated layout; + style::LineLayoutProperties::PossiblyEvaluated layout; gl::VertexVector<LineLayoutVertex> vertices; gl::IndexVector<gl::Triangles> triangles; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 1f2c81bc1c..b046571740 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -8,7 +8,7 @@ namespace mbgl { using namespace style; -SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::Evaluated layout_, +SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layout_, const std::map<std::string, std::pair< style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>& layerPaintProperties, float zoom, diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index d5141d2d96..7a498ab17d 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -16,7 +16,7 @@ namespace mbgl { class SymbolBucket : public Bucket { public: - SymbolBucket(style::SymbolLayoutProperties::Evaluated, + SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated, const std::map<std::string, std::pair<style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>&, float zoom, bool sdfIcons, @@ -29,7 +29,7 @@ public: bool hasIconData() const; bool hasCollisionBoxData() const; - const style::SymbolLayoutProperties::Evaluated layout; + const style::SymbolLayoutProperties::PossiblyEvaluated layout; const bool sdfIcons; const bool iconsNeedLinear; diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index ff59b14d65..e4557c953f 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -68,7 +68,7 @@ TextPaintProperties::Evaluated SymbolLayer::Impl::textPaintProperties() const { } -SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { return SymbolPropertyValues { layout_.get<IconRotationAlignment>(), // icon-pitch-alignment is not yet implemented; inherit the rotation alignment layout_.get<IconRotationAlignment>(), @@ -83,7 +83,7 @@ SymbolPropertyValues SymbolLayer::Impl::iconPropertyValues(const SymbolLayoutPro }; } -SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::Evaluated& layout_) const { +SymbolPropertyValues SymbolLayer::Impl::textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated& layout_) const { return SymbolPropertyValues { layout_.get<TextPitchAlignment>(), layout_.get<TextRotationAlignment>(), diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index 1e9f05e4c7..0c4b74e833 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -72,8 +72,8 @@ public: IconPaintProperties::Evaluated iconPaintProperties() const; TextPaintProperties::Evaluated textPaintProperties() const; - SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::Evaluated&) const; - SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::Evaluated&) const; + SymbolPropertyValues iconPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; + SymbolPropertyValues textPropertyValues(const SymbolLayoutProperties::PossiblyEvaluated&) const; SymbolLayoutProperties layout; SymbolPaintProperties paint; diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index 25cff4b92d..624ff2bdc5 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -16,7 +16,7 @@ class LayoutProperty { public: using UnevaluatedType = PropertyValue<T>; using EvaluatorType = PropertyEvaluator<T>; - using EvaluatedType = T; + using PossiblyEvaluatedType = T; using Type = T; }; @@ -25,7 +25,7 @@ class DataDrivenLayoutProperty { public: using UnevaluatedType = DataDrivenPropertyValue<T>; using EvaluatorType = DataDrivenPropertyEvaluator<T>; - using EvaluatedType = PossiblyEvaluatedPropertyValue<T>; + using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>; using Type = T; }; @@ -33,23 +33,65 @@ template <class... Ps> class LayoutProperties { public: using Properties = TypeList<Ps...>; - using EvaluatedTypes = TypeList<typename Ps::EvaluatedType...>; - using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>; template <class TypeList> using Tuple = IndexedTuple<Properties, TypeList>; + /* + For layout properties we implement a two step evaluation process: if you have a zoom level, + you can evaluate a set of unevaluated property values, producing a set of possibly evaluated + values, where non-data-driven property values have been fully evaluated, and data-driven values + have not. + + Once you also have a particular feature, you can evaluate that set of possibly evaluated values + fully, producing a set of fully evaluated values. + + This is in theory maximally efficient in terms of avoiding repeated evaluation of camera + functions, though it's more of a historical accident that a purposeful optimization. + */ + + using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>; + using PossiblyEvaluatedTypes = TypeList<typename Ps::PossiblyEvaluatedType...>; + using EvaluatedTypes = TypeList<typename Ps::Type...>; + class Evaluated : public Tuple<EvaluatedTypes> { public: using Tuple<EvaluatedTypes>::Tuple; + }; + + class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> { + public: + using Tuple<PossiblyEvaluatedTypes>::Tuple; + + template <class T> + static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) { + return t; + } + + template <class T> + static T evaluate(float z, const GeometryTileFeature& feature, + const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) { + return v.match( + [&] (const T& t) { + return t; + }, + [&] (const SourceFunction<T>& t) { + return t.evaluate(feature, defaultValue); + }, + [&] (const CompositeFunction<T>& t) { + return t.evaluate(z, feature, defaultValue); + }); + } template <class P> - typename P::Type evaluate(float z, const GeometryTileFeature& feature) const { - using T = typename P::Type; - return this->template get<P>().match( - [&] (const T& t) { return t; }, - [&] (const SourceFunction<T>& t) { return t.evaluate(feature, P::defaultValue()); }, - [&] (const CompositeFunction<T>& t) { return t.evaluate(z, feature, P::defaultValue()); }); + auto evaluate(float z, const GeometryTileFeature& feature) const { + return evaluate(z, feature, this->template get<P>(), P::defaultValue()); + } + + Evaluated evaluate(float z, const GeometryTileFeature& feature) const { + return Evaluated { + evaluate<Ps>(z, feature)... + }; } }; @@ -65,8 +107,8 @@ public: .evaluate(Evaluator(parameters, P::defaultValue())); } - Evaluated evaluate(const PropertyEvaluationParameters& parameters) const { - return Evaluated { + PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const { + return PossiblyEvaluated { evaluate<Ps>(parameters)... }; } diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index b13a6a71e5..d3edafa1a0 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -18,7 +18,7 @@ const float globalMinScale = 0.5f; // underscale by 1 zoom level SymbolQuad getIconQuad(const Anchor& anchor, const PositionedIcon& shapedIcon, const GeometryCoordinates& line, - const SymbolLayoutProperties::Evaluated& layout, + const SymbolLayoutProperties::PossiblyEvaluated& layout, const style::SymbolPlacementType placement, const Shaping& shapedText) { auto image = *(shapedIcon.image); @@ -292,7 +292,7 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, const float boxScale, const GeometryCoordinates& line, - const SymbolLayoutProperties::Evaluated& layout, + const SymbolLayoutProperties::PossiblyEvaluated& layout, const style::SymbolPlacementType placement, const GlyphPositions& face) { const float textRotate = layout.get<TextRotate>() * util::DEG2RAD; diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index f1529d8829..7e3b5ca405 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -54,7 +54,7 @@ typedef std::vector<SymbolQuad> SymbolQuads; SymbolQuad getIconQuad(const Anchor& anchor, const PositionedIcon& shapedIcon, const GeometryCoordinates& line, - const style::SymbolLayoutProperties::Evaluated&, + const style::SymbolLayoutProperties::PossiblyEvaluated&, style::SymbolPlacementType placement, const Shaping& shapedText); @@ -62,7 +62,7 @@ SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, const float boxScale, const GeometryCoordinates& line, - const style::SymbolLayoutProperties::Evaluated&, + const style::SymbolLayoutProperties::PossiblyEvaluated&, style::SymbolPlacementType placement, const GlyphPositions& face); |