diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-10-26 15:12:43 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-10 11:33:17 -0800 |
commit | 54e08b1f83504e12cbc19b08295d9f9ed5177ab5 (patch) | |
tree | 40513395d4d0ed2d9003ef30a708f21b2e83e5ab /src | |
parent | a5625675890213f94de7632d4ef152ade627c9a5 (diff) | |
download | qtlocation-mapboxgl-54e08b1f83504e12cbc19b08295d9f9ed5177ab5.tar.gz |
[core] Eliminate use of ClassProperties for paint
Diffstat (limited to 'src')
41 files changed, 543 insertions, 958 deletions
diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index bb6642c600..6941c59c38 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -26,19 +26,17 @@ void ShapeAnnotationImpl::updateStyle(Style& style) { if (style.getLayer(layerID)) return; - if (shape.properties.is<LinePaintProperties>()) { + if (shape.properties.is<LineAnnotationProperties>()) { type = ProjectedFeatureType::LineString; std::unique_ptr<LineLayer> layer = std::make_unique<LineLayer>(); layer->type = StyleLayerType::Line; layer->layout.join = JoinType::Round; - const LinePaintProperties& properties = shape.properties.get<LinePaintProperties>(); - ClassProperties paintProperties; - paintProperties.set(PropertyKey::LineOpacity, Function<float>(properties.opacity)); - paintProperties.set(PropertyKey::LineWidth, Function<float>(properties.width)); - paintProperties.set(PropertyKey::LineColor, Function<Color>(properties.color)); - layer->paints.paints.emplace(ClassID::Default, std::move(paintProperties)); + const LineAnnotationProperties& properties = shape.properties.get<LineAnnotationProperties>(); + layer->paint.opacity = properties.opacity; + layer->paint.width = properties.width; + layer->paint.color = properties.color; layer->id = layerID; layer->source = AnnotationManager::SourceID; @@ -46,18 +44,16 @@ void ShapeAnnotationImpl::updateStyle(Style& style) { style.addLayer(std::move(layer), AnnotationManager::PointLayerID); - } else if (shape.properties.is<FillPaintProperties>()) { + } else if (shape.properties.is<FillAnnotationProperties>()) { type = ProjectedFeatureType::Polygon; std::unique_ptr<FillLayer> layer = std::make_unique<FillLayer>(); layer->type = StyleLayerType::Fill; - const FillPaintProperties& properties = shape.properties.get<FillPaintProperties>(); - ClassProperties paintProperties; - paintProperties.set(PropertyKey::FillOpacity, Function<float>(properties.opacity)); - paintProperties.set(PropertyKey::FillColor, Function<Color>(properties.fill_color)); - paintProperties.set(PropertyKey::FillOutlineColor, Function<Color>(properties.stroke_color)); - layer->paints.paints.emplace(ClassID::Default, std::move(paintProperties)); + const FillAnnotationProperties& properties = shape.properties.get<FillAnnotationProperties>(); + layer->paint.opacity = properties.opacity; + layer->paint.color = properties.color; + layer->paint.outlineColor = properties.outlineColor; layer->id = layerID; layer->source = AnnotationManager::SourceID; diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp index 0a86e2db14..51000e53ba 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/layer/background_layer.cpp @@ -1,5 +1,4 @@ #include <mbgl/layer/background_layer.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/renderer/bucket.hpp> namespace mbgl { @@ -7,34 +6,32 @@ namespace mbgl { std::unique_ptr<StyleLayer> BackgroundLayer::clone() const { std::unique_ptr<BackgroundLayer> result = std::make_unique<BackgroundLayer>(); result->copy(*this); - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } void BackgroundLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<float>>("background-opacity", PropertyKey::BackgroundOpacity, paint, value); - parseProperty<Function<Color>>("background-color", PropertyKey::BackgroundColor, paint, value); - parseProperty<Function<Faded<std::string>>>("background-pattern", PropertyKey::BackgroundImage, paint, value); - }); + paint.opacity.parse("background-opacity", layer); + paint.color.parse("background-color", layer); + paint.pattern.parse("background-pattern", layer); } void BackgroundLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); + paint.opacity.cascade(parameters); + paint.color.cascade(parameters); + paint.pattern.cascade(parameters); } -bool BackgroundLayer::hasTransitions() const { - return paints.hasTransitions(); -} +bool BackgroundLayer::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; -void BackgroundLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); + hasTransitions |= paint.opacity.calculate(parameters); + hasTransitions |= paint.color.calculate(parameters); + hasTransitions |= paint.pattern.calculate(parameters); - paints.calculateTransitioned(PropertyKey::BackgroundOpacity, properties.opacity, parameters); - paints.calculateTransitioned(PropertyKey::BackgroundColor, properties.color, parameters); - paints.calculate(PropertyKey::BackgroundImage, properties.image, parameters); + passes = paint.opacity > 0 ? RenderPass::Translucent : RenderPass::None; - passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; + return hasTransitions; } std::unique_ptr<Bucket> BackgroundLayer::createBucket(StyleBucketParameters&) const { diff --git a/src/mbgl/layer/background_layer.hpp b/src/mbgl/layer/background_layer.hpp index 11d06b2cd2..a65b9e0183 100644 --- a/src/mbgl/layer/background_layer.hpp +++ b/src/mbgl/layer/background_layer.hpp @@ -2,11 +2,17 @@ #define MBGL_BACKGROUND_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { +class BackgroundPaintProperties { +public: + PaintProperty<float> opacity = 1.0f; + PaintProperty<Color> color = { {{ 0, 0, 0, 1 }} }; + PaintProperty<std::string, Faded<std::string>> pattern = { "" }; +}; + class BackgroundLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -15,15 +21,11 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - - PaintPropertiesMap paints; - - BackgroundPaintProperties properties; + BackgroundPaintProperties paint; }; } diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index 7680136555..e33476a4a8 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -1,5 +1,4 @@ #include <mbgl/layer/circle_layer.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/circle_bucket.hpp> @@ -8,40 +7,41 @@ namespace mbgl { std::unique_ptr<StyleLayer> CircleLayer::clone() const { std::unique_ptr<CircleLayer> result = std::make_unique<CircleLayer>(); result->copy(*this); - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } void CircleLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<float>>("circle-radius", PropertyKey::CircleRadius, paint, value); - parseProperty<Function<Color>>("circle-color", PropertyKey::CircleColor, paint, value); - parseProperty<Function<float>>("circle-opacity", PropertyKey::CircleOpacity, paint, value); - parseProperty<Function<std::array<float,2>>>("circle-translate", PropertyKey::CircleTranslate, paint, value); - parseProperty<Function<TranslateAnchorType>>("circle-translate-anchor", PropertyKey::CircleTranslateAnchor, paint, value); - parseProperty<Function<float>>("circle-blur", PropertyKey::CircleBlur, paint, value); - }); + paint.radius.parse("circle-radius", layer); + paint.color.parse("circle-color", layer); + paint.opacity.parse("circle-opacity", layer); + paint.translate.parse("circle-translate", layer); + paint.translateAnchor.parse("circle-translate-anchor", layer); + paint.blur.parse("circle-blur", layer); } void CircleLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); + paint.radius.cascade(parameters); + paint.color.cascade(parameters); + paint.opacity.cascade(parameters); + paint.translate.cascade(parameters); + paint.translateAnchor.cascade(parameters); + paint.blur.cascade(parameters); } -bool CircleLayer::hasTransitions() const { - return paints.hasTransitions(); -} +bool CircleLayer::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; -void CircleLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); + hasTransitions |= paint.radius.calculate(parameters); + hasTransitions |= paint.color.calculate(parameters); + hasTransitions |= paint.opacity.calculate(parameters); + hasTransitions |= paint.translate.calculate(parameters); + hasTransitions |= paint.translateAnchor.calculate(parameters); + hasTransitions |= paint.blur.calculate(parameters); - paints.calculateTransitioned(PropertyKey::CircleRadius, properties.radius, parameters); - paints.calculateTransitioned(PropertyKey::CircleColor, properties.color, parameters); - paints.calculateTransitioned(PropertyKey::CircleOpacity, properties.opacity, parameters); - paints.calculateTransitioned(PropertyKey::CircleTranslate, properties.translate, parameters); - paints.calculate(PropertyKey::CircleTranslateAnchor, properties.translateAnchor, parameters); - paints.calculateTransitioned(PropertyKey::CircleBlur, properties.blur, parameters); + passes = paint.isVisible() ? RenderPass::Translucent : RenderPass::None; - passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; + return hasTransitions; } std::unique_ptr<Bucket> CircleLayer::createBucket(StyleBucketParameters& parameters) const { diff --git a/src/mbgl/layer/circle_layer.hpp b/src/mbgl/layer/circle_layer.hpp index 29cdf513df..eac9a915cc 100644 --- a/src/mbgl/layer/circle_layer.hpp +++ b/src/mbgl/layer/circle_layer.hpp @@ -2,11 +2,24 @@ #define MBGL_CIRCLE_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { +class CirclePaintProperties { +public: + PaintProperty<float> radius = 5.0f; + PaintProperty<Color> color = { {{ 0, 0, 0, 1 }} }; + PaintProperty<float> opacity = 1.0f; + PaintProperty<std::array<float, 2>> translate = { {{ 0, 0 }} }; + PaintProperty<TranslateAnchorType> translateAnchor = TranslateAnchorType::Map; + PaintProperty<float> blur = 0; + + bool isVisible() const { + return radius > 0 && color.value[3] > 0 && opacity > 0; + } +}; + class CircleLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -15,15 +28,11 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - - PaintPropertiesMap paints; - - CirclePaintProperties properties; + CirclePaintProperties paint; }; } diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index ad68a240fc..52a6b8fe55 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -1,5 +1,4 @@ #include <mbgl/layer/fill_layer.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/fill_bucket.hpp> @@ -8,56 +7,54 @@ namespace mbgl { std::unique_ptr<StyleLayer> FillLayer::clone() const { std::unique_ptr<FillLayer> result = std::make_unique<FillLayer>(); result->copy(*this); - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } void FillLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<bool>>("fill-antialias", PropertyKey::FillAntialias, paint, value); - parseProperty<Function<float>>("fill-opacity", PropertyKey::FillOpacity, paint, value); - parseProperty<PropertyTransition>("fill-opacity-transition", PropertyKey::FillOpacity, paint, value); - parseProperty<Function<Color>>("fill-color", PropertyKey::FillColor, paint, value); - parseProperty<PropertyTransition>("fill-color-transition", PropertyKey::FillColor, paint, value); - parseProperty<Function<Color>>("fill-outline-color", PropertyKey::FillOutlineColor, paint, value); - parseProperty<PropertyTransition>("fill-outline-color-transition", PropertyKey::FillOutlineColor, paint, value); - parseProperty<Function<std::array<float, 2>>>("fill-translate", PropertyKey::FillTranslate, paint, value); - parseProperty<PropertyTransition>("fill-translate-transition", PropertyKey::FillTranslate, paint, value); - parseProperty<Function<TranslateAnchorType>>("fill-translate-anchor", PropertyKey::FillTranslateAnchor, paint, value); - parseProperty<Function<Faded<std::string>>>("fill-pattern", PropertyKey::FillImage, paint, value); - }); + paint.antialias.parse("fill-antialias", layer); + paint.opacity.parse("fill-opacity", layer); + paint.color.parse("fill-color", layer); + paint.outlineColor.parse("fill-outline-color", layer); + paint.translate.parse("fill-translate", layer); + paint.translateAnchor.parse("fill-translate-anchor", layer); + paint.pattern.parse("fill-pattern", layer); } void FillLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); -} - -bool FillLayer::hasTransitions() const { - return paints.hasTransitions(); + paint.antialias.cascade(parameters); + paint.opacity.cascade(parameters); + paint.color.cascade(parameters); + paint.outlineColor.cascade(parameters); + paint.translate.cascade(parameters); + paint.translateAnchor.cascade(parameters); + paint.pattern.cascade(parameters); } -void FillLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); +bool FillLayer::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; - paints.calculate(PropertyKey::FillAntialias, properties.antialias, parameters); - paints.calculateTransitioned(PropertyKey::FillOpacity, properties.opacity, parameters); - paints.calculateTransitioned(PropertyKey::FillColor, properties.fill_color, parameters); - paints.calculateTransitioned(PropertyKey::FillOutlineColor, properties.stroke_color, parameters); - paints.calculateTransitioned(PropertyKey::FillTranslate, properties.translate, parameters); - paints.calculate(PropertyKey::FillTranslateAnchor, properties.translateAnchor, parameters); - paints.calculate(PropertyKey::FillImage, properties.image, parameters); + hasTransitions |= paint.antialias.calculate(parameters); + hasTransitions |= paint.opacity.calculate(parameters); + hasTransitions |= paint.color.calculate(parameters); + hasTransitions |= paint.outlineColor.calculate(parameters); + hasTransitions |= paint.translate.calculate(parameters); + hasTransitions |= paint.translateAnchor.calculate(parameters); + hasTransitions |= paint.pattern.calculate(parameters); passes = RenderPass::None; - if (properties.antialias) { + if (paint.antialias) { passes |= RenderPass::Translucent; } - if (!properties.image.from.empty() || (properties.fill_color[3] * properties.opacity) < 1.0f) { + if (!paint.pattern.value.from.empty() || (paint.color.value[3] * paint.opacity) < 1.0f) { passes |= RenderPass::Translucent; } else { passes |= RenderPass::Opaque; } + + return hasTransitions; } std::unique_ptr<Bucket> FillLayer::createBucket(StyleBucketParameters& parameters) const { diff --git a/src/mbgl/layer/fill_layer.hpp b/src/mbgl/layer/fill_layer.hpp index 5a543889c5..c0ed228d48 100644 --- a/src/mbgl/layer/fill_layer.hpp +++ b/src/mbgl/layer/fill_layer.hpp @@ -2,11 +2,21 @@ #define MBGL_FILL_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { +class FillPaintProperties { +public: + PaintProperty<bool> antialias = true; + PaintProperty<float> opacity = 1.0f; + PaintProperty<Color> color = { {{ 0, 0, 0, 1 }} }; + PaintProperty<Color> outlineColor = { {{ 0, 0, 0, -1 }} }; + PaintProperty<std::array<float, 2>> translate = { {{ 0, 0 }} }; + PaintProperty<TranslateAnchorType> translateAnchor = TranslateAnchorType::Map; + PaintProperty<std::string, Faded<std::string>> pattern = { "" }; +}; + class FillLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -15,15 +25,11 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - - PaintPropertiesMap paints; - - FillPaintProperties properties; + FillPaintProperties paint; }; } diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index fa1f22d5f7..f4453f819d 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -1,5 +1,4 @@ #include <mbgl/layer/line_layer.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/style/style_bucket_parameters.hpp> #include <mbgl/renderer/line_bucket.hpp> #include <mbgl/map/tile_id.hpp> @@ -10,7 +9,7 @@ std::unique_ptr<StyleLayer> LineLayer::clone() const { std::unique_ptr<LineLayer> result = std::make_unique<LineLayer>(); result->copy(*this); result->layout = layout; - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } @@ -22,52 +21,51 @@ void LineLayer::parseLayout(const JSVal& value) { } void LineLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<float>>("line-opacity", PropertyKey::LineOpacity, paint, value); - parseProperty<PropertyTransition>("line-opacity-transition", PropertyKey::LineOpacity, paint, value); - parseProperty<Function<Color>>("line-color", PropertyKey::LineColor, paint, value); - parseProperty<PropertyTransition>("line-color-transition", PropertyKey::LineColor, paint, value); - parseProperty<Function<std::array<float,2>>>("line-translate", PropertyKey::LineTranslate, paint, value); - parseProperty<PropertyTransition>("line-translate-transition", PropertyKey::LineTranslate, paint, value); - parseProperty<Function<TranslateAnchorType>>("line-translate-anchor", PropertyKey::LineTranslateAnchor, paint, value); - parseProperty<Function<float>>("line-width", PropertyKey::LineWidth, paint, value); - parseProperty<PropertyTransition>("line-width-transition", PropertyKey::LineWidth, paint, value); - parseProperty<Function<float>>("line-gap-width", PropertyKey::LineGapWidth, paint, value); - parseProperty<PropertyTransition>("line-gap-width-transition", PropertyKey::LineGapWidth, paint, value); - parseProperty<Function<float>>("line-blur", PropertyKey::LineBlur, paint, value); - parseProperty<PropertyTransition>("line-blur-transition", PropertyKey::LineBlur, paint, value); - parseProperty<Function<Faded<std::vector<float>>>>("line-dasharray", PropertyKey::LineDashArray, paint, value); - parseProperty<Function<Faded<std::string>>>("line-pattern", PropertyKey::LineImage, paint, value); - }); + paint.opacity.parse("line-opacity", layer); + paint.color.parse("line-color", layer); + paint.translate.parse("line-translate", layer); + paint.translateAnchor.parse("line-translate-anchor", layer); + paint.width.parse("line-width", layer); + paint.gapWidth.parse("line-gap-width", layer); + paint.blur.parse("line-blur", layer); + paint.dasharray.parse("line-dasharray", layer); + paint.pattern.parse("line-pattern", layer); } void LineLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); -} - -bool LineLayer::hasTransitions() const { - return paints.hasTransitions(); + paint.opacity.cascade(parameters); + paint.color.cascade(parameters); + paint.translate.cascade(parameters); + paint.translateAnchor.cascade(parameters); + paint.width.cascade(parameters); + paint.gapWidth.cascade(parameters); + paint.blur.cascade(parameters); + paint.dasharray.cascade(parameters); + paint.pattern.cascade(parameters); } -void LineLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); - - paints.calculateTransitioned(PropertyKey::LineOpacity, properties.opacity, parameters); - paints.calculateTransitioned(PropertyKey::LineColor, properties.color, parameters); - paints.calculateTransitioned(PropertyKey::LineTranslate, properties.translate, parameters); - paints.calculate(PropertyKey::LineTranslateAnchor, properties.translateAnchor, parameters); - paints.calculateTransitioned(PropertyKey::LineWidth, properties.width, parameters); - paints.calculateTransitioned(PropertyKey::LineGapWidth, properties.gap_width, parameters); - paints.calculateTransitioned(PropertyKey::LineBlur, properties.blur, parameters); - paints.calculate(PropertyKey::LineDashArray, properties.dash_array, parameters); - paints.calculate(PropertyKey::LineImage, properties.image, parameters); - +bool LineLayer::recalculate(const StyleCalculationParameters& parameters) { // for scaling dasharrays StyleCalculationParameters dashArrayParams = parameters; dashArrayParams.z = std::floor(dashArrayParams.z); - paints.calculate(PropertyKey::LineWidth, properties.dash_line_width, dashArrayParams); + paint.width.calculate(dashArrayParams); + paint.dashLineWidth = paint.width; + + bool hasTransitions = false; + + hasTransitions |= paint.opacity.calculate(parameters); + hasTransitions |= paint.color.calculate(parameters); + hasTransitions |= paint.translate.calculate(parameters); + hasTransitions |= paint.translateAnchor.calculate(parameters); + hasTransitions |= paint.width.calculate(parameters); + hasTransitions |= paint.gapWidth.calculate(parameters); + hasTransitions |= paint.blur.calculate(parameters); + hasTransitions |= paint.dasharray.calculate(parameters); + hasTransitions |= paint.pattern.calculate(parameters); + + passes = paint.isVisible() ? RenderPass::Translucent : RenderPass::None; - passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; + return hasTransitions; } std::unique_ptr<Bucket> LineLayer::createBucket(StyleBucketParameters& parameters) const { diff --git a/src/mbgl/layer/line_layer.hpp b/src/mbgl/layer/line_layer.hpp index d35461131e..639ba34f57 100644 --- a/src/mbgl/layer/line_layer.hpp +++ b/src/mbgl/layer/line_layer.hpp @@ -2,9 +2,8 @@ #define MBGL_LINE_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> #include <mbgl/style/layout_property.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { @@ -16,6 +15,26 @@ public: LayoutProperty<float> roundLimit = 1.0f; }; +class LinePaintProperties { +public: + PaintProperty<float> opacity = 1.0f; + PaintProperty<Color> color = { {{ 0, 0, 0, 1 }} }; + PaintProperty<std::array<float, 2>> translate = { {{ 0, 0 }} }; + PaintProperty<TranslateAnchorType> translateAnchor = TranslateAnchorType::Map; + PaintProperty<float> width = 1; + PaintProperty<float> gapWidth = 0; + PaintProperty<float> blur = 0; + PaintProperty<std::vector<float>, Faded<std::vector<float>>> dasharray = { {} }; + PaintProperty<std::string, Faded<std::string>> pattern = { "" }; + + // Special case + float dashLineWidth = 1; + + bool isVisible() const { + return opacity > 0 && color.value[3] > 0 && width > 0; + } +}; + class LineLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -24,16 +43,12 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - LineLayoutProperties layout; - PaintPropertiesMap paints; - - LinePaintProperties properties; + LinePaintProperties paint; }; } diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp index 3e3536afc3..5a7e686441 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/layer/raster_layer.cpp @@ -1,5 +1,4 @@ #include <mbgl/layer/raster_layer.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/renderer/bucket.hpp> namespace mbgl { @@ -7,48 +6,44 @@ namespace mbgl { std::unique_ptr<StyleLayer> RasterLayer::clone() const { std::unique_ptr<RasterLayer> result = std::make_unique<RasterLayer>(); result->copy(*this); - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } void RasterLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<float>>("raster-opacity", PropertyKey::RasterOpacity, paint, value); - parseProperty<PropertyTransition>("raster-opacity-transition", PropertyKey::RasterOpacity, paint, value); - parseProperty<Function<float>>("raster-hue-rotate", PropertyKey::RasterHueRotate, paint, value); - parseProperty<PropertyTransition>("raster-hue-rotate-transition", PropertyKey::RasterHueRotate, paint, value); - parseProperty<Function<float>>("raster-brightness-min", PropertyKey::RasterBrightnessLow, paint, value); - parseProperty<Function<float>>("raster-brightness-max", PropertyKey::RasterBrightnessHigh, paint, value); - parseProperty<PropertyTransition>("raster-brightness-transition", PropertyKey::RasterBrightness, paint, value); - parseProperty<Function<float>>("raster-saturation", PropertyKey::RasterSaturation, paint, value); - parseProperty<PropertyTransition>("raster-saturation-transition", PropertyKey::RasterSaturation, paint, value); - parseProperty<Function<float>>("raster-contrast", PropertyKey::RasterContrast, paint, value); - parseProperty<PropertyTransition>("raster-contrast-transition", PropertyKey::RasterContrast, paint, value); - parseProperty<Function<float>>("raster-fade-duration", PropertyKey::RasterFade, paint, value); - parseProperty<PropertyTransition>("raster-fade-duration-transition", PropertyKey::RasterFade, paint, value); - }); + paint.opacity.parse("raster-opacity", layer); + paint.hueRotate.parse("raster-hue-rotate", layer); + paint.brightnessMin.parse("raster-brightness-min", layer); + paint.brightnessMax.parse("raster-brightness-max", layer); + paint.saturation.parse("raster-saturation", layer); + paint.contrast.parse("raster-contrast", layer); + paint.fadeDuration.parse("raster-fade-duration", layer); } void RasterLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); + paint.opacity.cascade(parameters); + paint.hueRotate.cascade(parameters); + paint.brightnessMin.cascade(parameters); + paint.brightnessMax.cascade(parameters); + paint.saturation.cascade(parameters); + paint.contrast.cascade(parameters); + paint.fadeDuration.cascade(parameters); } -bool RasterLayer::hasTransitions() const { - return paints.hasTransitions(); -} +bool RasterLayer::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; -void RasterLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); + hasTransitions |= paint.opacity.calculate(parameters); + hasTransitions |= paint.hueRotate.calculate(parameters); + hasTransitions |= paint.brightnessMin.calculate(parameters); + hasTransitions |= paint.brightnessMax.calculate(parameters); + hasTransitions |= paint.saturation.calculate(parameters); + hasTransitions |= paint.contrast.calculate(parameters); + hasTransitions |= paint.fadeDuration.calculate(parameters); - paints.calculateTransitioned(PropertyKey::RasterOpacity, properties.opacity, parameters); - paints.calculateTransitioned(PropertyKey::RasterHueRotate, properties.hue_rotate, parameters); - paints.calculateTransitioned(PropertyKey::RasterBrightnessLow, properties.brightness[0], parameters); - paints.calculateTransitioned(PropertyKey::RasterBrightnessHigh, properties.brightness[1], parameters); - paints.calculateTransitioned(PropertyKey::RasterSaturation, properties.saturation, parameters); - paints.calculateTransitioned(PropertyKey::RasterContrast, properties.contrast, parameters); - paints.calculateTransitioned(PropertyKey::RasterFade, properties.fade, parameters); + passes = paint.opacity > 0 ? RenderPass::Translucent : RenderPass::None; - passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; + return hasTransitions; } std::unique_ptr<Bucket> RasterLayer::createBucket(StyleBucketParameters&) const { diff --git a/src/mbgl/layer/raster_layer.hpp b/src/mbgl/layer/raster_layer.hpp index 650ffc8ef1..800236016d 100644 --- a/src/mbgl/layer/raster_layer.hpp +++ b/src/mbgl/layer/raster_layer.hpp @@ -2,11 +2,21 @@ #define MBGL_RASTER_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { +class RasterPaintProperties { +public: + PaintProperty<float> opacity = 1.0f; + PaintProperty<float> hueRotate = 0.0f; + PaintProperty<float> brightnessMin = 0.0f; + PaintProperty<float> brightnessMax = 1.0f; + PaintProperty<float> saturation = 0.0f; + PaintProperty<float> contrast = 0.0f; + PaintProperty<float> fadeDuration = 0.0f; +}; + class RasterLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -15,15 +25,11 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - - PaintPropertiesMap paints; - - RasterPaintProperties properties; + RasterPaintProperties paint; }; } diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index 932e500c5e..76c4970deb 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -1,8 +1,6 @@ #include <mbgl/layer/symbol_layer.hpp> #include <mbgl/renderer/symbol_bucket.hpp> #include <mbgl/map/tile_id.hpp> -#include <mbgl/style/property_evaluator.hpp> -#include <mbgl/style/property_parsing.hpp> #include <mbgl/style/style_bucket_parameters.hpp> namespace mbgl { @@ -11,7 +9,7 @@ std::unique_ptr<StyleLayer> SymbolLayer::clone() const { std::unique_ptr<SymbolLayer> result = std::make_unique<SymbolLayer>(); result->copy(*this); result->layout = layout; - result->paints.paints = paints.paints; + result->paint = paint; return std::move(result); } @@ -52,71 +50,70 @@ void SymbolLayer::parseLayout(const JSVal& value) { } void SymbolLayer::parsePaints(const JSVal& layer) { - paints.parseEach(layer, [&] (ClassProperties& paint, const JSVal& value) { - parseProperty<Function<float>>("icon-opacity", PropertyKey::IconOpacity, paint, value); - parseProperty<PropertyTransition>("icon-opacity-transition", PropertyKey::IconOpacity, paint, value); - parseProperty<Function<Color>>("icon-color", PropertyKey::IconColor, paint, value); - parseProperty<PropertyTransition>("icon-color-transition", PropertyKey::IconColor, paint, value); - parseProperty<Function<Color>>("icon-halo-color", PropertyKey::IconHaloColor, paint, value); - parseProperty<PropertyTransition>("icon-halo-color-transition", PropertyKey::IconHaloColor, paint, value); - parseProperty<Function<float>>("icon-halo-width", PropertyKey::IconHaloWidth, paint, value); - parseProperty<PropertyTransition>("icon-halo-width-transition", PropertyKey::IconHaloWidth, paint, value); - parseProperty<Function<float>>("icon-halo-blur", PropertyKey::IconHaloBlur, paint, value); - parseProperty<PropertyTransition>("icon-halo-blur-transition", PropertyKey::IconHaloBlur, paint, value); - parseProperty<Function<std::array<float, 2>>>("icon-translate", PropertyKey::IconTranslate, paint, value); - parseProperty<PropertyTransition>("icon-translate-transition", PropertyKey::IconTranslate, paint, value); - parseProperty<Function<TranslateAnchorType>>("icon-translate-anchor", PropertyKey::IconTranslateAnchor, paint, value); - - parseProperty<Function<float>>("text-opacity", PropertyKey::TextOpacity, paint, value); - parseProperty<PropertyTransition>("text-opacity-transition", PropertyKey::TextOpacity, paint, value); - parseProperty<Function<Color>>("text-color", PropertyKey::TextColor, paint, value); - parseProperty<PropertyTransition>("text-color-transition", PropertyKey::TextColor, paint, value); - parseProperty<Function<Color>>("text-halo-color", PropertyKey::TextHaloColor, paint, value); - parseProperty<PropertyTransition>("text-halo-color-transition", PropertyKey::TextHaloColor, paint, value); - parseProperty<Function<float>>("text-halo-width", PropertyKey::TextHaloWidth, paint, value); - parseProperty<PropertyTransition>("text-halo-width-transition", PropertyKey::TextHaloWidth, paint, value); - parseProperty<Function<float>>("text-halo-blur", PropertyKey::TextHaloBlur, paint, value); - parseProperty<PropertyTransition>("text-halo-blur-transition", PropertyKey::TextHaloBlur, paint, value); - parseProperty<Function<std::array<float, 2>>>("text-translate", PropertyKey::TextTranslate, paint, value); - parseProperty<PropertyTransition>("text-translate-transition", PropertyKey::TextTranslate, paint, value); - parseProperty<Function<TranslateAnchorType>>("text-translate-anchor", PropertyKey::TextTranslateAnchor, paint, value); - }); + paint.icon.opacity.parse("icon-opacity", layer); + paint.icon.color.parse("icon-color", layer); + paint.icon.haloColor.parse("icon-halo-color", layer); + paint.icon.haloWidth.parse("icon-halo-width", layer); + paint.icon.haloBlur.parse("icon-halo-blur", layer); + paint.icon.translate.parse("icon-translate", layer); + paint.icon.translateAnchor.parse("icon-translate-anchor", layer); + + paint.text.opacity.parse("text-opacity", layer); + paint.text.color.parse("text-color", layer); + paint.text.haloColor.parse("text-halo-color", layer); + paint.text.haloWidth.parse("text-halo-width", layer); + paint.text.haloBlur.parse("text-halo-blur", layer); + paint.text.translate.parse("text-translate", layer); + paint.text.translateAnchor.parse("text-translate-anchor", layer); } void SymbolLayer::cascade(const StyleCascadeParameters& parameters) { - paints.cascade(parameters); + paint.icon.opacity.cascade(parameters); + paint.icon.color.cascade(parameters); + paint.icon.haloColor.cascade(parameters); + paint.icon.haloWidth.cascade(parameters); + paint.icon.haloBlur.cascade(parameters); + paint.icon.translate.cascade(parameters); + paint.icon.translateAnchor.cascade(parameters); + + paint.text.opacity.cascade(parameters); + paint.text.color.cascade(parameters); + paint.text.haloColor.cascade(parameters); + paint.text.haloWidth.cascade(parameters); + paint.text.haloBlur.cascade(parameters); + paint.text.translate.cascade(parameters); + paint.text.translateAnchor.cascade(parameters); } -bool SymbolLayer::hasTransitions() const { - return paints.hasTransitions(); -} - -void SymbolLayer::recalculate(const StyleCalculationParameters& parameters) { - paints.removeExpiredTransitions(parameters.now); - - paints.calculateTransitioned(PropertyKey::IconOpacity, properties.icon.opacity, parameters); - paints.calculateTransitioned(PropertyKey::IconColor, properties.icon.color, parameters); - paints.calculateTransitioned(PropertyKey::IconHaloColor, properties.icon.halo_color, parameters); - paints.calculateTransitioned(PropertyKey::IconHaloWidth, properties.icon.halo_width, parameters); - paints.calculateTransitioned(PropertyKey::IconHaloBlur, properties.icon.halo_blur, parameters); - paints.calculateTransitioned(PropertyKey::IconTranslate, properties.icon.translate, parameters); - paints.calculate(PropertyKey::IconTranslateAnchor, properties.icon.translate_anchor, parameters); - - paints.calculateTransitioned(PropertyKey::TextOpacity, properties.text.opacity, parameters); - paints.calculateTransitioned(PropertyKey::TextColor, properties.text.color, parameters); - paints.calculateTransitioned(PropertyKey::TextHaloColor, properties.text.halo_color, parameters); - paints.calculateTransitioned(PropertyKey::TextHaloWidth, properties.text.halo_width, parameters); - paints.calculateTransitioned(PropertyKey::TextHaloBlur, properties.text.halo_blur, parameters); - paints.calculateTransitioned(PropertyKey::TextTranslate, properties.text.translate, parameters); - paints.calculate(PropertyKey::TextTranslateAnchor, properties.text.translate_anchor, parameters); +bool SymbolLayer::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= paint.icon.opacity.calculate(parameters); + hasTransitions |= paint.icon.color.calculate(parameters); + hasTransitions |= paint.icon.haloColor.calculate(parameters); + hasTransitions |= paint.icon.haloWidth.calculate(parameters); + hasTransitions |= paint.icon.haloBlur.calculate(parameters); + hasTransitions |= paint.icon.translate.calculate(parameters); + hasTransitions |= paint.icon.translateAnchor.calculate(parameters); + + hasTransitions |= paint.text.opacity.calculate(parameters); + hasTransitions |= paint.text.color.calculate(parameters); + hasTransitions |= paint.text.haloColor.calculate(parameters); + hasTransitions |= paint.text.haloWidth.calculate(parameters); + hasTransitions |= paint.text.haloBlur.calculate(parameters); + hasTransitions |= paint.text.translate.calculate(parameters); + hasTransitions |= paint.text.translateAnchor.calculate(parameters); // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: layout.icon.size.calculate(parameters); layout.text.size.calculate(parameters); - properties.icon.size = layout.icon.size; - properties.text.size = layout.text.size; + paint.icon.size = layout.icon.size; + paint.text.size = layout.text.size; + + passes = (paint.icon.isVisible() || paint.text.isVisible()) + ? RenderPass::Translucent : RenderPass::None; - passes = properties.isVisible() ? RenderPass::Translucent : RenderPass::None; + return hasTransitions; } std::unique_ptr<Bucket> SymbolLayer::createBucket(StyleBucketParameters& parameters) const { diff --git a/src/mbgl/layer/symbol_layer.hpp b/src/mbgl/layer/symbol_layer.hpp index 3871d7a2d4..9e4555350a 100644 --- a/src/mbgl/layer/symbol_layer.hpp +++ b/src/mbgl/layer/symbol_layer.hpp @@ -2,9 +2,8 @@ #define MBGL_SYMBOL_LAYER #include <mbgl/style/style_layer.hpp> -#include <mbgl/style/style_properties.hpp> -#include <mbgl/style/paint_properties_map.hpp> #include <mbgl/style/layout_property.hpp> +#include <mbgl/style/paint_property.hpp> namespace mbgl { @@ -55,6 +54,32 @@ public: float textMaxSize = 16.0f; }; +class SymbolPaintProperties { +public: + class PaintProperties { + public: + PaintProperties(float size_) : size(size_) {} + + PaintProperty<float> opacity = 1.0f; + PaintProperty<Color> color = { {{ 0, 0, 0, 1 }} }; + PaintProperty<Color> haloColor = { {{ 0, 0, 0, 0 }} }; + PaintProperty<float> haloWidth = 0.0f; + PaintProperty<float> haloBlur = 0.0f; + PaintProperty<std::array<float, 2>> translate = { {{ 0, 0 }} }; + PaintProperty<TranslateAnchorType> translateAnchor = TranslateAnchorType::Map; + + // Special case + float size; + + bool isVisible() const { + return opacity > 0 && (color.value[3] > 0 || haloColor.value[3] > 0) && size > 0; + } + }; + + PaintProperties icon { 1.0f }; + PaintProperties text { 16.0f }; +}; + class SymbolLayer : public StyleLayer { public: std::unique_ptr<StyleLayer> clone() const override; @@ -63,16 +88,12 @@ public: void parsePaints(const JSVal&) override; void cascade(const StyleCascadeParameters&) override; - void recalculate(const StyleCalculationParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const override; - bool hasTransitions() const override; - SymbolLayoutProperties layout; - PaintPropertiesMap paints; - - SymbolPaintProperties properties; + SymbolPaintProperties paint; }; } diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index c11463ee24..555d6684ac 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -282,8 +282,8 @@ std::vector<RenderItem> Painter::determineRenderOrder(const Style& style) { if (layer.visibility == VisibilityType::None) continue; if (layer.type == StyleLayerType::Background) { // This layer defines a background color/image. - auto& props = dynamic_cast<const BackgroundLayer&>(layer).properties; - if (props.image.from.empty()) { + auto& props = dynamic_cast<const BackgroundLayer&>(layer).paint; + if (props.pattern.value.from.empty()) { // This is a solid background. We can use glClear(). background = props.color; background[0] *= props.opacity; @@ -352,14 +352,14 @@ std::vector<RenderItem> Painter::determineRenderOrder(const Style& style) { void Painter::renderBackground(const BackgroundLayer& layer) { // Note: This function is only called for textured background. Otherwise, the background color // is created with glClear. - const BackgroundPaintProperties& properties = layer.properties; + const BackgroundPaintProperties& properties = layer.paint; - if (!properties.image.to.empty()) { + if (!properties.pattern.value.to.empty()) { if ((properties.opacity >= 1.0f) != (pass == RenderPass::Opaque)) return; - SpriteAtlasPosition imagePosA = spriteAtlas->getPosition(properties.image.from, true); - SpriteAtlasPosition imagePosB = spriteAtlas->getPosition(properties.image.to, true); + SpriteAtlasPosition imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); + SpriteAtlasPosition imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); float zoomFraction = state.getZoomFraction(); config.program = patternShader->program; @@ -368,7 +368,7 @@ void Painter::renderBackground(const BackgroundLayer& layer) { patternShader->u_pattern_br_a = imagePosA.br; patternShader->u_pattern_tl_b = imagePosB.tl; patternShader->u_pattern_br_b = imagePosB.br; - patternShader->u_mix = properties.image.t; + patternShader->u_mix = properties.pattern.value.t; patternShader->u_opacity = properties.opacity; LatLng latLng = state.getLatLng(); @@ -379,11 +379,11 @@ void Painter::renderBackground(const BackgroundLayer& layer) { mat3 matrixA; matrix::identity(matrixA); matrix::scale(matrixA, matrixA, - 1.0f / (sizeA[0] * properties.image.fromScale), - 1.0f / (sizeA[1] * properties.image.fromScale)); + 1.0f / (sizeA[0] * properties.pattern.value.fromScale), + 1.0f / (sizeA[1] * properties.pattern.value.fromScale)); matrix::translate(matrixA, matrixA, - std::fmod(center.x * 512, sizeA[0] * properties.image.fromScale), - std::fmod(center.y * 512, sizeA[1] * properties.image.fromScale)); + std::fmod(center.x * 512, sizeA[0] * properties.pattern.value.fromScale), + std::fmod(center.y * 512, sizeA[1] * properties.pattern.value.fromScale)); matrix::rotate(matrixA, matrixA, -state.getAngle()); matrix::scale(matrixA, matrixA, scale * state.getWidth() / 2, @@ -393,11 +393,11 @@ void Painter::renderBackground(const BackgroundLayer& layer) { mat3 matrixB; matrix::identity(matrixB); matrix::scale(matrixB, matrixB, - 1.0f / (sizeB[0] * properties.image.toScale), - 1.0f / (sizeB[1] * properties.image.toScale)); + 1.0f / (sizeB[0] * properties.pattern.value.toScale), + 1.0f / (sizeB[1] * properties.pattern.value.toScale)); matrix::translate(matrixB, matrixB, - std::fmod(center.x * 512, sizeB[0] * properties.image.toScale), - std::fmod(center.y * 512, sizeB[1] * properties.image.toScale)); + std::fmod(center.x * 512, sizeB[0] * properties.pattern.value.toScale), + std::fmod(center.y * 512, sizeB[1] * properties.pattern.value.toScale)); matrix::rotate(matrixB, matrixB, -state.getAngle()); matrix::scale(matrixB, matrixB, scale * state.getWidth() / 2, diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index 98443a561a..708064bf89 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -20,7 +20,7 @@ void Painter::renderCircle(CircleBucket& bucket, config.stencilTest = GL_FALSE; - const CirclePaintProperties& properties = layer.properties; + const CirclePaintProperties& properties = layer.paint; mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); Color color = properties.color; @@ -40,7 +40,7 @@ void Painter::renderCircle(CircleBucket& bucket, circleShader->u_matrix = vtxMatrix; circleShader->u_exmatrix = extrudeMatrix; circleShader->u_color = color; - circleShader->u_blur = std::max(properties.blur, antialiasing); + circleShader->u_blur = std::max<float>(properties.blur, antialiasing); circleShader->u_size = properties.radius; bucket.drawCircles(*circleShader); diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index e0e1c0c96a..d9e069d4e8 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -12,16 +12,16 @@ using namespace mbgl; void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileID& id, const mat4& matrix) { - const FillPaintProperties& properties = layer.properties; + const FillPaintProperties& properties = layer.paint; mat4 vtxMatrix = translatedMatrix(matrix, properties.translate, id, properties.translateAnchor); - Color fill_color = properties.fill_color; + Color fill_color = properties.color; fill_color[0] *= properties.opacity; fill_color[1] *= properties.opacity; fill_color[2] *= properties.opacity; fill_color[3] *= properties.opacity; - Color stroke_color = properties.stroke_color; + Color stroke_color = properties.outlineColor; if (stroke_color[3] < 0) { stroke_color = fill_color; } else { @@ -31,7 +31,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI stroke_color[3] *= properties.opacity; } - const bool pattern = !properties.image.from.empty(); + const bool pattern = !properties.pattern.value.from.empty(); bool outline = properties.antialias && !pattern && stroke_color != fill_color; bool fringeline = properties.antialias && !pattern && stroke_color == fill_color; @@ -63,20 +63,20 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI // Image fill. if (pass == RenderPass::Translucent) { - const SpriteAtlasPosition posA = spriteAtlas->getPosition(properties.image.from, true); - const SpriteAtlasPosition posB = spriteAtlas->getPosition(properties.image.to, true); + const SpriteAtlasPosition posA = spriteAtlas->getPosition(properties.pattern.value.from, true); + const SpriteAtlasPosition posB = spriteAtlas->getPosition(properties.pattern.value.to, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z) / id.overscaling; mat3 patternMatrixA; matrix::identity(patternMatrixA); matrix::scale(patternMatrixA, patternMatrixA, - 1.0f / (posA.size[0] * factor * properties.image.fromScale), - 1.0f / (posA.size[1] * factor * properties.image.fromScale)); + 1.0f / (posA.size[0] * factor * properties.pattern.value.fromScale), + 1.0f / (posA.size[1] * factor * properties.pattern.value.fromScale)); mat3 patternMatrixB; matrix::identity(patternMatrixB); matrix::scale(patternMatrixB, patternMatrixB, - 1.0f / (posB.size[0] * factor * properties.image.toScale), - 1.0f / (posB.size[1] * factor * properties.image.toScale)); + 1.0f / (posB.size[0] * factor * properties.pattern.value.toScale), + 1.0f / (posB.size[1] * factor * properties.pattern.value.toScale)); config.program = patternShader->program; patternShader->u_matrix = vtxMatrix; @@ -86,7 +86,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const TileI patternShader->u_pattern_br_b = posB.br; patternShader->u_opacity = properties.opacity; patternShader->u_image = 0; - patternShader->u_mix = properties.image.t; + patternShader->u_mix = properties.pattern.value.t; patternShader->u_patternmatrix_a = patternMatrixA; patternShader->u_patternmatrix_b = patternMatrixB; diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 1cdb5e2195..cfc85fcb48 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -23,7 +23,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI config.depthTest = GL_TRUE; config.depthMask = GL_FALSE; - const auto& properties = layer.properties; + const auto& properties = layer.paint; const auto& layout = bucket.layout; // the distance over which the line edge fades out. @@ -36,8 +36,8 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI float offset = 0; float shift = 0; - if (properties.gap_width != 0) { - inset = properties.gap_width / 2.0 + antialiasing * 0.5; + if (properties.gapWidth != 0) { + inset = properties.gapWidth / 2.0 + antialiasing * 0.5; edgeWidth = properties.width; // shift outer lines half a pixel towards the middle to eliminate the crack @@ -69,7 +69,7 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI setDepthSublayer(0); - if (!properties.dash_array.from.empty()) { + if (!properties.dasharray.value.from.empty()) { config.program = linesdfShader->program; @@ -80,14 +80,14 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI linesdfShader->u_blur = blur; linesdfShader->u_color = color; - LinePatternPos posA = lineAtlas->getDashPosition(properties.dash_array.from, layout.cap == CapType::Round); - LinePatternPos posB = lineAtlas->getDashPosition(properties.dash_array.to, layout.cap == CapType::Round); + LinePatternPos posA = lineAtlas->getDashPosition(properties.dasharray.value.from, layout.cap == CapType::Round); + LinePatternPos posB = lineAtlas->getDashPosition(properties.dasharray.value.to, layout.cap == CapType::Round); lineAtlas->bind(); float patternratio = std::pow(2.0, std::floor(::log2(state.getScale())) - id.z) / 8.0 * id.overscaling; - float scaleXA = patternratio / posA.width / properties.dash_line_width / properties.dash_array.fromScale; + float scaleXA = patternratio / posA.width / properties.dashLineWidth / properties.dasharray.value.fromScale; float scaleYA = -posA.height / 2.0; - float scaleXB = patternratio / posB.width / properties.dash_line_width / properties.dash_array.toScale; + float scaleXB = patternratio / posB.width / properties.dashLineWidth / properties.dasharray.value.toScale; float scaleYB = -posB.height / 2.0; linesdfShader->u_patternscale_a = {{ scaleXA, scaleYA }}; @@ -95,16 +95,16 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI linesdfShader->u_patternscale_b = {{ scaleXB, scaleYB }}; linesdfShader->u_tex_y_b = posB.y; linesdfShader->u_image = 0; - linesdfShader->u_sdfgamma = lineAtlas->width / (properties.dash_line_width * std::min(posA.width, posB.width) * 256.0 * data.pixelRatio) / 2; - linesdfShader->u_mix = properties.dash_array.t; + linesdfShader->u_sdfgamma = lineAtlas->width / (properties.dashLineWidth * std::min(posA.width, posB.width) * 256.0 * data.pixelRatio) / 2; + linesdfShader->u_mix = properties.dasharray.value.t; linesdfShader->u_extra = extra; linesdfShader->u_antialiasingmatrix = antialiasingMatrix; bucket.drawLineSDF(*linesdfShader); - } else if (!properties.image.from.empty()) { - SpriteAtlasPosition imagePosA = spriteAtlas->getPosition(properties.image.from, true); - SpriteAtlasPosition imagePosB = spriteAtlas->getPosition(properties.image.to, true); + } else if (!properties.pattern.value.from.empty()) { + SpriteAtlasPosition imagePosA = spriteAtlas->getPosition(properties.pattern.value.from, true); + SpriteAtlasPosition imagePosB = spriteAtlas->getPosition(properties.pattern.value.to, true); float factor = 8.0 / std::pow(2, state.getIntegerZoom() - id.z) * id.overscaling; @@ -116,13 +116,13 @@ void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, const TileI linepatternShader->u_ratio = ratio; linepatternShader->u_blur = blur; - linepatternShader->u_pattern_size_a = {{imagePosA.size[0] * factor * properties.image.fromScale, imagePosA.size[1]}}; + linepatternShader->u_pattern_size_a = {{imagePosA.size[0] * factor * properties.pattern.value.fromScale, imagePosA.size[1]}}; linepatternShader->u_pattern_tl_a = imagePosA.tl; linepatternShader->u_pattern_br_a = imagePosA.br; - linepatternShader->u_pattern_size_b = {{imagePosB.size[0] * factor * properties.image.toScale, imagePosB.size[1]}}; + linepatternShader->u_pattern_size_b = {{imagePosB.size[0] * factor * properties.pattern.value.toScale, imagePosB.size[1]}}; linepatternShader->u_pattern_tl_b = imagePosB.tl; linepatternShader->u_pattern_br_b = imagePosB.br; - linepatternShader->u_fade = properties.image.t; + linepatternShader->u_fade = properties.pattern.value.t; linepatternShader->u_opacity = properties.opacity; linepatternShader->u_extra = extra; linepatternShader->u_antialiasingmatrix = antialiasingMatrix; diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index 06e6b06c2e..9672d6f0d6 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -9,18 +9,18 @@ using namespace mbgl; void Painter::renderRaster(RasterBucket& bucket, const RasterLayer& layer, const TileID&, const mat4& matrix) { if (pass != RenderPass::Translucent) return; - const RasterPaintProperties& properties = layer.properties; + const RasterPaintProperties& properties = layer.paint; if (bucket.hasData()) { config.program = rasterShader->program; rasterShader->u_matrix = matrix; rasterShader->u_buffer = 0; rasterShader->u_opacity = properties.opacity; - rasterShader->u_brightness_low = properties.brightness[0]; - rasterShader->u_brightness_high = properties.brightness[1]; + rasterShader->u_brightness_low = properties.brightnessMin; + rasterShader->u_brightness_high = properties.brightnessMax; rasterShader->u_saturation_factor = saturationFactor(properties.saturation); rasterShader->u_contrast_factor = contrastFactor(properties.contrast); - rasterShader->u_spin_weights = spinWeights(properties.hue_rotate); + rasterShader->u_spin_weights = spinWeights(properties.hueRotate); config.stencilOp.reset(); config.stencilTest = GL_TRUE; diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 48ed4bd43f..343c9d5233 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -25,7 +25,7 @@ void Painter::renderSDF(SymbolBucket &bucket, SDFShader& sdfShader, void (SymbolBucket::*drawSDF)(SDFShader&)) { - mat4 vtxMatrix = translatedMatrix(matrix, styleProperties.translate, id, styleProperties.translate_anchor); + mat4 vtxMatrix = translatedMatrix(matrix, styleProperties.translate, id, styleProperties.translateAnchor); bool skewed = (bucketProperties.rotationAlignment == RotationAlignmentType::Map); mat4 exMatrix; @@ -89,28 +89,28 @@ void Painter::renderSDF(SymbolBucket &bucket, // We're drawing in the translucent pass which is bottom-to-top, so we need // to draw the halo first. - if (styleProperties.halo_color[3] > 0.0f && styleProperties.halo_width > 0.0f) { - sdfShader.u_gamma = (styleProperties.halo_blur * blurOffset / fontScale / sdfPx + gamma) * gammaScale; + if (styleProperties.haloColor.value[3] > 0.0f && styleProperties.haloWidth > 0.0f) { + sdfShader.u_gamma = (styleProperties.haloBlur * blurOffset / fontScale / sdfPx + gamma) * gammaScale; if (styleProperties.opacity < 1.0f) { - Color color = styleProperties.halo_color; + Color color = styleProperties.haloColor; color[0] *= styleProperties.opacity; color[1] *= styleProperties.opacity; color[2] *= styleProperties.opacity; color[3] *= styleProperties.opacity; sdfShader.u_color = color; } else { - sdfShader.u_color = styleProperties.halo_color; + sdfShader.u_color = styleProperties.haloColor; } - sdfShader.u_buffer = (haloOffset - styleProperties.halo_width / fontScale) / sdfPx; + sdfShader.u_buffer = (haloOffset - styleProperties.haloWidth / fontScale) / sdfPx; setDepthSublayer(0); (bucket.*drawSDF)(sdfShader); } // Then, we draw the text/icon over the halo - if (styleProperties.color[3] > 0.0f) { + if (styleProperties.color.value[3] > 0.0f) { sdfShader.u_gamma = gamma * gammaScale; if (styleProperties.opacity < 1.0f) { @@ -137,7 +137,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const return; } - const auto& properties = layer.properties; + const auto& properties = layer.paint; const auto& layout = bucket.layout; config.depthMask = GL_FALSE; @@ -206,7 +206,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, const SymbolLayer& layer, const *sdfIconShader, &SymbolBucket::drawIcons); } else { - mat4 vtxMatrix = translatedMatrix(matrix, properties.icon.translate, id, properties.icon.translate_anchor); + mat4 vtxMatrix = translatedMatrix(matrix, properties.icon.translate, id, properties.icon.translateAnchor); bool skewed = layout.icon.rotationAlignment == RotationAlignmentType::Map; mat4 exMatrix; diff --git a/src/mbgl/style/applied_class_properties.cpp b/src/mbgl/style/applied_class_properties.cpp deleted file mode 100644 index 9563250ba7..0000000000 --- a/src/mbgl/style/applied_class_properties.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include <mbgl/style/applied_class_properties.hpp> - -namespace mbgl { - -AppliedClassPropertyValue::AppliedClassPropertyValue(ClassID class_id, const TimePoint& begin_, const TimePoint& end_, const PropertyValue &value_) - : name(class_id), - begin(begin_), - end(end_), - value(value_) {} - -// Returns the ID of the most recent -ClassID AppliedClassPropertyValues::mostRecent() const { - return propertyValues.empty() ? ClassID::Fallback : propertyValues.back().name; -} - -void AppliedClassPropertyValues::add(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value) { - propertyValues.emplace_back(class_id, begin, end, value); -} - -bool AppliedClassPropertyValues::hasTransitions() const { - return propertyValues.size() > 1; -} - -// Erase all items in the property list that are before a completed transition. -// Then, if the only remaining property is a Fallback value, remove it too. -void AppliedClassPropertyValues::cleanup(const TimePoint& now) { - // Iterate backwards, but without using the rbegin/rend interface since we need forward - // iterators to use .erase(). - for (auto it = propertyValues.end(), begin = propertyValues.begin(); it != begin;) { - // If the property is finished, break iteration and delete all remaining items. - if ((--it)->end <= now) { - // Removes all items that precede the current iterator, but *not* the element currently - // pointed to by the iterator. This preserves the last completed transition as the - // first element in the property list. - propertyValues.erase(begin, it); - - // Also erase the pivot element if it's a fallback value. This means we can remove the - // entire applied properties object as well, because we already have the fallback - // value set as the default. - if (it->name == ClassID::Fallback) { - propertyValues.erase(it); - } - break; - } - } -} - -bool AppliedClassPropertyValues::empty() const { - return propertyValues.empty(); -} - -} diff --git a/src/mbgl/style/applied_class_properties.hpp b/src/mbgl/style/applied_class_properties.hpp deleted file mode 100644 index a33e2bd62b..0000000000 --- a/src/mbgl/style/applied_class_properties.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef MBGL_STYLE_APPLIED_CLASS_PROPERTIES -#define MBGL_STYLE_APPLIED_CLASS_PROPERTIES - -#include <mbgl/style/property_value.hpp> -#include <mbgl/style/class_dictionary.hpp> -#include <mbgl/util/chrono.hpp> - -#include <list> - -namespace mbgl { - -class AppliedClassPropertyValue { -public: - AppliedClassPropertyValue(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value); - -public: - const ClassID name; - const TimePoint begin; - const TimePoint end; - const PropertyValue value; -}; - - -class AppliedClassPropertyValues { -public: - std::list<AppliedClassPropertyValue> propertyValues; - -public: - // Returns the ID of the most recent - ClassID mostRecent() const; - void add(ClassID class_id, const TimePoint& begin, const TimePoint& end, const PropertyValue &value); - void cleanup(const TimePoint& now); - bool hasTransitions() const; - bool empty() const; -}; - -} - -#endif diff --git a/src/mbgl/style/class_properties.cpp b/src/mbgl/style/class_properties.cpp deleted file mode 100644 index 6122072220..0000000000 --- a/src/mbgl/style/class_properties.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include <mbgl/style/class_properties.hpp> - -namespace mbgl { - -PropertyTransition ClassProperties::getTransition(PropertyKey key) const { - auto it = transitions.find(key); - if (it == transitions.end()) { - return PropertyTransition(); - } else { - return it->second; - } -} - -} diff --git a/src/mbgl/style/class_properties.hpp b/src/mbgl/style/class_properties.hpp deleted file mode 100644 index 153fc11ee7..0000000000 --- a/src/mbgl/style/class_properties.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef MBGL_STYLE_CLASS_PROPERTIES -#define MBGL_STYLE_CLASS_PROPERTIES - -#include <mbgl/style/property_key.hpp> -#include <mbgl/style/property_value.hpp> -#include <mbgl/style/property_evaluator.hpp> -#include <mbgl/style/property_transition.hpp> - -#include <map> - -namespace mbgl { - -class ClassProperties { -public: - inline void set(PropertyKey key, const PropertyValue &value) { - properties.emplace(key, value); - } - - inline void set(PropertyKey key, const PropertyTransition &transition) { - transitions.emplace(key, transition); - } - - PropertyTransition getTransition(PropertyKey key) const; - - // Route-through iterable interface so that you can iterate on the object as is. - inline std::map<PropertyKey, PropertyValue>::const_iterator begin() const { - return properties.begin(); - } - inline std::map<PropertyKey, PropertyValue>::const_iterator end() const { - return properties.end(); - } - - template <typename T> - void calculate(PropertyKey key, T& target, const float z) const { - auto it = properties.find(key); - if (it != properties.end()) { - target = mapbox::util::apply_visitor(PropertyEvaluator<T>(StyleCalculationParameters(z)), it->second); - } - } - -public: - std::map<PropertyKey, PropertyValue> properties; - std::map<PropertyKey, PropertyTransition> transitions; -}; - -} - -#endif diff --git a/src/mbgl/style/function.hpp b/src/mbgl/style/function.hpp index c6ee9a229b..3f5c479512 100644 --- a/src/mbgl/style/function.hpp +++ b/src/mbgl/style/function.hpp @@ -29,8 +29,8 @@ public: T evaluate(const StyleCalculationParameters&) const; private: - const float base = 1; - const std::vector<std::pair<float, T>> stops; + float base = 1; + std::vector<std::pair<float, T>> stops; }; // Partial specialization for cross-faded properties (*-pattern, line-dasharray). @@ -50,7 +50,7 @@ public: Faded<T> evaluate(const StyleCalculationParameters&) const; private: - const std::vector<std::pair<float, T>> stops; + std::vector<std::pair<float, T>> stops; }; } diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index 5f24e5b133..5634efd0a3 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -17,7 +17,7 @@ public: void parse(const char * name, const JSVal& layout) { if (layout.HasMember(name)) { - parsedValue = detail::parseProperty<Function<T>>(name, layout[name]); + parsedValue = parseProperty<Function<T>>(name, layout[name]); } } diff --git a/src/mbgl/style/paint_properties_map.cpp b/src/mbgl/style/paint_properties_map.cpp deleted file mode 100644 index 4d7755ec3c..0000000000 --- a/src/mbgl/style/paint_properties_map.cpp +++ /dev/null @@ -1,126 +0,0 @@ -#include <mbgl/style/paint_properties_map.hpp> -#include <mbgl/style/property_transition.hpp> -#include <mbgl/style/property_fallback.hpp> -#include <mbgl/style/class_properties.hpp> -#include <mbgl/style/style_cascade_parameters.hpp> - -namespace mbgl { - -void PaintPropertiesMap::parseEach(const JSVal& layer, std::function<void (ClassProperties &, const JSVal &)> parsePaint) { - paints.clear(); - - rapidjson::Value::ConstMemberIterator itr = layer.MemberBegin(); - for (; itr != layer.MemberEnd(); ++itr) { - const std::string name { itr->name.GetString(), itr->name.GetStringLength() }; - if (name == "paint") { - parsePaint(paints[ClassID::Default], itr->value); - } else if (name.compare(0, 6, "paint.") == 0 && name.length() > 6) { - parsePaint(paints[ClassDictionary::Get().lookup(name.substr(6))], itr->value); - } - } -} - -void PaintPropertiesMap::cascade(const StyleCascadeParameters& parameters) { - // Stores all keys that we have already added transitions for. - std::set<PropertyKey> alreadyApplied; - - // We only apply the default style values if there are no classes set. - if (parameters.classes.empty()) { - cascadeClass(ClassID::Default, alreadyApplied, parameters); - return; - } - - // Reverse iterate through all class names and apply them last to first. - for (auto it = parameters.classes.rbegin(); it != parameters.classes.rend(); ++it) { - // From here on, we're only dealing with IDs to avoid comparing strings all the time. - cascadeClass(ClassDictionary::Get().lookup(*it), alreadyApplied, parameters); - } - - // As the last class, apply the default class. - cascadeClass(ClassID::Default, alreadyApplied, parameters); - - // Make sure that we also transition to the fallback value for keys that aren't changed by - // any applied classes. - for (auto& propertyPair : appliedStyle) { - const PropertyKey key = propertyPair.first; - if (alreadyApplied.find(key) != alreadyApplied.end()) { - // This property has already been set by a previous class, so we don't need to - // transition to the fallback. - continue; - } - - AppliedClassPropertyValues &appliedProperties = propertyPair.second; - // Make sure that we don't do double transitions to the fallback value. - if (appliedProperties.mostRecent() == ClassID::Fallback) { - continue; - } - - // This property key hasn't been set by a previous class, so we need to add a transition - // to the fallback value for that key. - const TimePoint begin = parameters.now + *parameters.defaultTransition.delay; - const TimePoint end = begin + *parameters.defaultTransition.duration; - const PropertyValue &value = PropertyFallbackValue::Get(key); - appliedProperties.add(ClassID::Fallback, begin, end, value); - } -} - -void PaintPropertiesMap::cascadeClass(const ClassID classID, - std::set<PropertyKey>& alreadyApplied, - const StyleCascadeParameters& parameters) { - auto styleIt = paints.find(classID); - if (styleIt == paints.end()) { - // There is no class in this layer with this class_name. - return; - } - - // Loop through all the properties in this style, and add transitions to them, if they're - // not already the most recent transition. - const ClassProperties& classProperties = styleIt->second; - for (const auto& propertyPair : classProperties) { - PropertyKey key = propertyPair.first; - if (alreadyApplied.find(key) != alreadyApplied.end()) { - // This property has already been set by a previous class. - continue; - } - - // Mark this property as written by a previous class, so that subsequent - // classes won't override this. - alreadyApplied.insert(key); - - // If the most recent transition is not the one with the highest priority, create - // a transition. - AppliedClassPropertyValues &appliedProperties = appliedStyle[key]; - if (appliedProperties.mostRecent() != classID) { - PropertyTransition transition = classProperties.getTransition(key); - Duration delay = transition.delay ? *transition.delay : *parameters.defaultTransition.delay; - Duration duration = transition.duration ? *transition.duration : *parameters.defaultTransition.duration; - const TimePoint begin = parameters.now + delay; - const TimePoint end = begin + duration; - const PropertyValue &value = propertyPair.second; - appliedProperties.add(classID, begin, end, value); - } - } -} - -bool PaintPropertiesMap::hasTransitions() const { - for (const auto& pair : appliedStyle) { - if (pair.second.hasTransitions()) { - return true; - } - } - return hasPendingTransitions; -} - -void PaintPropertiesMap::removeExpiredTransitions(const TimePoint& now) { - for (auto it = appliedStyle.begin(); it != appliedStyle.end();) { - AppliedClassPropertyValues& values = it->second; - values.cleanup(now); - // If the current properties object is empty, remove it from the map entirely. - values.empty() ? appliedStyle.erase(it++) : ++it; - } - - // Clear the pending transitions flag upon each update. - hasPendingTransitions = false; -} - -} diff --git a/src/mbgl/style/paint_properties_map.hpp b/src/mbgl/style/paint_properties_map.hpp deleted file mode 100644 index e32f723d8d..0000000000 --- a/src/mbgl/style/paint_properties_map.hpp +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef MBGL_PAINT_PROPERTIES_MAP -#define MBGL_PAINT_PROPERTIES_MAP - -#include <mbgl/style/applied_class_properties.hpp> -#include <mbgl/style/property_evaluator.hpp> -#include <mbgl/style/class_dictionary.hpp> -#include <mbgl/style/property_key.hpp> - -#include <mbgl/util/interpolate.hpp> - -#include <rapidjson/document.h> - -#include <map> -#include <set> -#include <functional> - -namespace mbgl { - -class ClassProperties; -class PropertyTransition; -class StyleCascadeParameters; - -using JSVal = rapidjson::Value; - -class PaintPropertiesMap { -public: - void cascade(const StyleCascadeParameters&); - - bool hasTransitions() const; - void removeExpiredTransitions(const TimePoint& now); - - // Call the function for each "paint" or "paint.*" object in the layer. - void parseEach(const JSVal& layer, std::function<void (ClassProperties&, const JSVal&)>); - - template <typename T> - void calculate(PropertyKey key, T& target, const StyleCalculationParameters& parameters) { - auto it = appliedStyle.find(key); - if (it != appliedStyle.end()) { - AppliedClassPropertyValues &applied = it->second; - // Iterate through all properties that we need to apply in order. - const PropertyEvaluator<T> evaluator(parameters); - for (auto& property : applied.propertyValues) { - if (parameters.now >= property.begin) { - // We overwrite the current property with the new value. - target = mapbox::util::apply_visitor(evaluator, property.value); - } else { - // Do not apply this property because its transition hasn't begun yet. - } - } - } - } - - template <typename T> - void calculateTransitioned(PropertyKey key, T& target, const StyleCalculationParameters& parameters) { - auto it = appliedStyle.find(key); - if (it != appliedStyle.end()) { - AppliedClassPropertyValues &applied = it->second; - // Iterate through all properties that we need to apply in order. - const PropertyEvaluator<T> evaluator(parameters); - for (auto& property : applied.propertyValues) { - if (parameters.now >= property.end) { - // We overwrite the current property with the new value. - target = mapbox::util::apply_visitor(evaluator, property.value); - } else if (parameters.now >= property.begin) { - // We overwrite the current property partially with the new value. - float progress = std::chrono::duration<float>(parameters.now - property.begin) / (property.end - property.begin); - target = util::interpolate(target, mapbox::util::apply_visitor(evaluator, property.value), progress); - hasPendingTransitions = true; - } else { - // Do not apply this property because its transition hasn't begun yet. - } - } - } - } - - // Raw parsed paint class to property value map. - std::map<ClassID, ClassProperties> paints; - -private: - // Applies all properties from a class, if they haven't been applied already. - void cascadeClass(const ClassID, - std::set<PropertyKey>&, - const StyleCascadeParameters&); - - // For every property, stores a list of applied property values, with - // optional transition times. - std::map<PropertyKey, AppliedClassPropertyValues> appliedStyle; - - // Stores whether there are pending transitions to be done on each update. - bool hasPendingTransitions = false; -}; - -}; - -#endif diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp new file mode 100644 index 0000000000..a82bf028ba --- /dev/null +++ b/src/mbgl/style/paint_property.hpp @@ -0,0 +1,152 @@ +#ifndef MBGL_PAINT_PROPERTY +#define MBGL_PAINT_PROPERTY + +#include <mbgl/style/class_dictionary.hpp> +#include <mbgl/style/property_parsing.hpp> +#include <mbgl/style/function.hpp> +#include <mbgl/style/property_transition.hpp> +#include <mbgl/style/style_cascade_parameters.hpp> +#include <mbgl/style/style_calculation_parameters.hpp> +#include <mbgl/util/interpolate.hpp> + +#include <rapidjson/document.h> + +#include <map> + +namespace mbgl { + +using JSVal = rapidjson::Value; + +template <typename T, typename Result = T> +class PaintProperty { +public: + using Fn = Function<Result>; + + PaintProperty(T fallbackValue_) + : fallbackValue(fallbackValue_), + value(fallbackValue_) { + values.emplace(ClassID::Fallback, Fn(fallbackValue)); + } + + PaintProperty(const PaintProperty& other) + : values(other.values), + transitions(other.transitions) { + } + + void operator=(const PaintProperty& other) { + values = other.values; + transitions = other.transitions; + } + + void parse(const char* name, const JSVal& layer) { + values.clear(); + values.emplace(ClassID::Fallback, Fn(fallbackValue)); + + std::string transitionName = { name }; + transitionName += "-transition"; + + for (auto it = layer.MemberBegin(); it != layer.MemberEnd(); ++it) { + const std::string paintName { it->name.GetString(), it->name.GetStringLength() }; + if (paintName.compare(0, 5, "paint") != 0) + continue; + + bool isClass = paintName.compare(0, 6, "paint.") == 0; + if (isClass && paintName.length() <= 6) + continue; + + ClassID classID = isClass ? ClassDictionary::Get().lookup(paintName.substr(6)) : ClassID::Default; + + if (it->value.HasMember(name)) { + auto v = parseProperty<Fn>(name, it->value[name]); + if (v) { + values.emplace(classID, *v); + } + } + + if (it->value.HasMember(transitionName.c_str())) { + auto v = parseProperty<PropertyTransition>(name, it->value[transitionName.c_str()]); + if (v) { + transitions.emplace(classID, *v); + } + } + } + } + + void cascade(const StyleCascadeParameters& parameters) { + Duration delay = *parameters.defaultTransition.delay; + Duration duration = *parameters.defaultTransition.duration; + + for (auto classID : parameters.classes) { + if (values.find(classID) == values.end()) + continue; + + if (transitions.find(classID) != transitions.end()) { + const PropertyTransition& transition = transitions[classID]; + if (transition.delay) delay = *transition.delay; + if (transition.duration) duration = *transition.duration; + } + + cascaded = std::make_unique<CascadedValue>(std::move(cascaded), + parameters.now + delay, + parameters.now + delay + duration, + values.at(classID)); + + break; + } + + assert(cascaded); + } + + bool calculate(const StyleCalculationParameters& parameters) { + assert(cascaded); + value = cascaded->calculate(parameters); + return cascaded->prior.operator bool(); + } + + operator T() const { return value; } + + T fallbackValue; + std::map<ClassID, Fn> values; + std::map<ClassID, PropertyTransition> transitions; + + struct CascadedValue { + CascadedValue(std::unique_ptr<CascadedValue> prior_, + TimePoint begin_, + TimePoint end_, + Fn value_) + : prior(std::move(prior_)), + begin(begin_), + end(end_), + value(value_) { + } + + Result calculate(const StyleCalculationParameters& parameters) { + Result final = value.evaluate(parameters); + if (!prior) { + // No prior value. + return final; + } else if (parameters.now >= end) { + // Transition from prior value is now complete. + prior.reset(); + return final; + } else { + // Interpolate between recursively-calculated prior value and final. + float t = std::chrono::duration<float>(parameters.now - begin) / (end - begin); + return util::interpolate(prior->calculate(parameters), final, t); + } + } + + std::unique_ptr<CascadedValue> prior; + TimePoint begin; + TimePoint end; + Fn value; + }; + + std::unique_ptr<CascadedValue> cascaded; + + Result value; +}; + +} + +#endif diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp deleted file mode 100644 index 81d2c93342..0000000000 --- a/src/mbgl/style/property_evaluator.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MBGL_PROPERTY_EVALUATOR -#define MBGL_PROPERTY_EVALUATOR - -#include <mbgl/style/zoom_history.hpp> -#include <mbgl/style/function.hpp> -#include <mbgl/style/style_calculation_parameters.hpp> - -namespace mbgl { - -struct ZoomHistory; - -template <typename T> -class PropertyEvaluator { -public: - typedef T result_type; - - PropertyEvaluator(const StyleCalculationParameters& parameters_) - : parameters(parameters_) {} - - template <typename P, typename std::enable_if<std::is_convertible<P, T>::value, int>::type = 0> - T operator()(const P &value) const { - return value; - } - - T operator()(const Function<T>& value) const { - return value.evaluate(parameters); - } - - template <typename P, typename std::enable_if<!std::is_convertible<P, T>::value, int>::type = 0> - T operator()(const P &) const { - return T(); - } - -private: - StyleCalculationParameters parameters; -}; - -} - -#endif diff --git a/src/mbgl/style/property_fallback.cpp b/src/mbgl/style/property_fallback.cpp deleted file mode 100644 index 31e46640be..0000000000 --- a/src/mbgl/style/property_fallback.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include <mbgl/style/property_fallback.hpp> -#include <mbgl/style/style_properties.hpp> - -namespace mbgl { - -const std::map<PropertyKey, PropertyValue> PropertyFallbackValue::properties = { - { PropertyKey::FillAntialias, FillPaintProperties().antialias }, - { PropertyKey::FillOpacity, FillPaintProperties().opacity }, - { PropertyKey::FillColor, FillPaintProperties().fill_color }, - // no FillOutlineColor on purpose. - { PropertyKey::FillTranslate, FillPaintProperties().translate }, - { PropertyKey::FillTranslateAnchor, FillPaintProperties().translateAnchor }, - - { PropertyKey::LineOpacity, LinePaintProperties().opacity }, - { PropertyKey::LineColor, LinePaintProperties().color }, - { PropertyKey::LineTranslate, LinePaintProperties().translate }, - { PropertyKey::LineTranslateAnchor, LinePaintProperties().translateAnchor }, - { PropertyKey::LineWidth, LinePaintProperties().width }, - { PropertyKey::LineGapWidth, LinePaintProperties().gap_width }, - { PropertyKey::LineBlur, LinePaintProperties().blur }, - - { PropertyKey::CircleRadius, CirclePaintProperties().radius }, - { PropertyKey::CircleColor, CirclePaintProperties().color }, - { PropertyKey::CircleOpacity, CirclePaintProperties().opacity }, - { PropertyKey::CircleTranslate, CirclePaintProperties().translate }, - { PropertyKey::CircleTranslateAnchor, CirclePaintProperties().translateAnchor }, - { PropertyKey::CircleBlur, CirclePaintProperties().blur }, - - { PropertyKey::IconOpacity, SymbolPaintProperties().icon.opacity }, - { PropertyKey::IconColor, SymbolPaintProperties().icon.color }, - { PropertyKey::IconHaloColor, SymbolPaintProperties().icon.halo_color }, - { PropertyKey::IconHaloWidth, SymbolPaintProperties().icon.halo_width }, - { PropertyKey::IconHaloBlur, SymbolPaintProperties().icon.halo_blur }, - { PropertyKey::IconTranslate, SymbolPaintProperties().icon.translate }, - { PropertyKey::IconTranslateAnchor, SymbolPaintProperties().icon.translate_anchor }, - - { PropertyKey::TextOpacity, SymbolPaintProperties().text.opacity }, - { PropertyKey::TextColor, SymbolPaintProperties().text.color }, - { PropertyKey::TextHaloColor, SymbolPaintProperties().text.halo_color }, - { PropertyKey::TextHaloWidth, SymbolPaintProperties().text.halo_width }, - { PropertyKey::TextHaloBlur, SymbolPaintProperties().text.halo_blur }, - { PropertyKey::TextTranslate, SymbolPaintProperties().text.translate }, - { PropertyKey::TextTranslateAnchor, SymbolPaintProperties().text.translate_anchor }, - - { PropertyKey::RasterOpacity, RasterPaintProperties().opacity }, - { PropertyKey::RasterHueRotate, RasterPaintProperties().hue_rotate }, - { PropertyKey::RasterBrightnessLow, RasterPaintProperties().brightness[0] }, - { PropertyKey::RasterBrightnessHigh, RasterPaintProperties().brightness[1] }, - { PropertyKey::RasterSaturation, RasterPaintProperties().saturation }, - { PropertyKey::RasterContrast, RasterPaintProperties().contrast }, - { PropertyKey::RasterFade, RasterPaintProperties().fade }, - - { PropertyKey::BackgroundOpacity, BackgroundPaintProperties().opacity }, - { PropertyKey::BackgroundColor, BackgroundPaintProperties().color }, -}; - -const PropertyValue PropertyFallbackValue::defaultProperty = false; - -} diff --git a/src/mbgl/style/property_fallback.hpp b/src/mbgl/style/property_fallback.hpp deleted file mode 100644 index 5c5eae0cd6..0000000000 --- a/src/mbgl/style/property_fallback.hpp +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_FALLBACK -#define MBGL_STYLE_PROPERTY_FALLBACK - -#include <mbgl/style/property_key.hpp> -#include <mbgl/style/property_value.hpp> - -#include <map> - -namespace mbgl { - -class PropertyFallbackValue { -public: - static const PropertyValue &Get(PropertyKey key) { - auto it = properties.find(key); - if (it != properties.end()) { - return it->second; - } else { - return defaultProperty; - } - } - -private: - static const std::map<PropertyKey, PropertyValue> properties; - static const PropertyValue defaultProperty; -}; - -} - -#endif diff --git a/src/mbgl/style/property_key.hpp b/src/mbgl/style/property_key.hpp deleted file mode 100644 index f9b6b796cf..0000000000 --- a/src/mbgl/style/property_key.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_KEY -#define MBGL_STYLE_PROPERTY_KEY - -namespace mbgl { - -enum class PropertyKey { - FillAntialias, - FillOpacity, - FillColor, - FillOutlineColor, - FillTranslate, // for transitions only - FillTranslateAnchor, - FillImage, - - LineOpacity, - LineColor, - LineTranslate, // for transitions only - LineTranslateAnchor, - LineWidth, - LineGapWidth, - LineBlur, - LineDashArray, // for transitions only - LineImage, - - CircleRadius, - CircleColor, - CircleOpacity, - CircleTranslate, - CircleTranslateAnchor, - CircleBlur, - - IconOpacity, - IconColor, - IconHaloColor, - IconHaloWidth, - IconHaloBlur, - IconTranslate, - IconTranslateAnchor, - - TextOpacity, - TextColor, - TextHaloColor, - TextHaloWidth, - TextHaloBlur, - TextTranslate, - TextTranslateAnchor, - - RasterOpacity, - RasterHueRotate, - RasterBrightness, // for transitions only - RasterBrightnessLow, - RasterBrightnessHigh, - RasterSaturation, - RasterContrast, - RasterFade, - - BackgroundOpacity, - BackgroundColor, - BackgroundImage, -}; - -} - -#endif diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 00b3db8918..9a67af8eb2 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -1,11 +1,14 @@ #include <mbgl/style/property_parsing.hpp> +#include <mbgl/style/property_transition.hpp> +#include <mbgl/style/function.hpp> #include <mbgl/platform/log.hpp> #include <csscolorparser/csscolorparser.hpp> +#include <vector> + namespace mbgl { -namespace detail { template <> optional<bool> parseProperty(const char* name, const JSVal& value) { @@ -402,4 +405,3 @@ optional<Function<Faded<std::string>>> parseProperty(const char* name, const JSV } } -} diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 182636df5c..c4547a9e1e 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -1,11 +1,13 @@ #ifndef MBGL_PROPERTY_PARSING #define MBGL_PROPERTY_PARSING -#include <mbgl/style/class_properties.hpp> +#include <mbgl/style/types.hpp> #include <mapbox/optional.hpp> #include <rapidjson/document.h> +#include <functional> + namespace mbgl { using JSVal = rapidjson::Value; @@ -13,25 +15,9 @@ using JSVal = rapidjson::Value; template <typename T> using optional = mapbox::util::optional<T>; -namespace detail { - template <typename T> optional<T> parseProperty(const char* name, const JSVal&); } -template <typename T> -void parseProperty(const char* name, PropertyKey key, ClassProperties& properties, const JSVal& value) { - if (!value.HasMember(name)) - return; - - const optional<T> res = detail::parseProperty<T>(name, value[name]); - - if (res) { - properties.set(key, *res); - } -} - -} - #endif diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp deleted file mode 100644 index 8d6b95753c..0000000000 --- a/src/mbgl/style/property_value.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef MBGL_STYLE_PROPERTY_VALUE -#define MBGL_STYLE_PROPERTY_VALUE - -#include <mapbox/variant.hpp> - -#include <mbgl/style/function.hpp> -#include <mbgl/style/types.hpp> - -#include <vector> -#include <array> - -namespace mbgl { - -typedef mapbox::util::variant< - Function<std::string>, - Function<TranslateAnchorType>, - Function<RotateAnchorType>, - Function<CapType>, - Function<JoinType>, - VisibilityType, - Function<PlacementType>, - Function<RotationAlignmentType>, - Function<TextTransformType>, - Function<TextJustifyType>, - Function<TextAnchorType>, - Function<std::array<float, 2>>, - Function<bool>, - Function<float>, - Function<Color>, - Function<Faded<std::vector<float>>>, - Function<Faded<std::string>> -> PropertyValue; - -} - -#endif diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index b7d6f61664..5509447275 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -7,6 +7,7 @@ #include <mbgl/style/style_layer.hpp> #include <mbgl/style/style_parser.hpp> #include <mbgl/style/property_transition.hpp> +#include <mbgl/style/class_dictionary.hpp> #include <mbgl/style/style_cascade_parameters.hpp> #include <mbgl/style/style_calculation_parameters.hpp> #include <mbgl/geometry/glyph_atlas.hpp> @@ -121,7 +122,16 @@ void Style::update(const TransformState& transform, } void Style::cascade() { - StyleCascadeParameters parameters(data.getClasses(), + std::vector<ClassID> classes; + + std::vector<std::string> classNames = data.getClasses(); + for (auto it = classNames.rbegin(); it != classNames.rend(); it++) { + classes.push_back(ClassDictionary::Get().lookup(*it)); + } + classes.push_back(ClassID::Default); + classes.push_back(ClassID::Fallback); + + StyleCascadeParameters parameters(classes, data.getAnimationTime(), PropertyTransition { data.getDefaultTransitionDuration(), data.getDefaultTransitionDelay() }); @@ -146,7 +156,7 @@ void Style::recalculate(float z) { data.getDefaultFadeDuration()); for (const auto& layer : layers) { - layer->recalculate(parameters); + hasPendingTransitions |= layer->recalculate(parameters); Source* source = getSource(layer->source); if (!source) { @@ -166,12 +176,7 @@ Source* Style::getSource(const std::string& id) const { } bool Style::hasTransitions() const { - for (const auto& layer : layers) { - if (layer->hasTransitions()) { - return true; - } - } - return false; + return hasPendingTransitions; } bool Style::isLoaded() const { diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index c9261bd6c4..412107b737 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -110,6 +110,7 @@ private: std::unique_ptr<uv::rwlock> mtx; ZoomHistory zoomHistory; + bool hasPendingTransitions = false; public: Worker workers; diff --git a/src/mbgl/style/style_cascade_parameters.hpp b/src/mbgl/style/style_cascade_parameters.hpp index 406491037a..154890fd97 100644 --- a/src/mbgl/style/style_cascade_parameters.hpp +++ b/src/mbgl/style/style_cascade_parameters.hpp @@ -2,6 +2,7 @@ #define STYLE_CASCADE_PARAMETERS #include <mbgl/util/chrono.hpp> +#include <mbgl/style/types.hpp> #include <vector> @@ -11,14 +12,14 @@ class PropertyTransition; class StyleCascadeParameters { public: - StyleCascadeParameters(const std::vector<std::string>& classes_, + StyleCascadeParameters(const std::vector<ClassID>& classes_, const TimePoint& now_, const PropertyTransition& defaultTransition_) : classes(classes_), now(now_), defaultTransition(defaultTransition_) {} - std::vector<std::string> classes; + std::vector<ClassID> classes; TimePoint now; PropertyTransition defaultTransition; }; diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/style/style_layer.hpp index 3e86625755..a1a0389fbe 100644 --- a/src/mbgl/style/style_layer.hpp +++ b/src/mbgl/style/style_layer.hpp @@ -8,7 +8,9 @@ #include <rapidjson/document.h> +#include <memory> #include <string> +#include <limits> namespace mbgl { @@ -36,13 +38,11 @@ public: virtual void cascade(const StyleCascadeParameters&) = 0; // Fully evaluate cascaded paint properties based on a zoom level. - virtual void recalculate(const StyleCalculationParameters&) = 0; + // Returns true if any paint properties have active transitions. + virtual bool recalculate(const StyleCalculationParameters&) = 0; virtual std::unique_ptr<Bucket> createBucket(StyleBucketParameters&) const = 0; - // Checks whether this layer has any active paint properties with transitions. - virtual bool hasTransitions() const = 0; - // Checks whether this layer needs to be rendered in the given render pass. bool hasRenderPass(RenderPass) const; diff --git a/src/mbgl/style/types.cpp b/src/mbgl/style/types.cpp deleted file mode 100644 index e69de29bb2..0000000000 --- a/src/mbgl/style/types.cpp +++ /dev/null diff --git a/src/mbgl/util/interpolate.hpp b/src/mbgl/util/interpolate.hpp index 55b1e2add4..28bbde8bf9 100644 --- a/src/mbgl/util/interpolate.hpp +++ b/src/mbgl/util/interpolate.hpp @@ -46,7 +46,8 @@ template<> inline TextJustifyType interpolate(const TextJustifyType a, const Tex template<> inline TextTransformType interpolate(const TextTransformType a, const TextTransformType, const double) { return a; } template<> inline RotationAlignmentType interpolate(const RotationAlignmentType a, const RotationAlignmentType, const double) { return a; } - +template<> inline Faded<std::string> interpolate(const Faded<std::string>, const Faded<std::string> b, const double) { return b; } +template<> inline Faded<std::vector<float>> interpolate(const Faded<std::vector<float>>, const Faded<std::vector<float>> b, const double) { return b; } } } |