From da4d735e2c465195e0fb9531ce9d4d7c5c9e6503 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 10 May 2017 11:34:00 -0700 Subject: [PATCH] [core] Unify {Paint,Layout,Light}Properties --- cmake/core-files.cmake | 3 +- cmake/test-files.cmake | 2 +- .../mbgl/style/data_driven_property_value.hpp | 2 +- include/mbgl/style/property_value.hpp | 2 +- src/mbgl/layout/symbol_layout.cpp | 4 +- src/mbgl/layout/symbol_layout.hpp | 2 +- src/mbgl/programs/collision_box_program.hpp | 3 +- src/mbgl/programs/debug_program.hpp | 3 +- .../programs/extrusion_texture_program.hpp | 3 +- src/mbgl/programs/line_program.cpp | 8 +- src/mbgl/programs/line_program.hpp | 6 +- src/mbgl/programs/program.hpp | 2 +- src/mbgl/programs/symbol_program.hpp | 2 +- src/mbgl/renderer/buckets/line_bucket.cpp | 2 +- src/mbgl/renderer/buckets/line_bucket.hpp | 2 +- src/mbgl/renderer/buckets/symbol_bucket.cpp | 3 +- src/mbgl/renderer/buckets/symbol_bucket.hpp | 2 +- .../layers/render_background_layer.hpp | 2 +- .../renderer/layers/render_circle_layer.hpp | 2 +- .../layers/render_fill_extrusion_layer.hpp | 2 +- .../renderer/layers/render_fill_layer.hpp | 2 +- .../renderer/layers/render_line_layer.hpp | 2 +- .../renderer/layers/render_raster_layer.hpp | 2 +- .../renderer/layers/render_symbol_layer.cpp | 8 +- .../renderer/layers/render_symbol_layer.hpp | 10 +- src/mbgl/renderer/paint_property_binder.hpp | 1 + src/mbgl/renderer/painter.cpp | 2 +- .../renderer/painters/painter_background.cpp | 4 +- src/mbgl/renderer/painters/painter_circle.cpp | 2 +- .../renderer/painters/painter_clipping.cpp | 2 +- src/mbgl/renderer/painters/painter_debug.cpp | 2 +- src/mbgl/renderer/painters/painter_fill.cpp | 2 +- .../painters/painter_fill_extrusion.cpp | 2 +- src/mbgl/renderer/painters/painter_line.cpp | 2 +- src/mbgl/renderer/painters/painter_raster.cpp | 2 +- src/mbgl/renderer/painters/painter_symbol.cpp | 2 +- src/mbgl/renderer/render_light.cpp | 4 +- src/mbgl/renderer/render_light.hpp | 70 +---- src/mbgl/renderer/transitioning_property.hpp | 75 ----- src/mbgl/style/conversion/stringify.hpp | 9 +- src/mbgl/style/layers/background_layer.cpp | 1 - .../layers/background_layer_properties.hpp | 3 +- src/mbgl/style/layers/circle_layer.cpp | 1 - .../style/layers/circle_layer_properties.hpp | 3 +- .../style/layers/fill_extrusion_layer.cpp | 1 - .../fill_extrusion_layer_properties.hpp | 3 +- src/mbgl/style/layers/fill_layer.cpp | 1 - .../style/layers/fill_layer_properties.hpp | 3 +- src/mbgl/style/layers/layer.cpp.ejs | 7 +- .../style/layers/layer_properties.hpp.ejs | 5 +- src/mbgl/style/layers/line_layer.cpp | 19 +- src/mbgl/style/layers/line_layer_impl.hpp | 2 +- .../style/layers/line_layer_properties.hpp | 5 +- src/mbgl/style/layers/raster_layer.cpp | 1 - .../style/layers/raster_layer_properties.hpp | 3 +- src/mbgl/style/layers/symbol_layer.cpp | 139 +++++---- src/mbgl/style/layers/symbol_layer_impl.hpp | 2 +- .../style/layers/symbol_layer_properties.hpp | 5 +- src/mbgl/style/layout_property.hpp | 95 +------ src/mbgl/style/light_impl.hpp | 16 +- src/mbgl/style/paint_property.hpp | 161 +---------- src/mbgl/style/properties.hpp | 268 ++++++++++++++++++ src/mbgl/style/style.cpp | 2 +- test/style/conversion/stringify.test.cpp | 15 +- ..._property.test.cpp => properties.test.cpp} | 43 +-- test/tile/vector_tile.test.cpp | 2 +- 66 files changed, 493 insertions(+), 575 deletions(-) delete mode 100644 src/mbgl/renderer/transitioning_property.hpp create mode 100644 src/mbgl/style/properties.hpp rename test/style/{paint_property.test.cpp => properties.test.cpp} (67%) diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index a19106135..f066f28e1 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -192,7 +192,6 @@ set(MBGL_CORE_FILES src/mbgl/renderer/tile_parameters.hpp src/mbgl/renderer/tile_pyramid.cpp src/mbgl/renderer/tile_pyramid.hpp - src/mbgl/renderer/transitioning_property.hpp src/mbgl/renderer/update_parameters.hpp # renderer/buckets @@ -343,11 +342,11 @@ set(MBGL_CORE_FILES src/mbgl/style/light_impl.cpp src/mbgl/style/light_impl.hpp src/mbgl/style/light_observer.hpp - src/mbgl/style/light_properties.hpp src/mbgl/style/observer.hpp src/mbgl/style/paint_property.hpp src/mbgl/style/parser.cpp src/mbgl/style/parser.hpp + src/mbgl/style/properties.hpp src/mbgl/style/rapidjson_conversion.hpp src/mbgl/style/source.cpp src/mbgl/style/source_impl.cpp diff --git a/cmake/test-files.cmake b/cmake/test-files.cmake index 5eb9d8d9f..9415add57 100644 --- a/cmake/test-files.cmake +++ b/cmake/test-files.cmake @@ -97,7 +97,7 @@ set(MBGL_TEST_FILES test/style/function/source_function.test.cpp # style - test/style/paint_property.test.cpp + test/style/properties.test.cpp test/style/source.test.cpp test/style/style.test.cpp test/style/style_image.test.cpp diff --git a/include/mbgl/style/data_driven_property_value.hpp b/include/mbgl/style/data_driven_property_value.hpp index 5acf80084..12a369abb 100644 --- a/include/mbgl/style/data_driven_property_value.hpp +++ b/include/mbgl/style/data_driven_property_value.hpp @@ -56,7 +56,7 @@ public: } template - auto evaluate(const Evaluator& evaluator) const { + auto evaluate(const Evaluator& evaluator, TimePoint = {}) const { return Value::visit(value, evaluator); } }; diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp index 8bec7388e..5259eecf2 100644 --- a/include/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -35,7 +35,7 @@ public: const CameraFunction& asCameraFunction() const { return value.template get>(); } template - auto evaluate(const Evaluator& evaluator) const { + auto evaluate(const Evaluator& evaluator, TimePoint = {}) const { return Value::visit(value, evaluator); } }; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 5142584c9..0e8b2fa63 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -50,8 +50,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters, mode(parameters.mode), tileSize(util::tileSize * overscaling), tilePixelRatio(float(util::EXTENT) / tileSize), - textSize(layers.at(0)->as()->impl().layout.unevaluated.get()), - iconSize(layers.at(0)->as()->impl().layout.unevaluated.get()) + textSize(layers.at(0)->as()->impl().layout.get()), + iconSize(layers.at(0)->as()->impl().layout.get()) { const SymbolLayer::Impl& leader = layers.at(0)->as()->impl(); diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 7d19aba67..7bdcf52f9 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -47,7 +47,7 @@ public: State state = Pending; std::map> layerPaintProperties; + std::pair> layerPaintProperties; private: void addFeature(const size_t, diff --git a/src/mbgl/programs/collision_box_program.hpp b/src/mbgl/programs/collision_box_program.hpp index 89b69484f..160fd4281 100644 --- a/src/mbgl/programs/collision_box_program.hpp +++ b/src/mbgl/programs/collision_box_program.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -29,7 +30,7 @@ class CollisionBoxProgram : public Program< uniforms::u_scale, uniforms::u_zoom, uniforms::u_maxzoom>, - style::PaintProperties<>> + style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/debug_program.hpp b/src/mbgl/programs/debug_program.hpp index de1666b4a..7a6d075cd 100644 --- a/src/mbgl/programs/debug_program.hpp +++ b/src/mbgl/programs/debug_program.hpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace mbgl { @@ -15,7 +16,7 @@ class DebugProgram : public Program< gl::Uniforms< uniforms::u_matrix, uniforms::u_color>, - style::PaintProperties<>> + style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/extrusion_texture_program.hpp b/src/mbgl/programs/extrusion_texture_program.hpp index 1519aa095..bd8220888 100644 --- a/src/mbgl/programs/extrusion_texture_program.hpp +++ b/src/mbgl/programs/extrusion_texture_program.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace mbgl { @@ -17,7 +18,7 @@ class ExtrusionTextureProgram : public Program< uniforms::u_world, uniforms::u_image, uniforms::u_opacity>, - style::PaintProperties<>> { + style::Properties<>> { public: using Program::Program; diff --git a/src/mbgl/programs/line_program.cpp b/src/mbgl/programs/line_program.cpp index d9778ba7c..e7e5c58e4 100644 --- a/src/mbgl/programs/line_program.cpp +++ b/src/mbgl/programs/line_program.cpp @@ -13,7 +13,7 @@ using namespace style; static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size"); template -Values makeValues(const LinePaintProperties::Evaluated& properties, +Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array& pixelsToGLUnits, @@ -33,7 +33,7 @@ Values makeValues(const LinePaintProperties::Evaluated& properties, } LineProgram::UniformValues -LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties, +LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array& pixelsToGLUnits) { @@ -46,7 +46,7 @@ LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties, } LineSDFProgram::UniformValues -LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties, +LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, float pixelRatio, const RenderTile& tile, const TransformState& state, @@ -84,7 +84,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties, } LinePatternProgram::UniformValues -LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properties, +LinePatternProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties, const RenderTile& tile, const TransformState& state, const std::array& pixelsToGLUnits, diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp index b2e55a4f3..9ad3882e7 100644 --- a/src/mbgl/programs/line_program.hpp +++ b/src/mbgl/programs/line_program.hpp @@ -91,7 +91,7 @@ public: */ static const int8_t extrudeScale = 63; - static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, + static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, const RenderTile&, const TransformState&, const std::array& pixelsToGLUnits); @@ -119,7 +119,7 @@ class LinePatternProgram : public Program< public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, + static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, const RenderTile&, const TransformState&, const std::array& pixelsToGLUnits, @@ -148,7 +148,7 @@ class LineSDFProgram : public Program< public: using Program::Program; - static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&, + static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&, float pixelRatio, const RenderTile&, const TransformState&, diff --git a/src/mbgl/programs/program.hpp b/src/mbgl/programs/program.hpp index 7eec15e75..a5db5cf8d 100644 --- a/src/mbgl/programs/program.hpp +++ b/src/mbgl/programs/program.hpp @@ -53,7 +53,7 @@ public: const gl::IndexBuffer& indexBuffer, const gl::SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, - const typename PaintProperties::Evaluated& currentProperties, + const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom) { program.draw( context, diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index ec68dc209..9eaa14095 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -365,7 +365,7 @@ public: const gl::IndexBuffer& indexBuffer, const gl::SegmentVector& segments, const PaintPropertyBinders& paintPropertyBinders, - const typename PaintProperties::Evaluated& currentProperties, + const typename PaintProperties::PossiblyEvaluated& currentProperties, float currentZoom) { program.draw( context, diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 3c5fa6bc6..ab9cfe937 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -14,7 +14,7 @@ using namespace style; LineBucket::LineBucket(const BucketParameters& parameters, const std::vector& layers, - const style::LineLayoutProperties& layout_) + const style::LineLayoutProperties::Unevaluated& layout_) : layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))), overscaling(parameters.tileID.overscaleFactor()) { for (const auto& layer : layers) { diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index c31954871..34d893595 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -19,7 +19,7 @@ class LineBucket : public Bucket { public: LineBucket(const BucketParameters&, const std::vector&, - const style::LineLayoutProperties&); + const style::LineLayoutProperties::Unevaluated&); void addFeature(const GeometryTileFeature&, const GeometryCollection&) override; diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp index 423161f24..bc4e5f57c 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -10,7 +10,8 @@ using namespace style; SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layout_, const std::map>& layerPaintProperties, + style::IconPaintProperties::PossiblyEvaluated, + style::TextPaintProperties::PossiblyEvaluated>>& layerPaintProperties, const style::DataDrivenPropertyValue& textSize, const style::DataDrivenPropertyValue& iconSize, float zoom, diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index f7e4bcfa2..f30c9cf10 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -18,7 +18,7 @@ namespace mbgl { class SymbolBucket : public Bucket { public: SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated, - const std::map>&, + const std::map>&, const style::DataDrivenPropertyValue& textSize, const style::DataDrivenPropertyValue& iconSize, float zoom, diff --git a/src/mbgl/renderer/layers/render_background_layer.hpp b/src/mbgl/renderer/layers/render_background_layer.hpp index 7eabf4734..c2dfc2736 100644 --- a/src/mbgl/renderer/layers/render_background_layer.hpp +++ b/src/mbgl/renderer/layers/render_background_layer.hpp @@ -19,7 +19,7 @@ public: // Paint properties style::BackgroundPaintProperties::Unevaluated unevaluated; - style::BackgroundPaintProperties::Evaluated evaluated; + style::BackgroundPaintProperties::PossiblyEvaluated evaluated; const style::BackgroundLayer::Impl& impl() const; }; diff --git a/src/mbgl/renderer/layers/render_circle_layer.hpp b/src/mbgl/renderer/layers/render_circle_layer.hpp index 2b517912c..64322487f 100644 --- a/src/mbgl/renderer/layers/render_circle_layer.hpp +++ b/src/mbgl/renderer/layers/render_circle_layer.hpp @@ -26,7 +26,7 @@ public: // Paint properties style::CirclePaintProperties::Unevaluated unevaluated; - style::CirclePaintProperties::Evaluated evaluated; + style::CirclePaintProperties::PossiblyEvaluated evaluated; const style::CircleLayer::Impl& impl() const; }; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp index f6166495c..8bacd3e93 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.hpp @@ -26,7 +26,7 @@ public: // Paint properties style::FillExtrusionPaintProperties::Unevaluated unevaluated; - style::FillExtrusionPaintProperties::Evaluated evaluated; + style::FillExtrusionPaintProperties::PossiblyEvaluated evaluated; const style::FillExtrusionLayer::Impl& impl() const; }; diff --git a/src/mbgl/renderer/layers/render_fill_layer.hpp b/src/mbgl/renderer/layers/render_fill_layer.hpp index d26ca10b4..238cb06aa 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.hpp +++ b/src/mbgl/renderer/layers/render_fill_layer.hpp @@ -26,7 +26,7 @@ public: // Paint properties style::FillPaintProperties::Unevaluated unevaluated; - style::FillPaintProperties::Evaluated evaluated; + style::FillPaintProperties::PossiblyEvaluated evaluated; const style::FillLayer::Impl& impl() const; }; diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index 0276e6a6d..23a78a367 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -26,7 +26,7 @@ public: // Paint properties style::LinePaintProperties::Unevaluated unevaluated; - style::LinePaintProperties::Evaluated evaluated; + style::LinePaintProperties::PossiblyEvaluated evaluated; const style::LineLayer::Impl& impl() const; diff --git a/src/mbgl/renderer/layers/render_raster_layer.hpp b/src/mbgl/renderer/layers/render_raster_layer.hpp index 50c213aa2..8cf62fa0d 100644 --- a/src/mbgl/renderer/layers/render_raster_layer.hpp +++ b/src/mbgl/renderer/layers/render_raster_layer.hpp @@ -19,7 +19,7 @@ public: // Paint properties style::RasterPaintProperties::Unevaluated unevaluated; - style::RasterPaintProperties::Evaluated evaluated; + style::RasterPaintProperties::PossiblyEvaluated evaluated; const style::RasterLayer::Impl& impl() const; }; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 7d6b1cc03..af8917a75 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -54,8 +54,8 @@ bool RenderSymbolLayer::hasTransition() const { return unevaluated.hasTransition(); } -style::IconPaintProperties::Evaluated RenderSymbolLayer::iconPaintProperties() const { - return style::IconPaintProperties::Evaluated { +style::IconPaintProperties::PossiblyEvaluated RenderSymbolLayer::iconPaintProperties() const { + return style::IconPaintProperties::PossiblyEvaluated { evaluated.get(), evaluated.get(), evaluated.get(), @@ -66,8 +66,8 @@ style::IconPaintProperties::Evaluated RenderSymbolLayer::iconPaintProperties() c }; } -style::TextPaintProperties::Evaluated RenderSymbolLayer::textPaintProperties() const { - return style::TextPaintProperties::Evaluated { +style::TextPaintProperties::PossiblyEvaluated RenderSymbolLayer::textPaintProperties() const { + return style::TextPaintProperties::PossiblyEvaluated { evaluated.get(), evaluated.get(), evaluated.get(), diff --git a/src/mbgl/renderer/layers/render_symbol_layer.hpp b/src/mbgl/renderer/layers/render_symbol_layer.hpp index ba1b04766..4308761ee 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.hpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.hpp @@ -13,7 +13,7 @@ namespace style { // {icon,text}-specific paint-property packs for use in the symbol Programs. // Since each program deals either with icons or text, using a smaller property set // lets us avoid unnecessarily binding attributes for properties the program wouldn't use. -class IconPaintProperties : public PaintProperties< +class IconPaintProperties : public Properties< IconOpacity, IconColor, IconHaloColor, @@ -23,7 +23,7 @@ class IconPaintProperties : public PaintProperties< IconTranslateAnchor > {}; -class TextPaintProperties : public PaintProperties< +class TextPaintProperties : public Properties< TextOpacity, TextColor, TextHaloColor, @@ -68,8 +68,8 @@ public: void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; - style::IconPaintProperties::Evaluated iconPaintProperties() const; - style::TextPaintProperties::Evaluated textPaintProperties() const; + style::IconPaintProperties::PossiblyEvaluated iconPaintProperties() const; + style::TextPaintProperties::PossiblyEvaluated textPaintProperties() const; style::SymbolPropertyValues iconPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const; style::SymbolPropertyValues textPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const; @@ -80,7 +80,7 @@ public: // Paint properties style::SymbolPaintProperties::Unevaluated unevaluated; - style::SymbolPaintProperties::Evaluated evaluated; + style::SymbolPaintProperties::PossiblyEvaluated evaluated; float iconSize = 1.0f; float textSize = 16.0f; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 3e53bcc88..14934fb6b 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace mbgl { diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 0c5e0e764..7649f86ca 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -350,7 +350,7 @@ void Painter::renderPass(PaintParameters& parameters, mat4 viewportMat; matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1); - const PaintProperties<>::Evaluated properties{}; + const Properties<>::PossiblyEvaluated properties{}; parameters.programs.extrusionTexture.draw( context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(), diff --git a/src/mbgl/renderer/painters/painter_background.cpp b/src/mbgl/renderer/painters/painter_background.cpp index fbd44b448..783880fe8 100644 --- a/src/mbgl/renderer/painters/painter_background.cpp +++ b/src/mbgl/renderer/painters/painter_background.cpp @@ -14,9 +14,9 @@ using namespace style; void Painter::renderBackground(PaintParameters& parameters, const RenderBackgroundLayer& layer) { // Note that for bottommost layers without a pattern, the background color is drawn with // glClear rather than this method. - const BackgroundPaintProperties::Evaluated& background = layer.evaluated; + const BackgroundPaintProperties::PossiblyEvaluated& background = layer.evaluated; - style::FillPaintProperties::Evaluated properties; + style::FillPaintProperties::PossiblyEvaluated properties; properties.get() = background.get(); properties.get() = { background.get() }; properties.get() = { background.get() }; diff --git a/src/mbgl/renderer/painters/painter_circle.cpp b/src/mbgl/renderer/painters/painter_circle.cpp index 0bca8ee94..367dd57bc 100644 --- a/src/mbgl/renderer/painters/painter_circle.cpp +++ b/src/mbgl/renderer/painters/painter_circle.cpp @@ -20,7 +20,7 @@ void Painter::renderCircle(PaintParameters& parameters, return; } - const CirclePaintProperties::Evaluated& properties = layer.evaluated; + const CirclePaintProperties::PossiblyEvaluated& properties = layer.evaluated; const bool scaleWithMap = properties.get() == CirclePitchScaleType::Map; parameters.programs.circle.draw( diff --git a/src/mbgl/renderer/painters/painter_clipping.cpp b/src/mbgl/renderer/painters/painter_clipping.cpp index 0d3b5f150..31e2b700b 100644 --- a/src/mbgl/renderer/painters/painter_clipping.cpp +++ b/src/mbgl/renderer/painters/painter_clipping.cpp @@ -6,7 +6,7 @@ namespace mbgl { void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& clip) { - static const style::FillPaintProperties::Evaluated properties {}; + static const style::FillPaintProperties::PossiblyEvaluated properties {}; static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0); programs->fill.draw( context, diff --git a/src/mbgl/renderer/painters/painter_debug.cpp b/src/mbgl/renderer/painters/painter_debug.cpp index a108cd2d0..4794d79d4 100644 --- a/src/mbgl/renderer/painters/painter_debug.cpp +++ b/src/mbgl/renderer/painters/painter_debug.cpp @@ -20,7 +20,7 @@ void Painter::renderTileDebug(const RenderTile& renderTile) { MBGL_DEBUG_GROUP(context, std::string { "debug " } + util::toString(renderTile.id)); - static const style::PaintProperties<>::Evaluated properties {}; + static const style::Properties<>::PossiblyEvaluated properties {}; static const DebugProgram::PaintPropertyBinders paintAttibuteData(properties, 0); auto draw = [&] (Color color, const auto& vertexBuffer, const auto& indexBuffer, const auto& segments, auto drawMode) { diff --git a/src/mbgl/renderer/painters/painter_fill.cpp b/src/mbgl/renderer/painters/painter_fill.cpp index 782fba3d4..0b77474ef 100644 --- a/src/mbgl/renderer/painters/painter_fill.cpp +++ b/src/mbgl/renderer/painters/painter_fill.cpp @@ -17,7 +17,7 @@ void Painter::renderFill(PaintParameters& parameters, FillBucket& bucket, const RenderFillLayer& layer, const RenderTile& tile) { - const FillPaintProperties::Evaluated& properties = layer.evaluated; + const FillPaintProperties::PossiblyEvaluated& properties = layer.evaluated; if (!properties.get().from.empty()) { if (pass != RenderPass::Translucent) { diff --git a/src/mbgl/renderer/painters/painter_fill_extrusion.cpp b/src/mbgl/renderer/painters/painter_fill_extrusion.cpp index c00597ab4..8e10cd736 100644 --- a/src/mbgl/renderer/painters/painter_fill_extrusion.cpp +++ b/src/mbgl/renderer/painters/painter_fill_extrusion.cpp @@ -18,7 +18,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters, FillExtrusionBucket& bucket, const RenderFillExtrusionLayer& layer, const RenderTile& tile) { - const FillExtrusionPaintProperties::Evaluated& properties = layer.evaluated; + const FillExtrusionPaintProperties::PossiblyEvaluated& properties = layer.evaluated; if (pass == RenderPass::Opaque) { return; diff --git a/src/mbgl/renderer/painters/painter_line.cpp b/src/mbgl/renderer/painters/painter_line.cpp index 20a16750d..dc99ef9af 100644 --- a/src/mbgl/renderer/painters/painter_line.cpp +++ b/src/mbgl/renderer/painters/painter_line.cpp @@ -21,7 +21,7 @@ void Painter::renderLine(PaintParameters& parameters, return; } - const LinePaintProperties::Evaluated& properties = layer.evaluated; + const LinePaintProperties::PossiblyEvaluated& properties = layer.evaluated; auto draw = [&] (auto& program, auto&& uniformValues) { program.draw( diff --git a/src/mbgl/renderer/painters/painter_raster.cpp b/src/mbgl/renderer/painters/painter_raster.cpp index 5d98fcf86..1f0d72be4 100644 --- a/src/mbgl/renderer/painters/painter_raster.cpp +++ b/src/mbgl/renderer/painters/painter_raster.cpp @@ -48,7 +48,7 @@ void Painter::renderRaster(PaintParameters& parameters, if (!bucket.hasData()) return; - const RasterPaintProperties::Evaluated& properties = layer.evaluated; + const RasterPaintProperties::PossiblyEvaluated& properties = layer.evaluated; const RasterProgram::PaintPropertyBinders paintAttributeData(properties, 0); assert(bucket.texture); diff --git a/src/mbgl/renderer/painters/painter_symbol.cpp b/src/mbgl/renderer/painters/painter_symbol.cpp index 8147a933b..45094777c 100644 --- a/src/mbgl/renderer/painters/painter_symbol.cpp +++ b/src/mbgl/renderer/painters/painter_symbol.cpp @@ -137,7 +137,7 @@ void Painter::renderSymbol(PaintParameters& parameters, } if (bucket.hasCollisionBoxData()) { - static const style::PaintProperties<>::Evaluated properties {}; + static const style::Properties<>::PossiblyEvaluated properties {}; static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0); programs->collisionBox.draw( diff --git a/src/mbgl/renderer/render_light.cpp b/src/mbgl/renderer/render_light.cpp index 1fc346fd2..23b7ecb9b 100644 --- a/src/mbgl/renderer/render_light.cpp +++ b/src/mbgl/renderer/render_light.cpp @@ -7,11 +7,11 @@ RenderLight::RenderLight(Immutable impl_) } void RenderLight::transition(const CascadeParameters& parameters) { - transitioning = TransitioningLight(impl->properties, std::move(transitioning), parameters); + transitioning = impl->properties.cascade(parameters, std::move(transitioning)); } void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) { - evaluated = EvaluatedLight(transitioning, parameters); + evaluated = transitioning.evaluate(parameters); } bool RenderLight::hasTransition() const { diff --git a/src/mbgl/renderer/render_light.hpp b/src/mbgl/renderer/render_light.hpp index 7e0662105..ce83616bb 100644 --- a/src/mbgl/renderer/render_light.hpp +++ b/src/mbgl/renderer/render_light.hpp @@ -1,75 +1,15 @@ #pragma once #include -#include -#include -#include -#include -#include - -#include +#include namespace mbgl { -template -class Transitioning; +class CascadeParameters; +class PropertyEvaluationParameters; -template -class Transitioning> : public IndexedTuple< - TypeList, - TypeList...>> -{ -private: - using Properties = TypeList; - using Raw = IndexedTuple; - using Super = IndexedTuple< - TypeList, - TypeList...>>; - -public: - Transitioning() = default; - Transitioning(const Raw& raw, Transitioning&& prior, const CascadeParameters& params) - : Super { - TransitioningProperty( - raw.template get().value, - std::move(prior.template get()), - raw.template get().transition.reverseMerge(params.transition), - params.now)... - } {} - - bool hasTransition() const { - bool result = false; - util::ignore({ result |= this->template get().hasTransition()... }); - return result; - } -}; - -template -class Evaluated; - -template -class Evaluated> : public IndexedTuple< - TypeList, - TypeList> -{ -private: - using Properties = TypeList; - using TransitioningPs = Transitioning; - using Super = IndexedTuple< - TypeList, - TypeList>; - -public: - Evaluated() = default; - Evaluated(TransitioningPs& transitioning, const PropertyEvaluationParameters& params) - : Super { - transitioning.template get() - .evaluate(PropertyEvaluator(params, Ps::defaultValue()), params.now)... - } {} -}; - -using TransitioningLight = Transitioning; -using EvaluatedLight = Evaluated; +using TransitioningLight = style::LightProperties::Unevaluated; +using EvaluatedLight = style::LightProperties::PossiblyEvaluated; class RenderLight { public: diff --git a/src/mbgl/renderer/transitioning_property.hpp b/src/mbgl/renderer/transitioning_property.hpp deleted file mode 100644 index c211ccf11..000000000 --- a/src/mbgl/renderer/transitioning_property.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include - -namespace mbgl { - -template -class TransitioningProperty { -public: - TransitioningProperty() = default; - - TransitioningProperty(Value value_, - TransitioningProperty prior_, - style::TransitionOptions transition, - TimePoint now) - : begin(now + transition.delay.value_or(Duration::zero())), - end(begin + transition.duration.value_or(Duration::zero())), - value(std::move(value_)) { - if (transition.isDefined()) { - prior = { std::move(prior_) }; - } - } - - template - auto evaluate(const Evaluator& evaluator, TimePoint now) { - auto finalValue = value.evaluate(evaluator); - if (!prior) { - // No prior value. - return finalValue; - } else if (now >= end) { - // Transition from prior value is now complete. - prior = {}; - return finalValue; - } else if (value.isDataDriven()) { - // Transitions to data-driven properties are not supported. - // We snap immediately to the data-driven value so that, when we perform layout, - // we see the data-driven function and can use it to populate vertex buffers. - prior = {}; - return finalValue; - } else if (now < begin) { - // Transition hasn't started yet. - return prior->get().evaluate(evaluator, now); - } else { - // Interpolate between recursively-calculated prior value and final. - float t = std::chrono::duration(now - begin) / (end - begin); - return util::interpolate(prior->get().evaluate(evaluator, now), finalValue, - util::DEFAULT_TRANSITION_EASE.solve(t, 0.001)); - } - } - - bool hasTransition() const { - return bool(prior); - } - - bool isUndefined() const { - return value.isUndefined(); - } - - const Value& getValue() const { - return value; - } - -private: - optional>> prior; - TimePoint begin; - TimePoint end; - Value value; -}; - -} // namespace mbgl diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp index 4afbf198e..6ae6fede4 100644 --- a/src/mbgl/style/conversion/stringify.hpp +++ b/src/mbgl/style/conversion/stringify.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -446,13 +446,6 @@ void stringify(Writer& writer, const DataDrivenPropertyValue& value) { } } -template -void stringify(Writer& writer, const LayoutProperties& ps) { - writer.StartObject(); - util::ignore({ (stringify(writer, ps.unevaluated.template get()), 0)... }); - writer.EndObject(); -} - } // namespace conversion } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 2aa15a779..1c5b6c3a6 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { diff --git a/src/mbgl/style/layers/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp index fae6c26a4..f9a67b214 100644 --- a/src/mbgl/style/layers/background_layer_properties.hpp +++ b/src/mbgl/style/layers/background_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -22,7 +23,7 @@ struct BackgroundOpacity : PaintProperty { static float defaultValue() { return 1; } }; -class BackgroundPaintProperties : public PaintProperties< +class BackgroundPaintProperties : public Properties< BackgroundColor, BackgroundPattern, BackgroundOpacity diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index ea812748d..e874f00ff 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { diff --git a/src/mbgl/style/layers/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp index 1cb4f5a63..734dab109 100644 --- a/src/mbgl/style/layers/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -50,7 +51,7 @@ struct CircleStrokeOpacity : DataDrivenPaintProperty #include -#include #include namespace mbgl { diff --git a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp index c1dd3b079..1819f98ae 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_extrusion_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -38,7 +39,7 @@ struct FillExtrusionBase : DataDrivenPaintProperty { static float defaultValue() { return 0; } }; -class FillExtrusionPaintProperties : public PaintProperties< +class FillExtrusionPaintProperties : public Properties< FillExtrusionOpacity, FillExtrusionColor, FillExtrusionTranslate, diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 003197284..d38b02774 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { diff --git a/src/mbgl/style/layers/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp index f44a18d0e..67c2ae1fa 100644 --- a/src/mbgl/style/layers/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -38,7 +39,7 @@ struct FillPattern : CrossFadedPaintProperty { static std::string defaultValue() { return ""; } }; -class FillPaintProperties : public PaintProperties< +class FillPaintProperties : public Properties< FillAntialias, FillOpacity, FillColor, diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index b07f7db30..738165e66 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -7,7 +7,6 @@ #include _layer.hpp> #include _layer_impl.hpp> -#include #include namespace mbgl { @@ -46,7 +45,7 @@ std::unique_ptr <%- camelize(type) %>Layer::cloneRef(const std::string& i <% if (layoutProperties.length) { -%> void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer& writer) const { - conversion::stringify(writer, layout); + layout.stringify(writer); } <% } else { -%> void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer&) const { @@ -119,14 +118,14 @@ void <%- camelize(type) %>Layer::setMaxZoom(float maxZoom) { } <%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return impl().layout.unevaluated.get<<%- camelize(property.name) %>>(); + return impl().layout.get<<%- camelize(property.name) %>>(); } void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value) { if (value == get<%- camelize(property.name) %>()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get<<%- camelize(property.name) %>>() = value; + impl_->layout.get<<%- camelize(property.name) %>>() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>"); } diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 2a736ca38..a271a27e8 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace mbgl { @@ -29,7 +30,7 @@ struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> <% } -%> <% if (layoutProperties.length) { -%> -class <%- camelize(type) %>LayoutProperties : public LayoutProperties< +class <%- camelize(type) %>LayoutProperties : public Properties< <% for (const property of layoutProperties.slice(0, -1)) { -%> <%- camelize(property.name) %>, <% } -%> @@ -37,7 +38,7 @@ class <%- camelize(type) %>LayoutProperties : public LayoutProperties< > {}; <% } -%> -class <%- camelize(type) %>PaintProperties : public PaintProperties< +class <%- camelize(type) %>PaintProperties : public Properties< <% for (const property of paintProperties.slice(0, -1)) { -%> <%- camelize(property.name) %>, <% } -%> diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 359078f91..c8684ec6f 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { @@ -34,7 +33,7 @@ std::unique_ptr LineLayer::cloneRef(const std::string& id_) const { } void LineLayer::Impl::stringifyLayout(rapidjson::Writer& writer) const { - conversion::stringify(writer, layout); + layout.stringify(writer); } // Source @@ -98,14 +97,14 @@ PropertyValue LineLayer::getDefaultLineCap() { } PropertyValue LineLayer::getLineCap() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void LineLayer::setLineCap(PropertyValue value) { if (value == getLineCap()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "line-cap"); } @@ -114,14 +113,14 @@ PropertyValue LineLayer::getDefaultLineJoin() { } PropertyValue LineLayer::getLineJoin() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void LineLayer::setLineJoin(PropertyValue value) { if (value == getLineJoin()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "line-join"); } @@ -130,14 +129,14 @@ PropertyValue LineLayer::getDefaultLineMiterLimit() { } PropertyValue LineLayer::getLineMiterLimit() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void LineLayer::setLineMiterLimit(PropertyValue value) { if (value == getLineMiterLimit()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit"); } @@ -146,14 +145,14 @@ PropertyValue LineLayer::getDefaultLineRoundLimit() { } PropertyValue LineLayer::getLineRoundLimit() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void LineLayer::setLineRoundLimit(PropertyValue value) { if (value == getLineRoundLimit()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "line-round-limit"); } diff --git a/src/mbgl/style/layers/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp index 8328378a1..2eab19a61 100644 --- a/src/mbgl/style/layers/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -13,7 +13,7 @@ public: void stringifyLayout(rapidjson::Writer&) const override; - LineLayoutProperties layout; + LineLayoutProperties::Unevaluated layout; LinePaintProperties::Cascading paint; }; diff --git a/src/mbgl/style/layers/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp index 724026e3a..62acad295 100644 --- a/src/mbgl/style/layers/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -70,14 +71,14 @@ struct LinePattern : CrossFadedPaintProperty { static std::string defaultValue() { return ""; } }; -class LineLayoutProperties : public LayoutProperties< +class LineLayoutProperties : public Properties< LineCap, LineJoin, LineMiterLimit, LineRoundLimit > {}; -class LinePaintProperties : public PaintProperties< +class LinePaintProperties : public Properties< LineOpacity, LineColor, LineTranslate, diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index fb31d9765..a17e34dd8 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { diff --git a/src/mbgl/style/layers/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp index 219fe34d8..732f5b2af 100644 --- a/src/mbgl/style/layers/raster_layer_properties.hpp +++ b/src/mbgl/style/layers/raster_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -38,7 +39,7 @@ struct RasterFadeDuration : PaintProperty { static float defaultValue() { return 300; } }; -class RasterPaintProperties : public PaintProperties< +class RasterPaintProperties : public Properties< RasterOpacity, RasterHueRotate, RasterBrightnessMin, diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index 75de1bb36..4a3ad2ffc 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -2,7 +2,6 @@ #include #include -#include #include namespace mbgl { @@ -34,7 +33,7 @@ std::unique_ptr SymbolLayer::cloneRef(const std::string& id_) const { } void SymbolLayer::Impl::stringifyLayout(rapidjson::Writer& writer) const { - conversion::stringify(writer, layout); + layout.stringify(writer); } // Source @@ -98,14 +97,14 @@ PropertyValue SymbolLayer::getDefaultSymbolPlacement() { } PropertyValue SymbolLayer::getSymbolPlacement() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setSymbolPlacement(PropertyValue value) { if (value == getSymbolPlacement()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "symbol-placement"); } @@ -114,14 +113,14 @@ PropertyValue SymbolLayer::getDefaultSymbolSpacing() { } PropertyValue SymbolLayer::getSymbolSpacing() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setSymbolSpacing(PropertyValue value) { if (value == getSymbolSpacing()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "symbol-spacing"); } @@ -130,14 +129,14 @@ PropertyValue SymbolLayer::getDefaultSymbolAvoidEdges() { } PropertyValue SymbolLayer::getSymbolAvoidEdges() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setSymbolAvoidEdges(PropertyValue value) { if (value == getSymbolAvoidEdges()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "symbol-avoid-edges"); } @@ -146,14 +145,14 @@ PropertyValue SymbolLayer::getDefaultIconAllowOverlap() { } PropertyValue SymbolLayer::getIconAllowOverlap() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconAllowOverlap(PropertyValue value) { if (value == getIconAllowOverlap()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-allow-overlap"); } @@ -162,14 +161,14 @@ PropertyValue SymbolLayer::getDefaultIconIgnorePlacement() { } PropertyValue SymbolLayer::getIconIgnorePlacement() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconIgnorePlacement(PropertyValue value) { if (value == getIconIgnorePlacement()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-ignore-placement"); } @@ -178,14 +177,14 @@ PropertyValue SymbolLayer::getDefaultIconOptional() { } PropertyValue SymbolLayer::getIconOptional() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconOptional(PropertyValue value) { if (value == getIconOptional()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-optional"); } @@ -194,14 +193,14 @@ PropertyValue SymbolLayer::getDefaultIconRotationAlignment() { } PropertyValue SymbolLayer::getIconRotationAlignment() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconRotationAlignment(PropertyValue value) { if (value == getIconRotationAlignment()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-rotation-alignment"); } @@ -210,14 +209,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultIconSize() { } DataDrivenPropertyValue SymbolLayer::getIconSize() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconSize(DataDrivenPropertyValue value) { if (value == getIconSize()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-size"); } @@ -226,14 +225,14 @@ PropertyValue SymbolLayer::getDefaultIconTextFit() { } PropertyValue SymbolLayer::getIconTextFit() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconTextFit(PropertyValue value) { if (value == getIconTextFit()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit"); } @@ -242,14 +241,14 @@ PropertyValue> SymbolLayer::getDefaultIconTextFitPadding() } PropertyValue> SymbolLayer::getIconTextFitPadding() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconTextFitPadding(PropertyValue> value) { if (value == getIconTextFitPadding()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding"); } @@ -258,14 +257,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultIconImage() { } DataDrivenPropertyValue SymbolLayer::getIconImage() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconImage(DataDrivenPropertyValue value) { if (value == getIconImage()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-image"); } @@ -274,14 +273,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultIconRotate() { } DataDrivenPropertyValue SymbolLayer::getIconRotate() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconRotate(DataDrivenPropertyValue value) { if (value == getIconRotate()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-rotate"); } @@ -290,14 +289,14 @@ PropertyValue SymbolLayer::getDefaultIconPadding() { } PropertyValue SymbolLayer::getIconPadding() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconPadding(PropertyValue value) { if (value == getIconPadding()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-padding"); } @@ -306,14 +305,14 @@ PropertyValue SymbolLayer::getDefaultIconKeepUpright() { } PropertyValue SymbolLayer::getIconKeepUpright() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconKeepUpright(PropertyValue value) { if (value == getIconKeepUpright()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright"); } @@ -322,14 +321,14 @@ DataDrivenPropertyValue> SymbolLayer::getDefaultIconOffset( } DataDrivenPropertyValue> SymbolLayer::getIconOffset() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setIconOffset(DataDrivenPropertyValue> value) { if (value == getIconOffset()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "icon-offset"); } @@ -338,14 +337,14 @@ PropertyValue SymbolLayer::getDefaultTextPitchAlignment() { } PropertyValue SymbolLayer::getTextPitchAlignment() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextPitchAlignment(PropertyValue value) { if (value == getTextPitchAlignment()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-pitch-alignment"); } @@ -354,14 +353,14 @@ PropertyValue SymbolLayer::getDefaultTextRotationAlignment() { } PropertyValue SymbolLayer::getTextRotationAlignment() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextRotationAlignment(PropertyValue value) { if (value == getTextRotationAlignment()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment"); } @@ -370,14 +369,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultTextField() { } DataDrivenPropertyValue SymbolLayer::getTextField() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextField(DataDrivenPropertyValue value) { if (value == getTextField()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-field"); } @@ -386,14 +385,14 @@ PropertyValue> SymbolLayer::getDefaultTextFont() { } PropertyValue> SymbolLayer::getTextFont() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextFont(PropertyValue> value) { if (value == getTextFont()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-font"); } @@ -402,14 +401,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultTextSize() { } DataDrivenPropertyValue SymbolLayer::getTextSize() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextSize(DataDrivenPropertyValue value) { if (value == getTextSize()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-size"); } @@ -418,14 +417,14 @@ PropertyValue SymbolLayer::getDefaultTextMaxWidth() { } PropertyValue SymbolLayer::getTextMaxWidth() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextMaxWidth(PropertyValue value) { if (value == getTextMaxWidth()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-max-width"); } @@ -434,14 +433,14 @@ PropertyValue SymbolLayer::getDefaultTextLineHeight() { } PropertyValue SymbolLayer::getTextLineHeight() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextLineHeight(PropertyValue value) { if (value == getTextLineHeight()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-line-height"); } @@ -450,14 +449,14 @@ PropertyValue SymbolLayer::getDefaultTextLetterSpacing() { } PropertyValue SymbolLayer::getTextLetterSpacing() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextLetterSpacing(PropertyValue value) { if (value == getTextLetterSpacing()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-letter-spacing"); } @@ -466,14 +465,14 @@ PropertyValue SymbolLayer::getDefaultTextJustify() { } PropertyValue SymbolLayer::getTextJustify() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextJustify(PropertyValue value) { if (value == getTextJustify()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-justify"); } @@ -482,14 +481,14 @@ PropertyValue SymbolLayer::getDefaultTextAnchor() { } PropertyValue SymbolLayer::getTextAnchor() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextAnchor(PropertyValue value) { if (value == getTextAnchor()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-anchor"); } @@ -498,14 +497,14 @@ PropertyValue SymbolLayer::getDefaultTextMaxAngle() { } PropertyValue SymbolLayer::getTextMaxAngle() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextMaxAngle(PropertyValue value) { if (value == getTextMaxAngle()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-max-angle"); } @@ -514,14 +513,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultTextRotate() { } DataDrivenPropertyValue SymbolLayer::getTextRotate() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextRotate(DataDrivenPropertyValue value) { if (value == getTextRotate()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-rotate"); } @@ -530,14 +529,14 @@ PropertyValue SymbolLayer::getDefaultTextPadding() { } PropertyValue SymbolLayer::getTextPadding() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextPadding(PropertyValue value) { if (value == getTextPadding()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-padding"); } @@ -546,14 +545,14 @@ PropertyValue SymbolLayer::getDefaultTextKeepUpright() { } PropertyValue SymbolLayer::getTextKeepUpright() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextKeepUpright(PropertyValue value) { if (value == getTextKeepUpright()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright"); } @@ -562,14 +561,14 @@ DataDrivenPropertyValue SymbolLayer::getDefaultTextTransform( } DataDrivenPropertyValue SymbolLayer::getTextTransform() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextTransform(DataDrivenPropertyValue value) { if (value == getTextTransform()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-transform"); } @@ -578,14 +577,14 @@ DataDrivenPropertyValue> SymbolLayer::getDefaultTextOffset( } DataDrivenPropertyValue> SymbolLayer::getTextOffset() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextOffset(DataDrivenPropertyValue> value) { if (value == getTextOffset()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-offset"); } @@ -594,14 +593,14 @@ PropertyValue SymbolLayer::getDefaultTextAllowOverlap() { } PropertyValue SymbolLayer::getTextAllowOverlap() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextAllowOverlap(PropertyValue value) { if (value == getTextAllowOverlap()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-allow-overlap"); } @@ -610,14 +609,14 @@ PropertyValue SymbolLayer::getDefaultTextIgnorePlacement() { } PropertyValue SymbolLayer::getTextIgnorePlacement() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextIgnorePlacement(PropertyValue value) { if (value == getTextIgnorePlacement()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-ignore-placement"); } @@ -626,14 +625,14 @@ PropertyValue SymbolLayer::getDefaultTextOptional() { } PropertyValue SymbolLayer::getTextOptional() const { - return impl().layout.unevaluated.get(); + return impl().layout.get(); } void SymbolLayer::setTextOptional(PropertyValue value) { if (value == getTextOptional()) return; auto impl_ = mutableImpl(); - impl_->layout.unevaluated.get() = value; + impl_->layout.get() = value; baseImpl = std::move(impl_); observer->onLayerLayoutPropertyChanged(*this, "text-optional"); } diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index d961dbb0b..28760e1f7 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -13,7 +13,7 @@ public: void stringifyLayout(rapidjson::Writer&) const override; - SymbolLayoutProperties layout; + SymbolLayoutProperties::Unevaluated layout; SymbolPaintProperties::Cascading paint; }; diff --git a/src/mbgl/style/layers/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp index 42f593890..d484d699d 100644 --- a/src/mbgl/style/layers/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mbgl { @@ -236,7 +237,7 @@ struct TextTranslateAnchor : PaintProperty { static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; } }; -class SymbolLayoutProperties : public LayoutProperties< +class SymbolLayoutProperties : public Properties< SymbolPlacement, SymbolSpacing, SymbolAvoidEdges, @@ -273,7 +274,7 @@ class SymbolLayoutProperties : public LayoutProperties< TextOptional > {}; -class SymbolPaintProperties : public PaintProperties< +class SymbolPaintProperties : public Properties< IconOpacity, IconColor, IconHaloColor, diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index 3b9d6114c..82a19e6a8 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -4,117 +4,30 @@ #include #include #include -#include namespace mbgl { - -class PropertyEvaluationParameters; - namespace style { template class LayoutProperty { public: + using CascadingType = std::nullptr_t; using UnevaluatedType = PropertyValue; using EvaluatorType = PropertyEvaluator; using PossiblyEvaluatedType = T; using Type = T; + static constexpr bool IsDataDriven = false; }; template class DataDrivenLayoutProperty { public: + using CascadingType = std::nullptr_t; using UnevaluatedType = DataDrivenPropertyValue; using EvaluatorType = DataDrivenPropertyEvaluator; using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue; using Type = T; -}; - -template -class LayoutProperties { -public: - using Properties = TypeList; - - template - using Tuple = IndexedTuple; - - /* - 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 undefined, constant, or camera function values have been fully evaluated, and - source or composite function 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 than a purposeful optimization. - */ - - using UnevaluatedTypes = TypeList; - using PossiblyEvaluatedTypes = TypeList; - using EvaluatedTypes = TypeList; - - class Evaluated : public Tuple { - public: - using Tuple::Tuple; - }; - - class PossiblyEvaluated : public Tuple { - public: - using Tuple::Tuple; - - template - static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) { - return t; - } - - template - static T evaluate(float z, const GeometryTileFeature& feature, - const PossiblyEvaluatedPropertyValue& v, const T& defaultValue) { - return v.match( - [&] (const T& t) { - return t; - }, - [&] (const SourceFunction& t) { - return t.evaluate(feature, defaultValue); - }, - [&] (const CompositeFunction& t) { - return t.evaluate(z, feature, defaultValue); - }); - } - - template - auto evaluate(float z, const GeometryTileFeature& feature) const { - return evaluate(z, feature, this->template get

(), P::defaultValue()); - } - - Evaluated evaluate(float z, const GeometryTileFeature& feature) const { - return Evaluated { - evaluate(z, feature)... - }; - } - }; - - class Unevaluated : public Tuple { - public: - using Tuple::Tuple; - }; - - template - auto evaluate(const PropertyEvaluationParameters& parameters) const { - using Evaluator = typename P::EvaluatorType; - return unevaluated.template get

() - .evaluate(Evaluator(parameters, P::defaultValue())); - } - - PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const { - return PossiblyEvaluated { - evaluate(parameters)... - }; - } - - Unevaluated unevaluated; + static constexpr bool IsDataDriven = true; }; } // namespace style diff --git a/src/mbgl/style/light_impl.hpp b/src/mbgl/style/light_impl.hpp index 4179c2b27..7cf160f43 100644 --- a/src/mbgl/style/light_impl.hpp +++ b/src/mbgl/style/light_impl.hpp @@ -2,9 +2,10 @@ #include #include -#include #include #include +#include +#include #include #include @@ -14,11 +15,12 @@ namespace style { template class LightProperty { public: + using CascadingType = Transitionable>; + using UnevaluatedType = Transitioning>; + using EvaluatorType = PropertyEvaluator; + using PossiblyEvaluatedType = T; using Type = T; - using ValueType = PropertyValue; - - PropertyValue value; - TransitionOptions transition; + static constexpr bool IsDataDriven = false; }; struct LightAnchor : LightProperty { @@ -46,11 +48,11 @@ struct LightIntensity : LightProperty { } }; -using LightProperties = TypeList; +using LightProperties = Properties; class Light::Impl { public: - IndexedTuple properties; + LightProperties::Cascading properties; }; } // namespace style diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index f1752e69d..b0dc5641f 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -1,186 +1,51 @@ #pragma once -#include +#include #include #include -#include #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include namespace mbgl { - -class GeometryTileFeature; - namespace style { -template -class CascadingPaintProperty { -public: - bool isUndefined() const { - return values.find(ClassID::Default) == values.end(); - } - - const Value& get(const optional& klass) const { - static const Value staticValue{}; - const auto it = values.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default); - return it == values.end() ? staticValue : it->second; - } - - void set(const Value& value_, const optional& klass) { - values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_; - } - - const TransitionOptions& getTransition(const optional& klass) const { - static const TransitionOptions staticValue{}; - const auto it = transitions.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default); - return it == transitions.end() ? staticValue : it->second; - } - - void setTransition(const TransitionOptions& transition, const optional& klass) { - transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition; - } - - template - TransitioningProperty cascade(const CascadeParameters& params, TransitioningProperty prior) const { - TransitionOptions transition; - Value value; - - for (const auto classID : params.classes) { - if (values.find(classID) != values.end()) { - value = values.at(classID); - break; - } - } - - for (const auto classID : params.classes) { - if (transitions.find(classID) != transitions.end()) { - transition = transitions.at(classID).reverseMerge(transition); - break; - } - } - - return TransitioningProperty(std::move(value), - std::move(prior), - transition.reverseMerge(params.transition), - params.now); - } - -private: - std::map values; - std::map transitions; -}; - template class PaintProperty { public: - using ValueType = PropertyValue; - using CascadingType = CascadingPaintProperty; - using UnevaluatedType = TransitioningProperty; + using CascadingType = Cascading>; + using UnevaluatedType = Transitioning>; using EvaluatorType = PropertyEvaluator; - using EvaluatedType = T; + using PossiblyEvaluatedType = T; + using Type = T; static constexpr bool IsDataDriven = false; }; template class DataDrivenPaintProperty { public: - using ValueType = DataDrivenPropertyValue; - using CascadingType = CascadingPaintProperty; - using UnevaluatedType = TransitioningProperty; + using CascadingType = Cascading>; + using UnevaluatedType = Transitioning>; using EvaluatorType = DataDrivenPropertyEvaluator; - using EvaluatedType = PossiblyEvaluatedPropertyValue; + using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue; + using Type = T; static constexpr bool IsDataDriven = true; - using Type = T; using Attribute = A; }; template class CrossFadedPaintProperty { public: - using ValueType = PropertyValue; - using CascadingType = CascadingPaintProperty; - using UnevaluatedType = TransitioningProperty; + using CascadingType = Cascading>; + using UnevaluatedType = Transitioning>; using EvaluatorType = CrossFadedPropertyEvaluator; - using EvaluatedType = Faded; + using PossiblyEvaluatedType = Faded; + using Type = T; static constexpr bool IsDataDriven = false; }; -template -struct IsDataDriven : std::integral_constant {}; - -template -class PaintProperties { -public: - using Properties = TypeList; - using DataDrivenProperties = FilteredTypeList; - using Binders = PaintPropertyBinders; - - using EvaluatedTypes = TypeList; - using UnevaluatedTypes = TypeList; - using CascadingTypes = TypeList; - - template - using Tuple = IndexedTuple; - - class Evaluated : public Tuple { - public: - using Tuple::Tuple; - }; - - class Unevaluated : public Tuple { - public: - using Tuple::Tuple; - - bool hasTransition() const { - bool result = false; - util::ignore({ result |= this->template get().hasTransition()... }); - return result; - } - - template - auto evaluate(const PropertyEvaluationParameters& parameters) { - using Evaluator = typename P::EvaluatorType; - - return this->template get

().evaluate( - Evaluator(parameters, P::defaultValue()), - parameters.now - ); - } - - Evaluated evaluate(const PropertyEvaluationParameters& parameters) { - return Evaluated { - evaluate(parameters)... - }; - } - - }; - - class Cascading : public Tuple { - public: - using Tuple::Tuple; - - Unevaluated cascade(const CascadeParameters& parameters, Unevaluated&& prior) const { - return Unevaluated { - this->template get().cascade( - parameters, - std::move(prior.template get()) - )... - }; - } - }; -}; - } // namespace style } // namespace mbgl diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp new file mode 100644 index 000000000..c808554c9 --- /dev/null +++ b/src/mbgl/style/properties.hpp @@ -0,0 +1,268 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace mbgl { + +class GeometryTileFeature; + +namespace style { + +template +class Transitioning { +public: + Transitioning() = default; + + Transitioning(Value value_, + Transitioning prior_, + TransitionOptions transition, + TimePoint now) + : begin(now + transition.delay.value_or(Duration::zero())), + end(begin + transition.duration.value_or(Duration::zero())), + value(std::move(value_)) { + if (transition.isDefined()) { + prior = { std::move(prior_) }; + } + } + + template + auto evaluate(const Evaluator& evaluator, TimePoint now) const { + auto finalValue = value.evaluate(evaluator); + if (!prior) { + // No prior value. + return finalValue; + } else if (now >= end) { + // Transition from prior value is now complete. + prior = {}; + return finalValue; + } else if (value.isDataDriven()) { + // Transitions to data-driven properties are not supported. + // We snap immediately to the data-driven value so that, when we perform layout, + // we see the data-driven function and can use it to populate vertex buffers. + prior = {}; + return finalValue; + } else if (now < begin) { + // Transition hasn't started yet. + return prior->get().evaluate(evaluator, now); + } else { + // Interpolate between recursively-calculated prior value and final. + float t = std::chrono::duration(now - begin) / (end - begin); + return util::interpolate(prior->get().evaluate(evaluator, now), finalValue, + util::DEFAULT_TRANSITION_EASE.solve(t, 0.001)); + } + } + + bool hasTransition() const { + return bool(prior); + } + + bool isUndefined() const { + return value.isUndefined(); + } + + const Value& getValue() const { + return value; + } + +private: + mutable optional>> prior; + TimePoint begin; + TimePoint end; + Value value; +}; + +template +class Transitionable { +public: + Value value; + TransitionOptions transition; + + Transitioning cascade(const CascadeParameters& params, Transitioning prior) const { + return Transitioning(value, + std::move(prior), + transition.reverseMerge(params.transition), + params.now); + } +}; +template +class Cascading { +public: + bool isUndefined() const { + return values.find(ClassID::Default) == values.end(); + } + + const Value& get(const optional& klass) const { + static const Value staticValue{}; + const auto it = values.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default); + return it == values.end() ? staticValue : it->second; + } + + void set(const Value& value_, const optional& klass) { + values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_; + } + + const TransitionOptions& getTransition(const optional& klass) const { + static const TransitionOptions staticValue{}; + const auto it = transitions.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default); + return it == transitions.end() ? staticValue : it->second; + } + + void setTransition(const TransitionOptions& transition, const optional& klass) { + transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition; + } + + Transitioning cascade(const CascadeParameters& params, Transitioning prior) const { + TransitionOptions transition; + Value value; + + for (const auto classID : params.classes) { + if (values.find(classID) != values.end()) { + value = values.at(classID); + break; + } + } + + for (const auto classID : params.classes) { + if (transitions.find(classID) != transitions.end()) { + transition = transitions.at(classID).reverseMerge(transition); + break; + } + } + + return Transitioning(std::move(value), + std::move(prior), + transition.reverseMerge(params.transition), + params.now); + } + +private: + std::map values; + std::map transitions; +}; + + +template +struct IsDataDriven : std::integral_constant {}; + +template +class Properties { +public: + /* + For style 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 undefined, constant, or camera function values have been fully evaluated, and + source or composite function 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 than a purposeful optimization. + */ + + using PropertyTypes = TypeList; + using CascadingTypes = TypeList; + using UnevaluatedTypes = TypeList; + using PossiblyEvaluatedTypes = TypeList; + using EvaluatedTypes = TypeList; + + using DataDrivenProperties = FilteredTypeList; + using Binders = PaintPropertyBinders; + + template + using Tuple = IndexedTuple; + + class Evaluated : public Tuple { + public: + using Tuple::Tuple; + }; + + class PossiblyEvaluated : public Tuple { + public: + using Tuple::Tuple; + + template + static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) { + return t; + } + + template + static T evaluate(float z, const GeometryTileFeature& feature, + const PossiblyEvaluatedPropertyValue& v, const T& defaultValue) { + return v.match( + [&] (const T& t) { + return t; + }, + [&] (const SourceFunction& t) { + return t.evaluate(feature, defaultValue); + }, + [&] (const CompositeFunction& t) { + return t.evaluate(z, feature, defaultValue); + }); + } + + template + auto evaluate(float z, const GeometryTileFeature& feature) const { + return evaluate(z, feature, this->template get

(), P::defaultValue()); + } + + Evaluated evaluate(float z, const GeometryTileFeature& feature) const { + return Evaluated { + evaluate(z, feature)... + }; + } + }; + + class Unevaluated : public Tuple { + public: + using Tuple::Tuple; + + bool hasTransition() const { + bool result = false; + util::ignore({ result |= this->template get().hasTransition()... }); + return result; + } + + template + auto evaluate(const PropertyEvaluationParameters& parameters) const { + using Evaluator = typename P::EvaluatorType; + return this->template get

() + .evaluate(Evaluator(parameters, P::defaultValue()), parameters.now); + } + + PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const { + return PossiblyEvaluated { + evaluate(parameters)... + }; + } + + template + void stringify(Writer& writer) const { + writer.StartObject(); + util::ignore({ (conversion::stringify(writer, this->template get()), 0)... }); + writer.EndObject(); + } + }; + + class Cascading : public Tuple { + public: + using Tuple::Tuple; + + Unevaluated cascade(const CascadeParameters& parameters, Unevaluated&& prior) const { + return Unevaluated { + this->template get() + .cascade(parameters, std::move(prior.template get()))... + }; + } + }; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 256949af3..7a76d289c 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -584,7 +584,7 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const result.order.emplace_back(*layer); continue; } - const BackgroundPaintProperties::Evaluated& paint = background->evaluated; + const BackgroundPaintProperties::PossiblyEvaluated& paint = background->evaluated; if (layerImpl.get() == layerImpls[0].get() && paint.get().from.empty()) { // This is a solid background. We can use glClear(). result.backgroundColor = paint.get() * paint.get(); diff --git a/test/style/conversion/stringify.test.cpp b/test/style/conversion/stringify.test.cpp index 1dae20b26..0b2940a0e 100644 --- a/test/style/conversion/stringify.test.cpp +++ b/test/style/conversion/stringify.test.cpp @@ -121,10 +121,17 @@ TEST(Stringify, PropertyValue) { } TEST(Stringify, Layout) { - ASSERT_EQ(stringify(SymbolLayoutProperties()), "{}"); + auto stringify = [] (const SymbolLayoutProperties::Unevaluated& layout) { + rapidjson::StringBuffer s; + rapidjson::Writer writer(s); + layout.stringify(writer); + return std::string(s.GetString()); + }; - SymbolLayoutProperties layout; - layout.unevaluated.get() = true; - layout.unevaluated.get() = 2.0; + ASSERT_EQ(stringify(SymbolLayoutProperties::Unevaluated()), "{}"); + + SymbolLayoutProperties::Unevaluated layout; + layout.get() = true; + layout.get() = 2.0; ASSERT_EQ(stringify(layout), "{\"symbol-avoid-edges\":true,\"icon-padding\":2.0}"); } diff --git a/test/style/paint_property.test.cpp b/test/style/properties.test.cpp similarity index 67% rename from test/style/paint_property.test.cpp rename to test/style/properties.test.cpp index fcca05f3b..279fadb8c 100644 --- a/test/style/paint_property.test.cpp +++ b/test/style/properties.test.cpp @@ -1,13 +1,14 @@ #include -#include -#include +#include +#include +#include using namespace mbgl; using namespace mbgl::style; using namespace std::literals::chrono_literals; -float evaluate(TransitioningProperty>& property, Duration delta = Duration::zero()) { +float evaluate(Transitioning>& property, Duration delta = Duration::zero()) { ZoomHistory zoomHistory; zoomHistory.update(0, TimePoint::min() + delta); @@ -25,7 +26,7 @@ float evaluate(TransitioningProperty>& property, Duration d return property.evaluate(evaluator, parameters.now); } -PossiblyEvaluatedPropertyValue evaluate(TransitioningProperty>& property, Duration delta = Duration::zero()) { +PossiblyEvaluatedPropertyValue evaluate(Transitioning>& property, Duration delta = Duration::zero()) { ZoomHistory zoomHistory; zoomHistory.update(0, TimePoint::min() + delta); @@ -43,15 +44,15 @@ PossiblyEvaluatedPropertyValue evaluate(TransitioningProperty> property; +TEST(TransitioningPropertyValue, EvaluateDefaultValue) { + Transitioning> property; ASSERT_EQ(0.0f, evaluate(property)); } -TEST(TransitioningProperty, EvaluateUntransitionedConstant) { - TransitioningProperty> property { +TEST(TransitioningPropertyValue, EvaluateUntransitionedConstant) { + Transitioning> property { PropertyValue(1.0f), - TransitioningProperty>(), + Transitioning>(), TransitionOptions(), TimePoint::min() }; @@ -59,18 +60,18 @@ TEST(TransitioningProperty, EvaluateUntransitionedConstant) { ASSERT_EQ(1.0f, evaluate(property)); } -TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) { +TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) { TransitionOptions transition; transition.duration = { 1000ms }; - TransitioningProperty> t0 { + Transitioning> t0 { PropertyValue(0.0f), - TransitioningProperty>(), + Transitioning>(), TransitionOptions(), TimePoint::min() }; - TransitioningProperty> t1 { + Transitioning> t1 { PropertyValue(1.0f), t0, transition, @@ -82,19 +83,19 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) { ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 1500ms)); } -TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) { +TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) { TransitionOptions transition; transition.delay = { 1000ms }; transition.duration = { 1000ms }; - TransitioningProperty> t0 { + Transitioning> t0 { PropertyValue(0.0f), - TransitioningProperty>(), + Transitioning>(), TransitionOptions(), TimePoint::min() }; - TransitioningProperty> t1 { + Transitioning> t1 { PropertyValue(1.0f), t0, transition, @@ -108,14 +109,14 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) { ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms)); } -TEST(TransitioningProperty, EvaluateDataDrivenValue) { +TEST(TransitioningDataDrivenPropertyValue, Evaluate) { TransitionOptions transition; transition.delay = { 1000ms }; transition.duration = { 1000ms }; - TransitioningProperty> t0 { + Transitioning> t0 { DataDrivenPropertyValue(0.0f), - TransitioningProperty>(), + Transitioning>(), TransitionOptions(), TimePoint::min() }; @@ -125,7 +126,7 @@ TEST(TransitioningProperty, EvaluateDataDrivenValue) { IdentityStops() }; - TransitioningProperty> t1 { + Transitioning> t1 { DataDrivenPropertyValue(sourceFunction), t0, transition, diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index 2eafa4699..03896199f 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -68,7 +68,7 @@ TEST(VectorTile, Issue7615) { style::SymbolLayoutProperties::PossiblyEvaluated(), std::map< std::string, - std::pair>(), + std::pair>(), 16.0f, 1.0f, 0.0f, false, false); // Simulate placement of a symbol layer.