From a43940afb2208c61b487bfd8729bbde1bd674794 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 13:15:44 -0700 Subject: [PATCH 1/8] [core] Runtime style layer API --- Makefile | 3 + include/mbgl/layer/background_layer.hpp | 39 ++ include/mbgl/layer/circle_layer.hpp | 54 ++ include/mbgl/layer/custom_layer.hpp | 30 + include/mbgl/layer/fill_layer.hpp | 57 ++ include/mbgl/layer/line_layer.hpp | 82 +++ include/mbgl/layer/raster_layer.hpp | 56 ++ include/mbgl/layer/symbol_layer.hpp | 175 ++++++ include/mbgl/style/layer.hpp | 78 +++ include/mbgl/style/types.hpp | 21 + package.json | 3 + .../default/mbgl/storage/offline_download.cpp | 1 - scripts/generate-style-code.js | 346 +++++++++++ src/mbgl/annotation/annotation_manager.cpp | 15 +- src/mbgl/annotation/fill_annotation_impl.cpp | 13 +- src/mbgl/annotation/line_annotation_impl.cpp | 16 +- .../style_sourced_annotation_impl.cpp | 26 +- src/mbgl/geometry/feature_index.cpp | 5 +- src/mbgl/layer/background_layer.cpp | 57 +- src/mbgl/layer/background_layer.hpp | 36 -- src/mbgl/layer/background_layer_impl.cpp | 26 + src/mbgl/layer/background_layer_impl.hpp | 24 + .../layer/background_layer_properties.cpp | 29 + .../layer/background_layer_properties.hpp | 25 + src/mbgl/layer/circle_layer.cpp | 118 ++-- src/mbgl/layer/circle_layer.hpp | 46 -- src/mbgl/layer/circle_layer_impl.cpp | 60 ++ src/mbgl/layer/circle_layer_impl.hpp | 31 + src/mbgl/layer/circle_layer_properties.cpp | 38 ++ src/mbgl/layer/circle_layer_properties.hpp | 28 + src/mbgl/layer/custom_layer.cpp | 69 +-- src/mbgl/layer/custom_layer_impl.cpp | 66 +++ ...custom_layer.hpp => custom_layer_impl.hpp} | 26 +- src/mbgl/layer/fill_layer.cpp | 133 +++-- src/mbgl/layer/fill_layer.hpp | 47 -- src/mbgl/layer/fill_layer_impl.cpp | 66 +++ src/mbgl/layer/fill_layer_impl.hpp | 31 + src/mbgl/layer/fill_layer_properties.cpp | 41 ++ src/mbgl/layer/fill_layer_properties.hpp | 29 + src/mbgl/layer/layer.cpp | 32 ++ .../style_layer.cpp => layer/layer_impl.cpp} | 8 +- .../style_layer.hpp => layer/layer_impl.hpp} | 52 +- src/mbgl/layer/line_layer.cpp | 229 ++++---- src/mbgl/layer/line_layer.hpp | 64 --- src/mbgl/layer/line_layer_impl.cpp | 114 ++++ src/mbgl/layer/line_layer_impl.hpp | 38 ++ src/mbgl/layer/line_layer_properties.cpp | 64 +++ src/mbgl/layer/line_layer_properties.hpp | 43 ++ src/mbgl/layer/raster_layer.cpp | 108 +++- src/mbgl/layer/raster_layer.hpp | 40 -- src/mbgl/layer/raster_layer_impl.cpp | 26 + src/mbgl/layer/raster_layer_impl.hpp | 24 + src/mbgl/layer/raster_layer_properties.cpp | 41 ++ src/mbgl/layer/raster_layer_properties.hpp | 29 + src/mbgl/layer/symbol_layer.cpp | 542 ++++++++++++------ src/mbgl/layer/symbol_layer_impl.cpp | 80 +++ src/mbgl/layer/symbol_layer_impl.hpp | 35 ++ src/mbgl/layer/symbol_layer_properties.cpp | 130 +++++ ..._layer.hpp => symbol_layer_properties.hpp} | 78 +-- src/mbgl/map/map.cpp | 1 - src/mbgl/renderer/bucket.hpp | 4 +- src/mbgl/renderer/circle_bucket.cpp | 2 +- src/mbgl/renderer/circle_bucket.hpp | 2 +- src/mbgl/renderer/fill_bucket.cpp | 2 +- src/mbgl/renderer/fill_bucket.hpp | 2 +- src/mbgl/renderer/line_bucket.cpp | 2 +- src/mbgl/renderer/line_bucket.hpp | 4 +- src/mbgl/renderer/painter.cpp | 13 +- src/mbgl/renderer/painter.hpp | 1 - src/mbgl/renderer/painter_background.cpp | 3 +- src/mbgl/renderer/painter_circle.cpp | 3 +- src/mbgl/renderer/painter_fill.cpp | 3 +- src/mbgl/renderer/painter_line.cpp | 7 +- src/mbgl/renderer/painter_raster.cpp | 3 +- src/mbgl/renderer/painter_symbol.cpp | 10 +- src/mbgl/renderer/raster_bucket.cpp | 2 +- src/mbgl/renderer/raster_bucket.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 2 +- src/mbgl/renderer/symbol_bucket.hpp | 4 +- src/mbgl/source/source.cpp | 2 +- src/mbgl/style/function.hpp | 28 - src/mbgl/style/function_evaluator.hpp | 2 +- src/mbgl/style/layout_property.hpp | 2 - src/mbgl/style/paint_property.hpp | 2 - src/mbgl/style/property_parsing.cpp | 3 + src/mbgl/style/property_parsing.hpp | 1 - src/mbgl/style/render_item.hpp | 6 +- src/mbgl/style/style.cpp | 58 +- src/mbgl/style/style.hpp | 10 +- src/mbgl/style/style_parser.cpp | 65 +-- src/mbgl/style/style_parser.hpp | 13 +- src/mbgl/text/quads.cpp | 2 +- src/mbgl/text/shaping.cpp | 2 +- src/mbgl/tile/raster_tile_data.cpp | 2 +- src/mbgl/tile/raster_tile_data.hpp | 4 +- src/mbgl/tile/tile_data.hpp | 4 +- src/mbgl/tile/tile_worker.cpp | 53 +- src/mbgl/tile/tile_worker.hpp | 8 +- src/mbgl/tile/vector_tile_data.cpp | 6 +- src/mbgl/tile/vector_tile_data.hpp | 2 +- src/mbgl/util/worker.cpp | 6 +- src/mbgl/util/worker.hpp | 2 +- test/style/functions.cpp | 1 - test/style/source.cpp | 5 +- test/style/style_layer.cpp | 24 +- 105 files changed, 3110 insertions(+), 1098 deletions(-) create mode 100644 include/mbgl/layer/background_layer.hpp create mode 100644 include/mbgl/layer/circle_layer.hpp create mode 100644 include/mbgl/layer/custom_layer.hpp create mode 100644 include/mbgl/layer/fill_layer.hpp create mode 100644 include/mbgl/layer/line_layer.hpp create mode 100644 include/mbgl/layer/raster_layer.hpp create mode 100644 include/mbgl/layer/symbol_layer.hpp create mode 100644 include/mbgl/style/layer.hpp create mode 100644 scripts/generate-style-code.js delete mode 100644 src/mbgl/layer/background_layer.hpp create mode 100644 src/mbgl/layer/background_layer_impl.cpp create mode 100644 src/mbgl/layer/background_layer_impl.hpp create mode 100644 src/mbgl/layer/background_layer_properties.cpp create mode 100644 src/mbgl/layer/background_layer_properties.hpp delete mode 100644 src/mbgl/layer/circle_layer.hpp create mode 100644 src/mbgl/layer/circle_layer_impl.cpp create mode 100644 src/mbgl/layer/circle_layer_impl.hpp create mode 100644 src/mbgl/layer/circle_layer_properties.cpp create mode 100644 src/mbgl/layer/circle_layer_properties.hpp create mode 100644 src/mbgl/layer/custom_layer_impl.cpp rename src/mbgl/layer/{custom_layer.hpp => custom_layer_impl.hpp} (57%) delete mode 100644 src/mbgl/layer/fill_layer.hpp create mode 100644 src/mbgl/layer/fill_layer_impl.cpp create mode 100644 src/mbgl/layer/fill_layer_impl.hpp create mode 100644 src/mbgl/layer/fill_layer_properties.cpp create mode 100644 src/mbgl/layer/fill_layer_properties.hpp create mode 100644 src/mbgl/layer/layer.cpp rename src/mbgl/{style/style_layer.cpp => layer/layer_impl.cpp} (50%) rename src/mbgl/{style/style_layer.hpp => layer/layer_impl.hpp} (67%) delete mode 100644 src/mbgl/layer/line_layer.hpp create mode 100644 src/mbgl/layer/line_layer_impl.cpp create mode 100644 src/mbgl/layer/line_layer_impl.hpp create mode 100644 src/mbgl/layer/line_layer_properties.cpp create mode 100644 src/mbgl/layer/line_layer_properties.hpp delete mode 100644 src/mbgl/layer/raster_layer.hpp create mode 100644 src/mbgl/layer/raster_layer_impl.cpp create mode 100644 src/mbgl/layer/raster_layer_impl.hpp create mode 100644 src/mbgl/layer/raster_layer_properties.cpp create mode 100644 src/mbgl/layer/raster_layer_properties.hpp create mode 100644 src/mbgl/layer/symbol_layer_impl.cpp create mode 100644 src/mbgl/layer/symbol_layer_impl.hpp create mode 100644 src/mbgl/layer/symbol_layer_properties.cpp rename src/mbgl/layer/{symbol_layer.hpp => symbol_layer_properties.hpp} (56%) delete mode 100644 src/mbgl/style/function.hpp diff --git a/Makefile b/Makefile index 8911e0029ed..49e96691957 100644 --- a/Makefile +++ b/Makefile @@ -296,6 +296,9 @@ tidy: compdb #### Miscellaneous targets ##################################################### +style-code: + node scripts/generate-style-code.js + clean: -find ./deps/gyp -name "*.pyc" -exec rm {} \; -rm -rf ./build \ diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/layer/background_layer.hpp new file mode 100644 index 00000000000..79f24990e6a --- /dev/null +++ b/include/mbgl/layer/background_layer.hpp @@ -0,0 +1,39 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +namespace mbgl { + +class BackgroundLayer : public Layer { +public: + BackgroundLayer(const std::string& layerID); + ~BackgroundLayer() final; + + // Paint properties + + Function getBackgroundColor() const; + void setBackgroundColor(Function); + + Function getBackgroundPattern() const; + void setBackgroundPattern(Function); + + Function getBackgroundOpacity() const; + void setBackgroundOpacity(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + BackgroundLayer(const Impl&); + BackgroundLayer(const BackgroundLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Background; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/layer/circle_layer.hpp new file mode 100644 index 00000000000..14b9da895f4 --- /dev/null +++ b/include/mbgl/layer/circle_layer.hpp @@ -0,0 +1,54 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +namespace mbgl { + +class CircleLayer : public Layer { +public: + CircleLayer(const std::string& layerID); + ~CircleLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Paint properties + + Function getCircleRadius() const; + void setCircleRadius(Function); + + Function getCircleColor() const; + void setCircleColor(Function); + + Function getCircleBlur() const; + void setCircleBlur(Function); + + Function getCircleOpacity() const; + void setCircleOpacity(Function); + + Function> getCircleTranslate() const; + void setCircleTranslate(Function>); + + Function getCircleTranslateAnchor() const; + void setCircleTranslateAnchor(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + CircleLayer(const Impl&); + CircleLayer(const CircleLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Circle; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/custom_layer.hpp b/include/mbgl/layer/custom_layer.hpp new file mode 100644 index 00000000000..81e91ddf50d --- /dev/null +++ b/include/mbgl/layer/custom_layer.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace mbgl { + +class CustomLayer : public Layer { +public: + CustomLayer(const std::string& id, + CustomLayerInitializeFunction, + CustomLayerRenderFunction, + CustomLayerDeinitializeFunction, + void* context); + ~CustomLayer() final; + + // Private implementation + + class Impl; + Impl* impl; + + CustomLayer(const Impl&); + CustomLayer(const CustomLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Custom; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/layer/fill_layer.hpp new file mode 100644 index 00000000000..dc0752f9e2e --- /dev/null +++ b/include/mbgl/layer/fill_layer.hpp @@ -0,0 +1,57 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +namespace mbgl { + +class FillLayer : public Layer { +public: + FillLayer(const std::string& layerID); + ~FillLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Paint properties + + Function getFillAntialias() const; + void setFillAntialias(Function); + + Function getFillOpacity() const; + void setFillOpacity(Function); + + Function getFillColor() const; + void setFillColor(Function); + + Function getFillOutlineColor() const; + void setFillOutlineColor(Function); + + Function> getFillTranslate() const; + void setFillTranslate(Function>); + + Function getFillTranslateAnchor() const; + void setFillTranslateAnchor(Function); + + Function getFillPattern() const; + void setFillPattern(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + FillLayer(const Impl&); + FillLayer(const FillLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Fill; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/layer/line_layer.hpp new file mode 100644 index 00000000000..0f898d3c697 --- /dev/null +++ b/include/mbgl/layer/line_layer.hpp @@ -0,0 +1,82 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +#include + +namespace mbgl { + +class LineLayer : public Layer { +public: + LineLayer(const std::string& layerID); + ~LineLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Layout properties + + Function getLineCap() const; + void setLineCap(Function); + + Function getLineJoin() const; + void setLineJoin(Function); + + Function getLineMiterLimit() const; + void setLineMiterLimit(Function); + + Function getLineRoundLimit() const; + void setLineRoundLimit(Function); + + // Paint properties + + Function getLineOpacity() const; + void setLineOpacity(Function); + + Function getLineColor() const; + void setLineColor(Function); + + Function> getLineTranslate() const; + void setLineTranslate(Function>); + + Function getLineTranslateAnchor() const; + void setLineTranslateAnchor(Function); + + Function getLineWidth() const; + void setLineWidth(Function); + + Function getLineGapWidth() const; + void setLineGapWidth(Function); + + Function getLineOffset() const; + void setLineOffset(Function); + + Function getLineBlur() const; + void setLineBlur(Function); + + Function> getLineDasharray() const; + void setLineDasharray(Function>); + + Function getLinePattern() const; + void setLinePattern(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + LineLayer(const Impl&); + LineLayer(const LineLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Line; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/layer/raster_layer.hpp new file mode 100644 index 00000000000..9dc27a274ab --- /dev/null +++ b/include/mbgl/layer/raster_layer.hpp @@ -0,0 +1,56 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +namespace mbgl { + +class RasterLayer : public Layer { +public: + RasterLayer(const std::string& layerID); + ~RasterLayer() final; + + // Source + + void setSource(const std::string& sourceID); + const std::string& getSourceID() const; + + // Paint properties + + Function getRasterOpacity() const; + void setRasterOpacity(Function); + + Function getRasterHueRotate() const; + void setRasterHueRotate(Function); + + Function getRasterBrightnessMin() const; + void setRasterBrightnessMin(Function); + + Function getRasterBrightnessMax() const; + void setRasterBrightnessMax(Function); + + Function getRasterSaturation() const; + void setRasterSaturation(Function); + + Function getRasterContrast() const; + void setRasterContrast(Function); + + Function getRasterFadeDuration() const; + void setRasterFadeDuration(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + RasterLayer(const Impl&); + RasterLayer(const RasterLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Raster; +} + +} // namespace mbgl diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/layer/symbol_layer.hpp new file mode 100644 index 00000000000..f9b29563907 --- /dev/null +++ b/include/mbgl/layer/symbol_layer.hpp @@ -0,0 +1,175 @@ +// This file is generated. Do not edit. + +#pragma once + +#include + +#include + +namespace mbgl { + +class SymbolLayer : public Layer { +public: + SymbolLayer(const std::string& layerID); + ~SymbolLayer() final; + + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + + // Layout properties + + Function getSymbolPlacement() const; + void setSymbolPlacement(Function); + + Function getSymbolSpacing() const; + void setSymbolSpacing(Function); + + Function getSymbolAvoidEdges() const; + void setSymbolAvoidEdges(Function); + + Function getIconAllowOverlap() const; + void setIconAllowOverlap(Function); + + Function getIconIgnorePlacement() const; + void setIconIgnorePlacement(Function); + + Function getIconOptional() const; + void setIconOptional(Function); + + Function getIconRotationAlignment() const; + void setIconRotationAlignment(Function); + + Function getIconSize() const; + void setIconSize(Function); + + Function getIconImage() const; + void setIconImage(Function); + + Function getIconRotate() const; + void setIconRotate(Function); + + Function getIconPadding() const; + void setIconPadding(Function); + + Function getIconKeepUpright() const; + void setIconKeepUpright(Function); + + Function> getIconOffset() const; + void setIconOffset(Function>); + + Function getTextRotationAlignment() const; + void setTextRotationAlignment(Function); + + Function getTextField() const; + void setTextField(Function); + + Function> getTextFont() const; + void setTextFont(Function>); + + Function getTextSize() const; + void setTextSize(Function); + + Function getTextMaxWidth() const; + void setTextMaxWidth(Function); + + Function getTextLineHeight() const; + void setTextLineHeight(Function); + + Function getTextLetterSpacing() const; + void setTextLetterSpacing(Function); + + Function getTextJustify() const; + void setTextJustify(Function); + + Function getTextAnchor() const; + void setTextAnchor(Function); + + Function getTextMaxAngle() const; + void setTextMaxAngle(Function); + + Function getTextRotate() const; + void setTextRotate(Function); + + Function getTextPadding() const; + void setTextPadding(Function); + + Function getTextKeepUpright() const; + void setTextKeepUpright(Function); + + Function getTextTransform() const; + void setTextTransform(Function); + + Function> getTextOffset() const; + void setTextOffset(Function>); + + Function getTextAllowOverlap() const; + void setTextAllowOverlap(Function); + + Function getTextIgnorePlacement() const; + void setTextIgnorePlacement(Function); + + Function getTextOptional() const; + void setTextOptional(Function); + + // Paint properties + + Function getIconOpacity() const; + void setIconOpacity(Function); + + Function getIconColor() const; + void setIconColor(Function); + + Function getIconHaloColor() const; + void setIconHaloColor(Function); + + Function getIconHaloWidth() const; + void setIconHaloWidth(Function); + + Function getIconHaloBlur() const; + void setIconHaloBlur(Function); + + Function> getIconTranslate() const; + void setIconTranslate(Function>); + + Function getIconTranslateAnchor() const; + void setIconTranslateAnchor(Function); + + Function getTextOpacity() const; + void setTextOpacity(Function); + + Function getTextColor() const; + void setTextColor(Function); + + Function getTextHaloColor() const; + void setTextHaloColor(Function); + + Function getTextHaloWidth() const; + void setTextHaloWidth(Function); + + Function getTextHaloBlur() const; + void setTextHaloBlur(Function); + + Function> getTextTranslate() const; + void setTextTranslate(Function>); + + Function getTextTranslateAnchor() const; + void setTextTranslateAnchor(Function); + + // Private implementation + + class Impl; + Impl* const impl; + + SymbolLayer(const Impl&); + SymbolLayer(const SymbolLayer&) = delete; +}; + +template <> +inline bool Layer::is() const { + return type == Type::Symbol; +} + +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp new file mode 100644 index 00000000000..e6c33a97840 --- /dev/null +++ b/include/mbgl/style/layer.hpp @@ -0,0 +1,78 @@ +#ifndef MBGL_LAYER +#define MBGL_LAYER + +#include +#include + +#include + +namespace mbgl { + +/** + * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style + * Specification. + * + * `Layer` is an abstract base class; concrete derived classes are provided for each layer type. `Layer` contains + * functionality that is common to all layer types: + * + * * Runtime type information: type predicates and casting + * * Accessors for properties common to all layer types: ID, visibility, etc. + * * Cloning and copying + * + * All other functionality lives in the derived classes. To instantiate a layer, create an instance of the desired + * type, passing the ID: + * + * auto circleLayer = std::make_unique("my-circle-layer"); + */ +class Layer : public mbgl::util::noncopyable { +public: + virtual ~Layer(); + + // Check whether this layer is of the given subtype. + template + bool is() const; + + // Dynamically cast this layer to the given subtype. + template + T* as() { + return is() ? reinterpret_cast(this) : nullptr; + } + + template + const T* as() const { + return is() ? reinterpret_cast(this) : nullptr; + } + + const std::string& getID() const; + + // Visibility + VisibilityType getVisibility() const; + void setVisibility(VisibilityType); + + // Create a new layer with the specified `id` and `ref`. All other properties + // are copied from this layer. + std::unique_ptr copy(const std::string& id, + const std::string& ref) const; + + // Private implementation + class Impl; + const std::unique_ptr baseImpl; + +protected: + enum class Type { + Fill, + Line, + Circle, + Symbol, + Raster, + Background, + Custom, + }; + + const Type type; + Layer(Type, std::unique_ptr); +}; + +} // namespace mbgl + +#endif diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 9b03ab8a2d7..a852a09a14c 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace mbgl { @@ -20,6 +21,26 @@ struct FontStackHash { std::size_t operator()(const FontStack&) const; }; +template +class Function { +public: + using Stop = std::pair; + using Stops = std::vector; + + Function(const T& constant) + : stops({{ 0, constant }}) {} + + explicit Function(const Stops& stops_, float base_) + : base(base_), stops(stops_) {} + + float getBase() const { return base; } + const std::vector>& getStops() const { return stops; } + +private: + float base = 1; + std::vector> stops; +}; + // ------------------------------------------------------------------------------------------------- enum class SourceType : uint8_t { diff --git a/package.json b/package.json index 4c94cdd3913..4fc0da158dd 100644 --- a/package.json +++ b/package.json @@ -18,8 +18,11 @@ }, "devDependencies": { "aws-sdk": "^2.3.5", + "csscolorparser": "^1.0.2", + "ejs": "^2.4.1", "express": "^4.11.1", "mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#e032997109c0ead5394ff64f2f0ea6b0f8efdc3f", + "mapbox-gl-style-spec": "^8.5.1", "mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#f45fd7aba98650c7f3bf778c9cbbfd3b548a4ee8", "node-gyp": "^3.3.1", "request": "^2.72.0", diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index d694235149b..76a9c38c8b5 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js new file mode 100644 index 00000000000..2904a1429af --- /dev/null +++ b/scripts/generate-style-code.js @@ -0,0 +1,346 @@ +'use strict'; + +const fs = require('fs'); +const ejs = require('ejs'); +const spec = require('mapbox-gl-style-spec').latest; +var parseCSSColor = require('csscolorparser').parseCSSColor; + +global.camelize = function (str) { + return str.replace(/(?:^|-)(.)/g, function (_, x) { + return x.toUpperCase(); + }); +} + +global.camelizeWithLeadingLowercase = function (str) { + return str.replace(/-(.)/g, function (_, x) { + return x.toUpperCase(); + }); +} + +global.propertyType = function (property) { + if (/-translate-anchor$/.test(property.name)) { + return 'TranslateAnchorType'; + } + if (/-rotation-alignment$/.test(property.name)) { + return 'RotationAlignmentType'; + } + switch (property.type) { + case 'boolean': + return 'bool'; + case 'number': + return 'float'; + case 'string': + return 'std::string'; + case 'enum': + return `${camelize(property.name)}Type`; + case 'color': + return `Color`; + case 'array': + if (property.length) { + return `std::array<${propertyType({type: property.value})}, ${property.length}>`; + } else { + return `std::vector<${propertyType({type: property.value})}>`; + } + default: throw new Error(`unknown type for ${property.name}`) + } +} + +global.defaultValue = function (property) { + switch (property.type) { + case 'number': + return property.default; + case 'string': + return JSON.stringify(property.default || ""); + case 'enum': + return `${propertyType(property)}::${camelize(property.default)}`; + case 'color': + return `{{ ${parseCSSColor(property.default).join(', ')} }}` + case 'array': + const defaults = (property.default || []).map((e) => defaultValue({ type: property.value, default: e })); + if (property.length) { + return `{{ ${defaults.join(', ')} }}`; + } else { + return `{ ${defaults.join(', ')} }`; + } + default: + return property.default; + } +} + +const layerHpp = ejs.compile(`<% + const type = locals.type; + const layoutProperties = locals.layoutProperties; + const paintProperties = locals.paintProperties; +-%> +// This file is generated. Do not edit. + +#pragma once + +#include +<% if (type === 'line' || type === 'symbol') { %> +#include +<% } -%> + +namespace mbgl { + +class <%- camelize(type) %>Layer : public Layer { +public: + <%- camelize(type) %>Layer(const std::string& layerID); + ~<%- camelize(type) %>Layer() final; + +<% if (type === 'raster') { -%> + // Source + + void setSource(const std::string& sourceID); + const std::string& getSourceID() const; + +<% } else if (type !== 'background') { -%> + // Source + + void setSource(const std::string& sourceID, const std::string& sourceLayer); + const std::string& getSourceID() const; + const std::string& getSourceLayer() const; + +<% } -%> +<% if (layoutProperties.length) { -%> + // Layout properties + +<% for (const property of layoutProperties) { -%> + Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + +<% } -%> +<% } -%> + // Paint properties + +<% for (const property of paintProperties) { -%> + Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + +<% } -%> + // Private implementation + + class Impl; + Impl* const impl; + + <%- camelize(type) %>Layer(const Impl&); + <%- camelize(type) %>Layer(const <%- camelize(type) %>Layer&) = delete; +}; + +template <> +inline bool Layer::is<<%- camelize(type) %>Layer>() const { + return type == Type::<%- camelize(type) %>; +} + +} // namespace mbgl +`, {strict: true}); + +const layerCpp = ejs.compile(`<% + const type = locals.type; + const layoutProperties = locals.layoutProperties; + const paintProperties = locals.paintProperties; +-%> +// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`. + +#include _layer.hpp> +#include _layer_impl.hpp> + +namespace mbgl { + +<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID) + : Layer(Type::<%- camelize(type) %>, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +<%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const Impl& other) + : Layer(Type::<%- camelize(type) %>, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +<%- camelize(type) %>Layer::~<%- camelize(type) %>Layer() = default; + +std::unique_ptr <%- camelize(type) %>Layer::Impl::clone() const { + return std::make_unique<<%- camelize(type) %>Layer>(*this); +} + +<% if (type === 'raster') { -%> +// Source + +void <%- camelize(type) %>Layer::setSource(const std::string& sourceID) { + impl->source = sourceID; +} + +const std::string& <%- camelize(type) %>Layer::getSourceID() const { + return impl->source; +} +<% } else if (type !== 'background') { -%> +// Source + +void <%- camelize(type) %>Layer::setSource(const std::string& sourceID, const std::string& sourceLayer) { + impl->source = sourceID; + impl->sourceLayer = sourceLayer; +} + +const std::string& <%- camelize(type) %>Layer::getSourceID() const { + return impl->source; +} + +const std::string& <%- camelize(type) %>Layer::getSourceLayer() const { + return impl->sourceLayer; +} +<% } -%> + +// Layout properties + +<% for (const property of layoutProperties) { -%> +Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return *impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue; +} + +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { + impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue = value; +} +<% } -%> + +// Paint properties +<% for (const property of paintProperties) { %> +Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.at(ClassID::Default); +} + +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { + impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.emplace(ClassID::Default, value); +} +<% } -%> + +} // namespace mbgl +`, {strict: true}); + +const propertiesHpp = ejs.compile(`<% + const type = locals.type; + const layoutProperties = locals.layoutProperties; + const paintProperties = locals.paintProperties; +-%> +// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +<% if (layoutProperties.length) { -%> +class <%- camelize(type) %>LayoutProperties { +public: + void parse(const JSValue&); + void recalculate(const StyleCalculationParameters&); + +<% for (const property of layoutProperties) { -%> + LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; +<% } -%> +}; + +<% } -%> +class <%- camelize(type) %>PaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + +<% for (const property of paintProperties) { -%> +<% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> + PaintProperty<<%- propertyType(property) %>, CrossFadedFunctionEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; +<% } else if (property.name === 'fill-outline-color') { -%> + PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} }; +<% } else { -%> + PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; +<% } -%> +<% } -%> +}; + +} // namespace mbgl +`, {strict: true}); + +const propertiesCpp = ejs.compile(`<% + const type = locals.type; + const layoutProperties = locals.layoutProperties; + const paintProperties = locals.paintProperties; +-%> +// This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`. + +#include _layer_properties.hpp> + +namespace mbgl { + +<% if (layoutProperties.length) { -%> +void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) { +<% for (const property of layoutProperties) { -%> + <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value); +<% } -%> +} + +void <%- camelize(type) %>LayoutProperties::recalculate(const StyleCalculationParameters& parameters) { +<% for (const property of layoutProperties) { -%> + <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); +<% } -%> +} + +<% } -%> +void <%- camelize(type) %>PaintProperties::parse(const JSValue& value) { +<% for (const property of paintProperties) { -%> + <%- camelizeWithLeadingLowercase(property.name) %>.parse(<%- JSON.stringify(property.name) %>, value); +<% } -%> +} + +void <%- camelize(type) %>PaintProperties::cascade(const StyleCascadeParameters& parameters) { +<% for (const property of paintProperties) { -%> + <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters); +<% } -%> +} + +bool <%- camelize(type) %>PaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + +<% for (const property of paintProperties) { -%> + hasTransitions |= <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); +<% } -%> + + return hasTransitions; +} + +} // namespace mbgl +`, {strict: true}); + +for (const type of spec.layer.type.values) { + const layoutProperties = Object.keys(spec[`layout_${type}`]).reduce((memo, name) => { + if (name !== 'visibility') { + spec[`layout_${type}`][name].name = name; + memo.push(spec[`layout_${type}`][name]); + } + return memo; + }, []); + + const paintProperties = Object.keys(spec[`paint_${type}`]).reduce((memo, name) => { + spec[`paint_${type}`][name].name = name; + memo.push(spec[`paint_${type}`][name]); + return memo; + }, []); + + const layer = { + type: type, + layoutProperties: layoutProperties, + paintProperties: paintProperties, + }; + + fs.writeFileSync(`include/mbgl/layer/${type}_layer.hpp`, layerHpp(layer)); + fs.writeFileSync(`src/mbgl/layer/${type}_layer.cpp`, layerCpp(layer)); + + fs.writeFileSync(`src/mbgl/layer/${type}_layer_properties.hpp`, propertiesHpp(layer)); + fs.writeFileSync(`src/mbgl/layer/${type}_layer_properties.cpp`, propertiesCpp(layer)); +} diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 4d7059f80f1..09442b165c4 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include @@ -108,13 +109,13 @@ void AnnotationManager::updateStyle(Style& style) { source->enabled = true; style.addSource(std::move(source)); - std::unique_ptr layer = std::make_unique(); - layer->id = PointLayerID; - layer->source = SourceID; - layer->sourceLayer = PointLayerID; - layer->layout.iconImage = std::string("{sprite}"); - layer->layout.iconAllowOverlap = true; - layer->spriteAtlas = &spriteAtlas; + std::unique_ptr layer = std::make_unique(PointLayerID); + + layer->setSource(SourceID, PointLayerID); + layer->setIconImage({"{sprite}"}); + layer->setIconAllowOverlap(true); + + layer->impl->spriteAtlas = &spriteAtlas; style.addLayer(std::move(layer)); } diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp index 093f53fb913..17bdd9c38e9 100644 --- a/src/mbgl/annotation/fill_annotation_impl.cpp +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -16,15 +16,12 @@ void FillAnnotationImpl::updateStyle(Style& style) const { if (style.getLayer(layerID)) return; - std::unique_ptr layer = std::make_unique(); + std::unique_ptr layer = std::make_unique(layerID); + layer->setSource(AnnotationManager::SourceID, layerID); - layer->paint.fillOpacity = annotation.opacity; - layer->paint.fillColor = annotation.color; - layer->paint.fillOutlineColor = annotation.outlineColor; - - layer->id = layerID; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; + layer->setFillOpacity(annotation.opacity); + layer->setFillColor(annotation.color); + layer->setFillOutlineColor(annotation.outlineColor); style.addLayer(std::move(layer), AnnotationManager::PointLayerID); } diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp index 5bcc142a5b0..11febc7de71 100644 --- a/src/mbgl/annotation/line_annotation_impl.cpp +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -16,16 +16,12 @@ void LineAnnotationImpl::updateStyle(Style& style) const { if (style.getLayer(layerID)) return; - std::unique_ptr layer = std::make_unique(); - layer->layout.lineJoin = LineJoinType::Round; - - layer->paint.lineOpacity = annotation.opacity; - layer->paint.lineWidth = annotation.width; - layer->paint.lineColor = annotation.color; - - layer->id = layerID; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; + std::unique_ptr layer = std::make_unique(layerID); + layer->setSource(AnnotationManager::SourceID, layerID); + layer->setLineJoin(LineJoinType::Round); + layer->setLineOpacity(annotation.opacity); + layer->setLineWidth(annotation.width); + layer->setLineColor(annotation.color); style.addLayer(std::move(layer), AnnotationManager::PointLayerID); } diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.cpp b/src/mbgl/annotation/style_sourced_annotation_impl.cpp index ae92d917aa0..e1e11a664af 100644 --- a/src/mbgl/annotation/style_sourced_annotation_impl.cpp +++ b/src/mbgl/annotation/style_sourced_annotation_impl.cpp @@ -1,7 +1,9 @@ #include #include #include -#include +#include +#include +#include namespace mbgl { @@ -16,19 +18,21 @@ void StyleSourcedAnnotationImpl::updateStyle(Style& style) const { if (style.getLayer(layerID)) return; - const StyleLayer* sourceLayer = style.getLayer(annotation.layerID); + const Layer* sourceLayer = style.getLayer(annotation.layerID); if (!sourceLayer) return; - std::unique_ptr layer = sourceLayer->clone(); - - layer->id = layerID; - layer->ref = ""; - layer->source = AnnotationManager::SourceID; - layer->sourceLayer = layer->id; - layer->visibility = VisibilityType::Visible; - - style.addLayer(std::move(layer), sourceLayer->id); + if (sourceLayer->is()) { + std::unique_ptr layer = sourceLayer->copy(layerID, ""); + layer->as()->setSource(AnnotationManager::SourceID, layerID); + layer->as()->setVisibility(VisibilityType::Visible); + style.addLayer(std::move(layer), sourceLayer->getID()); + } else if (sourceLayer->is()) { + std::unique_ptr layer = sourceLayer->copy(layerID, ""); + layer->as()->setSource(AnnotationManager::SourceID, layerID); + layer->as()->setVisibility(VisibilityType::Visible); + style.addLayer(std::move(layer), sourceLayer->getID()); + } } const ShapeAnnotationGeometry& StyleSourcedAnnotationImpl::geometry() const { diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index ab451bcd6a1..e72aa344fa1 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include #include #include @@ -116,7 +117,7 @@ void FeatureIndex::addFeature( auto styleLayer = style.getLayer(layerID); if (!styleLayer || (!styleLayer->is() && - !styleLayer->queryIntersectsGeometry(queryGeometry, geometryTileFeature->getGeometries(), bearing, pixelsToTileUnits))) { + !styleLayer->baseImpl->queryIntersectsGeometry(queryGeometry, geometryTileFeature->getGeometries(), bearing, pixelsToTileUnits))) { continue; } diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp index e2879f786e2..8d097344fc7 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/layer/background_layer.cpp @@ -1,38 +1,55 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include +#include namespace mbgl { -std::unique_ptr BackgroundLayer::clone() const { - return std::make_unique(*this); +BackgroundLayer::BackgroundLayer(const std::string& layerID) + : Layer(Type::Background, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; } -void BackgroundLayer::parsePaints(const JSValue& layer) { - paint.backgroundOpacity.parse("background-opacity", layer); - paint.backgroundColor.parse("background-color", layer); - paint.backgroundPattern.parse("background-pattern", layer); +BackgroundLayer::BackgroundLayer(const Impl& other) + : Layer(Type::Background, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { } -void BackgroundLayer::cascade(const StyleCascadeParameters& parameters) { - paint.backgroundOpacity.cascade(parameters); - paint.backgroundColor.cascade(parameters); - paint.backgroundPattern.cascade(parameters); +BackgroundLayer::~BackgroundLayer() = default; + +std::unique_ptr BackgroundLayer::Impl::clone() const { + return std::make_unique(*this); } -bool BackgroundLayer::recalculate(const StyleCalculationParameters& parameters) { - bool hasTransitions = false; - hasTransitions |= paint.backgroundOpacity.calculate(parameters); - hasTransitions |= paint.backgroundColor.calculate(parameters); - hasTransitions |= paint.backgroundPattern.calculate(parameters); +// Layout properties - passes = paint.backgroundOpacity > 0 ? RenderPass::Translucent : RenderPass::None; - return hasTransitions; +// Paint properties + +Function BackgroundLayer::getBackgroundColor() const { + return impl->paint.backgroundColor.values.at(ClassID::Default); +} + +void BackgroundLayer::setBackgroundColor(Function value) { + impl->paint.backgroundColor.values.emplace(ClassID::Default, value); +} + +Function BackgroundLayer::getBackgroundPattern() const { + return impl->paint.backgroundPattern.values.at(ClassID::Default); +} + +void BackgroundLayer::setBackgroundPattern(Function value) { + impl->paint.backgroundPattern.values.emplace(ClassID::Default, value); +} + +Function BackgroundLayer::getBackgroundOpacity() const { + return impl->paint.backgroundOpacity.values.at(ClassID::Default); } -std::unique_ptr BackgroundLayer::createBucket(StyleBucketParameters&) const { - return nullptr; +void BackgroundLayer::setBackgroundOpacity(Function value) { + impl->paint.backgroundOpacity.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/background_layer.hpp b/src/mbgl/layer/background_layer.hpp deleted file mode 100644 index 39142a3bd3d..00000000000 --- a/src/mbgl/layer/background_layer.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class BackgroundPaintProperties { -public: - PaintProperty backgroundOpacity { 1.0f }; - PaintProperty backgroundColor { {{ 0, 0, 0, 1 }} }; - PaintProperty backgroundPattern { "" }; -}; - -class BackgroundLayer : public StyleLayer { -public: - BackgroundLayer() : StyleLayer(Type::Background) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - BackgroundPaintProperties paint; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Background; -} - -} // namespace mbgl diff --git a/src/mbgl/layer/background_layer_impl.cpp b/src/mbgl/layer/background_layer_impl.cpp new file mode 100644 index 00000000000..626c8fc8055 --- /dev/null +++ b/src/mbgl/layer/background_layer_impl.cpp @@ -0,0 +1,26 @@ +#include +#include + +namespace mbgl { + +void BackgroundLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void BackgroundLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool BackgroundLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = paint.recalculate(parameters); + + passes = paint.backgroundOpacity > 0 ? RenderPass::Translucent : RenderPass::None; + + return hasTransitions; +} + +std::unique_ptr BackgroundLayer::Impl::createBucket(StyleBucketParameters&) const { + return nullptr; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/background_layer_impl.hpp b/src/mbgl/layer/background_layer_impl.hpp new file mode 100644 index 00000000000..6af31dd9219 --- /dev/null +++ b/src/mbgl/layer/background_layer_impl.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { + +class BackgroundLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + BackgroundPaintProperties paint; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.cpp b/src/mbgl/layer/background_layer_properties.cpp new file mode 100644 index 00000000000..d866df7eee8 --- /dev/null +++ b/src/mbgl/layer/background_layer_properties.cpp @@ -0,0 +1,29 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void BackgroundPaintProperties::parse(const JSValue& value) { + backgroundColor.parse("background-color", value); + backgroundPattern.parse("background-pattern", value); + backgroundOpacity.parse("background-opacity", value); +} + +void BackgroundPaintProperties::cascade(const StyleCascadeParameters& parameters) { + backgroundColor.cascade(parameters); + backgroundPattern.cascade(parameters); + backgroundOpacity.cascade(parameters); +} + +bool BackgroundPaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= backgroundColor.calculate(parameters); + hasTransitions |= backgroundPattern.calculate(parameters); + hasTransitions |= backgroundOpacity.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.hpp b/src/mbgl/layer/background_layer_properties.hpp new file mode 100644 index 00000000000..5e388a79284 --- /dev/null +++ b/src/mbgl/layer/background_layer_properties.hpp @@ -0,0 +1,25 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +class BackgroundPaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty backgroundColor { {{ 0, 0, 0, 1 }} }; + PaintProperty backgroundPattern { "" }; + PaintProperty backgroundOpacity { 1 }; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index 839d1282a99..bf385c997c7 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -1,81 +1,93 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include -#include -#include -#include -#include +#include namespace mbgl { -std::unique_ptr CircleLayer::clone() const { +CircleLayer::CircleLayer(const std::string& layerID) + : Layer(Type::Circle, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +CircleLayer::CircleLayer(const Impl& other) + : Layer(Type::Circle, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +CircleLayer::~CircleLayer() = default; + +std::unique_ptr CircleLayer::Impl::clone() const { return std::make_unique(*this); } -void CircleLayer::parsePaints(const JSValue& layer) { - paint.circleRadius.parse("circle-radius", layer); - paint.circleColor.parse("circle-color", layer); - paint.circleOpacity.parse("circle-opacity", layer); - paint.circleTranslate.parse("circle-translate", layer); - paint.circleTranslateAnchor.parse("circle-translate-anchor", layer); - paint.circleBlur.parse("circle-blur", layer); +// Source + +void CircleLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) { + impl->source = sourceID; + impl->sourceLayer = sourceLayer; } -void CircleLayer::cascade(const StyleCascadeParameters& parameters) { - paint.circleRadius.cascade(parameters); - paint.circleColor.cascade(parameters); - paint.circleOpacity.cascade(parameters); - paint.circleTranslate.cascade(parameters); - paint.circleTranslateAnchor.cascade(parameters); - paint.circleBlur.cascade(parameters); +const std::string& CircleLayer::getSourceID() const { + return impl->source; } -bool CircleLayer::recalculate(const StyleCalculationParameters& parameters) { - bool hasTransitions = false; +const std::string& CircleLayer::getSourceLayer() const { + return impl->sourceLayer; +} + +// Layout properties + - hasTransitions |= paint.circleRadius.calculate(parameters); - hasTransitions |= paint.circleColor.calculate(parameters); - hasTransitions |= paint.circleOpacity.calculate(parameters); - hasTransitions |= paint.circleTranslate.calculate(parameters); - hasTransitions |= paint.circleTranslateAnchor.calculate(parameters); - hasTransitions |= paint.circleBlur.calculate(parameters); +// Paint properties - passes = (paint.circleRadius > 0 && paint.circleColor.value[3] > 0 && paint.circleOpacity > 0) - ? RenderPass::Translucent : RenderPass::None; +Function CircleLayer::getCircleRadius() const { + return impl->paint.circleRadius.values.at(ClassID::Default); +} + +void CircleLayer::setCircleRadius(Function value) { + impl->paint.circleRadius.values.emplace(ClassID::Default, value); +} + +Function CircleLayer::getCircleColor() const { + return impl->paint.circleColor.values.at(ClassID::Default); +} - return hasTransitions; +void CircleLayer::setCircleColor(Function value) { + impl->paint.circleColor.values.emplace(ClassID::Default, value); } -std::unique_ptr CircleLayer::createBucket(StyleBucketParameters& parameters) const { - auto bucket = std::make_unique(parameters.mode); +Function CircleLayer::getCircleBlur() const { + return impl->paint.circleBlur.values.at(ClassID::Default); +} - auto& name = bucketName(); - parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = feature.getGeometries(); - bucket->addGeometry(geometries); - parameters.featureIndex.insert(geometries, index, layerName, name); - }); +void CircleLayer::setCircleBlur(Function value) { + impl->paint.circleBlur.values.emplace(ClassID::Default, value); +} - return std::move(bucket); +Function CircleLayer::getCircleOpacity() const { + return impl->paint.circleOpacity.values.at(ClassID::Default); } -float CircleLayer::getQueryRadius() const { - const std::array& translate = paint.circleTranslate; - return paint.circleRadius + util::length(translate[0], translate[1]); +void CircleLayer::setCircleOpacity(Function value) { + impl->paint.circleOpacity.values.emplace(ClassID::Default, value); } -bool CircleLayer::queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const { +Function> CircleLayer::getCircleTranslate() const { + return impl->paint.circleTranslate.values.at(ClassID::Default); +} - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.circleTranslate, paint.circleTranslateAnchor, bearing, pixelsToTileUnits); +void CircleLayer::setCircleTranslate(Function> value) { + impl->paint.circleTranslate.values.emplace(ClassID::Default, value); +} - auto circleRadius = paint.circleRadius * pixelsToTileUnits; +Function CircleLayer::getCircleTranslateAnchor() const { + return impl->paint.circleTranslateAnchor.values.at(ClassID::Default); +} - return util::multiPolygonIntersectsBufferedMultiPoint( - translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); +void CircleLayer::setCircleTranslateAnchor(Function value) { + impl->paint.circleTranslateAnchor.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer.hpp b/src/mbgl/layer/circle_layer.hpp deleted file mode 100644 index 543bae8f19f..00000000000 --- a/src/mbgl/layer/circle_layer.hpp +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class CirclePaintProperties { -public: - PaintProperty circleRadius { 5.0f }; - PaintProperty circleColor { {{ 0, 0, 0, 1 }} }; - PaintProperty circleOpacity { 1.0f }; - PaintProperty> circleTranslate { {{ 0, 0 }} }; - PaintProperty circleTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty circleBlur { 0 }; -}; - -class CircleLayer : public StyleLayer { -public: - CircleLayer() : StyleLayer(Type::Circle) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; - - CirclePaintProperties paint; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Circle; -} - -} // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_impl.cpp b/src/mbgl/layer/circle_layer_impl.cpp new file mode 100644 index 00000000000..b1ba778cd60 --- /dev/null +++ b/src/mbgl/layer/circle_layer_impl.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include + +namespace mbgl { + +void CircleLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void CircleLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool CircleLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = paint.recalculate(parameters); + + passes = (paint.circleRadius > 0 && paint.circleColor.value[3] > 0 && paint.circleOpacity > 0) + ? RenderPass::Translucent : RenderPass::None; + + return hasTransitions; +} + +std::unique_ptr CircleLayer::Impl::createBucket(StyleBucketParameters& parameters) const { + auto bucket = std::make_unique(parameters.mode); + + auto& name = bucketName(); + parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { + auto geometries = feature.getGeometries(); + bucket->addGeometry(geometries); + parameters.featureIndex.insert(geometries, index, layerName, name); + }); + + return std::move(bucket); +} + +float CircleLayer::Impl::getQueryRadius() const { + const std::array& translate = paint.circleTranslate; + return paint.circleRadius + util::length(translate[0], translate[1]); +} + +bool CircleLayer::Impl::queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const { + + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, paint.circleTranslate, paint.circleTranslateAnchor, bearing, pixelsToTileUnits); + + auto circleRadius = paint.circleRadius * pixelsToTileUnits; + + return util::multiPolygonIntersectsBufferedMultiPoint( + translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); +} + +} // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_impl.hpp b/src/mbgl/layer/circle_layer_impl.hpp new file mode 100644 index 00000000000..1cb19a62051 --- /dev/null +++ b/src/mbgl/layer/circle_layer_impl.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { + +class CircleLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + float getQueryRadius() const override; + bool queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const override; + + CirclePaintProperties paint; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_properties.cpp b/src/mbgl/layer/circle_layer_properties.cpp new file mode 100644 index 00000000000..48d99b579ee --- /dev/null +++ b/src/mbgl/layer/circle_layer_properties.cpp @@ -0,0 +1,38 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void CirclePaintProperties::parse(const JSValue& value) { + circleRadius.parse("circle-radius", value); + circleColor.parse("circle-color", value); + circleBlur.parse("circle-blur", value); + circleOpacity.parse("circle-opacity", value); + circleTranslate.parse("circle-translate", value); + circleTranslateAnchor.parse("circle-translate-anchor", value); +} + +void CirclePaintProperties::cascade(const StyleCascadeParameters& parameters) { + circleRadius.cascade(parameters); + circleColor.cascade(parameters); + circleBlur.cascade(parameters); + circleOpacity.cascade(parameters); + circleTranslate.cascade(parameters); + circleTranslateAnchor.cascade(parameters); +} + +bool CirclePaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= circleRadius.calculate(parameters); + hasTransitions |= circleColor.calculate(parameters); + hasTransitions |= circleBlur.calculate(parameters); + hasTransitions |= circleOpacity.calculate(parameters); + hasTransitions |= circleTranslate.calculate(parameters); + hasTransitions |= circleTranslateAnchor.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_properties.hpp b/src/mbgl/layer/circle_layer_properties.hpp new file mode 100644 index 00000000000..a88db27605b --- /dev/null +++ b/src/mbgl/layer/circle_layer_properties.hpp @@ -0,0 +1,28 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +class CirclePaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty circleRadius { 5 }; + PaintProperty circleColor { {{ 0, 0, 0, 1 }} }; + PaintProperty circleBlur { 0 }; + PaintProperty circleOpacity { 1 }; + PaintProperty> circleTranslate { {{ 0, 0 }} }; + PaintProperty circleTranslateAnchor { TranslateAnchorType::Map }; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/custom_layer.cpp b/src/mbgl/layer/custom_layer.cpp index 3b683bf8337..a33176e7f99 100644 --- a/src/mbgl/layer/custom_layer.cpp +++ b/src/mbgl/layer/custom_layer.cpp @@ -1,67 +1,22 @@ #include -#include -#include +#include namespace mbgl { -CustomLayer::CustomLayer(const std::string& id_, - CustomLayerInitializeFunction initializeFn_, - CustomLayerRenderFunction renderFn_, - CustomLayerDeinitializeFunction deinitializeFn_, - void* context_) - : StyleLayer(Type::Custom) { - id = id_; - initializeFn = initializeFn_; - renderFn = renderFn_; - deinitializeFn = deinitializeFn_; - context = context_; +CustomLayer::CustomLayer(const std::string& layerID, + CustomLayerInitializeFunction init, + CustomLayerRenderFunction render, + CustomLayerDeinitializeFunction deinit, + void* context) + : Layer(Type::Custom, std::make_unique(layerID, init, render, deinit, context)) + , impl(static_cast(baseImpl.get())) { } -CustomLayer::CustomLayer(const CustomLayer& other) - : StyleLayer(other) { - id = other.id; - // Don't copy anything else. +CustomLayer::CustomLayer(const Impl& other) + : Layer(Type::Custom, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { } -CustomLayer::~CustomLayer() { - if (deinitializeFn) { - deinitializeFn(context); - } -} - -void CustomLayer::initialize() { - assert(initializeFn); - initializeFn(context); -} - -void CustomLayer::render(const TransformState& state) const { - assert(renderFn); - - CustomLayerRenderParameters parameters; - - parameters.width = state.getWidth(); - parameters.height = state.getHeight(); - parameters.latitude = state.getLatLng().latitude; - parameters.longitude = state.getLatLng().longitude; - parameters.zoom = state.getZoom(); - parameters.bearing = -state.getAngle() * util::RAD2DEG; - parameters.pitch = state.getPitch(); - parameters.altitude = state.getAltitude(); - - renderFn(context, parameters); -} - -bool CustomLayer::recalculate(const StyleCalculationParameters&) { - passes = RenderPass::Translucent; - return false; -} - -std::unique_ptr CustomLayer::clone() const { - return std::make_unique(*this); -} - -std::unique_ptr CustomLayer::createBucket(StyleBucketParameters&) const { - return nullptr; -} +CustomLayer::~CustomLayer() = default; } // namespace mbgl diff --git a/src/mbgl/layer/custom_layer_impl.cpp b/src/mbgl/layer/custom_layer_impl.cpp new file mode 100644 index 00000000000..8a08c804ed4 --- /dev/null +++ b/src/mbgl/layer/custom_layer_impl.cpp @@ -0,0 +1,66 @@ +#include +#include +#include + +namespace mbgl { + +CustomLayer::Impl::Impl(const std::string& id_, + CustomLayerInitializeFunction initializeFn_, + CustomLayerRenderFunction renderFn_, + CustomLayerDeinitializeFunction deinitializeFn_, + void* context_) { + id = id_; + initializeFn = initializeFn_; + renderFn = renderFn_; + deinitializeFn = deinitializeFn_; + context = context_; +} + +CustomLayer::Impl::Impl(const CustomLayer::Impl& other) + : Layer::Impl(other) { + id = other.id; + // Don't copy anything else. +} + +CustomLayer::Impl::~Impl() { + if (deinitializeFn) { + deinitializeFn(context); + } +} + +std::unique_ptr CustomLayer::Impl::clone() const { + return std::make_unique(*this); +} + +void CustomLayer::Impl::initialize() { + assert(initializeFn); + initializeFn(context); +} + +void CustomLayer::Impl::render(const TransformState& state) const { + assert(renderFn); + + CustomLayerRenderParameters parameters; + + parameters.width = state.getWidth(); + parameters.height = state.getHeight(); + parameters.latitude = state.getLatLng().latitude; + parameters.longitude = state.getLatLng().longitude; + parameters.zoom = state.getZoom(); + parameters.bearing = -state.getAngle() * util::RAD2DEG; + parameters.pitch = state.getPitch(); + parameters.altitude = state.getAltitude(); + + renderFn(context, parameters); +} + +bool CustomLayer::Impl::recalculate(const StyleCalculationParameters&) { + passes = RenderPass::Translucent; + return false; +} + +std::unique_ptr CustomLayer::Impl::createBucket(StyleBucketParameters&) const { + return nullptr; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/custom_layer.hpp b/src/mbgl/layer/custom_layer_impl.hpp similarity index 57% rename from src/mbgl/layer/custom_layer.hpp rename to src/mbgl/layer/custom_layer_impl.hpp index 93d9c85e6c0..09709a2f9d4 100644 --- a/src/mbgl/layer/custom_layer.hpp +++ b/src/mbgl/layer/custom_layer_impl.hpp @@ -1,27 +1,28 @@ #pragma once -#include +#include +#include namespace mbgl { class TransformState; -class CustomLayer : public StyleLayer { +class CustomLayer::Impl : public Layer::Impl { public: - CustomLayer(const std::string& id, - CustomLayerInitializeFunction, - CustomLayerRenderFunction, - CustomLayerDeinitializeFunction, - void* context); + Impl(const std::string& id, + CustomLayerInitializeFunction, + CustomLayerRenderFunction, + CustomLayerDeinitializeFunction, + void* context); - CustomLayer(const CustomLayer&); - ~CustomLayer(); + Impl(const Impl&); + ~Impl() final; void initialize(); void render(const TransformState&) const; private: - std::unique_ptr clone() const final; + std::unique_ptr clone() const override; void parseLayout(const JSValue&) final {} void parsePaints(const JSValue&) final {} @@ -37,9 +38,4 @@ class CustomLayer : public StyleLayer { void* context = nullptr; }; -template <> -inline bool StyleLayer::is() const { - return type == Type::Custom; -} - } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index 850bac4ab46..9a376089df6 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -1,90 +1,101 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include -#include -#include -#include -#include +#include namespace mbgl { -std::unique_ptr FillLayer::clone() const { +FillLayer::FillLayer(const std::string& layerID) + : Layer(Type::Fill, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +FillLayer::FillLayer(const Impl& other) + : Layer(Type::Fill, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +FillLayer::~FillLayer() = default; + +std::unique_ptr FillLayer::Impl::clone() const { return std::make_unique(*this); } -void FillLayer::parsePaints(const JSValue& layer) { - paint.fillAntialias.parse("fill-antialias", layer); - paint.fillOpacity.parse("fill-opacity", layer); - paint.fillColor.parse("fill-color", layer); - paint.fillOutlineColor.parse("fill-outline-color", layer); - paint.fillTranslate.parse("fill-translate", layer); - paint.fillTranslateAnchor.parse("fill-translate-anchor", layer); - paint.fillPattern.parse("fill-pattern", layer); +// Source + +void FillLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) { + impl->source = sourceID; + impl->sourceLayer = sourceLayer; } -void FillLayer::cascade(const StyleCascadeParameters& parameters) { - paint.fillAntialias.cascade(parameters); - paint.fillOpacity.cascade(parameters); - paint.fillColor.cascade(parameters); - paint.fillOutlineColor.cascade(parameters); - paint.fillTranslate.cascade(parameters); - paint.fillTranslateAnchor.cascade(parameters); - paint.fillPattern.cascade(parameters); +const std::string& FillLayer::getSourceID() const { + return impl->source; } -bool FillLayer::recalculate(const StyleCalculationParameters& parameters) { - bool hasTransitions = false; +const std::string& FillLayer::getSourceLayer() const { + return impl->sourceLayer; +} - hasTransitions |= paint.fillAntialias.calculate(parameters); - hasTransitions |= paint.fillOpacity.calculate(parameters); - hasTransitions |= paint.fillColor.calculate(parameters); - hasTransitions |= paint.fillOutlineColor.calculate(parameters); - hasTransitions |= paint.fillTranslate.calculate(parameters); - hasTransitions |= paint.fillTranslateAnchor.calculate(parameters); - hasTransitions |= paint.fillPattern.calculate(parameters); +// Layout properties - passes = RenderPass::None; - if (paint.fillAntialias) { - passes |= RenderPass::Translucent; - } +// Paint properties - if (!paint.fillPattern.value.from.empty() || (paint.fillColor.value[3] * paint.fillOpacity) < 1.0f) { - passes |= RenderPass::Translucent; - } else { - passes |= RenderPass::Opaque; - } +Function FillLayer::getFillAntialias() const { + return impl->paint.fillAntialias.values.at(ClassID::Default); +} - return hasTransitions; +void FillLayer::setFillAntialias(Function value) { + impl->paint.fillAntialias.values.emplace(ClassID::Default, value); } -std::unique_ptr FillLayer::createBucket(StyleBucketParameters& parameters) const { - auto bucket = std::make_unique(); +Function FillLayer::getFillOpacity() const { + return impl->paint.fillOpacity.values.at(ClassID::Default); +} - auto& name = bucketName(); - parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = feature.getGeometries(); - bucket->addGeometry(geometries); - parameters.featureIndex.insert(geometries, index, layerName, name); - }); +void FillLayer::setFillOpacity(Function value) { + impl->paint.fillOpacity.values.emplace(ClassID::Default, value); +} - return std::move(bucket); +Function FillLayer::getFillColor() const { + return impl->paint.fillColor.values.at(ClassID::Default); } -float FillLayer::getQueryRadius() const { - const std::array& translate = paint.fillTranslate; - return util::length(translate[0], translate[1]); +void FillLayer::setFillColor(Function value) { + impl->paint.fillColor.values.emplace(ClassID::Default, value); } -bool FillLayer::queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const { +Function FillLayer::getFillOutlineColor() const { + return impl->paint.fillOutlineColor.values.at(ClassID::Default); +} - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.fillTranslate, paint.fillTranslateAnchor, bearing, pixelsToTileUnits); +void FillLayer::setFillOutlineColor(Function value) { + impl->paint.fillOutlineColor.values.emplace(ClassID::Default, value); +} + +Function> FillLayer::getFillTranslate() const { + return impl->paint.fillTranslate.values.at(ClassID::Default); +} + +void FillLayer::setFillTranslate(Function> value) { + impl->paint.fillTranslate.values.emplace(ClassID::Default, value); +} + +Function FillLayer::getFillTranslateAnchor() const { + return impl->paint.fillTranslateAnchor.values.at(ClassID::Default); +} + +void FillLayer::setFillTranslateAnchor(Function value) { + impl->paint.fillTranslateAnchor.values.emplace(ClassID::Default, value); +} + +Function FillLayer::getFillPattern() const { + return impl->paint.fillPattern.values.at(ClassID::Default); +} - return util::multiPolygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), geometry); +void FillLayer::setFillPattern(Function value) { + impl->paint.fillPattern.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer.hpp b/src/mbgl/layer/fill_layer.hpp deleted file mode 100644 index eb8a5072399..00000000000 --- a/src/mbgl/layer/fill_layer.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class FillPaintProperties { -public: - PaintProperty fillAntialias { true }; - PaintProperty fillOpacity { 1.0f }; - PaintProperty fillColor { {{ 0, 0, 0, 1 }} }; - PaintProperty fillOutlineColor { {{ 0, 0, 0, -1 }} }; - PaintProperty> fillTranslate { {{ 0, 0 }} }; - PaintProperty fillTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty fillPattern { "" }; -}; - -class FillLayer : public StyleLayer { -public: - FillLayer() : StyleLayer(Type::Fill) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; - - FillPaintProperties paint; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Fill; -} - -} // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_impl.cpp b/src/mbgl/layer/fill_layer_impl.cpp new file mode 100644 index 00000000000..21f482922dd --- /dev/null +++ b/src/mbgl/layer/fill_layer_impl.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include + +namespace mbgl { + +void FillLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void FillLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool FillLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = paint.recalculate(parameters); + + passes = RenderPass::None; + + if (paint.fillAntialias) { + passes |= RenderPass::Translucent; + } + + if (!paint.fillPattern.value.from.empty() || (paint.fillColor.value[3] * paint.fillOpacity) < 1.0f) { + passes |= RenderPass::Translucent; + } else { + passes |= RenderPass::Opaque; + } + + return hasTransitions; +} + +std::unique_ptr FillLayer::Impl::createBucket(StyleBucketParameters& parameters) const { + auto bucket = std::make_unique(); + + auto& name = bucketName(); + parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { + auto geometries = feature.getGeometries(); + bucket->addGeometry(geometries); + parameters.featureIndex.insert(geometries, index, layerName, name); + }); + + return std::move(bucket); +} + +float FillLayer::Impl::getQueryRadius() const { + const std::array& translate = paint.fillTranslate; + return util::length(translate[0], translate[1]); +} + +bool FillLayer::Impl::queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const { + + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, paint.fillTranslate, paint.fillTranslateAnchor, bearing, pixelsToTileUnits); + + return util::multiPolygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), geometry); +} + +} // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_impl.hpp b/src/mbgl/layer/fill_layer_impl.hpp new file mode 100644 index 00000000000..2af0d6491d7 --- /dev/null +++ b/src/mbgl/layer/fill_layer_impl.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { + +class FillLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + float getQueryRadius() const override; + bool queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const override; + + FillPaintProperties paint; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.cpp b/src/mbgl/layer/fill_layer_properties.cpp new file mode 100644 index 00000000000..e0d4f10bc9a --- /dev/null +++ b/src/mbgl/layer/fill_layer_properties.cpp @@ -0,0 +1,41 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void FillPaintProperties::parse(const JSValue& value) { + fillAntialias.parse("fill-antialias", value); + fillOpacity.parse("fill-opacity", value); + fillColor.parse("fill-color", value); + fillOutlineColor.parse("fill-outline-color", value); + fillTranslate.parse("fill-translate", value); + fillTranslateAnchor.parse("fill-translate-anchor", value); + fillPattern.parse("fill-pattern", value); +} + +void FillPaintProperties::cascade(const StyleCascadeParameters& parameters) { + fillAntialias.cascade(parameters); + fillOpacity.cascade(parameters); + fillColor.cascade(parameters); + fillOutlineColor.cascade(parameters); + fillTranslate.cascade(parameters); + fillTranslateAnchor.cascade(parameters); + fillPattern.cascade(parameters); +} + +bool FillPaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= fillAntialias.calculate(parameters); + hasTransitions |= fillOpacity.calculate(parameters); + hasTransitions |= fillColor.calculate(parameters); + hasTransitions |= fillOutlineColor.calculate(parameters); + hasTransitions |= fillTranslate.calculate(parameters); + hasTransitions |= fillTranslateAnchor.calculate(parameters); + hasTransitions |= fillPattern.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.hpp b/src/mbgl/layer/fill_layer_properties.hpp new file mode 100644 index 00000000000..fb327a2d6ca --- /dev/null +++ b/src/mbgl/layer/fill_layer_properties.hpp @@ -0,0 +1,29 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +class FillPaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty fillAntialias { true }; + PaintProperty fillOpacity { 1 }; + PaintProperty fillColor { {{ 0, 0, 0, 1 }} }; + PaintProperty fillOutlineColor { {{ 0, 0, 0, -1 }} }; + PaintProperty> fillTranslate { {{ 0, 0 }} }; + PaintProperty fillTranslateAnchor { TranslateAnchorType::Map }; + PaintProperty fillPattern { "" }; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/layer.cpp b/src/mbgl/layer/layer.cpp new file mode 100644 index 00000000000..154fbfe31f9 --- /dev/null +++ b/src/mbgl/layer/layer.cpp @@ -0,0 +1,32 @@ +#include +#include + +namespace mbgl { + +Layer::Layer(Type type_, std::unique_ptr baseImpl_) + : baseImpl(std::move(baseImpl_)), type(type_) { +} + +Layer::~Layer() = default; + +const std::string& Layer::getID() const { + return baseImpl->id; +} + +VisibilityType Layer::getVisibility() const { + return baseImpl->visibility; +} + +void Layer::setVisibility(VisibilityType value) { + baseImpl->visibility = value; +} + +std::unique_ptr Layer::copy(const std::string& id, + const std::string& ref) const { + std::unique_ptr result = baseImpl->clone(); + result->baseImpl->id = id; + result->baseImpl->ref = ref; + return result; +} + +} // namespace mbgl diff --git a/src/mbgl/style/style_layer.cpp b/src/mbgl/layer/layer_impl.cpp similarity index 50% rename from src/mbgl/style/style_layer.cpp rename to src/mbgl/layer/layer_impl.cpp index defdfca1106..315a1cb1b14 100644 --- a/src/mbgl/style/style_layer.cpp +++ b/src/mbgl/layer/layer_impl.cpp @@ -1,16 +1,16 @@ -#include +#include namespace mbgl { -const std::string& StyleLayer::bucketName() const { +const std::string& Layer::Impl::bucketName() const { return ref.empty() ? id : ref; } -bool StyleLayer::hasRenderPass(RenderPass pass) const { +bool Layer::Impl::hasRenderPass(RenderPass pass) const { return bool(passes & pass); } -bool StyleLayer::needsRendering() const { +bool Layer::Impl::needsRendering() const { return passes != RenderPass::None && visibility != VisibilityType::None; } diff --git a/src/mbgl/style/style_layer.hpp b/src/mbgl/layer/layer_impl.hpp similarity index 67% rename from src/mbgl/style/style_layer.hpp rename to src/mbgl/layer/layer_impl.hpp index 1388cbcb5ab..3d6b5cccfdb 100644 --- a/src/mbgl/style/style_layer.hpp +++ b/src/mbgl/layer/layer_impl.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -18,26 +19,23 @@ class StyleCalculationParameters; class StyleBucketParameters; class Bucket; -class StyleLayer { +/** + * `Layer::Impl` contains the internal implementation of `Layer`: the details that need to be accessible to other parts + * of the code, but hidden from the public API. Like `Layer`, it is an abstract base class, with derived classes for + * each layer type. + * + * Members that are public in `Layer` are part of the public API for all layers. + * Members that are public in `FooLayer` are part of the public API for "foo" layers. + * Members that are public in `Layer::Impl` are part of the internal API for all layers. + * Members that are public in `FooLayer::Impl` are part of the internal API for "foo" layers. + * Members that are private in `FooLayer::Impl` are internal to "foo" layers. + */ +class Layer::Impl { public: - virtual ~StyleLayer() = default; + virtual ~Impl() = default; - // Check whether this layer is of the given subtype. - template - bool is() const; - - // Dynamically cast this layer to the given subtype. - template - T* as() { - return is() ? reinterpret_cast(this) : nullptr; - } - template - const T* as() const { - return is() ? reinterpret_cast(this) : nullptr; - } - - // Create a copy of this layer. - virtual std::unique_ptr clone() const = 0; + // Create an identical copy of this layer. + virtual std::unique_ptr clone() const = 0; virtual void parseLayout(const JSValue& value) = 0; virtual void parsePaints(const JSValue& value) = 0; @@ -78,21 +76,9 @@ class StyleLayer { VisibilityType visibility = VisibilityType::Visible; protected: - enum class Type { - Fill, - Line, - Circle, - Symbol, - Raster, - Background, - Custom, - }; - - StyleLayer(Type type_) : type(type_) {} - StyleLayer(const StyleLayer&) = default; - StyleLayer& operator=(const StyleLayer&) = delete; - - const Type type; + Impl() = default; + Impl(const Impl&) = default; + Impl& operator=(const Impl&) = delete; // Stores what render passes this layer is currently enabled for. This depends on the // evaluated StyleProperties object and is updated accordingly. diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index d1d377462a1..0064a0b8dae 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -1,156 +1,153 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include -#include -#include -#include -#include +#include namespace mbgl { -std::unique_ptr LineLayer::clone() const { +LineLayer::LineLayer(const std::string& layerID) + : Layer(Type::Line, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +LineLayer::LineLayer(const Impl& other) + : Layer(Type::Line, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +LineLayer::~LineLayer() = default; + +std::unique_ptr LineLayer::Impl::clone() const { return std::make_unique(*this); } -void LineLayer::parseLayout(const JSValue& value) { - layout.lineCap.parse("line-cap", value); - layout.lineJoin.parse("line-join", value); - layout.lineMiterLimit.parse("line-miter-limit", value); - layout.lineRoundLimit.parse("line-round-limit", value); -} - -void LineLayer::parsePaints(const JSValue& layer) { - paint.lineOpacity.parse("line-opacity", layer); - paint.lineColor.parse("line-color", layer); - paint.lineTranslate.parse("line-translate", layer); - paint.lineTranslateAnchor.parse("line-translate-anchor", layer); - paint.lineWidth.parse("line-width", layer); - paint.lineGapWidth.parse("line-gap-width", layer); - paint.lineOffset.parse("line-offset", layer); - paint.lineBlur.parse("line-blur", layer); - paint.lineDasharray.parse("line-dasharray", layer); - paint.linePattern.parse("line-pattern", layer); +// Source + +void LineLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) { + impl->source = sourceID; + impl->sourceLayer = sourceLayer; +} + +const std::string& LineLayer::getSourceID() const { + return impl->source; +} + +const std::string& LineLayer::getSourceLayer() const { + return impl->sourceLayer; +} + +// Layout properties + +Function LineLayer::getLineCap() const { + return *impl->layout.lineCap.parsedValue; +} + +void LineLayer::setLineCap(Function value) { + impl->layout.lineCap.parsedValue = value; +} +Function LineLayer::getLineJoin() const { + return *impl->layout.lineJoin.parsedValue; +} + +void LineLayer::setLineJoin(Function value) { + impl->layout.lineJoin.parsedValue = value; +} +Function LineLayer::getLineMiterLimit() const { + return *impl->layout.lineMiterLimit.parsedValue; } -void LineLayer::cascade(const StyleCascadeParameters& parameters) { - paint.lineOpacity.cascade(parameters); - paint.lineColor.cascade(parameters); - paint.lineTranslate.cascade(parameters); - paint.lineTranslateAnchor.cascade(parameters); - paint.lineWidth.cascade(parameters); - paint.lineGapWidth.cascade(parameters); - paint.lineOffset.cascade(parameters); - paint.lineBlur.cascade(parameters); - paint.lineDasharray.cascade(parameters); - paint.linePattern.cascade(parameters); +void LineLayer::setLineMiterLimit(Function value) { + impl->layout.lineMiterLimit.parsedValue = value; +} +Function LineLayer::getLineRoundLimit() const { + return *impl->layout.lineRoundLimit.parsedValue; } -bool LineLayer::recalculate(const StyleCalculationParameters& parameters) { - // for scaling dasharrays - StyleCalculationParameters dashArrayParams = parameters; - dashArrayParams.z = std::floor(dashArrayParams.z); - paint.lineWidth.calculate(dashArrayParams); - dashLineWidth = paint.lineWidth; +void LineLayer::setLineRoundLimit(Function value) { + impl->layout.lineRoundLimit.parsedValue = value; +} - bool hasTransitions = false; +// Paint properties - hasTransitions |= paint.lineOpacity.calculate(parameters); - hasTransitions |= paint.lineColor.calculate(parameters); - hasTransitions |= paint.lineTranslate.calculate(parameters); - hasTransitions |= paint.lineTranslateAnchor.calculate(parameters); - hasTransitions |= paint.lineWidth.calculate(parameters); - hasTransitions |= paint.lineGapWidth.calculate(parameters); - hasTransitions |= paint.lineOffset.calculate(parameters); - hasTransitions |= paint.lineBlur.calculate(parameters); - hasTransitions |= paint.lineDasharray.calculate(parameters); - hasTransitions |= paint.linePattern.calculate(parameters); +Function LineLayer::getLineOpacity() const { + return impl->paint.lineOpacity.values.at(ClassID::Default); +} - passes = (paint.lineOpacity > 0 && paint.lineColor.value[3] > 0 && paint.lineWidth > 0) - ? RenderPass::Translucent : RenderPass::None; +void LineLayer::setLineOpacity(Function value) { + impl->paint.lineOpacity.values.emplace(ClassID::Default, value); +} - return hasTransitions; +Function LineLayer::getLineColor() const { + return impl->paint.lineColor.values.at(ClassID::Default); } -std::unique_ptr LineLayer::createBucket(StyleBucketParameters& parameters) const { - auto bucket = std::make_unique(parameters.tileID.overscaleFactor()); +void LineLayer::setLineColor(Function value) { + impl->paint.lineColor.values.emplace(ClassID::Default, value); +} - bucket->layout = layout; +Function> LineLayer::getLineTranslate() const { + return impl->paint.lineTranslate.values.at(ClassID::Default); +} - StyleCalculationParameters p(parameters.tileID.overscaledZ); - bucket->layout.lineCap.calculate(p); - bucket->layout.lineJoin.calculate(p); - bucket->layout.lineMiterLimit.calculate(p); - bucket->layout.lineRoundLimit.calculate(p); +void LineLayer::setLineTranslate(Function> value) { + impl->paint.lineTranslate.values.emplace(ClassID::Default, value); +} - auto& name = bucketName(); - parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { - auto geometries = feature.getGeometries(); - bucket->addGeometry(geometries); - parameters.featureIndex.insert(geometries, index, layerName, name); - }); +Function LineLayer::getLineTranslateAnchor() const { + return impl->paint.lineTranslateAnchor.values.at(ClassID::Default); +} - return std::move(bucket); +void LineLayer::setLineTranslateAnchor(Function value) { + impl->paint.lineTranslateAnchor.values.emplace(ClassID::Default, value); } +Function LineLayer::getLineWidth() const { + return impl->paint.lineWidth.values.at(ClassID::Default); +} -float LineLayer::getLineWidth() const { - if (paint.lineGapWidth > 0) { - return paint.lineGapWidth + 2 * paint.lineWidth; - } else { - return paint.lineWidth; - } +void LineLayer::setLineWidth(Function value) { + impl->paint.lineWidth.values.emplace(ClassID::Default, value); } -optional offsetLine(const GeometryCollection& rings, const double offset) { - if (offset == 0) return {}; +Function LineLayer::getLineGapWidth() const { + return impl->paint.lineGapWidth.values.at(ClassID::Default); +} - GeometryCollection newRings; - Point zero(0, 0); - for (const auto& ring : rings) { - newRings.emplace_back(); - auto& newRing = newRings.back(); +void LineLayer::setLineGapWidth(Function value) { + impl->paint.lineGapWidth.values.emplace(ClassID::Default, value); +} - for (auto i = ring.begin(); i != ring.end(); i++) { - auto& p = *i; - - Point aToB = i == ring.begin() ? - zero : - util::perp(util::unit(convertPoint(p - *(i - 1)))); - Point bToC = i + 1 == ring.end() ? - zero : - util::perp(util::unit(convertPoint(*(i + 1) - p))); - Point extrude = util::unit(aToB + bToC); - - const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y; - extrude *= (1.0 / cosHalfAngle); +Function LineLayer::getLineOffset() const { + return impl->paint.lineOffset.values.at(ClassID::Default); +} - newRing.push_back(convertPoint(extrude * offset) + p); - } - } +void LineLayer::setLineOffset(Function value) { + impl->paint.lineOffset.values.emplace(ClassID::Default, value); +} - return newRings; +Function LineLayer::getLineBlur() const { + return impl->paint.lineBlur.values.at(ClassID::Default); } -float LineLayer::getQueryRadius() const { - const std::array& translate = paint.lineTranslate; - return getLineWidth() / 2.0 + std::abs(paint.lineOffset) + util::length(translate[0], translate[1]); +void LineLayer::setLineBlur(Function value) { + impl->paint.lineBlur.values.emplace(ClassID::Default, value); } -bool LineLayer::queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const { +Function> LineLayer::getLineDasharray() const { + return impl->paint.lineDasharray.values.at(ClassID::Default); +} - const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits; +void LineLayer::setLineDasharray(Function> value) { + impl->paint.lineDasharray.values.emplace(ClassID::Default, value); +} - auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( - queryGeometry, paint.lineTranslate, paint.lineTranslateAnchor, bearing, pixelsToTileUnits); - auto offsetGeometry = offsetLine(geometry, paint.lineOffset * pixelsToTileUnits); +Function LineLayer::getLinePattern() const { + return impl->paint.linePattern.values.at(ClassID::Default); +} - return util::multiPolygonIntersectsBufferedMultiLine( - translatedQueryGeometry.value_or(queryGeometry), - offsetGeometry.value_or(geometry), - halfWidth); +void LineLayer::setLinePattern(Function value) { + impl->paint.linePattern.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/line_layer.hpp b/src/mbgl/layer/line_layer.hpp deleted file mode 100644 index 60bd9fad551..00000000000 --- a/src/mbgl/layer/line_layer.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { - -class LineLayoutProperties { -public: - LayoutProperty lineCap { LineCapType::Butt }; - LayoutProperty lineJoin { LineJoinType::Miter }; - LayoutProperty lineMiterLimit { 2.0f }; - LayoutProperty lineRoundLimit { 1.0f }; -}; - -class LinePaintProperties { -public: - PaintProperty lineOpacity { 1.0f }; - PaintProperty lineColor { {{ 0, 0, 0, 1 }} }; - PaintProperty> lineTranslate { {{ 0, 0 }} }; - PaintProperty lineTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty lineWidth { 1 }; - PaintProperty lineGapWidth { 0 }; - PaintProperty lineBlur { 0 }; - PaintProperty lineOffset { 0 }; - PaintProperty, CrossFadedFunctionEvaluator> lineDasharray { {} }; - PaintProperty linePattern { "" }; -}; - -class LineLayer : public StyleLayer { -public: - LineLayer() : StyleLayer(Type::Line) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - float getQueryRadius() const override; - bool queryIntersectsGeometry( - const GeometryCollection& queryGeometry, - const GeometryCollection& geometry, - const float bearing, - const float pixelsToTileUnits) const override; - - LineLayoutProperties layout; - LinePaintProperties paint; - - float dashLineWidth = 1; -private: - float getLineWidth() const; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Line; -} - -} // namespace mbgl diff --git a/src/mbgl/layer/line_layer_impl.cpp b/src/mbgl/layer/line_layer_impl.cpp new file mode 100644 index 00000000000..aee1687046a --- /dev/null +++ b/src/mbgl/layer/line_layer_impl.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include +#include + +namespace mbgl { + +void LineLayer::Impl::parseLayout(const JSValue& value) { + layout.parse(value); +} + +void LineLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void LineLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool LineLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + // for scaling dasharrays + StyleCalculationParameters dashArrayParams = parameters; + dashArrayParams.z = std::floor(dashArrayParams.z); + paint.lineWidth.calculate(dashArrayParams); + dashLineWidth = paint.lineWidth; + + bool hasTransitions = paint.recalculate(parameters); + + passes = (paint.lineOpacity > 0 && paint.lineColor.value[3] > 0 && paint.lineWidth > 0) + ? RenderPass::Translucent : RenderPass::None; + + return hasTransitions; +} + +std::unique_ptr LineLayer::Impl::createBucket(StyleBucketParameters& parameters) const { + auto bucket = std::make_unique(parameters.tileID.overscaleFactor()); + + bucket->layout = layout; + bucket->layout.recalculate(StyleCalculationParameters(parameters.tileID.overscaledZ)); + + auto& name = bucketName(); + parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { + auto geometries = feature.getGeometries(); + bucket->addGeometry(geometries); + parameters.featureIndex.insert(geometries, index, layerName, name); + }); + + return std::move(bucket); +} + +float LineLayer::Impl::getLineWidth() const { + if (paint.lineGapWidth > 0) { + return paint.lineGapWidth + 2 * paint.lineWidth; + } else { + return paint.lineWidth; + } +} + +optional offsetLine(const GeometryCollection& rings, const double offset) { + if (offset == 0) return {}; + + GeometryCollection newRings; + Point zero(0, 0); + for (const auto& ring : rings) { + newRings.emplace_back(); + auto& newRing = newRings.back(); + + for (auto i = ring.begin(); i != ring.end(); i++) { + auto& p = *i; + + Point aToB = i == ring.begin() ? + zero : + util::perp(util::unit(convertPoint(p - *(i - 1)))); + Point bToC = i + 1 == ring.end() ? + zero : + util::perp(util::unit(convertPoint(*(i + 1) - p))); + Point extrude = util::unit(aToB + bToC); + + const double cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y; + extrude *= (1.0 / cosHalfAngle); + + newRing.push_back(convertPoint(extrude * offset) + p); + } + } + + return newRings; +} + +float LineLayer::Impl::getQueryRadius() const { + const std::array& translate = paint.lineTranslate; + return getLineWidth() / 2.0 + std::abs(paint.lineOffset) + util::length(translate[0], translate[1]); +} + +bool LineLayer::Impl::queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const { + + const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits; + + auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry( + queryGeometry, paint.lineTranslate, paint.lineTranslateAnchor, bearing, pixelsToTileUnits); + auto offsetGeometry = offsetLine(geometry, paint.lineOffset * pixelsToTileUnits); + + return util::multiPolygonIntersectsBufferedMultiLine( + translatedQueryGeometry.value_or(queryGeometry), + offsetGeometry.value_or(geometry), + halfWidth); +} + +} // namespace mbgl diff --git a/src/mbgl/layer/line_layer_impl.hpp b/src/mbgl/layer/line_layer_impl.hpp new file mode 100644 index 00000000000..b602df52fa1 --- /dev/null +++ b/src/mbgl/layer/line_layer_impl.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { + +class LineLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + float getQueryRadius() const override; + bool queryIntersectsGeometry( + const GeometryCollection& queryGeometry, + const GeometryCollection& geometry, + const float bearing, + const float pixelsToTileUnits) const override; + + LineLayoutProperties layout; + LinePaintProperties paint; + + // Special case + float dashLineWidth = 1; + +private: + float getLineWidth() const; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.cpp b/src/mbgl/layer/line_layer_properties.cpp new file mode 100644 index 00000000000..4941a1ecd2a --- /dev/null +++ b/src/mbgl/layer/line_layer_properties.cpp @@ -0,0 +1,64 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void LineLayoutProperties::parse(const JSValue& value) { + lineCap.parse("line-cap", value); + lineJoin.parse("line-join", value); + lineMiterLimit.parse("line-miter-limit", value); + lineRoundLimit.parse("line-round-limit", value); +} + +void LineLayoutProperties::recalculate(const StyleCalculationParameters& parameters) { + lineCap.calculate(parameters); + lineJoin.calculate(parameters); + lineMiterLimit.calculate(parameters); + lineRoundLimit.calculate(parameters); +} + +void LinePaintProperties::parse(const JSValue& value) { + lineOpacity.parse("line-opacity", value); + lineColor.parse("line-color", value); + lineTranslate.parse("line-translate", value); + lineTranslateAnchor.parse("line-translate-anchor", value); + lineWidth.parse("line-width", value); + lineGapWidth.parse("line-gap-width", value); + lineOffset.parse("line-offset", value); + lineBlur.parse("line-blur", value); + lineDasharray.parse("line-dasharray", value); + linePattern.parse("line-pattern", value); +} + +void LinePaintProperties::cascade(const StyleCascadeParameters& parameters) { + lineOpacity.cascade(parameters); + lineColor.cascade(parameters); + lineTranslate.cascade(parameters); + lineTranslateAnchor.cascade(parameters); + lineWidth.cascade(parameters); + lineGapWidth.cascade(parameters); + lineOffset.cascade(parameters); + lineBlur.cascade(parameters); + lineDasharray.cascade(parameters); + linePattern.cascade(parameters); +} + +bool LinePaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= lineOpacity.calculate(parameters); + hasTransitions |= lineColor.calculate(parameters); + hasTransitions |= lineTranslate.calculate(parameters); + hasTransitions |= lineTranslateAnchor.calculate(parameters); + hasTransitions |= lineWidth.calculate(parameters); + hasTransitions |= lineGapWidth.calculate(parameters); + hasTransitions |= lineOffset.calculate(parameters); + hasTransitions |= lineBlur.calculate(parameters); + hasTransitions |= lineDasharray.calculate(parameters); + hasTransitions |= linePattern.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.hpp b/src/mbgl/layer/line_layer_properties.hpp new file mode 100644 index 00000000000..ae87d6da5e6 --- /dev/null +++ b/src/mbgl/layer/line_layer_properties.hpp @@ -0,0 +1,43 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +class LineLayoutProperties { +public: + void parse(const JSValue&); + void recalculate(const StyleCalculationParameters&); + + LayoutProperty lineCap { LineCapType::Butt }; + LayoutProperty lineJoin { LineJoinType::Miter }; + LayoutProperty lineMiterLimit { 2 }; + LayoutProperty lineRoundLimit { 1.05 }; +}; + +class LinePaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty lineOpacity { 1 }; + PaintProperty lineColor { {{ 0, 0, 0, 1 }} }; + PaintProperty> lineTranslate { {{ 0, 0 }} }; + PaintProperty lineTranslateAnchor { TranslateAnchorType::Map }; + PaintProperty lineWidth { 1 }; + PaintProperty lineGapWidth { 0 }; + PaintProperty lineOffset { 0 }; + PaintProperty lineBlur { 0 }; + PaintProperty, CrossFadedFunctionEvaluator> lineDasharray { { } }; + PaintProperty linePattern { "" }; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp index fa416090394..1ec2e4c0d42 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/layer/raster_layer.cpp @@ -1,50 +1,96 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include +#include namespace mbgl { -std::unique_ptr RasterLayer::clone() const { +RasterLayer::RasterLayer(const std::string& layerID) + : Layer(Type::Raster, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +RasterLayer::RasterLayer(const Impl& other) + : Layer(Type::Raster, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +RasterLayer::~RasterLayer() = default; + +std::unique_ptr RasterLayer::Impl::clone() const { return std::make_unique(*this); } -void RasterLayer::parsePaints(const JSValue& layer) { - paint.rasterOpacity.parse("raster-opacity", layer); - paint.rasterHueRotate.parse("raster-hue-rotate", layer); - paint.rasterBrightnessMin.parse("raster-brightness-min", layer); - paint.rasterBrightnessMax.parse("raster-brightness-max", layer); - paint.rasterSaturation.parse("raster-saturation", layer); - paint.rasterContrast.parse("raster-contrast", layer); - paint.rasterFadeDuration.parse("raster-fade-duration", layer); +// Source + +void RasterLayer::setSource(const std::string& sourceID) { + impl->source = sourceID; +} + +const std::string& RasterLayer::getSourceID() const { + return impl->source; +} + +// Layout properties + + +// Paint properties + +Function RasterLayer::getRasterOpacity() const { + return impl->paint.rasterOpacity.values.at(ClassID::Default); } -void RasterLayer::cascade(const StyleCascadeParameters& parameters) { - paint.rasterOpacity.cascade(parameters); - paint.rasterHueRotate.cascade(parameters); - paint.rasterBrightnessMin.cascade(parameters); - paint.rasterBrightnessMax.cascade(parameters); - paint.rasterSaturation.cascade(parameters); - paint.rasterContrast.cascade(parameters); - paint.rasterFadeDuration.cascade(parameters); +void RasterLayer::setRasterOpacity(Function value) { + impl->paint.rasterOpacity.values.emplace(ClassID::Default, value); } -bool RasterLayer::recalculate(const StyleCalculationParameters& parameters) { - bool hasTransitions = false; +Function RasterLayer::getRasterHueRotate() const { + return impl->paint.rasterHueRotate.values.at(ClassID::Default); +} - hasTransitions |= paint.rasterOpacity.calculate(parameters); - hasTransitions |= paint.rasterHueRotate.calculate(parameters); - hasTransitions |= paint.rasterBrightnessMin.calculate(parameters); - hasTransitions |= paint.rasterBrightnessMax.calculate(parameters); - hasTransitions |= paint.rasterSaturation.calculate(parameters); - hasTransitions |= paint.rasterContrast.calculate(parameters); - hasTransitions |= paint.rasterFadeDuration.calculate(parameters); +void RasterLayer::setRasterHueRotate(Function value) { + impl->paint.rasterHueRotate.values.emplace(ClassID::Default, value); +} - passes = paint.rasterOpacity > 0 ? RenderPass::Translucent : RenderPass::None; +Function RasterLayer::getRasterBrightnessMin() const { + return impl->paint.rasterBrightnessMin.values.at(ClassID::Default); +} + +void RasterLayer::setRasterBrightnessMin(Function value) { + impl->paint.rasterBrightnessMin.values.emplace(ClassID::Default, value); +} + +Function RasterLayer::getRasterBrightnessMax() const { + return impl->paint.rasterBrightnessMax.values.at(ClassID::Default); +} + +void RasterLayer::setRasterBrightnessMax(Function value) { + impl->paint.rasterBrightnessMax.values.emplace(ClassID::Default, value); +} + +Function RasterLayer::getRasterSaturation() const { + return impl->paint.rasterSaturation.values.at(ClassID::Default); +} + +void RasterLayer::setRasterSaturation(Function value) { + impl->paint.rasterSaturation.values.emplace(ClassID::Default, value); +} + +Function RasterLayer::getRasterContrast() const { + return impl->paint.rasterContrast.values.at(ClassID::Default); +} + +void RasterLayer::setRasterContrast(Function value) { + impl->paint.rasterContrast.values.emplace(ClassID::Default, value); +} - return hasTransitions; +Function RasterLayer::getRasterFadeDuration() const { + return impl->paint.rasterFadeDuration.values.at(ClassID::Default); } -std::unique_ptr RasterLayer::createBucket(StyleBucketParameters&) const { - return nullptr; +void RasterLayer::setRasterFadeDuration(Function value) { + impl->paint.rasterFadeDuration.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer.hpp b/src/mbgl/layer/raster_layer.hpp deleted file mode 100644 index d473505d568..00000000000 --- a/src/mbgl/layer/raster_layer.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class RasterPaintProperties { -public: - PaintProperty rasterOpacity { 1.0f }; - PaintProperty rasterHueRotate { 0.0f }; - PaintProperty rasterBrightnessMin { 0.0f }; - PaintProperty rasterBrightnessMax { 1.0f }; - PaintProperty rasterSaturation { 0.0f }; - PaintProperty rasterContrast { 0.0f }; - PaintProperty rasterFadeDuration { 0.0f }; -}; - -class RasterLayer : public StyleLayer { -public: - RasterLayer() : StyleLayer(Type::Raster) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - RasterPaintProperties paint; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Raster; -} - -} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_impl.cpp b/src/mbgl/layer/raster_layer_impl.cpp new file mode 100644 index 00000000000..f44a424f995 --- /dev/null +++ b/src/mbgl/layer/raster_layer_impl.cpp @@ -0,0 +1,26 @@ +#include +#include + +namespace mbgl { + +void RasterLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void RasterLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool RasterLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = paint.recalculate(parameters); + + passes = paint.rasterOpacity > 0 ? RenderPass::Translucent : RenderPass::None; + + return hasTransitions; +} + +std::unique_ptr RasterLayer::Impl::createBucket(StyleBucketParameters&) const { + return nullptr; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_impl.hpp b/src/mbgl/layer/raster_layer_impl.hpp new file mode 100644 index 00000000000..a83c7f259e4 --- /dev/null +++ b/src/mbgl/layer/raster_layer_impl.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { + +class RasterLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + RasterPaintProperties paint; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_properties.cpp b/src/mbgl/layer/raster_layer_properties.cpp new file mode 100644 index 00000000000..898188bc839 --- /dev/null +++ b/src/mbgl/layer/raster_layer_properties.cpp @@ -0,0 +1,41 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void RasterPaintProperties::parse(const JSValue& value) { + rasterOpacity.parse("raster-opacity", value); + rasterHueRotate.parse("raster-hue-rotate", value); + rasterBrightnessMin.parse("raster-brightness-min", value); + rasterBrightnessMax.parse("raster-brightness-max", value); + rasterSaturation.parse("raster-saturation", value); + rasterContrast.parse("raster-contrast", value); + rasterFadeDuration.parse("raster-fade-duration", value); +} + +void RasterPaintProperties::cascade(const StyleCascadeParameters& parameters) { + rasterOpacity.cascade(parameters); + rasterHueRotate.cascade(parameters); + rasterBrightnessMin.cascade(parameters); + rasterBrightnessMax.cascade(parameters); + rasterSaturation.cascade(parameters); + rasterContrast.cascade(parameters); + rasterFadeDuration.cascade(parameters); +} + +bool RasterPaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= rasterOpacity.calculate(parameters); + hasTransitions |= rasterHueRotate.calculate(parameters); + hasTransitions |= rasterBrightnessMin.calculate(parameters); + hasTransitions |= rasterBrightnessMax.calculate(parameters); + hasTransitions |= rasterSaturation.calculate(parameters); + hasTransitions |= rasterContrast.calculate(parameters); + hasTransitions |= rasterFadeDuration.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_properties.hpp b/src/mbgl/layer/raster_layer_properties.hpp new file mode 100644 index 00000000000..46bd00ff2e8 --- /dev/null +++ b/src/mbgl/layer/raster_layer_properties.hpp @@ -0,0 +1,29 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#pragma once + +#include +#include +#include + +namespace mbgl { + +class StyleCascadeParameters; +class StyleCalculationParameters; + +class RasterPaintProperties { +public: + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty rasterOpacity { 1 }; + PaintProperty rasterHueRotate { 0 }; + PaintProperty rasterBrightnessMin { 0 }; + PaintProperty rasterBrightnessMax { 1 }; + PaintProperty rasterSaturation { 0 }; + PaintProperty rasterContrast { 0 }; + PaintProperty rasterFadeDuration { 300 }; +}; + +} // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index b3222f93680..de2428fd250 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -1,188 +1,374 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #include -#include -#include +#include namespace mbgl { -std::unique_ptr SymbolLayer::clone() const { +SymbolLayer::SymbolLayer(const std::string& layerID) + : Layer(Type::Symbol, std::make_unique()) + , impl(static_cast(baseImpl.get())) { + impl->id = layerID; +} + +SymbolLayer::SymbolLayer(const Impl& other) + : Layer(Type::Symbol, std::make_unique(other)) + , impl(static_cast(baseImpl.get())) { +} + +SymbolLayer::~SymbolLayer() = default; + +std::unique_ptr SymbolLayer::Impl::clone() const { return std::make_unique(*this); } -void SymbolLayer::parseLayout(const JSValue& value) { - layout.symbolPlacement.parse("symbol-placement", value); - layout.symbolSpacing.parse("symbol-spacing", value); - layout.symbolAvoidEdges.parse("symbol-avoid-edges", value); - - layout.iconAllowOverlap.parse("icon-allow-overlap", value); - layout.iconIgnorePlacement.parse("icon-ignore-placement", value); - layout.iconOptional.parse("icon-optional", value); - layout.iconRotationAlignment.parse("icon-rotation-alignment", value); - layout.iconSize.parse("icon-size", value); - layout.iconImage.parse("icon-image", value); - layout.iconRotate.parse("icon-rotate", value); - layout.iconPadding.parse("icon-padding", value); - layout.iconKeepUpright.parse("icon-keep-upright", value); - layout.iconOffset.parse("icon-offset", value); - - layout.textRotationAlignment.parse("text-rotation-alignment", value); - layout.textField.parse("text-field", value); - layout.textFont.parse("text-font", value); - layout.textSize.parse("text-size", value); - layout.textMaxWidth.parse("text-max-width", value); - layout.textLineHeight.parse("text-line-height", value); - layout.textLetterSpacing.parse("text-letter-spacing", value); - layout.textJustify.parse("text-justify", value); - layout.textAnchor.parse("text-anchor", value); - layout.textMaxAngle.parse("text-max-angle", value); - layout.textRotate.parse("text-rotate", value); - layout.textPadding.parse("text-padding", value); - layout.textKeepUpright.parse("text-keep-upright", value); - layout.textTransform.parse("text-transform", value); - layout.textOffset.parse("text-offset", value); - layout.textAllowOverlap.parse("text-allow-overlap", value); - layout.textIgnorePlacement.parse("text-ignore-placement", value); - layout.textOptional.parse("text-optional", value); -} - -void SymbolLayer::parsePaints(const JSValue& layer) { - paint.iconOpacity.parse("icon-opacity", layer); - paint.iconColor.parse("icon-color", layer); - paint.iconHaloColor.parse("icon-halo-color", layer); - paint.iconHaloWidth.parse("icon-halo-width", layer); - paint.iconHaloBlur.parse("icon-halo-blur", layer); - paint.iconTranslate.parse("icon-translate", layer); - paint.iconTranslateAnchor.parse("icon-translate-anchor", layer); - - paint.textOpacity.parse("text-opacity", layer); - paint.textColor.parse("text-color", layer); - paint.textHaloColor.parse("text-halo-color", layer); - paint.textHaloWidth.parse("text-halo-width", layer); - paint.textHaloBlur.parse("text-halo-blur", layer); - paint.textTranslate.parse("text-translate", layer); - paint.textTranslateAnchor.parse("text-translate-anchor", layer); -} - -void SymbolLayer::cascade(const StyleCascadeParameters& parameters) { - paint.iconOpacity.cascade(parameters); - paint.iconColor.cascade(parameters); - paint.iconHaloColor.cascade(parameters); - paint.iconHaloWidth.cascade(parameters); - paint.iconHaloBlur.cascade(parameters); - paint.iconTranslate.cascade(parameters); - paint.iconTranslateAnchor.cascade(parameters); - - paint.textOpacity.cascade(parameters); - paint.textColor.cascade(parameters); - paint.textHaloColor.cascade(parameters); - paint.textHaloWidth.cascade(parameters); - paint.textHaloBlur.cascade(parameters); - paint.textTranslate.cascade(parameters); - paint.textTranslateAnchor.cascade(parameters); -} - -bool SymbolLayer::recalculate(const StyleCalculationParameters& parameters) { - bool hasTransitions = false; - - hasTransitions |= paint.iconOpacity.calculate(parameters); - hasTransitions |= paint.iconColor.calculate(parameters); - hasTransitions |= paint.iconHaloColor.calculate(parameters); - hasTransitions |= paint.iconHaloWidth.calculate(parameters); - hasTransitions |= paint.iconHaloBlur.calculate(parameters); - hasTransitions |= paint.iconTranslate.calculate(parameters); - hasTransitions |= paint.iconTranslateAnchor.calculate(parameters); - - hasTransitions |= paint.textOpacity.calculate(parameters); - hasTransitions |= paint.textColor.calculate(parameters); - hasTransitions |= paint.textHaloColor.calculate(parameters); - hasTransitions |= paint.textHaloWidth.calculate(parameters); - hasTransitions |= paint.textHaloBlur.calculate(parameters); - hasTransitions |= paint.textTranslate.calculate(parameters); - hasTransitions |= paint.textTranslateAnchor.calculate(parameters); - - // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: - layout.iconSize.calculate(parameters); - layout.textSize.calculate(parameters); - iconSize = layout.iconSize; - textSize = layout.textSize; - - passes = ((paint.iconOpacity > 0 && (paint.iconColor.value[3] > 0 || paint.iconHaloColor.value[3] > 0) && iconSize > 0) - || (paint.textOpacity > 0 && (paint.textColor.value[3] > 0 || paint.textHaloColor.value[3] > 0) && textSize > 0)) - ? RenderPass::Translucent : RenderPass::None; - - return hasTransitions; -} - -std::unique_ptr SymbolLayer::createBucket(StyleBucketParameters& parameters) const { - auto bucket = std::make_unique(parameters.tileID.overscaleFactor(), - parameters.tileID.overscaledZ, - parameters.mode, - id, - parameters.layer.getName()); - - bucket->layout = layout; - - StyleCalculationParameters p(parameters.tileID.overscaledZ); - bucket->layout.symbolPlacement.calculate(p); - if (bucket->layout.symbolPlacement.value == SymbolPlacementType::Line) { - bucket->layout.iconRotationAlignment.value = RotationAlignmentType::Map; - bucket->layout.textRotationAlignment.value = RotationAlignmentType::Map; - }; - bucket->layout.symbolSpacing.calculate(p); - bucket->layout.symbolAvoidEdges.calculate(p); - - bucket->layout.iconAllowOverlap.calculate(p); - bucket->layout.iconIgnorePlacement.calculate(p); - bucket->layout.iconOptional.calculate(p); - bucket->layout.iconRotationAlignment.calculate(p); - bucket->layout.iconImage.calculate(p); - bucket->layout.iconPadding.calculate(p); - bucket->layout.iconRotate.calculate(p); - bucket->layout.iconKeepUpright.calculate(p); - bucket->layout.iconOffset.calculate(p); - - bucket->layout.textRotationAlignment.calculate(p); - bucket->layout.textField.calculate(p); - bucket->layout.textFont.calculate(p); - bucket->layout.textMaxWidth.calculate(p); - bucket->layout.textLineHeight.calculate(p); - bucket->layout.textLetterSpacing.calculate(p); - bucket->layout.textMaxAngle.calculate(p); - bucket->layout.textRotate.calculate(p); - bucket->layout.textPadding.calculate(p); - bucket->layout.textIgnorePlacement.calculate(p); - bucket->layout.textOptional.calculate(p); - bucket->layout.textJustify.calculate(p); - bucket->layout.textAnchor.calculate(p); - bucket->layout.textKeepUpright.calculate(p); - bucket->layout.textTransform.calculate(p); - bucket->layout.textOffset.calculate(p); - bucket->layout.textAllowOverlap.calculate(p); - - bucket->layout.iconSize.calculate(StyleCalculationParameters(18)); - bucket->layout.textSize.calculate(StyleCalculationParameters(18)); - bucket->iconMaxSize = bucket->layout.iconSize; - bucket->textMaxSize = bucket->layout.textSize; - bucket->layout.iconSize.calculate(StyleCalculationParameters(p.z + 1)); - bucket->layout.textSize.calculate(StyleCalculationParameters(p.z + 1)); - - bucket->parseFeatures(parameters.layer, filter); - - if (bucket->needsDependencies(parameters.glyphStore, parameters.spriteStore)) { - parameters.partialParse = true; - } - - // We do not add features if the parser is in a "partial" state because - // the layer ordering needs to be respected when calculating text - // collisions. Although, at this point, we requested all the resources - // needed by this tile. - if (!parameters.partialParse) { - bucket->addFeatures(parameters.tileUID, - *spriteAtlas, - parameters.glyphAtlas, - parameters.glyphStore); - } - - return std::move(bucket); +// Source + +void SymbolLayer::setSource(const std::string& sourceID, const std::string& sourceLayer) { + impl->source = sourceID; + impl->sourceLayer = sourceLayer; +} + +const std::string& SymbolLayer::getSourceID() const { + return impl->source; +} + +const std::string& SymbolLayer::getSourceLayer() const { + return impl->sourceLayer; +} + +// Layout properties + +Function SymbolLayer::getSymbolPlacement() const { + return *impl->layout.symbolPlacement.parsedValue; +} + +void SymbolLayer::setSymbolPlacement(Function value) { + impl->layout.symbolPlacement.parsedValue = value; +} +Function SymbolLayer::getSymbolSpacing() const { + return *impl->layout.symbolSpacing.parsedValue; +} + +void SymbolLayer::setSymbolSpacing(Function value) { + impl->layout.symbolSpacing.parsedValue = value; +} +Function SymbolLayer::getSymbolAvoidEdges() const { + return *impl->layout.symbolAvoidEdges.parsedValue; +} + +void SymbolLayer::setSymbolAvoidEdges(Function value) { + impl->layout.symbolAvoidEdges.parsedValue = value; +} +Function SymbolLayer::getIconAllowOverlap() const { + return *impl->layout.iconAllowOverlap.parsedValue; +} + +void SymbolLayer::setIconAllowOverlap(Function value) { + impl->layout.iconAllowOverlap.parsedValue = value; +} +Function SymbolLayer::getIconIgnorePlacement() const { + return *impl->layout.iconIgnorePlacement.parsedValue; +} + +void SymbolLayer::setIconIgnorePlacement(Function value) { + impl->layout.iconIgnorePlacement.parsedValue = value; +} +Function SymbolLayer::getIconOptional() const { + return *impl->layout.iconOptional.parsedValue; +} + +void SymbolLayer::setIconOptional(Function value) { + impl->layout.iconOptional.parsedValue = value; +} +Function SymbolLayer::getIconRotationAlignment() const { + return *impl->layout.iconRotationAlignment.parsedValue; +} + +void SymbolLayer::setIconRotationAlignment(Function value) { + impl->layout.iconRotationAlignment.parsedValue = value; +} +Function SymbolLayer::getIconSize() const { + return *impl->layout.iconSize.parsedValue; +} + +void SymbolLayer::setIconSize(Function value) { + impl->layout.iconSize.parsedValue = value; +} +Function SymbolLayer::getIconImage() const { + return *impl->layout.iconImage.parsedValue; +} + +void SymbolLayer::setIconImage(Function value) { + impl->layout.iconImage.parsedValue = value; +} +Function SymbolLayer::getIconRotate() const { + return *impl->layout.iconRotate.parsedValue; +} + +void SymbolLayer::setIconRotate(Function value) { + impl->layout.iconRotate.parsedValue = value; +} +Function SymbolLayer::getIconPadding() const { + return *impl->layout.iconPadding.parsedValue; +} + +void SymbolLayer::setIconPadding(Function value) { + impl->layout.iconPadding.parsedValue = value; +} +Function SymbolLayer::getIconKeepUpright() const { + return *impl->layout.iconKeepUpright.parsedValue; +} + +void SymbolLayer::setIconKeepUpright(Function value) { + impl->layout.iconKeepUpright.parsedValue = value; +} +Function> SymbolLayer::getIconOffset() const { + return *impl->layout.iconOffset.parsedValue; +} + +void SymbolLayer::setIconOffset(Function> value) { + impl->layout.iconOffset.parsedValue = value; +} +Function SymbolLayer::getTextRotationAlignment() const { + return *impl->layout.textRotationAlignment.parsedValue; +} + +void SymbolLayer::setTextRotationAlignment(Function value) { + impl->layout.textRotationAlignment.parsedValue = value; +} +Function SymbolLayer::getTextField() const { + return *impl->layout.textField.parsedValue; +} + +void SymbolLayer::setTextField(Function value) { + impl->layout.textField.parsedValue = value; +} +Function> SymbolLayer::getTextFont() const { + return *impl->layout.textFont.parsedValue; +} + +void SymbolLayer::setTextFont(Function> value) { + impl->layout.textFont.parsedValue = value; +} +Function SymbolLayer::getTextSize() const { + return *impl->layout.textSize.parsedValue; +} + +void SymbolLayer::setTextSize(Function value) { + impl->layout.textSize.parsedValue = value; +} +Function SymbolLayer::getTextMaxWidth() const { + return *impl->layout.textMaxWidth.parsedValue; +} + +void SymbolLayer::setTextMaxWidth(Function value) { + impl->layout.textMaxWidth.parsedValue = value; +} +Function SymbolLayer::getTextLineHeight() const { + return *impl->layout.textLineHeight.parsedValue; +} + +void SymbolLayer::setTextLineHeight(Function value) { + impl->layout.textLineHeight.parsedValue = value; +} +Function SymbolLayer::getTextLetterSpacing() const { + return *impl->layout.textLetterSpacing.parsedValue; +} + +void SymbolLayer::setTextLetterSpacing(Function value) { + impl->layout.textLetterSpacing.parsedValue = value; +} +Function SymbolLayer::getTextJustify() const { + return *impl->layout.textJustify.parsedValue; +} + +void SymbolLayer::setTextJustify(Function value) { + impl->layout.textJustify.parsedValue = value; +} +Function SymbolLayer::getTextAnchor() const { + return *impl->layout.textAnchor.parsedValue; +} + +void SymbolLayer::setTextAnchor(Function value) { + impl->layout.textAnchor.parsedValue = value; +} +Function SymbolLayer::getTextMaxAngle() const { + return *impl->layout.textMaxAngle.parsedValue; +} + +void SymbolLayer::setTextMaxAngle(Function value) { + impl->layout.textMaxAngle.parsedValue = value; +} +Function SymbolLayer::getTextRotate() const { + return *impl->layout.textRotate.parsedValue; +} + +void SymbolLayer::setTextRotate(Function value) { + impl->layout.textRotate.parsedValue = value; +} +Function SymbolLayer::getTextPadding() const { + return *impl->layout.textPadding.parsedValue; +} + +void SymbolLayer::setTextPadding(Function value) { + impl->layout.textPadding.parsedValue = value; +} +Function SymbolLayer::getTextKeepUpright() const { + return *impl->layout.textKeepUpright.parsedValue; +} + +void SymbolLayer::setTextKeepUpright(Function value) { + impl->layout.textKeepUpright.parsedValue = value; +} +Function SymbolLayer::getTextTransform() const { + return *impl->layout.textTransform.parsedValue; +} + +void SymbolLayer::setTextTransform(Function value) { + impl->layout.textTransform.parsedValue = value; +} +Function> SymbolLayer::getTextOffset() const { + return *impl->layout.textOffset.parsedValue; +} + +void SymbolLayer::setTextOffset(Function> value) { + impl->layout.textOffset.parsedValue = value; +} +Function SymbolLayer::getTextAllowOverlap() const { + return *impl->layout.textAllowOverlap.parsedValue; +} + +void SymbolLayer::setTextAllowOverlap(Function value) { + impl->layout.textAllowOverlap.parsedValue = value; +} +Function SymbolLayer::getTextIgnorePlacement() const { + return *impl->layout.textIgnorePlacement.parsedValue; +} + +void SymbolLayer::setTextIgnorePlacement(Function value) { + impl->layout.textIgnorePlacement.parsedValue = value; +} +Function SymbolLayer::getTextOptional() const { + return *impl->layout.textOptional.parsedValue; +} + +void SymbolLayer::setTextOptional(Function value) { + impl->layout.textOptional.parsedValue = value; +} + +// Paint properties + +Function SymbolLayer::getIconOpacity() const { + return impl->paint.iconOpacity.values.at(ClassID::Default); +} + +void SymbolLayer::setIconOpacity(Function value) { + impl->paint.iconOpacity.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getIconColor() const { + return impl->paint.iconColor.values.at(ClassID::Default); +} + +void SymbolLayer::setIconColor(Function value) { + impl->paint.iconColor.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getIconHaloColor() const { + return impl->paint.iconHaloColor.values.at(ClassID::Default); +} + +void SymbolLayer::setIconHaloColor(Function value) { + impl->paint.iconHaloColor.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getIconHaloWidth() const { + return impl->paint.iconHaloWidth.values.at(ClassID::Default); +} + +void SymbolLayer::setIconHaloWidth(Function value) { + impl->paint.iconHaloWidth.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getIconHaloBlur() const { + return impl->paint.iconHaloBlur.values.at(ClassID::Default); +} + +void SymbolLayer::setIconHaloBlur(Function value) { + impl->paint.iconHaloBlur.values.emplace(ClassID::Default, value); +} + +Function> SymbolLayer::getIconTranslate() const { + return impl->paint.iconTranslate.values.at(ClassID::Default); +} + +void SymbolLayer::setIconTranslate(Function> value) { + impl->paint.iconTranslate.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getIconTranslateAnchor() const { + return impl->paint.iconTranslateAnchor.values.at(ClassID::Default); +} + +void SymbolLayer::setIconTranslateAnchor(Function value) { + impl->paint.iconTranslateAnchor.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextOpacity() const { + return impl->paint.textOpacity.values.at(ClassID::Default); +} + +void SymbolLayer::setTextOpacity(Function value) { + impl->paint.textOpacity.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextColor() const { + return impl->paint.textColor.values.at(ClassID::Default); +} + +void SymbolLayer::setTextColor(Function value) { + impl->paint.textColor.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextHaloColor() const { + return impl->paint.textHaloColor.values.at(ClassID::Default); +} + +void SymbolLayer::setTextHaloColor(Function value) { + impl->paint.textHaloColor.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextHaloWidth() const { + return impl->paint.textHaloWidth.values.at(ClassID::Default); +} + +void SymbolLayer::setTextHaloWidth(Function value) { + impl->paint.textHaloWidth.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextHaloBlur() const { + return impl->paint.textHaloBlur.values.at(ClassID::Default); +} + +void SymbolLayer::setTextHaloBlur(Function value) { + impl->paint.textHaloBlur.values.emplace(ClassID::Default, value); +} + +Function> SymbolLayer::getTextTranslate() const { + return impl->paint.textTranslate.values.at(ClassID::Default); +} + +void SymbolLayer::setTextTranslate(Function> value) { + impl->paint.textTranslate.values.emplace(ClassID::Default, value); +} + +Function SymbolLayer::getTextTranslateAnchor() const { + return impl->paint.textTranslateAnchor.values.at(ClassID::Default); +} + +void SymbolLayer::setTextTranslateAnchor(Function value) { + impl->paint.textTranslateAnchor.values.emplace(ClassID::Default, value); } } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer_impl.cpp b/src/mbgl/layer/symbol_layer_impl.cpp new file mode 100644 index 00000000000..3a0e0dceca9 --- /dev/null +++ b/src/mbgl/layer/symbol_layer_impl.cpp @@ -0,0 +1,80 @@ +#include +#include +#include + +namespace mbgl { + +void SymbolLayer::Impl::parseLayout(const JSValue& value) { + layout.parse(value); +} + +void SymbolLayer::Impl::parsePaints(const JSValue& layer) { + paint.parse(layer); +} + +void SymbolLayer::Impl::cascade(const StyleCascadeParameters& parameters) { + paint.cascade(parameters); +} + +bool SymbolLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = paint.recalculate(parameters); + + // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: + layout.iconSize.calculate(parameters); + layout.textSize.calculate(parameters); + iconSize = layout.iconSize; + textSize = layout.textSize; + + passes = ((paint.iconOpacity > 0 && (paint.iconColor.value[3] > 0 || paint.iconHaloColor.value[3] > 0) && iconSize > 0) + || (paint.textOpacity > 0 && (paint.textColor.value[3] > 0 || paint.textHaloColor.value[3] > 0) && textSize > 0)) + ? RenderPass::Translucent : RenderPass::None; + + return hasTransitions; +} + +std::unique_ptr SymbolLayer::Impl::createBucket(StyleBucketParameters& parameters) const { + auto bucket = std::make_unique(parameters.tileID.overscaleFactor(), + parameters.tileID.overscaledZ, + parameters.mode, + id, + parameters.layer.getName()); + + bucket->layout = layout; + + StyleCalculationParameters p(parameters.tileID.overscaledZ); + bucket->layout.symbolPlacement.calculate(p); + if (bucket->layout.symbolPlacement.value == SymbolPlacementType::Line) { + bucket->layout.iconRotationAlignment.value = RotationAlignmentType::Map; + bucket->layout.textRotationAlignment.value = RotationAlignmentType::Map; + }; + + bucket->layout.recalculate(p); + + bucket->layout.iconSize.calculate(StyleCalculationParameters(18)); + bucket->layout.textSize.calculate(StyleCalculationParameters(18)); + bucket->iconMaxSize = bucket->layout.iconSize; + bucket->textMaxSize = bucket->layout.textSize; + bucket->layout.iconSize.calculate(StyleCalculationParameters(p.z + 1)); + bucket->layout.textSize.calculate(StyleCalculationParameters(p.z + 1)); + + bucket->parseFeatures(parameters.layer, filter); + + if (bucket->needsDependencies(parameters.glyphStore, parameters.spriteStore)) { + parameters.partialParse = true; + } + + // We do not add features if the parser is in a "partial" state because + // the layer ordering needs to be respected when calculating text + // collisions. Although, at this point, we requested all the resources + // needed by this tile. + if (!parameters.partialParse) { + bucket->addFeatures(parameters.tileUID, + *spriteAtlas, + parameters.glyphAtlas, + parameters.glyphStore); + } + + return std::move(bucket); +} + +} // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer_impl.hpp b/src/mbgl/layer/symbol_layer_impl.hpp new file mode 100644 index 00000000000..46503ab916a --- /dev/null +++ b/src/mbgl/layer/symbol_layer_impl.hpp @@ -0,0 +1,35 @@ +#ifndef MBGL_SYMBOL_LAYER +#define MBGL_SYMBOL_LAYER + +#include +#include +#include + +namespace mbgl { + +class SpriteAtlas; + +class SymbolLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override; + void parsePaints(const JSValue&) override; + + void cascade(const StyleCascadeParameters&) override; + bool recalculate(const StyleCalculationParameters&) override; + + std::unique_ptr createBucket(StyleBucketParameters&) const override; + + SymbolLayoutProperties layout; + SymbolPaintProperties paint; + + float iconSize = 1.0f; + float textSize = 16.0f; + + SpriteAtlas* spriteAtlas = nullptr; +}; + +} // namespace mbgl + +#endif diff --git a/src/mbgl/layer/symbol_layer_properties.cpp b/src/mbgl/layer/symbol_layer_properties.cpp new file mode 100644 index 00000000000..4b9e9a5fb6b --- /dev/null +++ b/src/mbgl/layer/symbol_layer_properties.cpp @@ -0,0 +1,130 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + +#include + +namespace mbgl { + +void SymbolLayoutProperties::parse(const JSValue& value) { + symbolPlacement.parse("symbol-placement", value); + symbolSpacing.parse("symbol-spacing", value); + symbolAvoidEdges.parse("symbol-avoid-edges", value); + iconAllowOverlap.parse("icon-allow-overlap", value); + iconIgnorePlacement.parse("icon-ignore-placement", value); + iconOptional.parse("icon-optional", value); + iconRotationAlignment.parse("icon-rotation-alignment", value); + iconSize.parse("icon-size", value); + iconImage.parse("icon-image", value); + iconRotate.parse("icon-rotate", value); + iconPadding.parse("icon-padding", value); + iconKeepUpright.parse("icon-keep-upright", value); + iconOffset.parse("icon-offset", value); + textRotationAlignment.parse("text-rotation-alignment", value); + textField.parse("text-field", value); + textFont.parse("text-font", value); + textSize.parse("text-size", value); + textMaxWidth.parse("text-max-width", value); + textLineHeight.parse("text-line-height", value); + textLetterSpacing.parse("text-letter-spacing", value); + textJustify.parse("text-justify", value); + textAnchor.parse("text-anchor", value); + textMaxAngle.parse("text-max-angle", value); + textRotate.parse("text-rotate", value); + textPadding.parse("text-padding", value); + textKeepUpright.parse("text-keep-upright", value); + textTransform.parse("text-transform", value); + textOffset.parse("text-offset", value); + textAllowOverlap.parse("text-allow-overlap", value); + textIgnorePlacement.parse("text-ignore-placement", value); + textOptional.parse("text-optional", value); +} + +void SymbolLayoutProperties::recalculate(const StyleCalculationParameters& parameters) { + symbolPlacement.calculate(parameters); + symbolSpacing.calculate(parameters); + symbolAvoidEdges.calculate(parameters); + iconAllowOverlap.calculate(parameters); + iconIgnorePlacement.calculate(parameters); + iconOptional.calculate(parameters); + iconRotationAlignment.calculate(parameters); + iconSize.calculate(parameters); + iconImage.calculate(parameters); + iconRotate.calculate(parameters); + iconPadding.calculate(parameters); + iconKeepUpright.calculate(parameters); + iconOffset.calculate(parameters); + textRotationAlignment.calculate(parameters); + textField.calculate(parameters); + textFont.calculate(parameters); + textSize.calculate(parameters); + textMaxWidth.calculate(parameters); + textLineHeight.calculate(parameters); + textLetterSpacing.calculate(parameters); + textJustify.calculate(parameters); + textAnchor.calculate(parameters); + textMaxAngle.calculate(parameters); + textRotate.calculate(parameters); + textPadding.calculate(parameters); + textKeepUpright.calculate(parameters); + textTransform.calculate(parameters); + textOffset.calculate(parameters); + textAllowOverlap.calculate(parameters); + textIgnorePlacement.calculate(parameters); + textOptional.calculate(parameters); +} + +void SymbolPaintProperties::parse(const JSValue& value) { + iconOpacity.parse("icon-opacity", value); + iconColor.parse("icon-color", value); + iconHaloColor.parse("icon-halo-color", value); + iconHaloWidth.parse("icon-halo-width", value); + iconHaloBlur.parse("icon-halo-blur", value); + iconTranslate.parse("icon-translate", value); + iconTranslateAnchor.parse("icon-translate-anchor", value); + textOpacity.parse("text-opacity", value); + textColor.parse("text-color", value); + textHaloColor.parse("text-halo-color", value); + textHaloWidth.parse("text-halo-width", value); + textHaloBlur.parse("text-halo-blur", value); + textTranslate.parse("text-translate", value); + textTranslateAnchor.parse("text-translate-anchor", value); +} + +void SymbolPaintProperties::cascade(const StyleCascadeParameters& parameters) { + iconOpacity.cascade(parameters); + iconColor.cascade(parameters); + iconHaloColor.cascade(parameters); + iconHaloWidth.cascade(parameters); + iconHaloBlur.cascade(parameters); + iconTranslate.cascade(parameters); + iconTranslateAnchor.cascade(parameters); + textOpacity.cascade(parameters); + textColor.cascade(parameters); + textHaloColor.cascade(parameters); + textHaloWidth.cascade(parameters); + textHaloBlur.cascade(parameters); + textTranslate.cascade(parameters); + textTranslateAnchor.cascade(parameters); +} + +bool SymbolPaintProperties::recalculate(const StyleCalculationParameters& parameters) { + bool hasTransitions = false; + + hasTransitions |= iconOpacity.calculate(parameters); + hasTransitions |= iconColor.calculate(parameters); + hasTransitions |= iconHaloColor.calculate(parameters); + hasTransitions |= iconHaloWidth.calculate(parameters); + hasTransitions |= iconHaloBlur.calculate(parameters); + hasTransitions |= iconTranslate.calculate(parameters); + hasTransitions |= iconTranslateAnchor.calculate(parameters); + hasTransitions |= textOpacity.calculate(parameters); + hasTransitions |= textColor.calculate(parameters); + hasTransitions |= textHaloColor.calculate(parameters); + hasTransitions |= textHaloWidth.calculate(parameters); + hasTransitions |= textHaloBlur.calculate(parameters); + hasTransitions |= textTranslate.calculate(parameters); + hasTransitions |= textTranslateAnchor.calculate(parameters); + + return hasTransitions; +} + +} // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer.hpp b/src/mbgl/layer/symbol_layer_properties.hpp similarity index 56% rename from src/mbgl/layer/symbol_layer.hpp rename to src/mbgl/layer/symbol_layer_properties.hpp index 3119ee1f033..ccbecef00e5 100644 --- a/src/mbgl/layer/symbol_layer.hpp +++ b/src/mbgl/layer/symbol_layer_properties.hpp @@ -1,42 +1,46 @@ +// This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. + #pragma once -#include #include #include +#include namespace mbgl { -class SpriteAtlas; +class StyleCascadeParameters; +class StyleCalculationParameters; class SymbolLayoutProperties { public: + void parse(const JSValue&); + void recalculate(const StyleCalculationParameters&); + LayoutProperty symbolPlacement { SymbolPlacementType::Point }; - LayoutProperty symbolSpacing { 250.0f }; + LayoutProperty symbolSpacing { 250 }; LayoutProperty symbolAvoidEdges { false }; - LayoutProperty iconAllowOverlap { false }; LayoutProperty iconIgnorePlacement { false }; LayoutProperty iconOptional { false }; LayoutProperty iconRotationAlignment { RotationAlignmentType::Viewport }; - LayoutProperty iconSize { 1.0f }; + LayoutProperty iconSize { 1 }; LayoutProperty iconImage { "" }; - LayoutProperty iconRotate { 0.0f }; - LayoutProperty iconPadding { 2.0f }; + LayoutProperty iconRotate { 0 }; + LayoutProperty iconPadding { 2 }; LayoutProperty iconKeepUpright { false }; LayoutProperty> iconOffset { {{ 0, 0 }} }; - LayoutProperty textRotationAlignment { RotationAlignmentType::Viewport }; LayoutProperty textField { "" }; LayoutProperty> textFont { { "Open Sans Regular", "Arial Unicode MS Regular" } }; - LayoutProperty textSize { 16.0f }; - LayoutProperty textMaxWidth { 10.0f /* em */ }; - LayoutProperty textLineHeight { 1.2f /* em */ }; - LayoutProperty textLetterSpacing { 0.0f /* em */ }; + LayoutProperty textSize { 16 }; + LayoutProperty textMaxWidth { 10 }; + LayoutProperty textLineHeight { 1.2 }; + LayoutProperty textLetterSpacing { 0 }; LayoutProperty textJustify { TextJustifyType::Center }; LayoutProperty textAnchor { TextAnchorType::Center }; - LayoutProperty textMaxAngle { 45.0f /* degrees */ }; - LayoutProperty textRotate { 0.0f }; - LayoutProperty textPadding { 2.0f }; + LayoutProperty textMaxAngle { 45 }; + LayoutProperty textRotate { 0 }; + LayoutProperty textPadding { 2 }; LayoutProperty textKeepUpright { true }; LayoutProperty textTransform { TextTransformType::None }; LayoutProperty> textOffset { {{ 0, 0 }} }; @@ -47,48 +51,24 @@ class SymbolLayoutProperties { class SymbolPaintProperties { public: - PaintProperty iconOpacity { 1.0f }; + void parse(const JSValue&); + void cascade(const StyleCascadeParameters&); + bool recalculate(const StyleCalculationParameters&); + + PaintProperty iconOpacity { 1 }; PaintProperty iconColor { {{ 0, 0, 0, 1 }} }; PaintProperty iconHaloColor { {{ 0, 0, 0, 0 }} }; - PaintProperty iconHaloWidth { 0.0f }; - PaintProperty iconHaloBlur { 0.0f }; + PaintProperty iconHaloWidth { 0 }; + PaintProperty iconHaloBlur { 0 }; PaintProperty> iconTranslate { {{ 0, 0 }} }; PaintProperty iconTranslateAnchor { TranslateAnchorType::Map }; - - PaintProperty textOpacity { 1.0f }; + PaintProperty textOpacity { 1 }; PaintProperty textColor { {{ 0, 0, 0, 1 }} }; PaintProperty textHaloColor { {{ 0, 0, 0, 0 }} }; - PaintProperty textHaloWidth { 0.0f }; - PaintProperty textHaloBlur { 0.0f }; + PaintProperty textHaloWidth { 0 }; + PaintProperty textHaloBlur { 0 }; PaintProperty> textTranslate { {{ 0, 0 }} }; PaintProperty textTranslateAnchor { TranslateAnchorType::Map }; }; -class SymbolLayer : public StyleLayer { -public: - SymbolLayer() : StyleLayer(Type::Symbol) {} - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - SymbolLayoutProperties layout; - SymbolPaintProperties paint; - - float iconSize = 1.0f; - float textSize = 16.0f; - - SpriteAtlas* spriteAtlas = nullptr; -}; - -template <> -inline bool StyleLayer::is() const { - return type == Type::Symbol; -} - } // namespace mbgl diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index f89fde1f038..aee67775258 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index cffc0ba8dfe..89b0ceefb2e 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -13,7 +13,7 @@ namespace mbgl { class Painter; -class StyleLayer; +class Layer; class UnwrappedTileID; class CollisionTile; @@ -31,7 +31,7 @@ class Bucket : private util::noncopyable { // Every time this bucket is getting rendered, this function is called. This happens either // once or twice (for Opaque and Transparent render passes). - virtual void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) = 0; + virtual void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) = 0; virtual ~Bucket() = default; diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp index 6df186f2d0a..969e05131b4 100644 --- a/src/mbgl/renderer/circle_bucket.cpp +++ b/src/mbgl/renderer/circle_bucket.cpp @@ -21,7 +21,7 @@ void CircleBucket::upload(gl::ObjectStore& store) { } void CircleBucket::render(Painter& painter, - const StyleLayer& layer, + const Layer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { painter.renderCircle(*this, *layer.as(), tileID, matrix); diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index b0349c74269..9c95fce0453 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -19,7 +19,7 @@ class CircleBucket : public Bucket { ~CircleBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index 78d4c40a97f..4a9709f4e84 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -104,7 +104,7 @@ void FillBucket::upload(gl::ObjectStore& store) { } void FillBucket::render(Painter& painter, - const StyleLayer& layer, + const Layer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { painter.renderFill(*this, *layer.as(), tileID, matrix); diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index f1b137893c5..21e3239f294 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -21,7 +21,7 @@ class FillBucket : public Bucket { ~FillBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index c308f025882..8124a5daed2 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -444,7 +444,7 @@ void LineBucket::upload(gl::ObjectStore& store) { } void LineBucket::render(Painter& painter, - const StyleLayer& layer, + const Layer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { painter.renderLine(*this, *layer.as(), tileID, matrix); diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 8b60be5f001..1093ec2a48e 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include @@ -26,7 +26,7 @@ class LineBucket : public Bucket { ~LineBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index 486865dc784..ccc6e234084 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -7,11 +7,12 @@ #include #include -#include +#include #include #include #include +#include #include #include @@ -239,9 +240,9 @@ void Painter::renderPass(RenderPass pass_, currentLayer = i; const auto& item = *it; - const StyleLayer& layer = item.layer; + const Layer& layer = item.layer; - if (!layer.hasRenderPass(pass)) + if (!layer.baseImpl->hasRenderPass(pass)) continue; if (pass == RenderPass::Translucent) { @@ -258,12 +259,12 @@ void Painter::renderPass(RenderPass pass_, MBGL_DEBUG_GROUP("background"); renderBackground(*layer.as()); } else if (layer.is()) { - MBGL_DEBUG_GROUP(layer.id + " - custom"); + MBGL_DEBUG_GROUP(layer.baseImpl->id + " - custom"); VertexArrayObject::Unbind(); - layer.as()->render(state); + layer.as()->impl->render(state); config.setDirty(); } else { - MBGL_DEBUG_GROUP(layer.id + " - " + util::toString(item.tile->id)); + MBGL_DEBUG_GROUP(layer.baseImpl->id + " - " + util::toString(item.tile->id)); if (item.bucket->needsClipping()) { setClipping(item.tile->clip); } diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index 70d5312b387..ad26457555d 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -29,7 +29,6 @@ namespace mbgl { class Style; -class StyleLayer; class Tile; class SpriteAtlas; class GlyphAtlas; diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index 3f01b74403d..bc01d3c32fb 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -12,7 +13,7 @@ using namespace mbgl; void Painter::renderBackground(const BackgroundLayer& layer) { // Note that for bottommost layers without a pattern, the background color is drawn with // glClear rather than this method. - const BackgroundPaintProperties& properties = layer.paint; + const BackgroundPaintProperties& properties = layer.impl->paint; bool isPatterned = !properties.backgroundPattern.value.to.empty();// && false; optional imagePosA; diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index fe4348c362a..c371f4debed 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -20,7 +21,7 @@ void Painter::renderCircle(CircleBucket& bucket, config.depthMask = GL_FALSE; setDepthSublayer(0); - const CirclePaintProperties& properties = layer.paint; + const CirclePaintProperties& properties = layer.impl->paint; mat4 vtxMatrix = translatedMatrix(matrix, properties.circleTranslate, tileID, properties.circleTranslateAnchor); diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index 51cfa1b0685..b499d20da39 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -13,7 +14,7 @@ void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { - const FillPaintProperties& properties = layer.paint; + const FillPaintProperties& properties = layer.impl->paint; mat4 vtxMatrix = translatedMatrix(matrix, properties.fillTranslate, tileID, properties.fillTranslateAnchor); diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index d9e3d4037be..3cf1ad41471 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,7 @@ void Painter::renderLine(LineBucket& bucket, config.depthTest = GL_TRUE; config.depthMask = GL_FALSE; - const auto& properties = layer.paint; + const auto& properties = layer.impl->paint; const auto& layout = bucket.layout; // the distance over which the line edge fades out. @@ -75,8 +76,8 @@ void Painter::renderLine(LineBucket& bucket, LinePatternPos posA = lineAtlas->getDashPosition(properties.lineDasharray.value.from, layout.lineCap == LineCapType::Round, store); LinePatternPos posB = lineAtlas->getDashPosition(properties.lineDasharray.value.to, layout.lineCap == LineCapType::Round, store); - const float widthA = posA.width * properties.lineDasharray.value.fromScale * layer.dashLineWidth; - const float widthB = posB.width * properties.lineDasharray.value.toScale * layer.dashLineWidth; + const float widthA = posA.width * properties.lineDasharray.value.fromScale * layer.impl->dashLineWidth; + const float widthB = posB.width * properties.lineDasharray.value.toScale * layer.impl->dashLineWidth; float scaleXA = 1.0 / tileID.pixelsToTileUnits(widthA, state.getIntegerZoom()); float scaleYA = -posA.height / 2.0; diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index 7f55e23ac29..511ac963873 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include using namespace mbgl; @@ -12,7 +13,7 @@ void Painter::renderRaster(RasterBucket& bucket, const mat4& matrix) { if (pass != RenderPass::Translucent) return; - const RasterPaintProperties& properties = layer.paint; + const RasterPaintProperties& properties = layer.impl->paint; if (bucket.hasData()) { config.program = rasterShader->getID(); diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 55d2e27c117..97745680740 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -110,7 +110,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, return; } - const auto& paint = layer.paint; + const auto& paint = layer.impl->paint; const auto& layout = bucket.layout; config.depthMask = GL_FALSE; @@ -146,10 +146,10 @@ void Painter::renderSymbol(SymbolBucket& bucket, ? state.getAngle() : 0; - const float fontSize = layer.iconSize; + const float fontSize = layer.impl->iconSize; const float fontScale = fontSize / 1.0f; - SpriteAtlas* activeSpriteAtlas = layer.spriteAtlas; + SpriteAtlas* activeSpriteAtlas = layer.impl->spriteAtlas; const bool iconScaled = fontScale != 1 || frame.pixelRatio != activeSpriteAtlas->getPixelRatio() || bucket.iconsNeedLinear; const bool iconTransformed = layout.iconRotationAlignment == RotationAlignmentType::Map || angleOffset != 0 || state.getPitch() != 0; config.activeTexture = GL_TEXTURE0; @@ -172,7 +172,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, paint.iconHaloBlur, paint.iconTranslate, paint.iconTranslateAnchor, - layer.iconSize); + layer.impl->iconSize); } else { mat4 vtxMatrix = translatedMatrix(matrix, paint.iconTranslate, tileID, paint.iconTranslateAnchor); @@ -235,7 +235,7 @@ void Painter::renderSymbol(SymbolBucket& bucket, paint.textHaloBlur, paint.textTranslate, paint.textTranslateAnchor, - layer.textSize); + layer.impl->textSize); } if (bucket.hasCollisionBoxData()) { diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp index d6786969c99..b16d7f8161c 100644 --- a/src/mbgl/renderer/raster_bucket.cpp +++ b/src/mbgl/renderer/raster_bucket.cpp @@ -17,7 +17,7 @@ void RasterBucket::upload(gl::ObjectStore& store) { } void RasterBucket::render(Painter& painter, - const StyleLayer& layer, + const Layer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { painter.renderRaster(*this, *layer.as(), tileID, matrix); diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp index 33956fedcdf..9125ef2047c 100644 --- a/src/mbgl/renderer/raster_bucket.hpp +++ b/src/mbgl/renderer/raster_bucket.hpp @@ -14,7 +14,7 @@ class RasterBucket : public Bucket { RasterBucket(gl::TexturePool&); void upload(gl::ObjectStore&) override; - void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 2f5af330a49..67c8468ecdd 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -85,7 +85,7 @@ void SymbolBucket::upload(gl::ObjectStore& store) { } void SymbolBucket::render(Painter& painter, - const StyleLayer& layer, + const Layer& layer, const UnwrappedTileID& tileID, const mat4& matrix) { painter.renderSymbol(*this, *layer.as(), tileID, matrix); diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index 268bcb7c77e..b19a86b2751 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -70,7 +70,7 @@ class SymbolBucket : public Bucket { ~SymbolBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const StyleLayer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool hasTextData() const; bool hasIconData() const; diff --git a/src/mbgl/source/source.cpp b/src/mbgl/source/source.cpp index 1c55b9c0247..66546909ac3 100644 --- a/src/mbgl/source/source.cpp +++ b/src/mbgl/source/source.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mbgl/style/function.hpp b/src/mbgl/style/function.hpp deleted file mode 100644 index a04fc8bb4f4..00000000000 --- a/src/mbgl/style/function.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -template -class Function { -public: - using Stop = std::pair; - using Stops = std::vector; - - explicit Function(const T& constant) - : stops({{ 0, constant }}) {} - - explicit Function(const Stops& stops_, float base_) - : base(base_), stops(stops_) {} - - float getBase() const { return base; } - const std::vector>& getStops() const { return stops; } - -private: - float base = 1; - std::vector> stops; -}; - -} // namespace mbgl diff --git a/src/mbgl/style/function_evaluator.hpp b/src/mbgl/style/function_evaluator.hpp index 43549179df2..de49e79f98b 100644 --- a/src/mbgl/style/function_evaluator.hpp +++ b/src/mbgl/style/function_evaluator.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace mbgl { diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index 1df780be52b..a856e7589c7 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -27,7 +26,6 @@ class LayoutProperty { } } - void operator=(const T& v) { value = v; } operator T() const { return value; } optional> parsedValue; diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 256f045d0d5..4bbc5643982 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -97,7 +96,6 @@ class PaintProperty { return cascaded->prior.operator bool(); } - void operator=(const T& v) { values.emplace(ClassID::Default, Fn(v)); } operator T() const { return value; } std::map values; diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 362b0d7b5a4..67baa3ec8dc 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -1,4 +1,7 @@ #include +#include + +#include #include diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 8deb58c00be..17c9bf6ba8b 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include diff --git a/src/mbgl/style/render_item.hpp b/src/mbgl/style/render_item.hpp index a70c92f6207..ebf67998283 100644 --- a/src/mbgl/style/render_item.hpp +++ b/src/mbgl/style/render_item.hpp @@ -2,12 +2,12 @@ namespace mbgl { -class StyleLayer; +class Layer; class Tile; class Bucket; struct RenderItem { - inline RenderItem(const StyleLayer& layer_, + inline RenderItem(const Layer& layer_, const Tile* tile_ = nullptr, Bucket* bucket_ = nullptr) : tile(tile_), bucket(bucket_), layer(layer_) { @@ -15,7 +15,7 @@ struct RenderItem { const Tile* const tile; Bucket* const bucket; - const StyleLayer& layer; + const Layer& layer; }; } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index bc2a1d9a402..ee847ccf570 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -4,10 +4,14 @@ #include #include #include +#include #include +#include +#include +#include #include #include -#include +#include #include #include #include @@ -19,7 +23,6 @@ #include #include #include -#include #include #include @@ -109,35 +112,35 @@ void Style::addSource(std::unique_ptr source) { sources.emplace_back(std::move(source)); } -std::vector> Style::getLayers() const { - std::vector> result; +std::vector> Style::getLayers() const { + std::vector> result; result.reserve(layers.size()); for (const auto& layer : layers) { - result.push_back(layer->clone()); + result.push_back(layer->baseImpl->clone()); } return result; } -std::vector>::const_iterator Style::findLayer(const std::string& id) const { +std::vector>::const_iterator Style::findLayer(const std::string& id) const { return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) { - return layer->id == id; + return layer->baseImpl->id == id; }); } -StyleLayer* Style::getLayer(const std::string& id) const { +Layer* Style::getLayer(const std::string& id) const { auto it = findLayer(id); return it != layers.end() ? it->get() : nullptr; } -void Style::addLayer(std::unique_ptr layer, optional before) { +void Style::addLayer(std::unique_ptr layer, optional before) { if (SymbolLayer* symbolLayer = layer->as()) { - if (!symbolLayer->spriteAtlas) { - symbolLayer->spriteAtlas = spriteAtlas.get(); + if (!symbolLayer->impl->spriteAtlas) { + symbolLayer->impl->spriteAtlas = spriteAtlas.get(); } } if (CustomLayer* customLayer = layer->as()) { - customLayer->initialize(); + customLayer->impl->initialize(); } layers.emplace(before ? findLayer(*before) : layers.end(), std::move(layer)); @@ -187,7 +190,7 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) { transitionProperties = {}; for (const auto& layer : layers) { - layer->cascade(parameters); + layer->baseImpl->cascade(parameters); } } @@ -207,10 +210,10 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { hasPendingTransitions = false; for (const auto& layer : layers) { - hasPendingTransitions |= layer->recalculate(parameters); + hasPendingTransitions |= layer->baseImpl->recalculate(parameters); - Source* source = getSource(layer->source); - if (source && layer->needsRendering()) { + Source* source = getSource(layer->baseImpl->source); + if (source && layer->baseImpl->needsRendering()) { source->enabled = true; if (!source->loaded && !source->isLoading()) { source->load(fileSource); @@ -257,17 +260,18 @@ RenderData Style::getRenderData() const { } for (const auto& layer : layers) { - if (layer->visibility == VisibilityType::None) + if (layer->baseImpl->visibility == VisibilityType::None) continue; if (const BackgroundLayer* background = layer->as()) { - if (layer.get() == layers[0].get() && background->paint.backgroundPattern.value.from.empty()) { + const BackgroundPaintProperties& paint = background->impl->paint; + if (layer.get() == layers[0].get() && paint.backgroundPattern.value.from.empty()) { // This is a solid background. We can use glClear(). - result.backgroundColor = background->paint.backgroundColor; - result.backgroundColor[0] *= background->paint.backgroundOpacity; - result.backgroundColor[1] *= background->paint.backgroundOpacity; - result.backgroundColor[2] *= background->paint.backgroundOpacity; - result.backgroundColor[3] *= background->paint.backgroundOpacity; + result.backgroundColor = paint.backgroundColor; + result.backgroundColor[0] *= paint.backgroundOpacity; + result.backgroundColor[1] *= paint.backgroundOpacity; + result.backgroundColor[2] *= paint.backgroundOpacity; + result.backgroundColor[3] *= paint.backgroundOpacity; } else { // This is a textured background, or not the bottommost layer. We need to render it with a quad. result.order.emplace_back(*layer); @@ -280,9 +284,9 @@ RenderData Style::getRenderData() const { continue; } - Source* source = getSource(layer->source); + Source* source = getSource(layer->baseImpl->source); if (!source) { - Log::Warning(Event::Render, "can't find source for layer '%s'", layer->id.c_str()); + Log::Warning(Event::Render, "can't find source for layer '%s'", layer->baseImpl->id.c_str()); continue; } @@ -333,7 +337,7 @@ std::vector Style::queryRenderedFeatures(const StyleQueryParameters& pa // Combine all results based on the style layer order. for (const auto& layer : layers) { - auto it = resultsByLayer.find(layer->id); + auto it = resultsByLayer.find(layer->baseImpl->id); if (it != resultsByLayer.end()) { std::move(it->second.begin(), it->second.end(), std::back_inserter(result)); } @@ -345,7 +349,7 @@ std::vector Style::queryRenderedFeatures(const StyleQueryParameters& pa float Style::getQueryRadius() const { float additionalRadius = 0; for (auto& layer : layers) { - additionalRadius = util::max(additionalRadius, layer->getQueryRadius()); + additionalRadius = util::max(additionalRadius, layer->baseImpl->getQueryRadius()); } return additionalRadius; } diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 5fdd6cdc8e2..6892f4967a6 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -69,9 +69,9 @@ class Style : public GlyphStoreObserver, Source* getSource(const std::string& id) const; void addSource(std::unique_ptr); - std::vector> getLayers() const; - StyleLayer* getLayer(const std::string& id) const; - void addLayer(std::unique_ptr, + std::vector> getLayers() const; + Layer* getLayer(const std::string& id) const; + void addLayer(std::unique_ptr, optional beforeLayerID = {}); void removeLayer(const std::string& layerID); @@ -101,11 +101,11 @@ class Style : public GlyphStoreObserver, private: std::vector> sources; - std::vector> layers; + std::vector> layers; std::vector classes; optional transitionProperties; - std::vector>::const_iterator findLayer(const std::string& layerID) const; + std::vector>::const_iterator findLayer(const std::string& layerID) const; // GlyphStoreObserver implementation. void onGlyphsLoaded(const FontStack&, const GlyphRange&) override; diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 4f081e7d852..6a67ea9daa8 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include @@ -331,7 +333,7 @@ void StyleParser::parseLayers(const JSValue& value) { continue; } - layersMap.emplace(layerID, std::pair> { layerValue, nullptr }); + layersMap.emplace(layerID, std::pair> { layerValue, nullptr }); ids.push_back(layerID); } @@ -352,7 +354,7 @@ void StyleParser::parseLayers(const JSValue& value) { } } -void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::unique_ptr& layer) { +void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::unique_ptr& layer) { if (layer) { // Skip parsing this again. We already have a valid layer definition. return; @@ -386,15 +388,13 @@ void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::u it->second.second); stack.pop_front(); - StyleLayer* reference = it->second.second.get(); + Layer* reference = it->second.second.get(); if (!reference) { return; } - layer = reference->clone(); - layer->id = id; - layer->ref = ref; - + layer = reference->copy(id, ref); + layer->baseImpl->parsePaints(value); } else { // Otherwise, parse the source/source-layer/filter/render keys to form the bucket. if (!value.HasMember("type")) { @@ -411,75 +411,75 @@ void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::u std::string type { typeVal.GetString(), typeVal.GetStringLength() }; if (type == "fill") { - layer = std::make_unique(); + layer = std::make_unique(id); } else if (type == "line") { - layer = std::make_unique(); + layer = std::make_unique(id); } else if (type == "circle") { - layer = std::make_unique(); + layer = std::make_unique(id); } else if (type == "symbol") { - layer = std::make_unique(); + layer = std::make_unique(id); } else if (type == "raster") { - layer = std::make_unique(); + layer = std::make_unique(id); } else if (type == "background") { - layer = std::make_unique(); + layer = std::make_unique(id); } else { Log::Warning(Event::ParseStyle, "unknown type '%s' for layer '%s'", type.c_str(), id.c_str()); return; } - layer->id = id; + Layer::Impl* impl = layer->baseImpl.get(); if (value.HasMember("source")) { const JSValue& value_source = value["source"]; if (value_source.IsString()) { - layer->source = { value_source.GetString(), value_source.GetStringLength() }; - auto source_it = sourcesMap.find(layer->source); + impl->source = { value_source.GetString(), value_source.GetStringLength() }; + auto source_it = sourcesMap.find(impl->source); if (source_it == sourcesMap.end()) { - Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", layer->source.c_str(), layer->id.c_str()); + Log::Warning(Event::ParseStyle, "can't find source '%s' required for layer '%s'", impl->source.c_str(), impl->id.c_str()); } } else { - Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "source of layer '%s' must be a string", impl->id.c_str()); } } if (value.HasMember("source-layer")) { const JSValue& value_source_layer = value["source-layer"]; if (value_source_layer.IsString()) { - layer->sourceLayer = { value_source_layer.GetString(), value_source_layer.GetStringLength() }; + impl->sourceLayer = { value_source_layer.GetString(), value_source_layer.GetStringLength() }; } else { - Log::Warning(Event::ParseStyle, "source-layer of layer '%s' must be a string", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "source-layer of layer '%s' must be a string", impl->id.c_str()); } } if (value.HasMember("filter")) { - layer->filter = parseFilter(value["filter"]); + impl->filter = parseFilter(value["filter"]); } if (value.HasMember("minzoom")) { const JSValue& min_zoom = value["minzoom"]; if (min_zoom.IsNumber()) { - layer->minZoom = min_zoom.GetDouble(); + impl->minZoom = min_zoom.GetDouble(); } else { - Log::Warning(Event::ParseStyle, "minzoom of layer %s must be numeric", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "minzoom of layer %s must be numeric", impl->id.c_str()); } } if (value.HasMember("maxzoom")) { const JSValue& max_zoom = value["maxzoom"]; if (max_zoom.IsNumber()) { - layer->maxZoom = max_zoom.GetDouble(); + impl->maxZoom = max_zoom.GetDouble(); } else { - Log::Warning(Event::ParseStyle, "maxzoom of layer %s must be numeric", layer->id.c_str()); + Log::Warning(Event::ParseStyle, "maxzoom of layer %s must be numeric", impl->id.c_str()); } } if (value.HasMember("layout")) { parseVisibility(*layer, value["layout"]); - layer->parseLayout(value["layout"]); + impl->parseLayout(value["layout"]); } - } - layer->parsePaints(value); + impl->parsePaints(value); + } } MBGL_DEFINE_ENUM_CLASS(VisibilityTypeClass, VisibilityType, { @@ -487,15 +487,16 @@ MBGL_DEFINE_ENUM_CLASS(VisibilityTypeClass, VisibilityType, { { VisibilityType::None, "none" }, }); -void StyleParser::parseVisibility(StyleLayer& layer, const JSValue& value) { +void StyleParser::parseVisibility(Layer& layer, const JSValue& value) { + Layer::Impl& impl = *layer.baseImpl; if (!value.HasMember("visibility")) { return; } else if (!value["visibility"].IsString()) { Log::Warning(Event::ParseStyle, "value of 'visibility' must be a string"); - layer.visibility = VisibilityType::Visible; + impl.visibility = VisibilityType::Visible; return; } - layer.visibility = VisibilityTypeClass({ value["visibility"].GetString(), value["visibility"].GetStringLength() }); + impl.visibility = VisibilityTypeClass({ value["visibility"].GetString(), value["visibility"].GetStringLength() }); } Value parseFeatureType(const Value& value) { @@ -669,7 +670,7 @@ std::vector StyleParser::fontStacks() const { for (const auto& layer : layers) { if (layer->is()) { - LayoutProperty property = layer->as()->layout.textFont; + LayoutProperty property = layer->as()->impl->layout.textFont; if (property.parsedValue) { for (const auto& stop : property.parsedValue->getStops()) { result.insert(stop.second); diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/style_parser.hpp index 98481aec51f..b5445bbfb30 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/style_parser.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -14,9 +14,6 @@ namespace mbgl { -class StyleLayer; -class Source; - Filter parseFilter(const JSValue&); class StyleParser { @@ -29,7 +26,7 @@ class StyleParser { std::string glyphURL; std::vector> sources; - std::vector> layers; + std::vector> layers; // Statically evaluate layer properties to determine what font stacks are used. std::vector fontStacks() const; @@ -42,11 +39,11 @@ class StyleParser { private: void parseSources(const JSValue&); void parseLayers(const JSValue&); - void parseLayer(const std::string& id, const JSValue&, std::unique_ptr&); - void parseVisibility(StyleLayer&, const JSValue& value); + void parseLayer(const std::string& id, const JSValue&, std::unique_ptr&); + void parseVisibility(Layer&, const JSValue& value); std::unordered_map sourcesMap; - std::unordered_map>> layersMap; + std::unordered_map>> layersMap; // Store a stack of layer IDs we're parsing right now. This is to prevent reference cycles. std::forward_list stack; diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index f78d913e746..3cb508a1029 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index 9ad3c3e71d9..ce93b4977e0 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -1,5 +1,5 @@ #include -#include +#include namespace mbgl { diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp index 29b7ca6af8d..a5eab3fb236 100644 --- a/src/mbgl/tile/raster_tile_data.cpp +++ b/src/mbgl/tile/raster_tile_data.cpp @@ -61,7 +61,7 @@ RasterTileData::~RasterTileData() { cancel(); } -Bucket* RasterTileData::getBucket(StyleLayer const&) { +Bucket* RasterTileData::getBucket(const Layer&) { return bucket.get(); } diff --git a/src/mbgl/tile/raster_tile_data.hpp b/src/mbgl/tile/raster_tile_data.hpp index 74e0cc400da..ea9b144e25b 100644 --- a/src/mbgl/tile/raster_tile_data.hpp +++ b/src/mbgl/tile/raster_tile_data.hpp @@ -7,7 +7,7 @@ namespace mbgl { class FileSource; class AsyncRequest; -class StyleLayer; +class Layer; namespace gl { class TexturePool; } class RasterTileData : public TileData { @@ -22,7 +22,7 @@ class RasterTileData : public TileData { ~RasterTileData(); void cancel() override; - Bucket* getBucket(StyleLayer const &layer_desc) override; + Bucket* getBucket(const Layer&) override; private: gl::TexturePool& texturePool; diff --git a/src/mbgl/tile/tile_data.hpp b/src/mbgl/tile/tile_data.hpp index 297bfabcae0..035a7ed319e 100644 --- a/src/mbgl/tile/tile_data.hpp +++ b/src/mbgl/tile/tile_data.hpp @@ -16,7 +16,7 @@ namespace mbgl { -class StyleLayer; +class Layer; class Worker; class DebugBucket; class TransformState; @@ -29,7 +29,7 @@ class TileData : private util::noncopyable { // Mark this tile as no longer needed and cancel any pending work. virtual void cancel() = 0; - virtual Bucket* getBucket(const StyleLayer&) = 0; + virtual Bucket* getBucket(const Layer&) = 0; virtual bool parsePending(std::function) { return true; } virtual void redoPlacement(PlacementConfig, const std::function&) {} diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp index fdebe912296..9076684a2d4 100644 --- a/src/mbgl/tile/tile_worker.cpp +++ b/src/mbgl/tile/tile_worker.cpp @@ -1,11 +1,11 @@ #include #include #include -#include #include #include #include #include +#include #include #include #include @@ -37,7 +37,7 @@ TileWorker::~TileWorker() { glyphAtlas.removeGlyphs(reinterpret_cast(this)); } -TileParseResult TileWorker::parseAllLayers(std::vector> layers_, +TileParseResult TileWorker::parseAllLayers(std::vector> layers_, std::unique_ptr geometryTile_, PlacementConfig config) { // We're doing a fresh parse of the tile, because the underlying data has changed. @@ -55,12 +55,12 @@ TileParseResult TileWorker::parseAllLayers(std::vector parsed; for (auto i = layers.rbegin(); i != layers.rend(); i++) { - const StyleLayer* layer = i->get(); - if (parsed.find(layer->bucketName()) == parsed.end()) { - parsed.emplace(layer->bucketName()); + const Layer* layer = i->get(); + if (parsed.find(layer->baseImpl->bucketName()) == parsed.end()) { + parsed.emplace(layer->baseImpl->bucketName()); parseLayer(layer); } - featureIndex->addBucketLayerName(layer->bucketName(), layer->id); + featureIndex->addBucketLayerName(layer->baseImpl->bucketName(), layer->baseImpl->id); } return prepareResult(config); @@ -70,16 +70,15 @@ TileParseResult TileWorker::parsePendingLayers(const PlacementConfig config) { // Try parsing the remaining layers that we couldn't parse in the first step due to missing // dependencies. for (auto it = pending.begin(); it != pending.end();) { - auto& layer = *it->first; - auto bucket = dynamic_cast(it->second.get()); - assert(bucket); // Only symbol layers can be pending, so the dynamic cast should never fail. - - if (!bucket->needsDependencies(glyphStore, spriteStore)) { - bucket->addFeatures(reinterpret_cast(this), - *layer.spriteAtlas, - glyphAtlas, - glyphStore); - placementPending.emplace(layer.bucketName(), std::move(it->second)); + const SymbolLayer& symbolLayer = *it->first; + SymbolBucket* symbolBucket = dynamic_cast(it->second.get()); + + if (!symbolBucket->needsDependencies(glyphStore, spriteStore)) { + symbolBucket->addFeatures(reinterpret_cast(this), + *symbolLayer.impl->spriteAtlas, + glyphAtlas, + glyphStore); + placementPending.emplace(symbolLayer.impl->bucketName(), std::move(it->second)); pending.erase(it++); continue; } @@ -120,7 +119,7 @@ std::unique_ptr TileWorker::redoPlacement( auto collisionTile = std::make_unique(config); for (auto i = layers.rbegin(); i != layers.rend(); i++) { - const auto it = buckets->find((*i)->id); + const auto it = buckets->find((*i)->baseImpl->id); if (it != buckets->end()) { it->second->placeFeatures(*collisionTile); } @@ -129,7 +128,7 @@ std::unique_ptr TileWorker::redoPlacement( return collisionTile; } -void TileWorker::parseLayer(const StyleLayer* layer) { +void TileWorker::parseLayer(const Layer* layer) { // Cancel early when parsing. if (obsolete) return; @@ -139,19 +138,19 @@ void TileWorker::parseLayer(const StyleLayer* layer) { return; // Skip this bucket if we are to not render this - if ((layer->source != sourceID) || - (id.overscaledZ < std::floor(layer->minZoom)) || - (id.overscaledZ >= std::ceil(layer->maxZoom)) || - (layer->visibility == VisibilityType::None)) { + if ((layer->baseImpl->source != sourceID) || + (id.overscaledZ < std::floor(layer->baseImpl->minZoom)) || + (id.overscaledZ >= std::ceil(layer->baseImpl->maxZoom)) || + (layer->baseImpl->visibility == VisibilityType::None)) { return; } - auto geometryLayer = geometryTile->getLayer(layer->sourceLayer); + auto geometryLayer = geometryTile->getLayer(layer->baseImpl->sourceLayer); if (!geometryLayer) { // The layer specified in the bucket does not exist. Do nothing. if (debug::tileParseWarnings) { Log::Warning(Event::ParseTile, "layer '%s' does not exist in tile %s", - layer->sourceLayer.c_str(), util::toString(id).c_str()); + layer->baseImpl->sourceLayer.c_str(), util::toString(id).c_str()); } return; } @@ -167,17 +166,17 @@ void TileWorker::parseLayer(const StyleLayer* layer) { *featureIndex, mode); - std::unique_ptr bucket = layer->createBucket(parameters); + std::unique_ptr bucket = layer->baseImpl->createBucket(parameters); if (layer->is()) { if (partialParse) { // We cannot parse this bucket yet. Instead, we're saving it for later. pending.emplace_back(layer->as(), std::move(bucket)); } else { - placementPending.emplace(layer->bucketName(), std::move(bucket)); + placementPending.emplace(layer->baseImpl->bucketName(), std::move(bucket)); } } else { - insertBucket(layer->bucketName(), std::move(bucket)); + insertBucket(layer->baseImpl->bucketName(), std::move(bucket)); } } diff --git a/src/mbgl/tile/tile_worker.hpp b/src/mbgl/tile/tile_worker.hpp index 83bf6c7f43b..a04ef6a78f4 100644 --- a/src/mbgl/tile/tile_worker.hpp +++ b/src/mbgl/tile/tile_worker.hpp @@ -23,7 +23,7 @@ class SpriteStore; class GlyphAtlas; class GlyphStore; class Bucket; -class StyleLayer; +class Layer; class SymbolLayer; // We're using this class to shuttle the resulting buckets from the worker thread to the MapContext @@ -51,7 +51,7 @@ class TileWorker : public util::noncopyable { const MapMode); ~TileWorker(); - TileParseResult parseAllLayers(std::vector>, + TileParseResult parseAllLayers(std::vector>, std::unique_ptr geometryTile, PlacementConfig); @@ -62,7 +62,7 @@ class TileWorker : public util::noncopyable { private: TileParseResult prepareResult(const PlacementConfig& config); - void parseLayer(const StyleLayer*); + void parseLayer(const Layer*); void insertBucket(const std::string& name, std::unique_ptr); std::unique_ptr placeLayers(PlacementConfig); @@ -77,7 +77,7 @@ class TileWorker : public util::noncopyable { bool partialParse = false; - std::vector> layers; + std::vector> layers; std::unique_ptr featureIndex; std::unique_ptr geometryTile; diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index 428c605f266..db0ec8029e1 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -139,8 +139,8 @@ bool VectorTileData::parsePending(std::function callba return true; } -Bucket* VectorTileData::getBucket(const StyleLayer& layer) { - const auto it = buckets.find(layer.bucketName()); +Bucket* VectorTileData::getBucket(const Layer& layer) { + const auto it = buckets.find(layer.baseImpl->bucketName()); if (it == buckets.end()) { return nullptr; } diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp index 2545df801ba..4695338e1e2 100644 --- a/src/mbgl/tile/vector_tile_data.hpp +++ b/src/mbgl/tile/vector_tile_data.hpp @@ -27,7 +27,7 @@ class VectorTileData : public TileData { ~VectorTileData(); - Bucket* getBucket(const StyleLayer&) override; + Bucket* getBucket(const Layer&) override; bool parsePending(std::function callback) override; diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp index e116d3f6c67..43abe6792a3 100644 --- a/src/mbgl/util/worker.cpp +++ b/src/mbgl/util/worker.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -30,7 +30,7 @@ class Worker::Impl { } void parseGeometryTile(TileWorker* worker, - std::vector> layers, + std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { @@ -79,7 +79,7 @@ Worker::parseRasterTile(std::unique_ptr bucket, std::unique_ptr Worker::parseGeometryTile(TileWorker& worker, - std::vector> layers, + std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { diff --git a/src/mbgl/util/worker.hpp b/src/mbgl/util/worker.hpp index e07b8b8b442..68625f42bf4 100644 --- a/src/mbgl/util/worker.hpp +++ b/src/mbgl/util/worker.hpp @@ -40,7 +40,7 @@ class Worker : public mbgl::util::noncopyable { std::function callback); Request parseGeometryTile(TileWorker&, - std::vector>, + std::vector>, std::unique_ptr, PlacementConfig, std::function callback); diff --git a/test/style/functions.cpp b/test/style/functions.cpp index 2389459dbca..586941ecf0a 100644 --- a/test/style/functions.cpp +++ b/test/style/functions.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/test/style/source.cpp b/test/style/source.cpp index 5023a9efea5..b9eb1bc4345 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -274,9 +274,8 @@ TEST(Source, VectorTileCorrupt) { }; // Need to have at least one layer that uses the source. - auto layer = std::make_unique(); - layer->source = "source"; - layer->sourceLayer = "water"; + auto layer = std::make_unique("id"); + layer->setSource("source", "water"); test.style.addLayer(std::move(layer)); auto info = std::make_unique(); diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp index 3b1d3be337b..3274fe33775 100644 --- a/test/style/style_layer.cpp +++ b/test/style/style_layer.cpp @@ -1,24 +1,18 @@ #include - -#include #include +#include using namespace mbgl; -TEST(StyleLayer, Create) { - std::unique_ptr layer = std::make_unique(); - EXPECT_TRUE(reinterpret_cast(layer.get())); -} - -TEST(StyleLayer, Clone) { - std::unique_ptr layer = std::make_unique(); - std::unique_ptr clone = layer->clone(); +TEST(Layer, Clone) { + std::unique_ptr layer = std::make_unique("id"); + std::unique_ptr clone = layer->baseImpl->clone(); EXPECT_NE(layer.get(), clone.get()); - EXPECT_TRUE(reinterpret_cast(layer.get())); + EXPECT_TRUE(reinterpret_cast(clone->baseImpl.get())); } -TEST(StyleLayer, CloneCopiesBaseProperties) { - std::unique_ptr layer = std::make_unique(); - layer->id = "test"; - EXPECT_EQ("test", layer->clone()->id); +TEST(Layer, CloneCopiesBaseProperties) { + std::unique_ptr layer = std::make_unique("id"); + layer->impl->id = "test"; + EXPECT_EQ("test", layer->baseImpl->clone()->getID()); } From d7e1ecd19e321afaba631f9365b31e0a728a61c3 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 13:14:34 -0700 Subject: [PATCH 2/8] [core] Generalize Map::{add,remove}CustomLayer --- include/mbgl/layer/custom_layer.hpp | 39 +++++++++++++++++++ include/mbgl/map/map.hpp | 11 ++---- include/mbgl/map/view.hpp | 4 +- include/mbgl/style/types.hpp | 39 ------------------- platform/android/src/example_custom_layer.cpp | 2 +- platform/android/src/jni.cpp | 9 +++-- platform/ios/src/MGLMapView.mm | 9 +++-- platform/qt/src/qmapboxgl.cpp | 9 +++-- src/mbgl/map/map.cpp | 13 ++----- test/api/custom_layer.cpp | 4 +- 10 files changed, 65 insertions(+), 74 deletions(-) diff --git a/include/mbgl/layer/custom_layer.hpp b/include/mbgl/layer/custom_layer.hpp index 81e91ddf50d..9782d9593f8 100644 --- a/include/mbgl/layer/custom_layer.hpp +++ b/include/mbgl/layer/custom_layer.hpp @@ -4,6 +4,45 @@ namespace mbgl { +/** + * Initialize any GL state needed by the custom layer. This method is called once, from the + * rendering thread, at a point when the GL context is active but before rendering for the + * first time. + * + * Resources that are acquired in this method must be released in the UninitializeFunction. + */ +using CustomLayerInitializeFunction = void (*)(void* context); + +/** + * Parameters that define the current camera position for a CustomLayerRenderFunction. + */ +struct CustomLayerRenderParameters { + double width; + double height; + double latitude; + double longitude; + double zoom; + double bearing; + double pitch; + double altitude; +}; + +/** + * Render the layer. This method is called once per frame. The implementation should not make + * any assumptions about the GL state (other than that the correct context is active). It may + * make changes to the state, and is not required to reset values such as the depth mask, stencil + * mask, and corresponding test flags to their original values. + */ +using CustomLayerRenderFunction = void (*)(void* context, const CustomLayerRenderParameters&); + +/** + * Destroy any GL state needed by the custom layer, and deallocate context, if necessary. This + * method is called once, from the rendering thread, at a point when the GL context is active. + * + * Note that it may be called even when the InitializeFunction has not been called. + */ +using CustomLayerDeinitializeFunction = void (*)(void* context); + class CustomLayer : public Layer { public: CustomLayer(const std::string& id, diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index a728e2dd621..aadfdf9ada4 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -23,6 +22,7 @@ namespace mbgl { class FileSource; class View; class SpriteImage; +class Layer; struct CameraOptions; struct AnimationOptions; @@ -146,13 +146,8 @@ class Map : private util::noncopyable { AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&); - void addCustomLayer(const std::string& id, - CustomLayerInitializeFunction, - CustomLayerRenderFunction, - CustomLayerDeinitializeFunction, - void* context, - const char* before = nullptr); - void removeCustomLayer(const std::string& id); + void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); + void removeLayer(const std::string& layerID); // Feature queries std::vector queryRenderedFeatures(const ScreenCoordinate&, const optional>& layerIDs = {}); diff --git a/include/mbgl/map/view.hpp b/include/mbgl/map/view.hpp index 4431e2b33ca..9f12ee5fb64 100644 --- a/include/mbgl/map/view.hpp +++ b/include/mbgl/map/view.hpp @@ -36,8 +36,8 @@ class View { // as a matched pair, in four situations: // // 1. When releasing GL resources during Map destruction - // 2. When calling a CustomLayerInitializeFunction, during Map::addCustomLayer - // 3. When calling a CustomLayerDeinitializeFunction, during Map::removeCustomLayer + // 2. When calling a CustomLayerInitializeFunction, during Map::addLayer + // 3. When calling a CustomLayerDeinitializeFunction, during Map::removeLayer // 4. When rendering for Map::renderStill // // They are *not* called for Map::render; it is assumed that the correct context is already diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index a852a09a14c..ea09ccfb0cb 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -125,44 +125,5 @@ enum class TextTransformType : uint8_t { Lowercase, }; -/** - * Initialize any GL state needed by the custom layer. This method is called once, from the - * rendering thread, at a point when the GL context is active but before rendering for the - * first time. - * - * Resources that are acquired in this method must be released in the UninitializeFunction. - */ -using CustomLayerInitializeFunction = void (*)(void* context); - -/** - * Parameters that define the current camera position for a CustomLayerRenderFunction. - */ -struct CustomLayerRenderParameters { - double width; - double height; - double latitude; - double longitude; - double zoom; - double bearing; - double pitch; - double altitude; -}; - -/** - * Render the layer. This method is called once per frame. The implementation should not make - * any assumptions about the GL state (other than that the correct context is active). It may - * make changes to the state, and is not required to reset values such as the depth mask, stencil - * mask, and corresponding test flags to their original values. - */ -using CustomLayerRenderFunction = void (*)(void* context, const CustomLayerRenderParameters&); - -/** - * Destroy any GL state needed by the custom layer, and deallocate context, if necessary. This - * method is called once, from the rendering thread, at a point when the GL context is active. - * - * Note that it may be called even when the InitializeFunction has not been called. - */ -using CustomLayerDeinitializeFunction = void (*)(void* context); - } // namespace mbgl diff --git a/platform/android/src/example_custom_layer.cpp b/platform/android/src/example_custom_layer.cpp index a513b7faf64..99b6d7223a0 100644 --- a/platform/android/src/example_custom_layer.cpp +++ b/platform/android/src/example_custom_layer.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include static const GLchar * vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); }"; static const GLchar * fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 1, 0, 1); }"; diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index ed2563cf7b6..2b6b4429f21 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1111,20 +1112,20 @@ void nativeAddCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddCustomLayer"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->getMap().addCustomLayer( + nativeMapView->getMap().addLayer(std::make_unique( std_string_from_jstring(env, reinterpret_cast(jni::GetField(*env, customLayer, *customLayerIdId))), reinterpret_cast(jni::GetField(*env, customLayer, *customLayerInitializeFunctionId)), reinterpret_cast(jni::GetField(*env, customLayer, *customLayerRenderFunctionId)), reinterpret_cast(jni::GetField(*env, customLayer, *customLayerDeinitializeFunctionId)), - reinterpret_cast(jni::GetField(*env, customLayer, *customLayerContextId)), - before ? std_string_from_jstring(env, before).c_str() : nullptr); + reinterpret_cast(jni::GetField(*env, customLayer, *customLayerContextId))), + before ? mbgl::optional(std_string_from_jstring(env, before)) : mbgl::optional()); } void nativeRemoveCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jni::jstring* id) { mbgl::Log::Debug(mbgl::Event::JNI, "nativeRemoveCustomLayer"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->getMap().removeCustomLayer(std_string_from_jstring(env, id)); + nativeMapView->getMap().removeLayer(std_string_from_jstring(env, id)); } // Offline calls begin diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 87d821fba95..338dd4805f7 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -5004,14 +5005,14 @@ - (void)insertCustomStyleLayerWithIdentifier:(NSString *)identifier preparationH { NSAssert(identifier, @"Style layer needs an identifier"); MGLCustomStyleLayerHandlers *context = new MGLCustomStyleLayerHandlers(preparation, drawing, completion); - _mbglMap->addCustomLayer(identifier.UTF8String, MGLPrepareCustomStyleLayer, - MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer, - context, otherIdentifier.UTF8String); + _mbglMap->addLayer(std::make_unique(identifier.UTF8String, MGLPrepareCustomStyleLayer, + MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer, context), + otherIdentifier ? mbgl::optional(otherIdentifier.UTF8String) : mbgl::optional()); } - (void)removeCustomStyleLayerWithIdentifier:(NSString *)identifier { - _mbglMap->removeCustomLayer(identifier.UTF8String); + _mbglMap->removeLayer(identifier.UTF8String); } - (void)setCustomStyleLayersNeedDisplay diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 1f8657c044f..4354eac75dd 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -556,20 +557,20 @@ void QMapboxGL::addCustomLayer(const QString &id, void *context_, char *before) { - d_ptr->mapObj->addCustomLayer( + d_ptr->mapObj->addLayer(std::make_unique( id.toStdString(), reinterpret_cast(initFn), // This cast is safe as long as both mbgl:: and QMapbox:: // CustomLayerRenderParameters members remains the same. (mbgl::CustomLayerRenderFunction)renderFn, reinterpret_cast(deinitFn), - context_, - before == NULL ? nullptr : before); + context_), + before ? mbgl::optional(before) : mbgl::optional()); } void QMapboxGL::removeCustomLayer(const QString& id) { - d_ptr->mapObj->removeCustomLayer(id.toStdString()); + d_ptr->mapObj->removeLayer(id.toStdString()); } void QMapboxGL::render() diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index aee67775258..4f1c4634ca8 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -740,24 +740,17 @@ std::vector Map::queryRenderedFeatures(const ScreenBox& box, const opti #pragma mark - Style API -void Map::addCustomLayer(const std::string& id, - CustomLayerInitializeFunction initialize, - CustomLayerRenderFunction render_, - CustomLayerDeinitializeFunction deinitialize, - void* context_, - const char* before) { +void Map::addLayer(std::unique_ptr layer, const optional& before) { impl->view.activate(); - impl->style->addLayer( - std::make_unique(id, initialize, render_, deinitialize, context_), - before ? std::string(before) : optional()); + impl->style->addLayer(std::move(layer), before); impl->updateFlags |= Update::Classes; impl->asyncUpdate.send(); impl->view.deactivate(); } -void Map::removeCustomLayer(const std::string& id) { +void Map::removeLayer(const std::string& id) { impl->view.activate(); impl->style->removeLayer(id); diff --git a/test/api/custom_layer.cpp b/test/api/custom_layer.cpp index 4ad25bbfd58..b3ff335d4e8 100644 --- a/test/api/custom_layer.cpp +++ b/test/api/custom_layer.cpp @@ -77,7 +77,7 @@ TEST(CustomLayer, Basic) { Map map(view, fileSource, MapMode::Still); map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); - map.addCustomLayer( + map.addLayer(std::make_unique( "custom", [] (void* context) { reinterpret_cast(context)->initialize(); @@ -87,7 +87,7 @@ TEST(CustomLayer, Basic) { }, [] (void* context) { delete reinterpret_cast(context); - }, new TestLayer()); + }, new TestLayer())); test::checkImage("test/fixtures/custom_layer/basic", test::render(map)); } From ba4a8a97316d65ab595bb7edf759f463bbd10049 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 14:44:46 -0700 Subject: [PATCH 3/8] [tests] Add basic tests for Map::{add,remove}Layer --- test/fixtures/map/add_layer/expected.png | Bin 0 -> 1685 bytes test/fixtures/map/remove_layer/expected.png | Bin 0 -> 1238 bytes test/map/map.cpp | 48 ++++++++++++++++---- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 test/fixtures/map/add_layer/expected.png create mode 100644 test/fixtures/map/remove_layer/expected.png diff --git a/test/fixtures/map/add_layer/expected.png b/test/fixtures/map/add_layer/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..8fa3f0f5db7e671b6a9be553b043aa739b6590a0 GIT binary patch literal 1685 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=C}ko-U3d z6^w7MF!C}e@Gu{2tUvG2)MMY&7&m>L@#lT+4Gw_`;?Adi8V-mXFz7WpL>ypfIW0c7 zfw6#@0UJjPE04pDnv0wg z4CW3BItdJio_6~kVA#RPl*q^|pch}l#CCvJfP-72q2T8tVFQM|hEXd<18OuyjpmEd f0%Qo5wBl>OG5_10B6Aj4&oFqp`njxgN@xNAq(%Fv literal 0 HcmV?d00001 diff --git a/test/fixtures/map/remove_layer/expected.png b/test/fixtures/map/remove_layer/expected.png new file mode 100644 index 0000000000000000000000000000000000000000..04f8682f8806e2d9a513e366fb46fb1b2336a583 GIT binary patch literal 1238 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G!U;i$lZxy-8q?;3=Aw2JY5_^ zDj45hFa#+)wBW1%+iZ>whr|O7jLd925(WvQjL|?CO$np9fG)Y<12Z$D4FjXpE{9-X PX~f{^>gTe~DWM4f@<$XU literal 0 HcmV?d00001 diff --git a/test/map/map.cpp b/test/map/map.cpp index 4ee44ca6136..c6f6843a0d8 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -8,15 +8,20 @@ #include #include #include +#include using namespace mbgl; using namespace std::literals::string_literals; -TEST(Map, Offline) { +struct MapTest { util::RunLoop runLoop; + std::shared_ptr display { std::make_shared() }; + HeadlessView view { display, 1 }; + StubFileSource fileSource; +}; - auto display = std::make_shared(); - HeadlessView view(display, 1); +TEST(Map, Offline) { + MapTest test; DefaultFileSource fileSource(":memory:", "."); auto expiredItem = [] (const std::string& path) { @@ -35,7 +40,7 @@ TEST(Map, Offline) { fileSource.put(Resource::glyphs(prefix + "{fontstack}/{range}.pbf", {{"Helvetica"}}, {0, 255}), expiredItem("glyph.pbf")); NetworkStatus::Set(NetworkStatus::Status::Offline); - Map map(view, fileSource, MapMode::Still); + Map map(test.view, fileSource, MapMode::Still); map.setStyleURL(prefix + "style.json"); test::checkImage("test/fixtures/map/offline", @@ -47,13 +52,36 @@ TEST(Map, Offline) { } TEST(Map, DoubleStyleLoad) { - util::RunLoop runLoop; + MapTest test; - std::shared_ptr display = std::make_shared(); - HeadlessView view(display, 1, 512, 512); - StubFileSource fileSource; - - Map map(view, fileSource); + Map map(test.view, test.fileSource, MapMode::Still); map.setStyleJSON("", ""); map.setStyleJSON("", ""); } + +TEST(Map, AddLayer) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + + auto layer = std::make_unique("background"); + layer->setBackgroundColor({{{ 1, 0, 0, 1 }}}); + map.addLayer(std::move(layer)); + + test::checkImage("test/fixtures/map/add_layer", test::render(map)); +} + +TEST(Map, RemoveLayer) { + MapTest test; + + Map map(test.view, test.fileSource, MapMode::Still); + map.setStyleJSON(util::read_file("test/fixtures/api/empty.json"), ""); + + auto layer = std::make_unique("background"); + layer->setBackgroundColor({{{ 1, 0, 0, 1 }}}); + map.addLayer(std::move(layer)); + map.removeLayer("background"); + + test::checkImage("test/fixtures/map/remove_layer", test::render(map)); +} From cadc617c762d453cca2c9bac41f9c1db984c5fac Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 25 Apr 2016 13:59:09 -0700 Subject: [PATCH 4/8] [core] Introduce PropertyValue PropertyValue represents the three possible types of style property value: undefined, constant, or function. --- include/mbgl/layer/background_layer.hpp | 13 +- include/mbgl/layer/circle_layer.hpp | 25 +- include/mbgl/layer/fill_layer.hpp | 29 +- include/mbgl/layer/line_layer.hpp | 57 +-- include/mbgl/layer/raster_layer.hpp | 29 +- include/mbgl/layer/symbol_layer.hpp | 181 ++++----- include/mbgl/style/types.hpp | 3 - scripts/generate-style-code.js | 32 +- src/mbgl/layer/background_layer.cpp | 24 +- .../layer/background_layer_properties.hpp | 2 +- src/mbgl/layer/circle_layer.cpp | 48 +-- src/mbgl/layer/fill_layer.cpp | 56 +-- src/mbgl/layer/fill_layer_properties.hpp | 2 +- src/mbgl/layer/line_layer.cpp | 112 +++--- src/mbgl/layer/line_layer_properties.hpp | 4 +- src/mbgl/layer/raster_layer.cpp | 56 +-- src/mbgl/layer/symbol_layer.cpp | 360 +++++++++--------- src/mbgl/style/function_evaluator.hpp | 42 -- src/mbgl/style/layout_property.hpp | 30 +- src/mbgl/style/paint_property.hpp | 53 +-- ...n_evaluator.cpp => property_evaluator.cpp} | 99 +++-- src/mbgl/style/property_evaluator.hpp | 63 +++ src/mbgl/style/property_parsing.hpp | 7 +- src/mbgl/style/property_value.hpp | 36 ++ src/mbgl/style/style_parser.cpp | 13 +- test/style/functions.cpp | 75 ++-- 26 files changed, 767 insertions(+), 684 deletions(-) delete mode 100644 src/mbgl/style/function_evaluator.hpp rename src/mbgl/style/{function_evaluator.cpp => property_evaluator.cpp} (56%) create mode 100644 src/mbgl/style/property_evaluator.hpp create mode 100644 src/mbgl/style/property_value.hpp diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/layer/background_layer.hpp index 79f24990e6a..211597f6ead 100644 --- a/include/mbgl/layer/background_layer.hpp +++ b/include/mbgl/layer/background_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include namespace mbgl { @@ -13,14 +14,14 @@ class BackgroundLayer : public Layer { // Paint properties - Function getBackgroundColor() const; - void setBackgroundColor(Function); + PropertyValue getBackgroundColor() const; + void setBackgroundColor(PropertyValue); - Function getBackgroundPattern() const; - void setBackgroundPattern(Function); + PropertyValue getBackgroundPattern() const; + void setBackgroundPattern(PropertyValue); - Function getBackgroundOpacity() const; - void setBackgroundOpacity(Function); + PropertyValue getBackgroundOpacity() const; + void setBackgroundOpacity(PropertyValue); // Private implementation diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/layer/circle_layer.hpp index 14b9da895f4..28e5c2fa7ac 100644 --- a/include/mbgl/layer/circle_layer.hpp +++ b/include/mbgl/layer/circle_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include namespace mbgl { @@ -19,23 +20,23 @@ class CircleLayer : public Layer { // Paint properties - Function getCircleRadius() const; - void setCircleRadius(Function); + PropertyValue getCircleRadius() const; + void setCircleRadius(PropertyValue); - Function getCircleColor() const; - void setCircleColor(Function); + PropertyValue getCircleColor() const; + void setCircleColor(PropertyValue); - Function getCircleBlur() const; - void setCircleBlur(Function); + PropertyValue getCircleBlur() const; + void setCircleBlur(PropertyValue); - Function getCircleOpacity() const; - void setCircleOpacity(Function); + PropertyValue getCircleOpacity() const; + void setCircleOpacity(PropertyValue); - Function> getCircleTranslate() const; - void setCircleTranslate(Function>); + PropertyValue> getCircleTranslate() const; + void setCircleTranslate(PropertyValue>); - Function getCircleTranslateAnchor() const; - void setCircleTranslateAnchor(Function); + PropertyValue getCircleTranslateAnchor() const; + void setCircleTranslateAnchor(PropertyValue); // Private implementation diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/layer/fill_layer.hpp index dc0752f9e2e..76c043957de 100644 --- a/include/mbgl/layer/fill_layer.hpp +++ b/include/mbgl/layer/fill_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include namespace mbgl { @@ -19,26 +20,26 @@ class FillLayer : public Layer { // Paint properties - Function getFillAntialias() const; - void setFillAntialias(Function); + PropertyValue getFillAntialias() const; + void setFillAntialias(PropertyValue); - Function getFillOpacity() const; - void setFillOpacity(Function); + PropertyValue getFillOpacity() const; + void setFillOpacity(PropertyValue); - Function getFillColor() const; - void setFillColor(Function); + PropertyValue getFillColor() const; + void setFillColor(PropertyValue); - Function getFillOutlineColor() const; - void setFillOutlineColor(Function); + PropertyValue getFillOutlineColor() const; + void setFillOutlineColor(PropertyValue); - Function> getFillTranslate() const; - void setFillTranslate(Function>); + PropertyValue> getFillTranslate() const; + void setFillTranslate(PropertyValue>); - Function getFillTranslateAnchor() const; - void setFillTranslateAnchor(Function); + PropertyValue getFillTranslateAnchor() const; + void setFillTranslateAnchor(PropertyValue); - Function getFillPattern() const; - void setFillPattern(Function); + PropertyValue getFillPattern() const; + void setFillPattern(PropertyValue); // Private implementation diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/layer/line_layer.hpp index 0f898d3c697..b4387991163 100644 --- a/include/mbgl/layer/line_layer.hpp +++ b/include/mbgl/layer/line_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include @@ -21,49 +22,49 @@ class LineLayer : public Layer { // Layout properties - Function getLineCap() const; - void setLineCap(Function); + PropertyValue getLineCap() const; + void setLineCap(PropertyValue); - Function getLineJoin() const; - void setLineJoin(Function); + PropertyValue getLineJoin() const; + void setLineJoin(PropertyValue); - Function getLineMiterLimit() const; - void setLineMiterLimit(Function); + PropertyValue getLineMiterLimit() const; + void setLineMiterLimit(PropertyValue); - Function getLineRoundLimit() const; - void setLineRoundLimit(Function); + PropertyValue getLineRoundLimit() const; + void setLineRoundLimit(PropertyValue); // Paint properties - Function getLineOpacity() const; - void setLineOpacity(Function); + PropertyValue getLineOpacity() const; + void setLineOpacity(PropertyValue); - Function getLineColor() const; - void setLineColor(Function); + PropertyValue getLineColor() const; + void setLineColor(PropertyValue); - Function> getLineTranslate() const; - void setLineTranslate(Function>); + PropertyValue> getLineTranslate() const; + void setLineTranslate(PropertyValue>); - Function getLineTranslateAnchor() const; - void setLineTranslateAnchor(Function); + PropertyValue getLineTranslateAnchor() const; + void setLineTranslateAnchor(PropertyValue); - Function getLineWidth() const; - void setLineWidth(Function); + PropertyValue getLineWidth() const; + void setLineWidth(PropertyValue); - Function getLineGapWidth() const; - void setLineGapWidth(Function); + PropertyValue getLineGapWidth() const; + void setLineGapWidth(PropertyValue); - Function getLineOffset() const; - void setLineOffset(Function); + PropertyValue getLineOffset() const; + void setLineOffset(PropertyValue); - Function getLineBlur() const; - void setLineBlur(Function); + PropertyValue getLineBlur() const; + void setLineBlur(PropertyValue); - Function> getLineDasharray() const; - void setLineDasharray(Function>); + PropertyValue> getLineDasharray() const; + void setLineDasharray(PropertyValue>); - Function getLinePattern() const; - void setLinePattern(Function); + PropertyValue getLinePattern() const; + void setLinePattern(PropertyValue); // Private implementation diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/layer/raster_layer.hpp index 9dc27a274ab..5d747737c05 100644 --- a/include/mbgl/layer/raster_layer.hpp +++ b/include/mbgl/layer/raster_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include namespace mbgl { @@ -18,26 +19,26 @@ class RasterLayer : public Layer { // Paint properties - Function getRasterOpacity() const; - void setRasterOpacity(Function); + PropertyValue getRasterOpacity() const; + void setRasterOpacity(PropertyValue); - Function getRasterHueRotate() const; - void setRasterHueRotate(Function); + PropertyValue getRasterHueRotate() const; + void setRasterHueRotate(PropertyValue); - Function getRasterBrightnessMin() const; - void setRasterBrightnessMin(Function); + PropertyValue getRasterBrightnessMin() const; + void setRasterBrightnessMin(PropertyValue); - Function getRasterBrightnessMax() const; - void setRasterBrightnessMax(Function); + PropertyValue getRasterBrightnessMax() const; + void setRasterBrightnessMax(PropertyValue); - Function getRasterSaturation() const; - void setRasterSaturation(Function); + PropertyValue getRasterSaturation() const; + void setRasterSaturation(PropertyValue); - Function getRasterContrast() const; - void setRasterContrast(Function); + PropertyValue getRasterContrast() const; + void setRasterContrast(PropertyValue); - Function getRasterFadeDuration() const; - void setRasterFadeDuration(Function); + PropertyValue getRasterFadeDuration() const; + void setRasterFadeDuration(PropertyValue); // Private implementation diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/layer/symbol_layer.hpp index f9b29563907..23395152014 100644 --- a/include/mbgl/layer/symbol_layer.hpp +++ b/include/mbgl/layer/symbol_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include @@ -21,142 +22,142 @@ class SymbolLayer : public Layer { // Layout properties - Function getSymbolPlacement() const; - void setSymbolPlacement(Function); + PropertyValue getSymbolPlacement() const; + void setSymbolPlacement(PropertyValue); - Function getSymbolSpacing() const; - void setSymbolSpacing(Function); + PropertyValue getSymbolSpacing() const; + void setSymbolSpacing(PropertyValue); - Function getSymbolAvoidEdges() const; - void setSymbolAvoidEdges(Function); + PropertyValue getSymbolAvoidEdges() const; + void setSymbolAvoidEdges(PropertyValue); - Function getIconAllowOverlap() const; - void setIconAllowOverlap(Function); + PropertyValue getIconAllowOverlap() const; + void setIconAllowOverlap(PropertyValue); - Function getIconIgnorePlacement() const; - void setIconIgnorePlacement(Function); + PropertyValue getIconIgnorePlacement() const; + void setIconIgnorePlacement(PropertyValue); - Function getIconOptional() const; - void setIconOptional(Function); + PropertyValue getIconOptional() const; + void setIconOptional(PropertyValue); - Function getIconRotationAlignment() const; - void setIconRotationAlignment(Function); + PropertyValue getIconRotationAlignment() const; + void setIconRotationAlignment(PropertyValue); - Function getIconSize() const; - void setIconSize(Function); + PropertyValue getIconSize() const; + void setIconSize(PropertyValue); - Function getIconImage() const; - void setIconImage(Function); + PropertyValue getIconImage() const; + void setIconImage(PropertyValue); - Function getIconRotate() const; - void setIconRotate(Function); + PropertyValue getIconRotate() const; + void setIconRotate(PropertyValue); - Function getIconPadding() const; - void setIconPadding(Function); + PropertyValue getIconPadding() const; + void setIconPadding(PropertyValue); - Function getIconKeepUpright() const; - void setIconKeepUpright(Function); + PropertyValue getIconKeepUpright() const; + void setIconKeepUpright(PropertyValue); - Function> getIconOffset() const; - void setIconOffset(Function>); + PropertyValue> getIconOffset() const; + void setIconOffset(PropertyValue>); - Function getTextRotationAlignment() const; - void setTextRotationAlignment(Function); + PropertyValue getTextRotationAlignment() const; + void setTextRotationAlignment(PropertyValue); - Function getTextField() const; - void setTextField(Function); + PropertyValue getTextField() const; + void setTextField(PropertyValue); - Function> getTextFont() const; - void setTextFont(Function>); + PropertyValue> getTextFont() const; + void setTextFont(PropertyValue>); - Function getTextSize() const; - void setTextSize(Function); + PropertyValue getTextSize() const; + void setTextSize(PropertyValue); - Function getTextMaxWidth() const; - void setTextMaxWidth(Function); + PropertyValue getTextMaxWidth() const; + void setTextMaxWidth(PropertyValue); - Function getTextLineHeight() const; - void setTextLineHeight(Function); + PropertyValue getTextLineHeight() const; + void setTextLineHeight(PropertyValue); - Function getTextLetterSpacing() const; - void setTextLetterSpacing(Function); + PropertyValue getTextLetterSpacing() const; + void setTextLetterSpacing(PropertyValue); - Function getTextJustify() const; - void setTextJustify(Function); + PropertyValue getTextJustify() const; + void setTextJustify(PropertyValue); - Function getTextAnchor() const; - void setTextAnchor(Function); + PropertyValue getTextAnchor() const; + void setTextAnchor(PropertyValue); - Function getTextMaxAngle() const; - void setTextMaxAngle(Function); + PropertyValue getTextMaxAngle() const; + void setTextMaxAngle(PropertyValue); - Function getTextRotate() const; - void setTextRotate(Function); + PropertyValue getTextRotate() const; + void setTextRotate(PropertyValue); - Function getTextPadding() const; - void setTextPadding(Function); + PropertyValue getTextPadding() const; + void setTextPadding(PropertyValue); - Function getTextKeepUpright() const; - void setTextKeepUpright(Function); + PropertyValue getTextKeepUpright() const; + void setTextKeepUpright(PropertyValue); - Function getTextTransform() const; - void setTextTransform(Function); + PropertyValue getTextTransform() const; + void setTextTransform(PropertyValue); - Function> getTextOffset() const; - void setTextOffset(Function>); + PropertyValue> getTextOffset() const; + void setTextOffset(PropertyValue>); - Function getTextAllowOverlap() const; - void setTextAllowOverlap(Function); + PropertyValue getTextAllowOverlap() const; + void setTextAllowOverlap(PropertyValue); - Function getTextIgnorePlacement() const; - void setTextIgnorePlacement(Function); + PropertyValue getTextIgnorePlacement() const; + void setTextIgnorePlacement(PropertyValue); - Function getTextOptional() const; - void setTextOptional(Function); + PropertyValue getTextOptional() const; + void setTextOptional(PropertyValue); // Paint properties - Function getIconOpacity() const; - void setIconOpacity(Function); + PropertyValue getIconOpacity() const; + void setIconOpacity(PropertyValue); - Function getIconColor() const; - void setIconColor(Function); + PropertyValue getIconColor() const; + void setIconColor(PropertyValue); - Function getIconHaloColor() const; - void setIconHaloColor(Function); + PropertyValue getIconHaloColor() const; + void setIconHaloColor(PropertyValue); - Function getIconHaloWidth() const; - void setIconHaloWidth(Function); + PropertyValue getIconHaloWidth() const; + void setIconHaloWidth(PropertyValue); - Function getIconHaloBlur() const; - void setIconHaloBlur(Function); + PropertyValue getIconHaloBlur() const; + void setIconHaloBlur(PropertyValue); - Function> getIconTranslate() const; - void setIconTranslate(Function>); + PropertyValue> getIconTranslate() const; + void setIconTranslate(PropertyValue>); - Function getIconTranslateAnchor() const; - void setIconTranslateAnchor(Function); + PropertyValue getIconTranslateAnchor() const; + void setIconTranslateAnchor(PropertyValue); - Function getTextOpacity() const; - void setTextOpacity(Function); + PropertyValue getTextOpacity() const; + void setTextOpacity(PropertyValue); - Function getTextColor() const; - void setTextColor(Function); + PropertyValue getTextColor() const; + void setTextColor(PropertyValue); - Function getTextHaloColor() const; - void setTextHaloColor(Function); + PropertyValue getTextHaloColor() const; + void setTextHaloColor(PropertyValue); - Function getTextHaloWidth() const; - void setTextHaloWidth(Function); + PropertyValue getTextHaloWidth() const; + void setTextHaloWidth(PropertyValue); - Function getTextHaloBlur() const; - void setTextHaloBlur(Function); + PropertyValue getTextHaloBlur() const; + void setTextHaloBlur(PropertyValue); - Function> getTextTranslate() const; - void setTextTranslate(Function>); + PropertyValue> getTextTranslate() const; + void setTextTranslate(PropertyValue>); - Function getTextTranslateAnchor() const; - void setTextTranslateAnchor(Function); + PropertyValue getTextTranslateAnchor() const; + void setTextTranslateAnchor(PropertyValue); // Private implementation diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index ea09ccfb0cb..56f3570357f 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -27,9 +27,6 @@ class Function { using Stop = std::pair; using Stops = std::vector; - Function(const T& constant) - : stops({{ 0, constant }}) {} - explicit Function(const Stops& stops_, float base_) : base(base_), stops(stops_) {} diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 2904a1429af..b26e0520f63 100644 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -77,10 +77,12 @@ const layerHpp = ejs.compile(`<% #pragma once #include -<% if (type === 'line' || type === 'symbol') { %> +#include + +<% if (type === 'line' || type === 'symbol') { -%> #include -<% } -%> +<% } -%> namespace mbgl { class <%- camelize(type) %>Layer : public Layer { @@ -106,16 +108,16 @@ public: // Layout properties <% for (const property of layoutProperties) { -%> - Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; - void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>); <% } -%> <% } -%> // Paint properties <% for (const property of paintProperties) { -%> - Function<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; - void set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>>); + PropertyValue<<%- propertyType(property) %>> get<%- camelize(property.name) %>() const; + void set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>>); <% } -%> // Private implementation @@ -194,23 +196,23 @@ const std::string& <%- camelize(type) %>Layer::getSourceLayer() const { // Layout properties <% for (const property of layoutProperties) { -%> -Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return *impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue; +PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.get(); } -void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { - impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.parsedValue = value; +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { + impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); } <% } -%> // Paint properties <% for (const property of paintProperties) { %> -Function<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { - return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.at(ClassID::Default); +PropertyValue<<%- propertyType(property) %>> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const { + return impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.get(); } -void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(Function<<%- propertyType(property) %>> value) { - impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.values.emplace(ClassID::Default, value); +void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue<<%- propertyType(property) %>> value) { + impl->paint.<%- camelizeWithLeadingLowercase(property.name) %>.set(value); } <% } -%> @@ -255,7 +257,7 @@ public: <% for (const property of paintProperties) { -%> <% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> - PaintProperty<<%- propertyType(property) %>, CrossFadedFunctionEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; + PaintProperty<<%- propertyType(property) %>, CrossFadedPropertyEvaluator> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; <% } else if (property.name === 'fill-outline-color') { -%> PaintProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { {{ 0, 0, 0, -1 }} }; <% } else { -%> diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/layer/background_layer.cpp index 8d097344fc7..36cf6be07cf 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/layer/background_layer.cpp @@ -28,28 +28,28 @@ std::unique_ptr BackgroundLayer::Impl::clone() const { // Paint properties -Function BackgroundLayer::getBackgroundColor() const { - return impl->paint.backgroundColor.values.at(ClassID::Default); +PropertyValue BackgroundLayer::getBackgroundColor() const { + return impl->paint.backgroundColor.get(); } -void BackgroundLayer::setBackgroundColor(Function value) { - impl->paint.backgroundColor.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundColor(PropertyValue value) { + impl->paint.backgroundColor.set(value); } -Function BackgroundLayer::getBackgroundPattern() const { - return impl->paint.backgroundPattern.values.at(ClassID::Default); +PropertyValue BackgroundLayer::getBackgroundPattern() const { + return impl->paint.backgroundPattern.get(); } -void BackgroundLayer::setBackgroundPattern(Function value) { - impl->paint.backgroundPattern.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundPattern(PropertyValue value) { + impl->paint.backgroundPattern.set(value); } -Function BackgroundLayer::getBackgroundOpacity() const { - return impl->paint.backgroundOpacity.values.at(ClassID::Default); +PropertyValue BackgroundLayer::getBackgroundOpacity() const { + return impl->paint.backgroundOpacity.get(); } -void BackgroundLayer::setBackgroundOpacity(Function value) { - impl->paint.backgroundOpacity.values.emplace(ClassID::Default, value); +void BackgroundLayer::setBackgroundOpacity(PropertyValue value) { + impl->paint.backgroundOpacity.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.hpp b/src/mbgl/layer/background_layer_properties.hpp index 5e388a79284..20db9b22fbf 100644 --- a/src/mbgl/layer/background_layer_properties.hpp +++ b/src/mbgl/layer/background_layer_properties.hpp @@ -18,7 +18,7 @@ class BackgroundPaintProperties { bool recalculate(const StyleCalculationParameters&); PaintProperty backgroundColor { {{ 0, 0, 0, 1 }} }; - PaintProperty backgroundPattern { "" }; + PaintProperty backgroundPattern { "" }; PaintProperty backgroundOpacity { 1 }; }; diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index bf385c997c7..b1ca06dff78 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -42,52 +42,52 @@ const std::string& CircleLayer::getSourceLayer() const { // Paint properties -Function CircleLayer::getCircleRadius() const { - return impl->paint.circleRadius.values.at(ClassID::Default); +PropertyValue CircleLayer::getCircleRadius() const { + return impl->paint.circleRadius.get(); } -void CircleLayer::setCircleRadius(Function value) { - impl->paint.circleRadius.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleRadius(PropertyValue value) { + impl->paint.circleRadius.set(value); } -Function CircleLayer::getCircleColor() const { - return impl->paint.circleColor.values.at(ClassID::Default); +PropertyValue CircleLayer::getCircleColor() const { + return impl->paint.circleColor.get(); } -void CircleLayer::setCircleColor(Function value) { - impl->paint.circleColor.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleColor(PropertyValue value) { + impl->paint.circleColor.set(value); } -Function CircleLayer::getCircleBlur() const { - return impl->paint.circleBlur.values.at(ClassID::Default); +PropertyValue CircleLayer::getCircleBlur() const { + return impl->paint.circleBlur.get(); } -void CircleLayer::setCircleBlur(Function value) { - impl->paint.circleBlur.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleBlur(PropertyValue value) { + impl->paint.circleBlur.set(value); } -Function CircleLayer::getCircleOpacity() const { - return impl->paint.circleOpacity.values.at(ClassID::Default); +PropertyValue CircleLayer::getCircleOpacity() const { + return impl->paint.circleOpacity.get(); } -void CircleLayer::setCircleOpacity(Function value) { - impl->paint.circleOpacity.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleOpacity(PropertyValue value) { + impl->paint.circleOpacity.set(value); } -Function> CircleLayer::getCircleTranslate() const { - return impl->paint.circleTranslate.values.at(ClassID::Default); +PropertyValue> CircleLayer::getCircleTranslate() const { + return impl->paint.circleTranslate.get(); } -void CircleLayer::setCircleTranslate(Function> value) { - impl->paint.circleTranslate.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleTranslate(PropertyValue> value) { + impl->paint.circleTranslate.set(value); } -Function CircleLayer::getCircleTranslateAnchor() const { - return impl->paint.circleTranslateAnchor.values.at(ClassID::Default); +PropertyValue CircleLayer::getCircleTranslateAnchor() const { + return impl->paint.circleTranslateAnchor.get(); } -void CircleLayer::setCircleTranslateAnchor(Function value) { - impl->paint.circleTranslateAnchor.values.emplace(ClassID::Default, value); +void CircleLayer::setCircleTranslateAnchor(PropertyValue value) { + impl->paint.circleTranslateAnchor.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index 9a376089df6..f7a9418c0e1 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -42,60 +42,60 @@ const std::string& FillLayer::getSourceLayer() const { // Paint properties -Function FillLayer::getFillAntialias() const { - return impl->paint.fillAntialias.values.at(ClassID::Default); +PropertyValue FillLayer::getFillAntialias() const { + return impl->paint.fillAntialias.get(); } -void FillLayer::setFillAntialias(Function value) { - impl->paint.fillAntialias.values.emplace(ClassID::Default, value); +void FillLayer::setFillAntialias(PropertyValue value) { + impl->paint.fillAntialias.set(value); } -Function FillLayer::getFillOpacity() const { - return impl->paint.fillOpacity.values.at(ClassID::Default); +PropertyValue FillLayer::getFillOpacity() const { + return impl->paint.fillOpacity.get(); } -void FillLayer::setFillOpacity(Function value) { - impl->paint.fillOpacity.values.emplace(ClassID::Default, value); +void FillLayer::setFillOpacity(PropertyValue value) { + impl->paint.fillOpacity.set(value); } -Function FillLayer::getFillColor() const { - return impl->paint.fillColor.values.at(ClassID::Default); +PropertyValue FillLayer::getFillColor() const { + return impl->paint.fillColor.get(); } -void FillLayer::setFillColor(Function value) { - impl->paint.fillColor.values.emplace(ClassID::Default, value); +void FillLayer::setFillColor(PropertyValue value) { + impl->paint.fillColor.set(value); } -Function FillLayer::getFillOutlineColor() const { - return impl->paint.fillOutlineColor.values.at(ClassID::Default); +PropertyValue FillLayer::getFillOutlineColor() const { + return impl->paint.fillOutlineColor.get(); } -void FillLayer::setFillOutlineColor(Function value) { - impl->paint.fillOutlineColor.values.emplace(ClassID::Default, value); +void FillLayer::setFillOutlineColor(PropertyValue value) { + impl->paint.fillOutlineColor.set(value); } -Function> FillLayer::getFillTranslate() const { - return impl->paint.fillTranslate.values.at(ClassID::Default); +PropertyValue> FillLayer::getFillTranslate() const { + return impl->paint.fillTranslate.get(); } -void FillLayer::setFillTranslate(Function> value) { - impl->paint.fillTranslate.values.emplace(ClassID::Default, value); +void FillLayer::setFillTranslate(PropertyValue> value) { + impl->paint.fillTranslate.set(value); } -Function FillLayer::getFillTranslateAnchor() const { - return impl->paint.fillTranslateAnchor.values.at(ClassID::Default); +PropertyValue FillLayer::getFillTranslateAnchor() const { + return impl->paint.fillTranslateAnchor.get(); } -void FillLayer::setFillTranslateAnchor(Function value) { - impl->paint.fillTranslateAnchor.values.emplace(ClassID::Default, value); +void FillLayer::setFillTranslateAnchor(PropertyValue value) { + impl->paint.fillTranslateAnchor.set(value); } -Function FillLayer::getFillPattern() const { - return impl->paint.fillPattern.values.at(ClassID::Default); +PropertyValue FillLayer::getFillPattern() const { + return impl->paint.fillPattern.get(); } -void FillLayer::setFillPattern(Function value) { - impl->paint.fillPattern.values.emplace(ClassID::Default, value); +void FillLayer::setFillPattern(PropertyValue value) { + impl->paint.fillPattern.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.hpp b/src/mbgl/layer/fill_layer_properties.hpp index fb327a2d6ca..2ae67ef0a09 100644 --- a/src/mbgl/layer/fill_layer_properties.hpp +++ b/src/mbgl/layer/fill_layer_properties.hpp @@ -23,7 +23,7 @@ class FillPaintProperties { PaintProperty fillOutlineColor { {{ 0, 0, 0, -1 }} }; PaintProperty> fillTranslate { {{ 0, 0 }} }; PaintProperty fillTranslateAnchor { TranslateAnchorType::Map }; - PaintProperty fillPattern { "" }; + PaintProperty fillPattern { "" }; }; } // namespace mbgl diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index 0064a0b8dae..c77a5c3e830 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -39,115 +39,115 @@ const std::string& LineLayer::getSourceLayer() const { // Layout properties -Function LineLayer::getLineCap() const { - return *impl->layout.lineCap.parsedValue; +PropertyValue LineLayer::getLineCap() const { + return impl->layout.lineCap.get(); } -void LineLayer::setLineCap(Function value) { - impl->layout.lineCap.parsedValue = value; +void LineLayer::setLineCap(PropertyValue value) { + impl->layout.lineCap.set(value); } -Function LineLayer::getLineJoin() const { - return *impl->layout.lineJoin.parsedValue; +PropertyValue LineLayer::getLineJoin() const { + return impl->layout.lineJoin.get(); } -void LineLayer::setLineJoin(Function value) { - impl->layout.lineJoin.parsedValue = value; +void LineLayer::setLineJoin(PropertyValue value) { + impl->layout.lineJoin.set(value); } -Function LineLayer::getLineMiterLimit() const { - return *impl->layout.lineMiterLimit.parsedValue; +PropertyValue LineLayer::getLineMiterLimit() const { + return impl->layout.lineMiterLimit.get(); } -void LineLayer::setLineMiterLimit(Function value) { - impl->layout.lineMiterLimit.parsedValue = value; +void LineLayer::setLineMiterLimit(PropertyValue value) { + impl->layout.lineMiterLimit.set(value); } -Function LineLayer::getLineRoundLimit() const { - return *impl->layout.lineRoundLimit.parsedValue; +PropertyValue LineLayer::getLineRoundLimit() const { + return impl->layout.lineRoundLimit.get(); } -void LineLayer::setLineRoundLimit(Function value) { - impl->layout.lineRoundLimit.parsedValue = value; +void LineLayer::setLineRoundLimit(PropertyValue value) { + impl->layout.lineRoundLimit.set(value); } // Paint properties -Function LineLayer::getLineOpacity() const { - return impl->paint.lineOpacity.values.at(ClassID::Default); +PropertyValue LineLayer::getLineOpacity() const { + return impl->paint.lineOpacity.get(); } -void LineLayer::setLineOpacity(Function value) { - impl->paint.lineOpacity.values.emplace(ClassID::Default, value); +void LineLayer::setLineOpacity(PropertyValue value) { + impl->paint.lineOpacity.set(value); } -Function LineLayer::getLineColor() const { - return impl->paint.lineColor.values.at(ClassID::Default); +PropertyValue LineLayer::getLineColor() const { + return impl->paint.lineColor.get(); } -void LineLayer::setLineColor(Function value) { - impl->paint.lineColor.values.emplace(ClassID::Default, value); +void LineLayer::setLineColor(PropertyValue value) { + impl->paint.lineColor.set(value); } -Function> LineLayer::getLineTranslate() const { - return impl->paint.lineTranslate.values.at(ClassID::Default); +PropertyValue> LineLayer::getLineTranslate() const { + return impl->paint.lineTranslate.get(); } -void LineLayer::setLineTranslate(Function> value) { - impl->paint.lineTranslate.values.emplace(ClassID::Default, value); +void LineLayer::setLineTranslate(PropertyValue> value) { + impl->paint.lineTranslate.set(value); } -Function LineLayer::getLineTranslateAnchor() const { - return impl->paint.lineTranslateAnchor.values.at(ClassID::Default); +PropertyValue LineLayer::getLineTranslateAnchor() const { + return impl->paint.lineTranslateAnchor.get(); } -void LineLayer::setLineTranslateAnchor(Function value) { - impl->paint.lineTranslateAnchor.values.emplace(ClassID::Default, value); +void LineLayer::setLineTranslateAnchor(PropertyValue value) { + impl->paint.lineTranslateAnchor.set(value); } -Function LineLayer::getLineWidth() const { - return impl->paint.lineWidth.values.at(ClassID::Default); +PropertyValue LineLayer::getLineWidth() const { + return impl->paint.lineWidth.get(); } -void LineLayer::setLineWidth(Function value) { - impl->paint.lineWidth.values.emplace(ClassID::Default, value); +void LineLayer::setLineWidth(PropertyValue value) { + impl->paint.lineWidth.set(value); } -Function LineLayer::getLineGapWidth() const { - return impl->paint.lineGapWidth.values.at(ClassID::Default); +PropertyValue LineLayer::getLineGapWidth() const { + return impl->paint.lineGapWidth.get(); } -void LineLayer::setLineGapWidth(Function value) { - impl->paint.lineGapWidth.values.emplace(ClassID::Default, value); +void LineLayer::setLineGapWidth(PropertyValue value) { + impl->paint.lineGapWidth.set(value); } -Function LineLayer::getLineOffset() const { - return impl->paint.lineOffset.values.at(ClassID::Default); +PropertyValue LineLayer::getLineOffset() const { + return impl->paint.lineOffset.get(); } -void LineLayer::setLineOffset(Function value) { - impl->paint.lineOffset.values.emplace(ClassID::Default, value); +void LineLayer::setLineOffset(PropertyValue value) { + impl->paint.lineOffset.set(value); } -Function LineLayer::getLineBlur() const { - return impl->paint.lineBlur.values.at(ClassID::Default); +PropertyValue LineLayer::getLineBlur() const { + return impl->paint.lineBlur.get(); } -void LineLayer::setLineBlur(Function value) { - impl->paint.lineBlur.values.emplace(ClassID::Default, value); +void LineLayer::setLineBlur(PropertyValue value) { + impl->paint.lineBlur.set(value); } -Function> LineLayer::getLineDasharray() const { - return impl->paint.lineDasharray.values.at(ClassID::Default); +PropertyValue> LineLayer::getLineDasharray() const { + return impl->paint.lineDasharray.get(); } -void LineLayer::setLineDasharray(Function> value) { - impl->paint.lineDasharray.values.emplace(ClassID::Default, value); +void LineLayer::setLineDasharray(PropertyValue> value) { + impl->paint.lineDasharray.set(value); } -Function LineLayer::getLinePattern() const { - return impl->paint.linePattern.values.at(ClassID::Default); +PropertyValue LineLayer::getLinePattern() const { + return impl->paint.linePattern.get(); } -void LineLayer::setLinePattern(Function value) { - impl->paint.linePattern.values.emplace(ClassID::Default, value); +void LineLayer::setLinePattern(PropertyValue value) { + impl->paint.linePattern.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.hpp b/src/mbgl/layer/line_layer_properties.hpp index ae87d6da5e6..f4dad055bd6 100644 --- a/src/mbgl/layer/line_layer_properties.hpp +++ b/src/mbgl/layer/line_layer_properties.hpp @@ -36,8 +36,8 @@ class LinePaintProperties { PaintProperty lineGapWidth { 0 }; PaintProperty lineOffset { 0 }; PaintProperty lineBlur { 0 }; - PaintProperty, CrossFadedFunctionEvaluator> lineDasharray { { } }; - PaintProperty linePattern { "" }; + PaintProperty, CrossFadedPropertyEvaluator> lineDasharray { { } }; + PaintProperty linePattern { "" }; }; } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/layer/raster_layer.cpp index 1ec2e4c0d42..661c44b7d5d 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/layer/raster_layer.cpp @@ -37,60 +37,60 @@ const std::string& RasterLayer::getSourceID() const { // Paint properties -Function RasterLayer::getRasterOpacity() const { - return impl->paint.rasterOpacity.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterOpacity() const { + return impl->paint.rasterOpacity.get(); } -void RasterLayer::setRasterOpacity(Function value) { - impl->paint.rasterOpacity.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterOpacity(PropertyValue value) { + impl->paint.rasterOpacity.set(value); } -Function RasterLayer::getRasterHueRotate() const { - return impl->paint.rasterHueRotate.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterHueRotate() const { + return impl->paint.rasterHueRotate.get(); } -void RasterLayer::setRasterHueRotate(Function value) { - impl->paint.rasterHueRotate.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterHueRotate(PropertyValue value) { + impl->paint.rasterHueRotate.set(value); } -Function RasterLayer::getRasterBrightnessMin() const { - return impl->paint.rasterBrightnessMin.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterBrightnessMin() const { + return impl->paint.rasterBrightnessMin.get(); } -void RasterLayer::setRasterBrightnessMin(Function value) { - impl->paint.rasterBrightnessMin.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterBrightnessMin(PropertyValue value) { + impl->paint.rasterBrightnessMin.set(value); } -Function RasterLayer::getRasterBrightnessMax() const { - return impl->paint.rasterBrightnessMax.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterBrightnessMax() const { + return impl->paint.rasterBrightnessMax.get(); } -void RasterLayer::setRasterBrightnessMax(Function value) { - impl->paint.rasterBrightnessMax.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterBrightnessMax(PropertyValue value) { + impl->paint.rasterBrightnessMax.set(value); } -Function RasterLayer::getRasterSaturation() const { - return impl->paint.rasterSaturation.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterSaturation() const { + return impl->paint.rasterSaturation.get(); } -void RasterLayer::setRasterSaturation(Function value) { - impl->paint.rasterSaturation.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterSaturation(PropertyValue value) { + impl->paint.rasterSaturation.set(value); } -Function RasterLayer::getRasterContrast() const { - return impl->paint.rasterContrast.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterContrast() const { + return impl->paint.rasterContrast.get(); } -void RasterLayer::setRasterContrast(Function value) { - impl->paint.rasterContrast.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterContrast(PropertyValue value) { + impl->paint.rasterContrast.set(value); } -Function RasterLayer::getRasterFadeDuration() const { - return impl->paint.rasterFadeDuration.values.at(ClassID::Default); +PropertyValue RasterLayer::getRasterFadeDuration() const { + return impl->paint.rasterFadeDuration.get(); } -void RasterLayer::setRasterFadeDuration(Function value) { - impl->paint.rasterFadeDuration.values.emplace(ClassID::Default, value); +void RasterLayer::setRasterFadeDuration(PropertyValue value) { + impl->paint.rasterFadeDuration.set(value); } } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index de2428fd250..6152d7104ad 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -39,336 +39,336 @@ const std::string& SymbolLayer::getSourceLayer() const { // Layout properties -Function SymbolLayer::getSymbolPlacement() const { - return *impl->layout.symbolPlacement.parsedValue; +PropertyValue SymbolLayer::getSymbolPlacement() const { + return impl->layout.symbolPlacement.get(); } -void SymbolLayer::setSymbolPlacement(Function value) { - impl->layout.symbolPlacement.parsedValue = value; +void SymbolLayer::setSymbolPlacement(PropertyValue value) { + impl->layout.symbolPlacement.set(value); } -Function SymbolLayer::getSymbolSpacing() const { - return *impl->layout.symbolSpacing.parsedValue; +PropertyValue SymbolLayer::getSymbolSpacing() const { + return impl->layout.symbolSpacing.get(); } -void SymbolLayer::setSymbolSpacing(Function value) { - impl->layout.symbolSpacing.parsedValue = value; +void SymbolLayer::setSymbolSpacing(PropertyValue value) { + impl->layout.symbolSpacing.set(value); } -Function SymbolLayer::getSymbolAvoidEdges() const { - return *impl->layout.symbolAvoidEdges.parsedValue; +PropertyValue SymbolLayer::getSymbolAvoidEdges() const { + return impl->layout.symbolAvoidEdges.get(); } -void SymbolLayer::setSymbolAvoidEdges(Function value) { - impl->layout.symbolAvoidEdges.parsedValue = value; +void SymbolLayer::setSymbolAvoidEdges(PropertyValue value) { + impl->layout.symbolAvoidEdges.set(value); } -Function SymbolLayer::getIconAllowOverlap() const { - return *impl->layout.iconAllowOverlap.parsedValue; +PropertyValue SymbolLayer::getIconAllowOverlap() const { + return impl->layout.iconAllowOverlap.get(); } -void SymbolLayer::setIconAllowOverlap(Function value) { - impl->layout.iconAllowOverlap.parsedValue = value; +void SymbolLayer::setIconAllowOverlap(PropertyValue value) { + impl->layout.iconAllowOverlap.set(value); } -Function SymbolLayer::getIconIgnorePlacement() const { - return *impl->layout.iconIgnorePlacement.parsedValue; +PropertyValue SymbolLayer::getIconIgnorePlacement() const { + return impl->layout.iconIgnorePlacement.get(); } -void SymbolLayer::setIconIgnorePlacement(Function value) { - impl->layout.iconIgnorePlacement.parsedValue = value; +void SymbolLayer::setIconIgnorePlacement(PropertyValue value) { + impl->layout.iconIgnorePlacement.set(value); } -Function SymbolLayer::getIconOptional() const { - return *impl->layout.iconOptional.parsedValue; +PropertyValue SymbolLayer::getIconOptional() const { + return impl->layout.iconOptional.get(); } -void SymbolLayer::setIconOptional(Function value) { - impl->layout.iconOptional.parsedValue = value; +void SymbolLayer::setIconOptional(PropertyValue value) { + impl->layout.iconOptional.set(value); } -Function SymbolLayer::getIconRotationAlignment() const { - return *impl->layout.iconRotationAlignment.parsedValue; +PropertyValue SymbolLayer::getIconRotationAlignment() const { + return impl->layout.iconRotationAlignment.get(); } -void SymbolLayer::setIconRotationAlignment(Function value) { - impl->layout.iconRotationAlignment.parsedValue = value; +void SymbolLayer::setIconRotationAlignment(PropertyValue value) { + impl->layout.iconRotationAlignment.set(value); } -Function SymbolLayer::getIconSize() const { - return *impl->layout.iconSize.parsedValue; +PropertyValue SymbolLayer::getIconSize() const { + return impl->layout.iconSize.get(); } -void SymbolLayer::setIconSize(Function value) { - impl->layout.iconSize.parsedValue = value; +void SymbolLayer::setIconSize(PropertyValue value) { + impl->layout.iconSize.set(value); } -Function SymbolLayer::getIconImage() const { - return *impl->layout.iconImage.parsedValue; +PropertyValue SymbolLayer::getIconImage() const { + return impl->layout.iconImage.get(); } -void SymbolLayer::setIconImage(Function value) { - impl->layout.iconImage.parsedValue = value; +void SymbolLayer::setIconImage(PropertyValue value) { + impl->layout.iconImage.set(value); } -Function SymbolLayer::getIconRotate() const { - return *impl->layout.iconRotate.parsedValue; +PropertyValue SymbolLayer::getIconRotate() const { + return impl->layout.iconRotate.get(); } -void SymbolLayer::setIconRotate(Function value) { - impl->layout.iconRotate.parsedValue = value; +void SymbolLayer::setIconRotate(PropertyValue value) { + impl->layout.iconRotate.set(value); } -Function SymbolLayer::getIconPadding() const { - return *impl->layout.iconPadding.parsedValue; +PropertyValue SymbolLayer::getIconPadding() const { + return impl->layout.iconPadding.get(); } -void SymbolLayer::setIconPadding(Function value) { - impl->layout.iconPadding.parsedValue = value; +void SymbolLayer::setIconPadding(PropertyValue value) { + impl->layout.iconPadding.set(value); } -Function SymbolLayer::getIconKeepUpright() const { - return *impl->layout.iconKeepUpright.parsedValue; +PropertyValue SymbolLayer::getIconKeepUpright() const { + return impl->layout.iconKeepUpright.get(); } -void SymbolLayer::setIconKeepUpright(Function value) { - impl->layout.iconKeepUpright.parsedValue = value; +void SymbolLayer::setIconKeepUpright(PropertyValue value) { + impl->layout.iconKeepUpright.set(value); } -Function> SymbolLayer::getIconOffset() const { - return *impl->layout.iconOffset.parsedValue; +PropertyValue> SymbolLayer::getIconOffset() const { + return impl->layout.iconOffset.get(); } -void SymbolLayer::setIconOffset(Function> value) { - impl->layout.iconOffset.parsedValue = value; +void SymbolLayer::setIconOffset(PropertyValue> value) { + impl->layout.iconOffset.set(value); } -Function SymbolLayer::getTextRotationAlignment() const { - return *impl->layout.textRotationAlignment.parsedValue; +PropertyValue SymbolLayer::getTextRotationAlignment() const { + return impl->layout.textRotationAlignment.get(); } -void SymbolLayer::setTextRotationAlignment(Function value) { - impl->layout.textRotationAlignment.parsedValue = value; +void SymbolLayer::setTextRotationAlignment(PropertyValue value) { + impl->layout.textRotationAlignment.set(value); } -Function SymbolLayer::getTextField() const { - return *impl->layout.textField.parsedValue; +PropertyValue SymbolLayer::getTextField() const { + return impl->layout.textField.get(); } -void SymbolLayer::setTextField(Function value) { - impl->layout.textField.parsedValue = value; +void SymbolLayer::setTextField(PropertyValue value) { + impl->layout.textField.set(value); } -Function> SymbolLayer::getTextFont() const { - return *impl->layout.textFont.parsedValue; +PropertyValue> SymbolLayer::getTextFont() const { + return impl->layout.textFont.get(); } -void SymbolLayer::setTextFont(Function> value) { - impl->layout.textFont.parsedValue = value; +void SymbolLayer::setTextFont(PropertyValue> value) { + impl->layout.textFont.set(value); } -Function SymbolLayer::getTextSize() const { - return *impl->layout.textSize.parsedValue; +PropertyValue SymbolLayer::getTextSize() const { + return impl->layout.textSize.get(); } -void SymbolLayer::setTextSize(Function value) { - impl->layout.textSize.parsedValue = value; +void SymbolLayer::setTextSize(PropertyValue value) { + impl->layout.textSize.set(value); } -Function SymbolLayer::getTextMaxWidth() const { - return *impl->layout.textMaxWidth.parsedValue; +PropertyValue SymbolLayer::getTextMaxWidth() const { + return impl->layout.textMaxWidth.get(); } -void SymbolLayer::setTextMaxWidth(Function value) { - impl->layout.textMaxWidth.parsedValue = value; +void SymbolLayer::setTextMaxWidth(PropertyValue value) { + impl->layout.textMaxWidth.set(value); } -Function SymbolLayer::getTextLineHeight() const { - return *impl->layout.textLineHeight.parsedValue; +PropertyValue SymbolLayer::getTextLineHeight() const { + return impl->layout.textLineHeight.get(); } -void SymbolLayer::setTextLineHeight(Function value) { - impl->layout.textLineHeight.parsedValue = value; +void SymbolLayer::setTextLineHeight(PropertyValue value) { + impl->layout.textLineHeight.set(value); } -Function SymbolLayer::getTextLetterSpacing() const { - return *impl->layout.textLetterSpacing.parsedValue; +PropertyValue SymbolLayer::getTextLetterSpacing() const { + return impl->layout.textLetterSpacing.get(); } -void SymbolLayer::setTextLetterSpacing(Function value) { - impl->layout.textLetterSpacing.parsedValue = value; +void SymbolLayer::setTextLetterSpacing(PropertyValue value) { + impl->layout.textLetterSpacing.set(value); } -Function SymbolLayer::getTextJustify() const { - return *impl->layout.textJustify.parsedValue; +PropertyValue SymbolLayer::getTextJustify() const { + return impl->layout.textJustify.get(); } -void SymbolLayer::setTextJustify(Function value) { - impl->layout.textJustify.parsedValue = value; +void SymbolLayer::setTextJustify(PropertyValue value) { + impl->layout.textJustify.set(value); } -Function SymbolLayer::getTextAnchor() const { - return *impl->layout.textAnchor.parsedValue; +PropertyValue SymbolLayer::getTextAnchor() const { + return impl->layout.textAnchor.get(); } -void SymbolLayer::setTextAnchor(Function value) { - impl->layout.textAnchor.parsedValue = value; +void SymbolLayer::setTextAnchor(PropertyValue value) { + impl->layout.textAnchor.set(value); } -Function SymbolLayer::getTextMaxAngle() const { - return *impl->layout.textMaxAngle.parsedValue; +PropertyValue SymbolLayer::getTextMaxAngle() const { + return impl->layout.textMaxAngle.get(); } -void SymbolLayer::setTextMaxAngle(Function value) { - impl->layout.textMaxAngle.parsedValue = value; +void SymbolLayer::setTextMaxAngle(PropertyValue value) { + impl->layout.textMaxAngle.set(value); } -Function SymbolLayer::getTextRotate() const { - return *impl->layout.textRotate.parsedValue; +PropertyValue SymbolLayer::getTextRotate() const { + return impl->layout.textRotate.get(); } -void SymbolLayer::setTextRotate(Function value) { - impl->layout.textRotate.parsedValue = value; +void SymbolLayer::setTextRotate(PropertyValue value) { + impl->layout.textRotate.set(value); } -Function SymbolLayer::getTextPadding() const { - return *impl->layout.textPadding.parsedValue; +PropertyValue SymbolLayer::getTextPadding() const { + return impl->layout.textPadding.get(); } -void SymbolLayer::setTextPadding(Function value) { - impl->layout.textPadding.parsedValue = value; +void SymbolLayer::setTextPadding(PropertyValue value) { + impl->layout.textPadding.set(value); } -Function SymbolLayer::getTextKeepUpright() const { - return *impl->layout.textKeepUpright.parsedValue; +PropertyValue SymbolLayer::getTextKeepUpright() const { + return impl->layout.textKeepUpright.get(); } -void SymbolLayer::setTextKeepUpright(Function value) { - impl->layout.textKeepUpright.parsedValue = value; +void SymbolLayer::setTextKeepUpright(PropertyValue value) { + impl->layout.textKeepUpright.set(value); } -Function SymbolLayer::getTextTransform() const { - return *impl->layout.textTransform.parsedValue; +PropertyValue SymbolLayer::getTextTransform() const { + return impl->layout.textTransform.get(); } -void SymbolLayer::setTextTransform(Function value) { - impl->layout.textTransform.parsedValue = value; +void SymbolLayer::setTextTransform(PropertyValue value) { + impl->layout.textTransform.set(value); } -Function> SymbolLayer::getTextOffset() const { - return *impl->layout.textOffset.parsedValue; +PropertyValue> SymbolLayer::getTextOffset() const { + return impl->layout.textOffset.get(); } -void SymbolLayer::setTextOffset(Function> value) { - impl->layout.textOffset.parsedValue = value; +void SymbolLayer::setTextOffset(PropertyValue> value) { + impl->layout.textOffset.set(value); } -Function SymbolLayer::getTextAllowOverlap() const { - return *impl->layout.textAllowOverlap.parsedValue; +PropertyValue SymbolLayer::getTextAllowOverlap() const { + return impl->layout.textAllowOverlap.get(); } -void SymbolLayer::setTextAllowOverlap(Function value) { - impl->layout.textAllowOverlap.parsedValue = value; +void SymbolLayer::setTextAllowOverlap(PropertyValue value) { + impl->layout.textAllowOverlap.set(value); } -Function SymbolLayer::getTextIgnorePlacement() const { - return *impl->layout.textIgnorePlacement.parsedValue; +PropertyValue SymbolLayer::getTextIgnorePlacement() const { + return impl->layout.textIgnorePlacement.get(); } -void SymbolLayer::setTextIgnorePlacement(Function value) { - impl->layout.textIgnorePlacement.parsedValue = value; +void SymbolLayer::setTextIgnorePlacement(PropertyValue value) { + impl->layout.textIgnorePlacement.set(value); } -Function SymbolLayer::getTextOptional() const { - return *impl->layout.textOptional.parsedValue; +PropertyValue SymbolLayer::getTextOptional() const { + return impl->layout.textOptional.get(); } -void SymbolLayer::setTextOptional(Function value) { - impl->layout.textOptional.parsedValue = value; +void SymbolLayer::setTextOptional(PropertyValue value) { + impl->layout.textOptional.set(value); } // Paint properties -Function SymbolLayer::getIconOpacity() const { - return impl->paint.iconOpacity.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconOpacity() const { + return impl->paint.iconOpacity.get(); } -void SymbolLayer::setIconOpacity(Function value) { - impl->paint.iconOpacity.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconOpacity(PropertyValue value) { + impl->paint.iconOpacity.set(value); } -Function SymbolLayer::getIconColor() const { - return impl->paint.iconColor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconColor() const { + return impl->paint.iconColor.get(); } -void SymbolLayer::setIconColor(Function value) { - impl->paint.iconColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconColor(PropertyValue value) { + impl->paint.iconColor.set(value); } -Function SymbolLayer::getIconHaloColor() const { - return impl->paint.iconHaloColor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconHaloColor() const { + return impl->paint.iconHaloColor.get(); } -void SymbolLayer::setIconHaloColor(Function value) { - impl->paint.iconHaloColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloColor(PropertyValue value) { + impl->paint.iconHaloColor.set(value); } -Function SymbolLayer::getIconHaloWidth() const { - return impl->paint.iconHaloWidth.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconHaloWidth() const { + return impl->paint.iconHaloWidth.get(); } -void SymbolLayer::setIconHaloWidth(Function value) { - impl->paint.iconHaloWidth.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloWidth(PropertyValue value) { + impl->paint.iconHaloWidth.set(value); } -Function SymbolLayer::getIconHaloBlur() const { - return impl->paint.iconHaloBlur.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconHaloBlur() const { + return impl->paint.iconHaloBlur.get(); } -void SymbolLayer::setIconHaloBlur(Function value) { - impl->paint.iconHaloBlur.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconHaloBlur(PropertyValue value) { + impl->paint.iconHaloBlur.set(value); } -Function> SymbolLayer::getIconTranslate() const { - return impl->paint.iconTranslate.values.at(ClassID::Default); +PropertyValue> SymbolLayer::getIconTranslate() const { + return impl->paint.iconTranslate.get(); } -void SymbolLayer::setIconTranslate(Function> value) { - impl->paint.iconTranslate.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconTranslate(PropertyValue> value) { + impl->paint.iconTranslate.set(value); } -Function SymbolLayer::getIconTranslateAnchor() const { - return impl->paint.iconTranslateAnchor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getIconTranslateAnchor() const { + return impl->paint.iconTranslateAnchor.get(); } -void SymbolLayer::setIconTranslateAnchor(Function value) { - impl->paint.iconTranslateAnchor.values.emplace(ClassID::Default, value); +void SymbolLayer::setIconTranslateAnchor(PropertyValue value) { + impl->paint.iconTranslateAnchor.set(value); } -Function SymbolLayer::getTextOpacity() const { - return impl->paint.textOpacity.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextOpacity() const { + return impl->paint.textOpacity.get(); } -void SymbolLayer::setTextOpacity(Function value) { - impl->paint.textOpacity.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextOpacity(PropertyValue value) { + impl->paint.textOpacity.set(value); } -Function SymbolLayer::getTextColor() const { - return impl->paint.textColor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextColor() const { + return impl->paint.textColor.get(); } -void SymbolLayer::setTextColor(Function value) { - impl->paint.textColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextColor(PropertyValue value) { + impl->paint.textColor.set(value); } -Function SymbolLayer::getTextHaloColor() const { - return impl->paint.textHaloColor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextHaloColor() const { + return impl->paint.textHaloColor.get(); } -void SymbolLayer::setTextHaloColor(Function value) { - impl->paint.textHaloColor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloColor(PropertyValue value) { + impl->paint.textHaloColor.set(value); } -Function SymbolLayer::getTextHaloWidth() const { - return impl->paint.textHaloWidth.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextHaloWidth() const { + return impl->paint.textHaloWidth.get(); } -void SymbolLayer::setTextHaloWidth(Function value) { - impl->paint.textHaloWidth.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloWidth(PropertyValue value) { + impl->paint.textHaloWidth.set(value); } -Function SymbolLayer::getTextHaloBlur() const { - return impl->paint.textHaloBlur.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextHaloBlur() const { + return impl->paint.textHaloBlur.get(); } -void SymbolLayer::setTextHaloBlur(Function value) { - impl->paint.textHaloBlur.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextHaloBlur(PropertyValue value) { + impl->paint.textHaloBlur.set(value); } -Function> SymbolLayer::getTextTranslate() const { - return impl->paint.textTranslate.values.at(ClassID::Default); +PropertyValue> SymbolLayer::getTextTranslate() const { + return impl->paint.textTranslate.get(); } -void SymbolLayer::setTextTranslate(Function> value) { - impl->paint.textTranslate.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextTranslate(PropertyValue> value) { + impl->paint.textTranslate.set(value); } -Function SymbolLayer::getTextTranslateAnchor() const { - return impl->paint.textTranslateAnchor.values.at(ClassID::Default); +PropertyValue SymbolLayer::getTextTranslateAnchor() const { + return impl->paint.textTranslateAnchor.get(); } -void SymbolLayer::setTextTranslateAnchor(Function value) { - impl->paint.textTranslateAnchor.values.emplace(ClassID::Default, value); +void SymbolLayer::setTextTranslateAnchor(PropertyValue value) { + impl->paint.textTranslateAnchor.set(value); } } // namespace mbgl diff --git a/src/mbgl/style/function_evaluator.hpp b/src/mbgl/style/function_evaluator.hpp deleted file mode 100644 index de49e79f98b..00000000000 --- a/src/mbgl/style/function_evaluator.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class StyleCalculationParameters; - -template -class NormalFunctionEvaluator { -public: - using ResultType = T; - T operator()(const Function&, const StyleCalculationParameters&) const; -}; - -template -struct Faded { - Faded() = default; - Faded(const T& v) : to(v) {} - - T from; - float fromScale = 0; - T to; - float toScale = 0; - float t = 0; -}; - -template -class CrossFadedFunctionEvaluator { -public: - using ResultType = Faded; - Faded operator()(const Function&, const StyleCalculationParameters&) const; -}; - -namespace util { -template -struct Interpolator> - : Uninterpolated {}; -} - -} // namespace mbgl diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index a856e7589c7..b4857aeae5a 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -1,7 +1,8 @@ #pragma once +#include #include -#include +#include #include #include @@ -11,25 +12,38 @@ namespace mbgl { template class LayoutProperty { public: - explicit LayoutProperty(T v) : value(std::move(v)) {} + explicit LayoutProperty(T v) + : value(std::move(v)), + defaultValue(value) {} + + const PropertyValue& get() const { + return currentValue; + } + + void set(const PropertyValue& value_) { + currentValue = value_; + } void parse(const char * name, const JSValue& layout) { if (layout.HasMember(name)) { - parsedValue = parseProperty(name, layout[name]); + currentValue = parseProperty(name, layout[name]); } } void calculate(const StyleCalculationParameters& parameters) { - if (parsedValue) { - NormalFunctionEvaluator evaluator; - value = evaluator(*parsedValue, parameters); + if (currentValue) { + PropertyEvaluator evaluator(parameters, defaultValue); + value = PropertyValue::visit(currentValue, evaluator); } } + // TODO: remove / privatize operator T() const { return value; } - - optional> parsedValue; T value; + +private: + T defaultValue; + PropertyValue currentValue; }; } // namespace mbgl diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 4bbc5643982..8428a905331 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -15,15 +15,14 @@ namespace mbgl { -template class Evaluator = NormalFunctionEvaluator> +template class Evaluator = PropertyEvaluator> class PaintProperty { public: - using Fn = Function; using Result = typename Evaluator::ResultType; - explicit PaintProperty(T fallbackValue) - : value(fallbackValue) { - values.emplace(ClassID::Fallback, Fn(fallbackValue)); + explicit PaintProperty(T defaultValue_) + : defaultValue(defaultValue_) { + values.emplace(ClassID::Fallback, defaultValue_); } PaintProperty(const PaintProperty& other) @@ -31,6 +30,14 @@ class PaintProperty { transitions(other.transitions) { } + const PropertyValue& get() const { + return values.at(ClassID::Default); + } + + void set(const PropertyValue& value_) { + values.emplace(ClassID::Default, value_); + } + void parse(const char* name, const JSValue& layer) { mbgl::util::erase_if(values, [] (const auto& p) { return p.first != ClassID::Fallback; }); @@ -49,15 +56,13 @@ class PaintProperty { ClassID classID = isClass ? ClassDictionary::Get().lookup(paintName.substr(6)) : ClassID::Default; if (it->value.HasMember(name)) { - auto v = parseProperty(name, it->value[name]); - if (v) { - values.emplace(classID, *v); + if (auto v = parseProperty(name, it->value[name])) { + values.emplace(classID, v); } } if (it->value.HasMember(transitionName.c_str())) { - auto v = parsePropertyTransition(name, it->value[transitionName.c_str()]); - if (v) { + if (auto v = parsePropertyTransition(name, it->value[transitionName.c_str()])) { transitions.emplace(classID, *v); } } @@ -92,52 +97,54 @@ class PaintProperty { bool calculate(const StyleCalculationParameters& parameters) { assert(cascaded); - value = cascaded->calculate(parameters); + Evaluator evaluator(parameters, defaultValue); + value = cascaded->calculate(evaluator, parameters.now); return cascaded->prior.operator bool(); } + // TODO: remove / privatize operator T() const { return value; } + Result value; - std::map values; +private: + T defaultValue; + std::map> values; std::map transitions; struct CascadedValue { CascadedValue(std::unique_ptr prior_, TimePoint begin_, TimePoint end_, - Fn value_) + PropertyValue value_) : prior(std::move(prior_)), begin(begin_), end(end_), value(std::move(value_)) { } - Result calculate(const StyleCalculationParameters& parameters) { - Evaluator evaluator; - Result final = evaluator(value, parameters); + Result calculate(const Evaluator& evaluator, const TimePoint& now) { + Result final = PropertyValue::visit(value, evaluator); if (!prior) { // No prior value. return final; - } else if (parameters.now >= end) { + } else if (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(parameters.now - begin) / (end - begin); - return util::interpolate(prior->calculate(parameters), final, t); + float t = std::chrono::duration(now - begin) / (end - begin); + return util::interpolate(prior->calculate(evaluator, now), final, t); } } std::unique_ptr prior; TimePoint begin; TimePoint end; - Fn value; + PropertyValue value; }; std::unique_ptr cascaded; - - Result value; }; } // namespace mbgl diff --git a/src/mbgl/style/function_evaluator.cpp b/src/mbgl/style/property_evaluator.cpp similarity index 56% rename from src/mbgl/style/function_evaluator.cpp rename to src/mbgl/style/property_evaluator.cpp index c58e1d39d2d..08eea899c25 100644 --- a/src/mbgl/style/function_evaluator.cpp +++ b/src/mbgl/style/property_evaluator.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -30,7 +30,7 @@ template <> inline TextTransformType defaultStopsValue() { return {}; }; template <> inline RotationAlignmentType defaultStopsValue() { return {}; }; template -T NormalFunctionEvaluator::operator()(const Function& fn, const StyleCalculationParameters& parameters) const { +T PropertyEvaluator::operator()(const Function& fn) const { float base = fn.getBase(); const std::vector>& stops = fn.getStops(); float z = parameters.z; @@ -79,68 +79,65 @@ T NormalFunctionEvaluator::operator()(const Function& fn, const StyleCalcu } } -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator>; -template class NormalFunctionEvaluator>; -template class NormalFunctionEvaluator>; - -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; -template class NormalFunctionEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator>; +template class PropertyEvaluator>; +template class PropertyEvaluator>; + +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; +template class PropertyEvaluator; template -inline size_t getBiggestStopLessThan(const std::vector>& stops, float z) { +Faded CrossFadedPropertyEvaluator::operator()(const Undefined&) const { + return calculate(defaultValue, defaultValue, defaultValue); +} + +template +Faded CrossFadedPropertyEvaluator::operator()(const T& constant) const { + return calculate(constant, constant, constant); +} + +template +inline T getBiggestStopLessThan(const Function& function, float z) { + const auto& stops = function.getStops(); for (uint32_t i = 0; i < stops.size(); i++) { if (stops[i].first > z) { - return i == 0 ? i : i - 1; + return stops[i == 0 ? i : i - 1].second; } } - return stops.size() - 1; + return stops.at(stops.size() - 1).second; } template -Faded CrossFadedFunctionEvaluator::operator()(const Function& fn, const StyleCalculationParameters& parameters) const { - Faded result; +Faded CrossFadedPropertyEvaluator::operator()(const Function& function) const { + return calculate(getBiggestStopLessThan(function, parameters.z - 1.0f), + getBiggestStopLessThan(function, parameters.z), + getBiggestStopLessThan(function, parameters.z + 1.0f)); +} - const std::vector>& stops = fn.getStops(); - float z = parameters.z; +template +Faded CrossFadedPropertyEvaluator::calculate(const T& min, const T& mid, const T& max) const { + const float z = parameters.z; const float fraction = z - std::floor(z); - std::chrono::duration d = parameters.defaultFadeDuration; - float t = std::min((parameters.now - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f); - float fromScale = 1.0f; - float toScale = 1.0f; - size_t from, to; - - if (z > parameters.zoomHistory.lastIntegerZoom) { - result.t = fraction + (1.0f - fraction) * t; - from = getBiggestStopLessThan(stops, z - 1.0f); - to = getBiggestStopLessThan(stops, z); - fromScale *= 2.0f; - - } else { - result.t = 1 - (1 - t) * fraction; - to = getBiggestStopLessThan(stops, z); - from = getBiggestStopLessThan(stops, z + 1.0f); - fromScale /= 2.0f; - } + const std::chrono::duration d = parameters.defaultFadeDuration; + const float t = std::min((parameters.now - parameters.zoomHistory.lastIntegerZoomTime) / d, 1.0f); - result.from = stops[from].second; - result.to = stops[to].second; - result.fromScale = fromScale; - result.toScale = toScale; - return result; + return z > parameters.zoomHistory.lastIntegerZoom + ? Faded { min, mid, 2.0f, 1.0f, fraction + (1.0f - fraction) * t } + : Faded { max, mid, 0.5f, 1.0f, 1 - (1 - t) * fraction }; } -template class CrossFadedFunctionEvaluator; -template class CrossFadedFunctionEvaluator>; +template class CrossFadedPropertyEvaluator; +template class CrossFadedPropertyEvaluator>; } // namespace mbgl diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp new file mode 100644 index 00000000000..112c373a44a --- /dev/null +++ b/src/mbgl/style/property_evaluator.hpp @@ -0,0 +1,63 @@ +#pragma once + +#include +#include + +namespace mbgl { + +class StyleCalculationParameters; + +template +class PropertyEvaluator { +public: + using ResultType = T; + + PropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + : parameters(parameters_), + defaultValue(defaultValue_) {} + + T operator()(const Undefined&) const { return defaultValue; } + T operator()(const T& constant) const { return constant; } + T operator()(const Function&) const; + +private: + const StyleCalculationParameters& parameters; + T defaultValue; +}; + +template +struct Faded { + T from; + T to; + float fromScale; + float toScale; + float t; +}; + +template +class CrossFadedPropertyEvaluator { +public: + using ResultType = Faded; + + CrossFadedPropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + : parameters(parameters_), + defaultValue(defaultValue_) {} + + Faded operator()(const Undefined&) const; + Faded operator()(const T& constant) const; + Faded operator()(const Function&) const; + +private: + Faded calculate(const T& min, const T& mid, const T& max) const; + + const StyleCalculationParameters& parameters; + T defaultValue; +}; + +namespace util { +template +struct Interpolator> + : Uninterpolated {}; +} + +} // namespace mbgl diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index 17c9bf6ba8b..c0fe5ce2bc3 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -35,7 +36,7 @@ template <> optional> parseConstant(const char*, const JSValu template <> optional> parseConstant(const char*, const JSValue&); template -optional> parseProperty(const char* name, const JSValue& value) { +PropertyValue parseProperty(const char* name, const JSValue& value) { if (!value.IsObject()) { auto constant = parseConstant(name, value); @@ -43,7 +44,7 @@ optional> parseProperty(const char* name, const JSValue& value) { return {}; } - return { Function(*constant) }; + return *constant; } if (!value.HasMember("stops")) { @@ -100,7 +101,7 @@ optional> parseProperty(const char* name, const JSValue& value) { stops.emplace_back(z.GetDouble(), *v); } - return { Function(stops, base) }; + return Function(stops, base); } optional parsePropertyTransition(const char * name, const JSValue&); diff --git a/src/mbgl/style/property_value.hpp b/src/mbgl/style/property_value.hpp new file mode 100644 index 00000000000..377e4f17e05 --- /dev/null +++ b/src/mbgl/style/property_value.hpp @@ -0,0 +1,36 @@ +#pragma once + +#include +#include + +namespace mbgl { + +class Undefined {}; + +template +class PropertyValue { +private: + using Value = variant>; + Value value; + +public: + PropertyValue() : value() {} + PropertyValue( T constant) : value(constant) {} + PropertyValue(Function function) : value(function) {} + + bool isUndefined() const { return value.which() == 0; } + bool isConstant() const { return value.which() == 1; } + bool isFunction() const { return value.which() == 2; } + + const T & asConstant() const { return value.template get< T >(); } + const Function& asFunction() const { return value.template get>(); } + + explicit operator bool() const { return !isUndefined(); }; + + template + static auto visit(const PropertyValue& value, Visitor&& visitor) { + return Value::visit(value.value, visitor); + } +}; + +} diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/style_parser.cpp index 6a67ea9daa8..95ab36498dc 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/style_parser.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include @@ -670,13 +669,15 @@ std::vector StyleParser::fontStacks() const { for (const auto& layer : layers) { if (layer->is()) { - LayoutProperty property = layer->as()->impl->layout.textFont; - if (property.parsedValue) { - for (const auto& stop : property.parsedValue->getStops()) { + PropertyValue textFont = layer->as()->getTextFont(); + if (textFont.isUndefined()) { + result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); + } else if (textFont.isConstant()) { + result.insert(textFont.asConstant()); + } else if (textFont.isFunction()) { + for (const auto& stop : textFont.asFunction().getStops()) { result.insert(stop.second); } - } else { - result.insert(property.value); } } } diff --git a/test/style/functions.cpp b/test/style/functions.cpp index 586941ecf0a..8812c77b559 100644 --- a/test/style/functions.cpp +++ b/test/style/functions.cpp @@ -1,62 +1,63 @@ #include #include -#include +#include #include using namespace mbgl; +float evaluate(PropertyValue value, float zoom) { + return PropertyValue::visit(value, PropertyEvaluator(StyleCalculationParameters(zoom), 0)); +} + TEST(Function, Constant) { - NormalFunctionEvaluator evaluate; - EXPECT_EQ(2.0f, evaluate(Function(2), StyleCalculationParameters(0))); - EXPECT_EQ(3.8f, evaluate(Function(3.8), StyleCalculationParameters(0))); - EXPECT_EQ(22.0f, evaluate(Function(22), StyleCalculationParameters(0))); - EXPECT_EQ(2.0f, evaluate(Function(2), StyleCalculationParameters(4))); - EXPECT_EQ(3.8f, evaluate(Function(3.8), StyleCalculationParameters(4))); - EXPECT_EQ(22.0f, evaluate(Function(22), StyleCalculationParameters(4))); - EXPECT_EQ(2.0f, evaluate(Function(2), StyleCalculationParameters(22))); - EXPECT_EQ(3.8f, evaluate(Function(3.8), StyleCalculationParameters(22))); - EXPECT_EQ(22.0f, evaluate(Function(22), StyleCalculationParameters(22))); + EXPECT_EQ(2.0f, evaluate(2, 0)); + EXPECT_EQ(3.8f, evaluate(3.8, 0)); + EXPECT_EQ(22.0f, evaluate(22, 0)); + EXPECT_EQ(2.0f, evaluate(2, 4)); + EXPECT_EQ(3.8f, evaluate(3.8, 4)); + EXPECT_EQ(22.0f, evaluate(22, 4)); + EXPECT_EQ(2.0f, evaluate(2, 22)); + EXPECT_EQ(3.8f, evaluate(3.8, 22)); + EXPECT_EQ(22.0f, evaluate(22, 22)); } TEST(Function, Stops) { - NormalFunctionEvaluator evaluate; - // Explicit constant slope in fringe regions. Function slope_1({ { 0, 1.5 }, { 6, 1.5 }, { 8, 3 }, { 22, 3 } }, 1.75); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(0))); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(4))); - EXPECT_EQ(1.5, evaluate(slope_1, StyleCalculationParameters(6))); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, StyleCalculationParameters(7))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(8))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(9))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(15))); - EXPECT_EQ(3.0, evaluate(slope_1, StyleCalculationParameters(22))); + EXPECT_EQ(1.5, evaluate(slope_1, 0)); + EXPECT_EQ(1.5, evaluate(slope_1, 4)); + EXPECT_EQ(1.5, evaluate(slope_1, 6)); + ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_1, 7)); + EXPECT_EQ(3.0, evaluate(slope_1, 8)); + EXPECT_EQ(3.0, evaluate(slope_1, 9)); + EXPECT_EQ(3.0, evaluate(slope_1, 15)); + EXPECT_EQ(3.0, evaluate(slope_1, 22)); // Test constant values in fringe regions. Function slope_2({ { 6, 1.5 }, { 8, 3 } }, 1.75); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(0))); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(4))); - EXPECT_EQ(1.5, evaluate(slope_2, StyleCalculationParameters(6))); - ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, StyleCalculationParameters(7))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(8))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(9))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(15))); - EXPECT_EQ(3.0, evaluate(slope_2, StyleCalculationParameters(22))); + EXPECT_EQ(1.5, evaluate(slope_2, 0)); + EXPECT_EQ(1.5, evaluate(slope_2, 4)); + EXPECT_EQ(1.5, evaluate(slope_2, 6)); + ASSERT_FLOAT_EQ(2.0454545454545454, evaluate(slope_2, 7)); + EXPECT_EQ(3.0, evaluate(slope_2, 8)); + EXPECT_EQ(3.0, evaluate(slope_2, 9)); + EXPECT_EQ(3.0, evaluate(slope_2, 15)); + EXPECT_EQ(3.0, evaluate(slope_2, 22)); // Test no values. Function slope_3({}, 1.75); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(2))); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(6))); - EXPECT_EQ(1, evaluate(slope_3, StyleCalculationParameters(12))); + EXPECT_EQ(1, evaluate(slope_3, 2)); + EXPECT_EQ(1, evaluate(slope_3, 6)); + EXPECT_EQ(1, evaluate(slope_3, 12)); // Explicit constant slope in fringe regions. Function slope_4({ { 0, 2 }, { 8, 10 } }, 1); - EXPECT_EQ(2, evaluate(slope_4, StyleCalculationParameters(0))); - EXPECT_EQ(3, evaluate(slope_4, StyleCalculationParameters(1))); - EXPECT_EQ(4, evaluate(slope_4, StyleCalculationParameters(2))); - EXPECT_EQ(4.75, evaluate(slope_4, StyleCalculationParameters(2.75))); - EXPECT_EQ(10, evaluate(slope_4, StyleCalculationParameters(8))); + EXPECT_EQ(2, evaluate(slope_4, 0)); + EXPECT_EQ(3, evaluate(slope_4, 1)); + EXPECT_EQ(4, evaluate(slope_4, 2)); + EXPECT_EQ(4.75, evaluate(slope_4, 2.75)); + EXPECT_EQ(10, evaluate(slope_4, 8)); } From 67ee51360c1bf72d54544cecb8d8fd638ad4df14 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 27 Apr 2016 15:57:48 -0700 Subject: [PATCH 5/8] [core] Add Filter accessors --- include/mbgl/layer/background_layer.hpp | 1 + include/mbgl/layer/circle_layer.hpp | 4 ++++ include/mbgl/layer/fill_layer.hpp | 4 ++++ include/mbgl/layer/line_layer.hpp | 4 ++++ include/mbgl/layer/raster_layer.hpp | 1 + include/mbgl/layer/symbol_layer.hpp | 4 ++++ {src => include}/mbgl/style/filter.hpp | 0 {src => include}/mbgl/util/variant.hpp | 0 scripts/generate-style-code.js | 14 ++++++++++++++ src/mbgl/layer/circle_layer.cpp | 10 ++++++++++ src/mbgl/layer/fill_layer.cpp | 10 ++++++++++ src/mbgl/layer/line_layer.cpp | 10 ++++++++++ src/mbgl/layer/symbol_layer.cpp | 10 ++++++++++ 13 files changed, 72 insertions(+) rename {src => include}/mbgl/style/filter.hpp (100%) rename {src => include}/mbgl/util/variant.hpp (100%) diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/layer/background_layer.hpp index 211597f6ead..bba16d3839b 100644 --- a/include/mbgl/layer/background_layer.hpp +++ b/include/mbgl/layer/background_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include namespace mbgl { diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/layer/circle_layer.hpp index 28e5c2fa7ac..81f84d36a82 100644 --- a/include/mbgl/layer/circle_layer.hpp +++ b/include/mbgl/layer/circle_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include namespace mbgl { @@ -18,6 +19,9 @@ class CircleLayer : public Layer { const std::string& getSourceID() const; const std::string& getSourceLayer() const; + void setFilter(const Filter&); + const Filter& getFilter() const; + // Paint properties PropertyValue getCircleRadius() const; diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/layer/fill_layer.hpp index 76c043957de..10cf4f3bbd5 100644 --- a/include/mbgl/layer/fill_layer.hpp +++ b/include/mbgl/layer/fill_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include namespace mbgl { @@ -18,6 +19,9 @@ class FillLayer : public Layer { const std::string& getSourceID() const; const std::string& getSourceLayer() const; + void setFilter(const Filter&); + const Filter& getFilter() const; + // Paint properties PropertyValue getFillAntialias() const; diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/layer/line_layer.hpp index b4387991163..aeec3632813 100644 --- a/include/mbgl/layer/line_layer.hpp +++ b/include/mbgl/layer/line_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include @@ -20,6 +21,9 @@ class LineLayer : public Layer { const std::string& getSourceID() const; const std::string& getSourceLayer() const; + void setFilter(const Filter&); + const Filter& getFilter() const; + // Layout properties PropertyValue getLineCap() const; diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/layer/raster_layer.hpp index 5d747737c05..7dc2532a2f8 100644 --- a/include/mbgl/layer/raster_layer.hpp +++ b/include/mbgl/layer/raster_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include namespace mbgl { diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/layer/symbol_layer.hpp index 23395152014..006506b3d88 100644 --- a/include/mbgl/layer/symbol_layer.hpp +++ b/include/mbgl/layer/symbol_layer.hpp @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include @@ -20,6 +21,9 @@ class SymbolLayer : public Layer { const std::string& getSourceID() const; const std::string& getSourceLayer() const; + void setFilter(const Filter&); + const Filter& getFilter() const; + // Layout properties PropertyValue getSymbolPlacement() const; diff --git a/src/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp similarity index 100% rename from src/mbgl/style/filter.hpp rename to include/mbgl/style/filter.hpp diff --git a/src/mbgl/util/variant.hpp b/include/mbgl/util/variant.hpp similarity index 100% rename from src/mbgl/util/variant.hpp rename to include/mbgl/util/variant.hpp diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index b26e0520f63..02f904983b5 100644 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -77,6 +77,7 @@ const layerHpp = ejs.compile(`<% #pragma once #include +#include #include <% if (type === 'line' || type === 'symbol') { -%> @@ -103,6 +104,9 @@ public: const std::string& getSourceID() const; const std::string& getSourceLayer() const; + void setFilter(const Filter&); + const Filter& getFilter() const; + <% } -%> <% if (layoutProperties.length) { -%> // Layout properties @@ -191,6 +195,16 @@ const std::string& <%- camelize(type) %>Layer::getSourceID() const { const std::string& <%- camelize(type) %>Layer::getSourceLayer() const { return impl->sourceLayer; } + +// Filter + +void <%- camelize(type) %>Layer::setFilter(const Filter& filter) { + impl->filter = filter; +} + +const Filter& <%- camelize(type) %>Layer::getFilter() const { + return impl->filter; +} <% } -%> // Layout properties diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/layer/circle_layer.cpp index b1ca06dff78..efc0e9488d0 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/layer/circle_layer.cpp @@ -37,6 +37,16 @@ const std::string& CircleLayer::getSourceLayer() const { return impl->sourceLayer; } +// Filter + +void CircleLayer::setFilter(const Filter& filter) { + impl->filter = filter; +} + +const Filter& CircleLayer::getFilter() const { + return impl->filter; +} + // Layout properties diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/layer/fill_layer.cpp index f7a9418c0e1..77efaa61aa0 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/layer/fill_layer.cpp @@ -37,6 +37,16 @@ const std::string& FillLayer::getSourceLayer() const { return impl->sourceLayer; } +// Filter + +void FillLayer::setFilter(const Filter& filter) { + impl->filter = filter; +} + +const Filter& FillLayer::getFilter() const { + return impl->filter; +} + // Layout properties diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/layer/line_layer.cpp index c77a5c3e830..e1a7d813af0 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/layer/line_layer.cpp @@ -37,6 +37,16 @@ const std::string& LineLayer::getSourceLayer() const { return impl->sourceLayer; } +// Filter + +void LineLayer::setFilter(const Filter& filter) { + impl->filter = filter; +} + +const Filter& LineLayer::getFilter() const { + return impl->filter; +} + // Layout properties PropertyValue LineLayer::getLineCap() const { diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/layer/symbol_layer.cpp index 6152d7104ad..66d018b5813 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/layer/symbol_layer.cpp @@ -37,6 +37,16 @@ const std::string& SymbolLayer::getSourceLayer() const { return impl->sourceLayer; } +// Filter + +void SymbolLayer::setFilter(const Filter& filter) { + impl->filter = filter; +} + +const Filter& SymbolLayer::getFilter() const { + return impl->filter; +} + // Layout properties PropertyValue SymbolLayer::getSymbolPlacement() const { From 18149cbcc27a926f280b08d8d0e09104b2147688 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 27 Apr 2016 16:03:04 -0700 Subject: [PATCH 6/8] [core] Add {min,max}Zoom accessors --- include/mbgl/style/layer.hpp | 6 ++++++ src/mbgl/layer/layer.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index e6c33a97840..4a40cc0cff1 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -49,6 +49,12 @@ class Layer : public mbgl::util::noncopyable { VisibilityType getVisibility() const; void setVisibility(VisibilityType); + // Zoom range + float getMinZoom() const; + void setMinZoom(float) const; + float getMaxZoom() const; + void setMaxZoom(float) const; + // Create a new layer with the specified `id` and `ref`. All other properties // are copied from this layer. std::unique_ptr copy(const std::string& id, diff --git a/src/mbgl/layer/layer.cpp b/src/mbgl/layer/layer.cpp index 154fbfe31f9..c26eb9a723d 100644 --- a/src/mbgl/layer/layer.cpp +++ b/src/mbgl/layer/layer.cpp @@ -21,6 +21,22 @@ void Layer::setVisibility(VisibilityType value) { baseImpl->visibility = value; } +float Layer::getMinZoom() const { + return baseImpl->minZoom; +} + +void Layer::setMinZoom(float minZoom) const { + baseImpl->minZoom = minZoom; +} + +float Layer::getMaxZoom() const { + return baseImpl->maxZoom; +} + +void Layer::setMaxZoom(float maxZoom) const { + baseImpl->maxZoom = maxZoom; +} + std::unique_ptr Layer::copy(const std::string& id, const std::string& ref) const { std::unique_ptr result = baseImpl->clone(); From c902f9098b331302aaa1baac77d1575db624a132 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 26 Apr 2016 16:39:56 -0700 Subject: [PATCH 7/8] [core] Rationalize naming for style-related code --- include/mbgl/annotation/annotation.hpp | 3 +- include/mbgl/map/map.hpp | 15 ++-- include/mbgl/storage/offline.hpp | 4 +- include/mbgl/storage/resource.hpp | 2 +- include/mbgl/style/filter.hpp | 2 + include/mbgl/style/function.hpp | 27 +++++++ include/mbgl/style/layer.hpp | 7 +- .../layers}/background_layer.hpp | 4 + .../{layer => style/layers}/circle_layer.hpp | 4 + .../{layer => style/layers}/custom_layer.hpp | 2 + .../{layer => style/layers}/fill_layer.hpp | 4 + .../{layer => style/layers}/line_layer.hpp | 4 + .../{layer => style/layers}/raster_layer.hpp | 4 + .../{layer => style/layers}/symbol_layer.hpp | 4 + .../mbgl/style/property_value.hpp | 6 +- ..._transition.hpp => transition_options.hpp} | 6 +- include/mbgl/style/types.hpp | 41 +--------- include/mbgl/util/color.hpp | 10 +++ include/mbgl/util/font_stack.hpp | 17 +++++ platform/android/src/example_custom_layer.cpp | 4 +- platform/android/src/jni.cpp | 10 +-- platform/default/glfw_view.cpp | 4 +- platform/default/mbgl/storage/offline.cpp | 8 +- .../default/mbgl/storage/offline_download.cpp | 30 ++++---- .../default/mbgl/storage/offline_download.hpp | 19 ++--- platform/ios/src/MGLMapView.mm | 12 +-- platform/qt/src/qmapboxgl.cpp | 10 +-- scripts/generate-style-code.js | 40 ++++++---- src/mbgl/annotation/annotation_manager.cpp | 10 ++- src/mbgl/annotation/annotation_manager.hpp | 5 +- src/mbgl/annotation/fill_annotation_impl.cpp | 4 +- src/mbgl/annotation/fill_annotation_impl.hpp | 2 +- src/mbgl/annotation/line_annotation_impl.cpp | 4 +- src/mbgl/annotation/line_annotation_impl.hpp | 2 +- src/mbgl/annotation/shape_annotation_impl.cpp | 1 + src/mbgl/annotation/shape_annotation_impl.hpp | 7 +- .../style_sourced_annotation_impl.cpp | 6 +- .../style_sourced_annotation_impl.hpp | 2 +- src/mbgl/geometry/feature_index.cpp | 14 ++-- src/mbgl/geometry/feature_index.hpp | 11 ++- src/mbgl/layer/background_layer_impl.hpp | 24 ------ src/mbgl/layer/raster_layer_impl.hpp | 24 ------ src/mbgl/map/map.cpp | 42 ++++++----- src/mbgl/{style => map}/zoom_history.hpp | 0 src/mbgl/renderer/bucket.hpp | 7 +- src/mbgl/renderer/circle_bucket.cpp | 8 +- src/mbgl/renderer/circle_bucket.hpp | 2 +- src/mbgl/renderer/fill_bucket.cpp | 22 +++--- src/mbgl/renderer/fill_bucket.hpp | 2 +- src/mbgl/renderer/line_bucket.cpp | 8 +- src/mbgl/renderer/line_bucket.hpp | 7 +- src/mbgl/renderer/painter.cpp | 17 +++-- src/mbgl/renderer/painter.hpp | 45 +++++------ src/mbgl/renderer/painter_background.cpp | 10 ++- src/mbgl/renderer/painter_circle.cpp | 10 ++- src/mbgl/renderer/painter_clipping.cpp | 2 +- src/mbgl/renderer/painter_fill.cpp | 10 ++- src/mbgl/renderer/painter_line.cpp | 10 ++- src/mbgl/renderer/painter_raster.cpp | 10 ++- src/mbgl/renderer/painter_symbol.cpp | 9 ++- src/mbgl/renderer/raster_bucket.cpp | 8 +- src/mbgl/renderer/raster_bucket.hpp | 2 +- src/mbgl/renderer/symbol_bucket.cpp | 4 +- src/mbgl/renderer/symbol_bucket.hpp | 10 +-- ...t_parameters.cpp => bucket_parameters.cpp} | 6 +- ...t_parameters.hpp => bucket_parameters.hpp} | 7 +- src/mbgl/style/calculation_parameters.hpp | 30 ++++++++ src/mbgl/style/cascade_parameters.hpp | 22 ++++++ src/mbgl/style/class_dictionary.cpp | 2 + src/mbgl/style/class_dictionary.hpp | 2 + src/mbgl/style/filter_evaluator.hpp | 2 + src/mbgl/{layer => style}/layer.cpp | 4 +- src/mbgl/{layer => style}/layer_impl.cpp | 4 +- src/mbgl/{layer => style}/layer_impl.hpp | 16 ++-- .../layers}/background_layer.cpp | 6 +- .../layers}/background_layer_impl.cpp | 10 ++- .../style/layers/background_layer_impl.hpp | 26 +++++++ .../layers}/background_layer_properties.cpp | 8 +- .../layers}/background_layer_properties.hpp | 10 ++- .../{layer => style/layers}/circle_layer.cpp | 6 +- .../layers}/circle_layer_impl.cpp | 12 +-- .../layers}/circle_layer_impl.hpp | 14 ++-- .../layers}/circle_layer_properties.cpp | 8 +- .../layers}/circle_layer_properties.hpp | 10 ++- .../{layer => style/layers}/custom_layer.cpp | 6 +- .../layers}/custom_layer_impl.cpp | 8 +- .../layers}/custom_layer_impl.hpp | 13 ++-- .../{layer => style/layers}/fill_layer.cpp | 6 +- .../layers}/fill_layer_impl.cpp | 12 +-- .../layers}/fill_layer_impl.hpp | 14 ++-- .../layers}/fill_layer_properties.cpp | 8 +- .../layers}/fill_layer_properties.hpp | 10 ++- .../{layer => style/layers}/line_layer.cpp | 6 +- .../layers}/line_layer_impl.cpp | 16 ++-- .../layers}/line_layer_impl.hpp | 14 ++-- .../layers}/line_layer_properties.cpp | 10 ++- .../layers}/line_layer_properties.hpp | 12 +-- .../{layer => style/layers}/raster_layer.cpp | 6 +- .../layers}/raster_layer_impl.cpp | 10 ++- src/mbgl/style/layers/raster_layer_impl.hpp | 26 +++++++ .../layers}/raster_layer_properties.cpp | 8 +- .../layers}/raster_layer_properties.hpp | 10 ++- .../{layer => style/layers}/symbol_layer.cpp | 6 +- .../layers}/symbol_layer_impl.cpp | 22 +++--- .../layers}/symbol_layer_impl.hpp | 20 ++--- .../layers}/symbol_layer_properties.cpp | 10 ++- .../layers}/symbol_layer_properties.hpp | 12 +-- src/mbgl/style/layout_property.hpp | 4 +- .../{style_observer.hpp => observer.hpp} | 14 ++-- src/mbgl/style/paint_property.hpp | 18 +++-- .../style/{style_parser.cpp => parser.cpp} | 69 ++++++++--------- .../style/{style_parser.hpp => parser.hpp} | 21 +++--- src/mbgl/style/property_evaluator.cpp | 5 +- src/mbgl/style/property_evaluator.hpp | 15 ++-- src/mbgl/style/property_parsing.cpp | 7 +- src/mbgl/style/property_parsing.hpp | 7 +- ...ry_parameters.hpp => query_parameters.hpp} | 5 +- src/mbgl/style/render_item.hpp | 9 ++- src/mbgl/{source => style}/source.cpp | 52 ++++++------- src/mbgl/{source => style}/source.hpp | 26 ++++--- .../{source => style}/source_observer.hpp | 6 +- src/mbgl/style/style.cpp | 52 ++++++------- src/mbgl/style/style.hpp | 39 +++++----- .../style/style_calculation_parameters.hpp | 28 ------- src/mbgl/style/style_cascade_parameters.hpp | 20 ----- src/mbgl/style/style_render_parameters.hpp | 15 ---- ...e_parameters.hpp => update_parameters.hpp} | 12 ++- src/mbgl/text/glyph_pbf.hpp | 2 +- src/mbgl/text/glyph_store.hpp | 2 +- src/mbgl/text/glyph_store_observer.hpp | 1 + src/mbgl/text/quads.cpp | 4 +- src/mbgl/text/quads.hpp | 74 ++++++++++--------- src/mbgl/text/shaping.cpp | 4 +- src/mbgl/text/shaping.hpp | 34 +++++---- src/mbgl/tile/raster_tile_data.cpp | 4 +- src/mbgl/tile/raster_tile_data.hpp | 8 +- src/mbgl/tile/tile_data.hpp | 7 +- src/mbgl/tile/tile_worker.cpp | 18 +++-- src/mbgl/tile/tile_worker.hpp | 11 ++- src/mbgl/tile/vector_tile.cpp | 2 +- src/mbgl/tile/vector_tile_data.cpp | 6 +- src/mbgl/tile/vector_tile_data.hpp | 11 ++- .../{style/types.cpp => util/font_stack.cpp} | 2 +- .../source_info.hpp => util/tileset.hpp} | 5 +- src/mbgl/util/worker.cpp | 4 +- src/mbgl/util/worker.hpp | 2 +- test/api/custom_layer.cpp | 3 +- test/map/map.cpp | 3 +- test/src/mbgl/test/stub_style_observer.hpp | 11 ++- test/storage/offline.cpp | 32 ++++---- test/style/filter.cpp | 3 +- test/style/functions.cpp | 5 +- test/style/source.cpp | 58 +++++++-------- test/style/style.cpp | 3 +- test/style/style_layer.cpp | 5 +- test/style/style_parser.cpp | 10 +-- 156 files changed, 1083 insertions(+), 809 deletions(-) create mode 100644 include/mbgl/style/function.hpp rename include/mbgl/{layer => style/layers}/background_layer.hpp (93%) rename include/mbgl/{layer => style/layers}/circle_layer.hpp (95%) rename include/mbgl/{layer => style/layers}/custom_layer.hpp (98%) rename include/mbgl/{layer => style/layers}/fill_layer.hpp (95%) rename include/mbgl/{layer => style/layers}/line_layer.hpp (97%) rename include/mbgl/{layer => style/layers}/raster_layer.hpp (95%) rename include/mbgl/{layer => style/layers}/symbol_layer.hpp (98%) rename {src => include}/mbgl/style/property_value.hpp (91%) rename include/mbgl/style/{property_transition.hpp => transition_options.hpp} (59%) create mode 100644 include/mbgl/util/color.hpp create mode 100644 include/mbgl/util/font_stack.hpp delete mode 100644 src/mbgl/layer/background_layer_impl.hpp delete mode 100644 src/mbgl/layer/raster_layer_impl.hpp rename src/mbgl/{style => map}/zoom_history.hpp (100%) rename src/mbgl/style/{style_bucket_parameters.cpp => bucket_parameters.cpp} (80%) rename src/mbgl/style/{style_bucket_parameters.hpp => bucket_parameters.hpp} (93%) create mode 100644 src/mbgl/style/calculation_parameters.hpp create mode 100644 src/mbgl/style/cascade_parameters.hpp rename src/mbgl/{layer => style}/layer.cpp (93%) rename src/mbgl/{layer => style}/layer_impl.cpp (81%) rename src/mbgl/{layer => style}/layer_impl.hpp (89%) rename src/mbgl/{layer => style/layers}/background_layer.cpp (90%) rename src/mbgl/{layer => style/layers}/background_layer_impl.cpp (54%) create mode 100644 src/mbgl/style/layers/background_layer_impl.hpp rename src/mbgl/{layer => style/layers}/background_layer_properties.cpp (73%) rename src/mbgl/{layer => style/layers}/background_layer_properties.hpp (74%) rename src/mbgl/{layer => style/layers}/circle_layer.cpp (94%) rename src/mbgl/{layer => style/layers}/circle_layer_impl.cpp (82%) rename src/mbgl/{layer => style/layers}/circle_layer_impl.hpp (60%) rename src/mbgl/{layer => style/layers}/circle_layer_properties.cpp (82%) rename src/mbgl/{layer => style/layers}/circle_layer_properties.hpp (78%) rename src/mbgl/{layer => style/layers}/custom_layer.cpp (82%) rename src/mbgl/{layer => style/layers}/custom_layer_impl.cpp (87%) rename src/mbgl/{layer => style/layers}/custom_layer_impl.hpp (71%) rename src/mbgl/{layer => style/layers}/fill_layer.cpp (95%) rename src/mbgl/{layer => style/layers}/fill_layer_impl.cpp (83%) rename src/mbgl/{layer => style/layers}/fill_layer_impl.hpp (60%) rename src/mbgl/{layer => style/layers}/fill_layer_properties.cpp (83%) rename src/mbgl/{layer => style/layers}/fill_layer_properties.hpp (80%) rename src/mbgl/{layer => style/layers}/line_layer.cpp (96%) rename src/mbgl/{layer => style/layers}/line_layer_impl.cpp (87%) rename src/mbgl/{layer => style/layers}/line_layer_impl.hpp (65%) rename src/mbgl/{layer => style/layers}/line_layer_properties.cpp (86%) rename src/mbgl/{layer => style/layers}/line_layer_properties.hpp (83%) rename src/mbgl/{layer => style/layers}/raster_layer.cpp (94%) rename src/mbgl/{layer => style/layers}/raster_layer_impl.cpp (54%) create mode 100644 src/mbgl/style/layers/raster_layer_impl.hpp rename src/mbgl/{layer => style/layers}/raster_layer_properties.cpp (84%) rename src/mbgl/{layer => style/layers}/raster_layer_properties.hpp (78%) rename src/mbgl/{layer => style/layers}/symbol_layer.cpp (98%) rename src/mbgl/{layer => style/layers}/symbol_layer_impl.cpp (77%) rename src/mbgl/{layer => style/layers}/symbol_layer_impl.hpp (52%) rename src/mbgl/{layer => style/layers}/symbol_layer_properties.cpp (93%) rename src/mbgl/{layer => style/layers}/symbol_layer_properties.hpp (92%) rename src/mbgl/style/{style_observer.hpp => observer.hpp} (59%) rename src/mbgl/style/{style_parser.cpp => parser.cpp} (91%) rename src/mbgl/style/{style_parser.hpp => parser.hpp} (74%) rename src/mbgl/style/{style_query_parameters.hpp => query_parameters.hpp} (80%) rename src/mbgl/{source => style}/source.cpp (89%) rename src/mbgl/{source => style}/source.hpp (85%) rename src/mbgl/{source => style}/source_observer.hpp (92%) delete mode 100644 src/mbgl/style/style_calculation_parameters.hpp delete mode 100644 src/mbgl/style/style_cascade_parameters.hpp delete mode 100644 src/mbgl/style/style_render_parameters.hpp rename src/mbgl/style/{style_update_parameters.hpp => update_parameters.hpp} (92%) rename src/mbgl/{style/types.cpp => util/font_stack.cpp} (91%) rename src/mbgl/{source/source_info.hpp => util/tileset.hpp} (86%) diff --git a/include/mbgl/annotation/annotation.hpp b/include/mbgl/annotation/annotation.hpp index 8b0c3026a87..6cb26e6a820 100644 --- a/include/mbgl/annotation/annotation.hpp +++ b/include/mbgl/annotation/annotation.hpp @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include #include #include diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index aadfdf9ada4..b44b53ff991 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -22,10 +22,13 @@ namespace mbgl { class FileSource; class View; class SpriteImage; -class Layer; struct CameraOptions; struct AnimationOptions; +namespace style { +class Layer; +} + class Map : private util::noncopyable { public: explicit Map(View&, FileSource&, @@ -47,9 +50,9 @@ class Map : private util::noncopyable { void update(Update update); // Styling - void addClass(const std::string&, const PropertyTransition& = {}); - void removeClass(const std::string&, const PropertyTransition& = {}); - void setClasses(const std::vector&, const PropertyTransition& = {}); + void addClass(const std::string&, const style::TransitionOptions& = {}); + void removeClass(const std::string&, const style::TransitionOptions& = {}); + void setClasses(const std::vector&, const style::TransitionOptions& = {}); bool hasClass(const std::string&) const; std::vector getClasses() const; @@ -146,7 +149,7 @@ class Map : private util::noncopyable { AnnotationIDs getPointAnnotationsInBounds(const LatLngBounds&); - void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); + void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); void removeLayer(const std::string& layerID); // Feature queries diff --git a/include/mbgl/storage/offline.hpp b/include/mbgl/storage/offline.hpp index e0c5ba62473..990c8470bbd 100644 --- a/include/mbgl/storage/offline.hpp +++ b/include/mbgl/storage/offline.hpp @@ -12,7 +12,7 @@ namespace mbgl { class TileID; -class SourceInfo; +class Tileset; /* * An offline region defined by a style URL, geographic bounding box, zoom range, and @@ -30,7 +30,7 @@ class OfflineTilePyramidRegionDefinition { OfflineTilePyramidRegionDefinition(const std::string&, const LatLngBounds&, double, double, float); /* Private */ - std::vector tileCover(SourceType, uint16_t tileSize, const SourceInfo&) const; + std::vector tileCover(SourceType, uint16_t tileSize, const Tileset&) const; const std::string styleURL; const LatLngBounds bounds; diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp index 62ee5496637..a75de380a16 100644 --- a/include/mbgl/storage/resource.hpp +++ b/include/mbgl/storage/resource.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include diff --git a/include/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp index 6ad6969fbf1..9cf84f5e1d2 100644 --- a/include/mbgl/style/filter.hpp +++ b/include/mbgl/style/filter.hpp @@ -7,6 +7,7 @@ #include namespace mbgl { +namespace style { typedef variant< class NullFilter, @@ -100,4 +101,5 @@ class NotHasFilter { std::string key; }; +} // namespace style } // namespace mbgl diff --git a/include/mbgl/style/function.hpp b/include/mbgl/style/function.hpp new file mode 100644 index 00000000000..da2659c76ac --- /dev/null +++ b/include/mbgl/style/function.hpp @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace style { + +template +class Function { +public: + using Stop = std::pair; + using Stops = std::vector; + + explicit Function(const Stops& stops_, float base_) + : base(base_), stops(stops_) {} + + float getBase() const { return base; } + const std::vector>& getStops() const { return stops; } + +private: + float base = 1; + std::vector> stops; +}; + +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 4a40cc0cff1..1f4a6fdf35b 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -1,5 +1,4 @@ -#ifndef MBGL_LAYER -#define MBGL_LAYER +#pragma once #include #include @@ -7,6 +6,7 @@ #include namespace mbgl { +namespace style { /** * The runtime representation of a [layer](https://www.mapbox.com/mapbox-gl-style-spec/#layers) from the Mapbox Style @@ -79,6 +79,5 @@ class Layer : public mbgl::util::noncopyable { Layer(Type, std::unique_ptr); }; +} // namespace style } // namespace mbgl - -#endif diff --git a/include/mbgl/layer/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp similarity index 93% rename from include/mbgl/layer/background_layer.hpp rename to include/mbgl/style/layers/background_layer.hpp index bba16d3839b..2eb84ee499a 100644 --- a/include/mbgl/layer/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -6,7 +6,10 @@ #include #include +#include + namespace mbgl { +namespace style { class BackgroundLayer : public Layer { public: @@ -38,4 +41,5 @@ inline bool Layer::is() const { return type == Type::Background; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp similarity index 95% rename from include/mbgl/layer/circle_layer.hpp rename to include/mbgl/style/layers/circle_layer.hpp index 81f84d36a82..10d281b6ac6 100644 --- a/include/mbgl/layer/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -6,7 +6,10 @@ #include #include +#include + namespace mbgl { +namespace style { class CircleLayer : public Layer { public: @@ -56,4 +59,5 @@ inline bool Layer::is() const { return type == Type::Circle; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/custom_layer.hpp b/include/mbgl/style/layers/custom_layer.hpp similarity index 98% rename from include/mbgl/layer/custom_layer.hpp rename to include/mbgl/style/layers/custom_layer.hpp index 9782d9593f8..d3867e2c4f7 100644 --- a/include/mbgl/layer/custom_layer.hpp +++ b/include/mbgl/style/layers/custom_layer.hpp @@ -3,6 +3,7 @@ #include namespace mbgl { +namespace style { /** * Initialize any GL state needed by the custom layer. This method is called once, from the @@ -66,4 +67,5 @@ inline bool Layer::is() const { return type == Type::Custom; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp similarity index 95% rename from include/mbgl/layer/fill_layer.hpp rename to include/mbgl/style/layers/fill_layer.hpp index 10cf4f3bbd5..a14bf4a3906 100644 --- a/include/mbgl/layer/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -6,7 +6,10 @@ #include #include +#include + namespace mbgl { +namespace style { class FillLayer : public Layer { public: @@ -59,4 +62,5 @@ inline bool Layer::is() const { return type == Type::Fill; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp similarity index 97% rename from include/mbgl/layer/line_layer.hpp rename to include/mbgl/style/layers/line_layer.hpp index aeec3632813..fb9e37811a9 100644 --- a/include/mbgl/layer/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -6,9 +6,12 @@ #include #include +#include + #include namespace mbgl { +namespace style { class LineLayer : public Layer { public: @@ -84,4 +87,5 @@ inline bool Layer::is() const { return type == Type::Line; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp similarity index 95% rename from include/mbgl/layer/raster_layer.hpp rename to include/mbgl/style/layers/raster_layer.hpp index 7dc2532a2f8..6d0c7dd91cd 100644 --- a/include/mbgl/layer/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -6,7 +6,10 @@ #include #include +#include + namespace mbgl { +namespace style { class RasterLayer : public Layer { public: @@ -55,4 +58,5 @@ inline bool Layer::is() const { return type == Type::Raster; } +} // namespace style } // namespace mbgl diff --git a/include/mbgl/layer/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp similarity index 98% rename from include/mbgl/layer/symbol_layer.hpp rename to include/mbgl/style/layers/symbol_layer.hpp index 006506b3d88..3806310c956 100644 --- a/include/mbgl/layer/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -6,9 +6,12 @@ #include #include +#include + #include namespace mbgl { +namespace style { class SymbolLayer : public Layer { public: @@ -177,4 +180,5 @@ inline bool Layer::is() const { return type == Type::Symbol; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp similarity index 91% rename from src/mbgl/style/property_value.hpp rename to include/mbgl/style/property_value.hpp index 377e4f17e05..d8f83a0fb33 100644 --- a/src/mbgl/style/property_value.hpp +++ b/include/mbgl/style/property_value.hpp @@ -1,9 +1,10 @@ #pragma once #include -#include +#include namespace mbgl { +namespace style { class Undefined {}; @@ -33,4 +34,5 @@ class PropertyValue { } }; -} +} // namespace style +} // namespace mbgl diff --git a/include/mbgl/style/property_transition.hpp b/include/mbgl/style/transition_options.hpp similarity index 59% rename from include/mbgl/style/property_transition.hpp rename to include/mbgl/style/transition_options.hpp index b9a301feea8..87faff21f87 100644 --- a/include/mbgl/style/property_transition.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -4,14 +4,16 @@ #include namespace mbgl { +namespace style { -class PropertyTransition { +class TransitionOptions { public: - PropertyTransition(const optional& duration_ = {}, const optional& delay_ = {}) + TransitionOptions(const optional& duration_ = {}, const optional& delay_ = {}) : duration(duration_), delay(delay_) {} optional duration; optional delay; }; +} // namespace style } // namespace mbgl diff --git a/include/mbgl/style/types.hpp b/include/mbgl/style/types.hpp index 56f3570357f..27b524a800f 100644 --- a/include/mbgl/style/types.hpp +++ b/include/mbgl/style/types.hpp @@ -2,44 +2,9 @@ #include -#include -#include -#include -#include - namespace mbgl { -// Stores a premultiplied color, with all four channels ranging from 0..1 -using Color = std::array; - -// An array of font names -using FontStack = std::vector; - -std::string fontStackToString(const FontStack&); - -struct FontStackHash { - std::size_t operator()(const FontStack&) const; -}; - -template -class Function { -public: - using Stop = std::pair; - using Stops = std::vector; - - explicit Function(const Stops& stops_, float base_) - : base(base_), stops(stops_) {} - - float getBase() const { return base; } - const std::vector>& getStops() const { return stops; } - -private: - float base = 1; - std::vector> stops; -}; - -// ------------------------------------------------------------------------------------------------- - +// TODO: should be in public source.hpp header and style namespace enum class SourceType : uint8_t { Vector, Raster, @@ -56,7 +21,7 @@ MBGL_DEFINE_ENUM_CLASS(SourceTypeClass, SourceType, { { SourceType::Annotations, "annotations" }, }); -// ------------------------------------------------------------------------------------------------- +namespace style { enum class VisibilityType : bool { Visible, @@ -122,5 +87,5 @@ enum class TextTransformType : uint8_t { Lowercase, }; +} // namespace style } // namespace mbgl - diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp new file mode 100644 index 00000000000..d7fe61c6405 --- /dev/null +++ b/include/mbgl/util/color.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace mbgl { + +// Stores a premultiplied color, with all four channels ranging from 0..1 +using Color = std::array; + +} // namespace mbgl diff --git a/include/mbgl/util/font_stack.hpp b/include/mbgl/util/font_stack.hpp new file mode 100644 index 00000000000..d0b431e9ea3 --- /dev/null +++ b/include/mbgl/util/font_stack.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +namespace mbgl { + +// An array of font names +using FontStack = std::vector; + +std::string fontStackToString(const FontStack&); + +struct FontStackHash { + std::size_t operator()(const FontStack&) const; +}; + +} // namespace mbgl diff --git a/platform/android/src/example_custom_layer.cpp b/platform/android/src/example_custom_layer.cpp index 99b6d7223a0..516a8f2cd57 100644 --- a/platform/android/src/example_custom_layer.cpp +++ b/platform/android/src/example_custom_layer.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include static const GLchar * vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); }"; static const GLchar * fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 1, 0, 1); }"; @@ -64,7 +64,7 @@ void nativeInitialize(void *context) { reinterpret_cast(context)->initialize(); } -void nativeRender(void *context, const mbgl::CustomLayerRenderParameters& /*parameters*/) { +void nativeRender(void *context, const mbgl::style::CustomLayerRenderParameters& /*parameters*/) { reinterpret_cast(context)->render(); } diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 2b6b4429f21..5c0f7b15307 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include @@ -1112,11 +1112,11 @@ void nativeAddCustomLayer(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr mbgl::Log::Debug(mbgl::Event::JNI, "nativeAddCustomLayer"); assert(nativeMapViewPtr != 0); NativeMapView *nativeMapView = reinterpret_cast(nativeMapViewPtr); - nativeMapView->getMap().addLayer(std::make_unique( + nativeMapView->getMap().addLayer(std::make_unique( std_string_from_jstring(env, reinterpret_cast(jni::GetField(*env, customLayer, *customLayerIdId))), - reinterpret_cast(jni::GetField(*env, customLayer, *customLayerInitializeFunctionId)), - reinterpret_cast(jni::GetField(*env, customLayer, *customLayerRenderFunctionId)), - reinterpret_cast(jni::GetField(*env, customLayer, *customLayerDeinitializeFunctionId)), + reinterpret_cast(jni::GetField(*env, customLayer, *customLayerInitializeFunctionId)), + reinterpret_cast(jni::GetField(*env, customLayer, *customLayerRenderFunctionId)), + reinterpret_cast(jni::GetField(*env, customLayer, *customLayerDeinitializeFunctionId)), reinterpret_cast(jni::GetField(*env, customLayer, *customLayerContextId))), before ? mbgl::optional(std_string_from_jstring(env, before)) : mbgl::optional()); } diff --git a/platform/default/glfw_view.cpp b/platform/default/glfw_view.cpp index 2280c3f2aee..67e9748a706 100644 --- a/platform/default/glfw_view.cpp +++ b/platform/default/glfw_view.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include #include @@ -146,7 +146,7 @@ void GLFWView::onKey(GLFWwindow *window, int key, int /*scancode*/, int action, break; case GLFW_KEY_R: if (!mods) { - static const mbgl::PropertyTransition transition { { mbgl::Milliseconds(300) } }; + static const mbgl::style::TransitionOptions transition { { mbgl::Milliseconds(300) } }; if (view->map->hasClass("night")) { view->map->removeClass("night", transition); } else { diff --git a/platform/default/mbgl/storage/offline.cpp b/platform/default/mbgl/storage/offline.cpp index b13aa050395..d8e0357ae21 100644 --- a/platform/default/mbgl/storage/offline.cpp +++ b/platform/default/mbgl/storage/offline.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include @@ -23,9 +23,9 @@ OfflineTilePyramidRegionDefinition::OfflineTilePyramidRegionDefinition( } } -std::vector OfflineTilePyramidRegionDefinition::tileCover(SourceType type, uint16_t tileSize, const SourceInfo& info) const { - double minZ = std::max(util::coveringZoomLevel(minZoom, type, tileSize), info.minZoom); - double maxZ = std::min(util::coveringZoomLevel(maxZoom, type, tileSize), info.maxZoom); +std::vector OfflineTilePyramidRegionDefinition::tileCover(SourceType type, uint16_t tileSize, const Tileset& tileset) const { + double minZ = std::max(util::coveringZoomLevel(minZoom, type, tileSize), tileset.minZoom); + double maxZ = std::min(util::coveringZoomLevel(maxZoom, type, tileSize), tileset.maxZoom); assert(minZ >= 0); assert(maxZ >= 0); diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 76a9c38c8b5..11ca862925a 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include @@ -46,7 +46,7 @@ void OfflineDownload::setState(OfflineRegionDownloadState state) { observer->statusChanged(status); } -std::vector OfflineDownload::spriteResources(const StyleParser& parser) const { +std::vector OfflineDownload::spriteResources(const style::Parser& parser) const { std::vector result; if (!parser.spriteURL.empty()) { @@ -57,7 +57,7 @@ std::vector OfflineDownload::spriteResources(const StyleParser& parser return result; } -std::vector OfflineDownload::glyphResources(const StyleParser& parser) const { +std::vector OfflineDownload::glyphResources(const style::Parser& parser) const { std::vector result; if (!parser.glyphURL.empty()) { @@ -71,11 +71,11 @@ std::vector OfflineDownload::glyphResources(const StyleParser& parser) return result; } -std::vector OfflineDownload::tileResources(SourceType type, uint16_t tileSize, const SourceInfo& info) const { +std::vector OfflineDownload::tileResources(SourceType type, uint16_t tileSize, const Tileset& tileset) const { std::vector result; - for (const auto& tile : definition.tileCover(type, tileSize, info)) { - result.push_back(Resource::tile(info.tiles[0], definition.pixelRatio, tile.x, tile.y, tile.z)); + for (const auto& tile : definition.tileCover(type, tileSize, tileset)) { + result.push_back(Resource::tile(tileset.tiles[0], definition.pixelRatio, tile.x, tile.y, tile.z)); } return result; @@ -94,7 +94,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const { return result; } - StyleParser parser; + style::Parser parser; parser.parse(*styleResponse->data); result.requiredResourceCountIsPrecise = true; @@ -103,14 +103,14 @@ OfflineRegionStatus OfflineDownload::getStatus() const { switch (source->type) { case SourceType::Vector: case SourceType::Raster: - if (source->getInfo()) { - result.requiredResourceCount += tileResources(source->type, source->tileSize, *source->getInfo()).size(); + if (source->getTileset()) { + result.requiredResourceCount += tileResources(source->type, source->tileSize, *source->getTileset()).size(); } else { result.requiredResourceCount += 1; optional sourceResponse = offlineDatabase.get(Resource::source(source->url)); if (sourceResponse) { result.requiredResourceCount += tileResources(source->type, source->tileSize, - *StyleParser::parseTileJSON(*sourceResponse->data, source->url, source->type, source->tileSize)).size(); + *style::parseTileJSON(*sourceResponse->data, source->url, source->type, source->tileSize)).size(); } else { result.requiredResourceCountIsPrecise = false; } @@ -144,7 +144,7 @@ void OfflineDownload::activateDownload() { ensureResource(Resource::style(definition.styleURL), [&] (Response styleResponse) { status.requiredResourceCountIsPrecise = true; - StyleParser parser; + style::Parser parser; parser.parse(*styleResponse.data); for (const auto& source : parser.sources) { @@ -155,14 +155,14 @@ void OfflineDownload::activateDownload() { switch (type) { case SourceType::Vector: case SourceType::Raster: - if (source->getInfo()) { - ensureTiles(type, tileSize, *source->getInfo()); + if (source->getTileset()) { + ensureTiles(type, tileSize, *source->getTileset()); } else { status.requiredResourceCountIsPrecise = false; requiredSourceURLs.insert(url); ensureResource(Resource::source(url), [=] (Response sourceResponse) { - ensureTiles(type, tileSize, *StyleParser::parseTileJSON(*sourceResponse.data, url, type, tileSize)); + ensureTiles(type, tileSize, *style::parseTileJSON(*sourceResponse.data, url, type, tileSize)); requiredSourceURLs.erase(url); if (requiredSourceURLs.empty()) { @@ -198,7 +198,7 @@ void OfflineDownload::deactivateDownload() { requests.clear(); } -void OfflineDownload::ensureTiles(SourceType type, uint16_t tileSize, const SourceInfo& info) { +void OfflineDownload::ensureTiles(SourceType type, uint16_t tileSize, const Tileset& info) { for (const auto& resource : tileResources(type, tileSize, info)) { ensureResource(resource); } diff --git a/platform/default/mbgl/storage/offline_download.hpp b/platform/default/mbgl/storage/offline_download.hpp index 706cdf98d8d..1a0d7536d8b 100644 --- a/platform/default/mbgl/storage/offline_download.hpp +++ b/platform/default/mbgl/storage/offline_download.hpp @@ -1,7 +1,6 @@ - #pragma once +#pragma once #include -#include #include #include @@ -14,9 +13,11 @@ class FileSource; class AsyncRequest; class Resource; class Response; -class SourceInfo; -class StyleParser; -class Source; +class Tileset; + +namespace style { +class Parser; +} /** * Coordinates the request and storage of all resources for an offline region. @@ -37,9 +38,9 @@ class OfflineDownload { void activateDownload(); void deactivateDownload(); - std::vector spriteResources(const StyleParser&) const; - std::vector glyphResources(const StyleParser&) const; - std::vector tileResources(SourceType, uint16_t, const SourceInfo&) const; + std::vector spriteResources(const style::Parser&) const; + std::vector glyphResources(const style::Parser&) const; + std::vector tileResources(SourceType, uint16_t, const Tileset&) const; /* * Ensure that the resource is stored in the database, requesting it if necessary. @@ -47,7 +48,7 @@ class OfflineDownload { * is deactivated, all in progress requests are cancelled. */ void ensureResource(const Resource&, std::function = {}); - void ensureTiles(SourceType, uint16_t, const SourceInfo&); + void ensureTiles(SourceType, uint16_t, const Tileset&); bool checkTileCountLimit(const Resource& resource); int64_t id; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 338dd4805f7..cc2f7c35186 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -15,9 +15,9 @@ #include #include #include -#include +#include +#include #include -#include #include #include #include @@ -2700,7 +2700,7 @@ - (void)setStyleClasses:(NS_ARRAY_OF(NSString *) *)appliedClasses transitionDura newAppliedClasses.insert(newAppliedClasses.end(), [appliedClass UTF8String]); } - mbgl::PropertyTransition transition { { MGLDurationInSeconds(transitionDuration) } }; + mbgl::style::TransitionOptions transition { { MGLDurationInSeconds(transitionDuration) } }; _mbglMap->setClasses(newAppliedClasses, transition); } @@ -4973,7 +4973,7 @@ void MGLPrepareCustomStyleLayer(void *context) } } -void MGLDrawCustomStyleLayer(void *context, const mbgl::CustomLayerRenderParameters ¶ms) +void MGLDrawCustomStyleLayer(void *context, const mbgl::style::CustomLayerRenderParameters ¶ms) { CGSize size = CGSizeMake(params.width, params.height); CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(params.latitude, params.longitude); @@ -5005,8 +5005,8 @@ - (void)insertCustomStyleLayerWithIdentifier:(NSString *)identifier preparationH { NSAssert(identifier, @"Style layer needs an identifier"); MGLCustomStyleLayerHandlers *context = new MGLCustomStyleLayerHandlers(preparation, drawing, completion); - _mbglMap->addLayer(std::make_unique(identifier.UTF8String, MGLPrepareCustomStyleLayer, - MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer, context), + _mbglMap->addLayer(std::make_unique(identifier.UTF8String, MGLPrepareCustomStyleLayer, + MGLDrawCustomStyleLayer, MGLFinishCustomStyleLayer, context), otherIdentifier ? mbgl::optional(otherIdentifier.UTF8String) : mbgl::optional()); } diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index 4354eac75dd..144d545d3c7 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include @@ -557,13 +557,13 @@ void QMapboxGL::addCustomLayer(const QString &id, void *context_, char *before) { - d_ptr->mapObj->addLayer(std::make_unique( + d_ptr->mapObj->addLayer(std::make_unique( id.toStdString(), - reinterpret_cast(initFn), + reinterpret_cast(initFn), // This cast is safe as long as both mbgl:: and QMapbox:: // CustomLayerRenderParameters members remains the same. - (mbgl::CustomLayerRenderFunction)renderFn, - reinterpret_cast(deinitFn), + (mbgl::style::CustomLayerRenderFunction)renderFn, + reinterpret_cast(deinitFn), context_), before ? mbgl::optional(before) : mbgl::optional()); } diff --git a/scripts/generate-style-code.js b/scripts/generate-style-code.js index 02f904983b5..0f2dcdc42c2 100644 --- a/scripts/generate-style-code.js +++ b/scripts/generate-style-code.js @@ -80,11 +80,14 @@ const layerHpp = ejs.compile(`<% #include #include +#include + <% if (type === 'line' || type === 'symbol') { -%> #include <% } -%> namespace mbgl { +namespace style { class <%- camelize(type) %>Layer : public Layer { public: @@ -138,6 +141,7 @@ inline bool Layer::is<<%- camelize(type) %>Layer>() const { return type == Type::<%- camelize(type) %>; } +} // namespace style } // namespace mbgl `, {strict: true}); @@ -148,10 +152,11 @@ const layerCpp = ejs.compile(`<% -%> // This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`. -#include _layer.hpp> -#include _layer_impl.hpp> +#include _layer.hpp> +#include _layer_impl.hpp> namespace mbgl { +namespace style { <%- camelize(type) %>Layer::<%- camelize(type) %>Layer(const std::string& layerID) : Layer(Type::<%- camelize(type) %>, std::make_unique()) @@ -230,6 +235,7 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue } <% } -%> +} // namespace style } // namespace mbgl `, {strict: true}); @@ -247,15 +253,16 @@ const propertiesHpp = ejs.compile(`<% #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; <% if (layoutProperties.length) { -%> class <%- camelize(type) %>LayoutProperties { public: void parse(const JSValue&); - void recalculate(const StyleCalculationParameters&); + void recalculate(const CalculationParameters&); <% for (const property of layoutProperties) { -%> LayoutProperty<<%- propertyType(property) %>> <%- camelizeWithLeadingLowercase(property.name) %> { <%- defaultValue(property) %> }; @@ -266,8 +273,8 @@ public: class <%- camelize(type) %>PaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); <% for (const property of paintProperties) { -%> <% if (/-pattern$/.test(property.name) || property.name === 'line-dasharray') { -%> @@ -280,6 +287,7 @@ public: <% } -%> }; +} // namespace style } // namespace mbgl `, {strict: true}); @@ -290,9 +298,10 @@ const propertiesCpp = ejs.compile(`<% -%> // This file is generated. Edit scripts/generate-style-code.js, then run \`make style-code\`. -#include _layer_properties.hpp> +#include _layer_properties.hpp> namespace mbgl { +namespace style { <% if (layoutProperties.length) { -%> void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) { @@ -301,7 +310,7 @@ void <%- camelize(type) %>LayoutProperties::parse(const JSValue& value) { <% } -%> } -void <%- camelize(type) %>LayoutProperties::recalculate(const StyleCalculationParameters& parameters) { +void <%- camelize(type) %>LayoutProperties::recalculate(const CalculationParameters& parameters) { <% for (const property of layoutProperties) { -%> <%- camelizeWithLeadingLowercase(property.name) %>.calculate(parameters); <% } -%> @@ -314,13 +323,13 @@ void <%- camelize(type) %>PaintProperties::parse(const JSValue& value) { <% } -%> } -void <%- camelize(type) %>PaintProperties::cascade(const StyleCascadeParameters& parameters) { +void <%- camelize(type) %>PaintProperties::cascade(const CascadeParameters& parameters) { <% for (const property of paintProperties) { -%> <%- camelizeWithLeadingLowercase(property.name) %>.cascade(parameters); <% } -%> } -bool <%- camelize(type) %>PaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool <%- camelize(type) %>PaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; <% for (const property of paintProperties) { -%> @@ -330,6 +339,7 @@ bool <%- camelize(type) %>PaintProperties::recalculate(const StyleCalculationPar return hasTransitions; } +} // namespace style } // namespace mbgl `, {strict: true}); @@ -354,9 +364,9 @@ for (const type of spec.layer.type.values) { paintProperties: paintProperties, }; - fs.writeFileSync(`include/mbgl/layer/${type}_layer.hpp`, layerHpp(layer)); - fs.writeFileSync(`src/mbgl/layer/${type}_layer.cpp`, layerCpp(layer)); + fs.writeFileSync(`include/mbgl/style/layers/${type}_layer.hpp`, layerHpp(layer)); + fs.writeFileSync(`src/mbgl/style/layers/${type}_layer.cpp`, layerCpp(layer)); - fs.writeFileSync(`src/mbgl/layer/${type}_layer_properties.hpp`, propertiesHpp(layer)); - fs.writeFileSync(`src/mbgl/layer/${type}_layer_properties.cpp`, propertiesCpp(layer)); + fs.writeFileSync(`src/mbgl/style/layers/${type}_layer_properties.hpp`, propertiesHpp(layer)); + fs.writeFileSync(`src/mbgl/style/layers/${type}_layer_properties.cpp`, propertiesCpp(layer)); } diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index 09442b165c4..e332850357b 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -4,15 +4,17 @@ #include #include #include -#include +#include #include -#include -#include +#include +#include #include namespace mbgl { +using namespace style; + const std::string AnnotationManager::SourceID = "com.mapbox.annotations"; const std::string AnnotationManager::PointLayerID = "com.mapbox.annotations.points"; @@ -105,7 +107,7 @@ std::unique_ptr AnnotationManager::getTile(const CanonicalTileID void AnnotationManager::updateStyle(Style& style) { // Create annotation source, point layer, and point bucket if (!style.getSource(SourceID)) { - std::unique_ptr source = std::make_unique(SourceType::Annotations, SourceID, "", util::tileSize, std::make_unique(), nullptr); + std::unique_ptr source = std::make_unique(SourceType::Annotations, SourceID, "", util::tileSize, std::make_unique(), nullptr); source->enabled = true; style.addSource(std::move(source)); diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 6862739ebbf..73907e10c89 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -18,7 +18,10 @@ class AnnotationTile; class AnnotationTileMonitor; class SymbolAnnotationImpl; class ShapeAnnotationImpl; + +namespace style { class Style; +} class AnnotationManager : private util::noncopyable { public: @@ -36,7 +39,7 @@ class AnnotationManager : private util::noncopyable { double getTopOffsetPixelsForIcon(const std::string& name); SpriteAtlas& getSpriteAtlas() { return spriteAtlas; } - void updateStyle(Style&); + void updateStyle(style::Style&); void addTileMonitor(AnnotationTileMonitor&); void removeTileMonitor(AnnotationTileMonitor&); diff --git a/src/mbgl/annotation/fill_annotation_impl.cpp b/src/mbgl/annotation/fill_annotation_impl.cpp index 17bdd9c38e9..31c9f6d7201 100644 --- a/src/mbgl/annotation/fill_annotation_impl.cpp +++ b/src/mbgl/annotation/fill_annotation_impl.cpp @@ -1,11 +1,11 @@ #include #include #include -#include +#include namespace mbgl { -namespace geojsonvt = mapbox::geojsonvt; +using namespace style; FillAnnotationImpl::FillAnnotationImpl(const AnnotationID id_, const FillAnnotation& annotation_, const uint8_t maxZoom_) : ShapeAnnotationImpl(id_, maxZoom_), diff --git a/src/mbgl/annotation/fill_annotation_impl.hpp b/src/mbgl/annotation/fill_annotation_impl.hpp index c396499e384..b879860c08f 100644 --- a/src/mbgl/annotation/fill_annotation_impl.hpp +++ b/src/mbgl/annotation/fill_annotation_impl.hpp @@ -9,7 +9,7 @@ class FillAnnotationImpl : public ShapeAnnotationImpl { public: FillAnnotationImpl(const AnnotationID, const FillAnnotation&, const uint8_t maxZoom); - void updateStyle(Style&) const final; + void updateStyle(style::Style&) const final; const ShapeAnnotationGeometry& geometry() const final; private: diff --git a/src/mbgl/annotation/line_annotation_impl.cpp b/src/mbgl/annotation/line_annotation_impl.cpp index 11febc7de71..85177591f44 100644 --- a/src/mbgl/annotation/line_annotation_impl.cpp +++ b/src/mbgl/annotation/line_annotation_impl.cpp @@ -1,11 +1,11 @@ #include #include #include -#include +#include namespace mbgl { -namespace geojsonvt = mapbox::geojsonvt; +using namespace style; LineAnnotationImpl::LineAnnotationImpl(const AnnotationID id_, const LineAnnotation& annotation_, const uint8_t maxZoom_) : ShapeAnnotationImpl(id_, maxZoom_), diff --git a/src/mbgl/annotation/line_annotation_impl.hpp b/src/mbgl/annotation/line_annotation_impl.hpp index 05d650c0516..c9a37dd3904 100644 --- a/src/mbgl/annotation/line_annotation_impl.hpp +++ b/src/mbgl/annotation/line_annotation_impl.hpp @@ -9,7 +9,7 @@ class LineAnnotationImpl : public ShapeAnnotationImpl { public: LineAnnotationImpl(const AnnotationID, const LineAnnotation&, const uint8_t maxZoom); - void updateStyle(Style&) const final; + void updateStyle(style::Style&) const final; const ShapeAnnotationGeometry& geometry() const final; private: diff --git a/src/mbgl/annotation/shape_annotation_impl.cpp b/src/mbgl/annotation/shape_annotation_impl.cpp index 283e736c6d8..be6e12558d1 100644 --- a/src/mbgl/annotation/shape_annotation_impl.cpp +++ b/src/mbgl/annotation/shape_annotation_impl.cpp @@ -10,6 +10,7 @@ namespace mbgl { +using namespace style; namespace geojsonvt = mapbox::geojsonvt; ShapeAnnotationImpl::ShapeAnnotationImpl(const AnnotationID id_, const uint8_t maxZoom_) diff --git a/src/mbgl/annotation/shape_annotation_impl.hpp b/src/mbgl/annotation/shape_annotation_impl.hpp index 7f36f8b888c..e6ba9a4bd70 100644 --- a/src/mbgl/annotation/shape_annotation_impl.hpp +++ b/src/mbgl/annotation/shape_annotation_impl.hpp @@ -9,16 +9,19 @@ namespace mbgl { -class Style; class AnnotationTile; class CanonicalTileID; +namespace style { +class Style; +} + class ShapeAnnotationImpl { public: ShapeAnnotationImpl(const AnnotationID, const uint8_t maxZoom); virtual ~ShapeAnnotationImpl() = default; - virtual void updateStyle(Style&) const = 0; + virtual void updateStyle(style::Style&) const = 0; virtual const ShapeAnnotationGeometry& geometry() const = 0; void updateTile(const CanonicalTileID&, AnnotationTile&); diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.cpp b/src/mbgl/annotation/style_sourced_annotation_impl.cpp index e1e11a664af..43a27c8aacc 100644 --- a/src/mbgl/annotation/style_sourced_annotation_impl.cpp +++ b/src/mbgl/annotation/style_sourced_annotation_impl.cpp @@ -2,12 +2,12 @@ #include #include #include -#include -#include +#include +#include namespace mbgl { -namespace geojsonvt = mapbox::geojsonvt; +using namespace style; StyleSourcedAnnotationImpl::StyleSourcedAnnotationImpl(const AnnotationID id_, const StyleSourcedAnnotation& annotation_, const uint8_t maxZoom_) : ShapeAnnotationImpl(id_, maxZoom_), diff --git a/src/mbgl/annotation/style_sourced_annotation_impl.hpp b/src/mbgl/annotation/style_sourced_annotation_impl.hpp index 98e9910c662..09ef474fc0a 100644 --- a/src/mbgl/annotation/style_sourced_annotation_impl.hpp +++ b/src/mbgl/annotation/style_sourced_annotation_impl.hpp @@ -9,7 +9,7 @@ class StyleSourcedAnnotationImpl : public ShapeAnnotationImpl { public: StyleSourcedAnnotationImpl(const AnnotationID, const StyleSourcedAnnotation&, const uint8_t maxZoom); - void updateStyle(Style&) const final; + void updateStyle(style::Style&) const final; const ShapeAnnotationGeometry& geometry() const final; private: diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index e72aa344fa1..8c10344915e 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -1,8 +1,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -59,7 +59,7 @@ void FeatureIndex::query( const optional>& filterLayerIDs, const GeometryTile& geometryTile, const CanonicalTileID& tileID, - const Style& style) const { + const style::Style& style) const { mapbox::geometry::box box = mapbox::geometry::envelope(queryGeometry); @@ -94,7 +94,7 @@ void FeatureIndex::addFeature( const optional>& filterLayerIDs, const GeometryTile& geometryTile, const CanonicalTileID& tileID, - const Style& style, + const style::Style& style, const float bearing, const float pixelsToTileUnits) const { @@ -116,7 +116,7 @@ void FeatureIndex::addFeature( auto styleLayer = style.getLayer(layerID); if (!styleLayer || - (!styleLayer->is() && + (!styleLayer->is() && !styleLayer->baseImpl->queryIntersectsGeometry(queryGeometry, geometryTileFeature->getGeometries(), bearing, pixelsToTileUnits))) { continue; } @@ -128,7 +128,7 @@ void FeatureIndex::addFeature( optional FeatureIndex::translateQueryGeometry( const GeometryCollection& queryGeometry, const std::array& translate, - const TranslateAnchorType anchorType, + const style::TranslateAnchorType anchorType, const float bearing, const float pixelsToTileUnits) { if (translate[0] == 0 && translate[1] == 0) { @@ -136,7 +136,7 @@ optional FeatureIndex::translateQueryGeometry( } GeometryCoordinate translateVec(translate[0] * pixelsToTileUnits, translate[1] * pixelsToTileUnits); - if (anchorType == TranslateAnchorType::Viewport) { + if (anchorType == style::TranslateAnchorType::Viewport) { translateVec = util::rotate(translateVec, -bearing); } diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index 0dcc154f02f..c944a981306 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -10,9 +11,11 @@ namespace mbgl { +namespace style { class Style; +} + class CollisionTile; -enum class TranslateAnchorType : bool; class CanonicalTileID; class IndexedSubfeature { @@ -39,12 +42,12 @@ class FeatureIndex { const optional>& layerIDs, const GeometryTile&, const CanonicalTileID&, - const Style&) const; + const style::Style&) const; static optional translateQueryGeometry( const GeometryCollection& queryGeometry, const std::array& translate, - const TranslateAnchorType, + const style::TranslateAnchorType, const float bearing, const float pixelsToTileUnits); @@ -60,7 +63,7 @@ class FeatureIndex { const optional>& filterLayerIDs, const GeometryTile&, const CanonicalTileID&, - const Style&, + const style::Style&, const float bearing, const float pixelsToTileUnits) const; diff --git a/src/mbgl/layer/background_layer_impl.hpp b/src/mbgl/layer/background_layer_impl.hpp deleted file mode 100644 index 6af31dd9219..00000000000 --- a/src/mbgl/layer/background_layer_impl.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { - -class BackgroundLayer::Impl : public Layer::Impl { -public: - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - BackgroundPaintProperties paint; -}; - -} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_impl.hpp b/src/mbgl/layer/raster_layer_impl.hpp deleted file mode 100644 index a83c7f259e4..00000000000 --- a/src/mbgl/layer/raster_layer_impl.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include -#include - -namespace mbgl { - -class RasterLayer::Impl : public Layer::Impl { -public: - std::unique_ptr clone() const override; - - void parseLayout(const JSValue&) override {}; - void parsePaints(const JSValue&) override; - - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; - - std::unique_ptr createBucket(StyleBucketParameters&) const override; - - RasterPaintProperties paint; -}; - -} // namespace mbgl diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 4f1c4634ca8..ec961a6485d 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -5,11 +5,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -25,13 +25,15 @@ namespace mbgl { +using namespace style; + enum class RenderState { never, partial, fully }; -class Map::Impl : public StyleObserver { +class Map::Impl : public style::Observer { public: Impl(View&, FileSource&, MapMode, GLContextMode, ConstrainMode, ViewportMode); @@ -221,17 +223,17 @@ void Map::Impl::update() { style->recalculate(transform.getZoom(), timePoint, mode); } - StyleUpdateParameters parameters(pixelRatio, - debugOptions, - timePoint, - transform.getState(), - style->workers, - fileSource, - *texturePool, - style->shouldReparsePartialTiles, - mode, - *annotationManager, - *style); + style::UpdateParameters parameters(pixelRatio, + debugOptions, + timePoint, + transform.getState(), + style->workers, + fileSource, + *texturePool, + style->shouldReparsePartialTiles, + mode, + *annotationManager, + *style); style->update(parameters); @@ -799,19 +801,19 @@ bool Map::isFullyLoaded() const { return impl->style->isLoaded(); } -void Map::addClass(const std::string& className, const PropertyTransition& properties) { +void Map::addClass(const std::string& className, const TransitionOptions& properties) { if (impl->style->addClass(className, properties)) { update(Update::Classes); } } -void Map::removeClass(const std::string& className, const PropertyTransition& properties) { +void Map::removeClass(const std::string& className, const TransitionOptions& properties) { if (impl->style->removeClass(className, properties)) { update(Update::Classes); } } -void Map::setClasses(const std::vector& classNames, const PropertyTransition& properties) { +void Map::setClasses(const std::vector& classNames, const TransitionOptions& properties) { impl->style->setClasses(classNames, properties); update(Update::Classes); } diff --git a/src/mbgl/style/zoom_history.hpp b/src/mbgl/map/zoom_history.hpp similarity index 100% rename from src/mbgl/style/zoom_history.hpp rename to src/mbgl/map/zoom_history.hpp diff --git a/src/mbgl/renderer/bucket.hpp b/src/mbgl/renderer/bucket.hpp index 89b0ceefb2e..c7ebe480ed9 100644 --- a/src/mbgl/renderer/bucket.hpp +++ b/src/mbgl/renderer/bucket.hpp @@ -13,7 +13,6 @@ namespace mbgl { class Painter; -class Layer; class UnwrappedTileID; class CollisionTile; @@ -21,6 +20,10 @@ namespace gl { class ObjectStore; } +namespace style { +class Layer; +} + class Bucket : private util::noncopyable { public: Bucket() : uploaded(false) {} @@ -31,7 +34,7 @@ class Bucket : private util::noncopyable { // Every time this bucket is getting rendered, this function is called. This happens either // once or twice (for Opaque and Transparent render passes). - virtual void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) = 0; + virtual void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) = 0; virtual ~Bucket() = default; diff --git a/src/mbgl/renderer/circle_bucket.cpp b/src/mbgl/renderer/circle_bucket.cpp index 969e05131b4..4ae63fed46f 100644 --- a/src/mbgl/renderer/circle_bucket.cpp +++ b/src/mbgl/renderer/circle_bucket.cpp @@ -2,10 +2,12 @@ #include #include -#include +#include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; CircleBucket::CircleBucket(MapMode mode_) : mode(mode_) { } @@ -97,3 +99,5 @@ void CircleBucket::drawCircles(CircleShader& shader, gl::ObjectStore& store) { elementsIndex += group->elements_length * elementsBuffer_.itemSize; } } + +} diff --git a/src/mbgl/renderer/circle_bucket.hpp b/src/mbgl/renderer/circle_bucket.hpp index 9c95fce0453..fa34aa088a2 100644 --- a/src/mbgl/renderer/circle_bucket.hpp +++ b/src/mbgl/renderer/circle_bucket.hpp @@ -19,7 +19,7 @@ class CircleBucket : public Bucket { ~CircleBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/fill_bucket.cpp b/src/mbgl/renderer/fill_bucket.cpp index 4a9709f4e84..02f346decbe 100644 --- a/src/mbgl/renderer/fill_bucket.cpp +++ b/src/mbgl/renderer/fill_bucket.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -12,22 +12,24 @@ #include -struct GeometryTooLongException : std::exception {}; - -using namespace mbgl; - namespace mapbox { namespace util { -template <> struct nth<0, GeometryCoordinate> { - inline static int64_t get(const GeometryCoordinate& t) { return t.x; }; +template <> struct nth<0, mbgl::GeometryCoordinate> { + inline static int64_t get(const mbgl::GeometryCoordinate& t) { return t.x; }; }; -template <> struct nth<1, GeometryCoordinate> { - inline static int64_t get(const GeometryCoordinate& t) { return t.y; }; +template <> struct nth<1, mbgl::GeometryCoordinate> { + inline static int64_t get(const mbgl::GeometryCoordinate& t) { return t.y; }; }; } } +namespace mbgl { + +using namespace style; + +struct GeometryTooLongException : std::exception {}; + FillBucket::FillBucket() { } @@ -165,3 +167,5 @@ void FillBucket::drawVertices(OutlinePatternShader& shader, gl::ObjectStore& sto elements_index += group->elements_length * lineElementsBuffer.itemSize; } } + +} diff --git a/src/mbgl/renderer/fill_bucket.hpp b/src/mbgl/renderer/fill_bucket.hpp index 21e3239f294..35d70d169c0 100644 --- a/src/mbgl/renderer/fill_bucket.hpp +++ b/src/mbgl/renderer/fill_bucket.hpp @@ -21,7 +21,7 @@ class FillBucket : public Bucket { ~FillBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp index 8124a5daed2..d207cdb8c55 100644 --- a/src/mbgl/renderer/line_bucket.cpp +++ b/src/mbgl/renderer/line_bucket.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -11,7 +11,9 @@ #include -using namespace mbgl; +namespace mbgl { + +using namespace style; LineBucket::LineBucket(uint32_t overscaling_) : overscaling(overscaling_) { } @@ -505,3 +507,5 @@ void LineBucket::drawLinePatterns(LinepatternShader& shader, gl::ObjectStore& st elements_index += group->elements_length * triangleElementsBuffer.itemSize; } } + +} diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp index 1093ec2a48e..d746f29c7ed 100644 --- a/src/mbgl/renderer/line_bucket.hpp +++ b/src/mbgl/renderer/line_bucket.hpp @@ -5,13 +5,12 @@ #include #include #include -#include +#include #include namespace mbgl { -class Style; class LineVertexBuffer; class TriangleElementsBuffer; class LineShader; @@ -26,7 +25,7 @@ class LineBucket : public Bucket { ~LineBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; @@ -50,7 +49,7 @@ class LineBucket : public Bucket { std::vector& triangleStore); public: - LineLayoutProperties layout; + style::LineLayoutProperties layout; private: LineVertexBuffer vertexBuffer; diff --git a/src/mbgl/renderer/painter.cpp b/src/mbgl/renderer/painter.cpp index ccc6e234084..1864bf7ef11 100644 --- a/src/mbgl/renderer/painter.cpp +++ b/src/mbgl/renderer/painter.cpp @@ -1,18 +1,17 @@ #include -#include +#include #include #include #include #include -#include -#include +#include -#include -#include -#include +#include +#include +#include #include #include @@ -46,7 +45,9 @@ #include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; Painter::Painter(const TransformState& state_, gl::ObjectStore& store_) : state(state_), @@ -308,3 +309,5 @@ void Painter::setDepthSublayer(int n) { float farDepth = nearDepth + depthRangeSize; config.depthRange = { nearDepth, farDepth }; } + +} diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index ad26457555d..f040fee67f3 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -13,7 +13,7 @@ #include #include -#include +#include #include @@ -28,27 +28,19 @@ namespace mbgl { -class Style; class Tile; class SpriteAtlas; class GlyphAtlas; class LineAtlas; -class Source; struct FrameData; class TileData; class DebugBucket; class FillBucket; -class FillLayer; class LineBucket; -class LineLayer; class CircleBucket; -class CircleLayer; class SymbolBucket; -class SymbolLayer; class RasterBucket; -class RasterLayer; -class BackgroundLayer; class SDFShader; class PlainShader; @@ -72,6 +64,17 @@ namespace util { class ObjectStore; } +namespace style { +class Style; +class Source; +class FillLayer; +class LineLayer; +class CircleLayer; +class SymbolLayer; +class RasterLayer; +class BackgroundLayer; +} + struct FrameData { std::array framebufferSize; TimePoint timePoint; @@ -86,8 +89,8 @@ class Painter : private util::noncopyable { Painter(const TransformState&, gl::ObjectStore&); ~Painter(); - void render(const Style& style, - const FrameData& frame, + void render(const style::Style&, + const FrameData&, SpriteAtlas& annotationSpriteAtlas); // Renders debug information for a tile. @@ -99,12 +102,12 @@ class Painter : private util::noncopyable { void renderClipMasks(); void renderDebugText(TileData&, const mat4&); - void renderFill(FillBucket&, const FillLayer&, const UnwrappedTileID&, const mat4&); - void renderLine(LineBucket&, const LineLayer&, const UnwrappedTileID&, const mat4&); - void renderCircle(CircleBucket&, const CircleLayer&, const UnwrappedTileID&, const mat4&); - void renderSymbol(SymbolBucket&, const SymbolLayer&, const UnwrappedTileID&, const mat4&); - void renderRaster(RasterBucket&, const RasterLayer&, const UnwrappedTileID&, const mat4&); - void renderBackground(const BackgroundLayer&); + void renderFill(FillBucket&, const style::FillLayer&, const UnwrappedTileID&, const mat4&); + void renderLine(LineBucket&, const style::LineLayer&, const UnwrappedTileID&, const mat4&); + void renderCircle(CircleBucket&, const style::CircleLayer&, const UnwrappedTileID&, const mat4&); + void renderSymbol(SymbolBucket&, const style::SymbolLayer&, const UnwrappedTileID&, const mat4&); + void renderRaster(RasterBucket&, const style::RasterLayer&, const UnwrappedTileID&, const mat4&); + void renderBackground(const style::BackgroundLayer&); float saturationFactor(float saturation); float contrastFactor(float contrast); @@ -118,9 +121,9 @@ class Painter : private util::noncopyable { mat4 translatedMatrix(const mat4& matrix, const std::array& translation, const UnwrappedTileID& id, - TranslateAnchorType anchor); + style::TranslateAnchorType anchor); - std::vector determineRenderOrder(const Style& style); + std::vector determineRenderOrder(const style::Style&); template void renderPass(RenderPass, @@ -138,7 +141,7 @@ class Painter : private util::noncopyable { void (SymbolBucket::*drawSDF)(SDFShader&, gl::ObjectStore&), // Layout - RotationAlignmentType rotationAlignment, + style::RotationAlignmentType rotationAlignment, float layoutSize, // Paint @@ -148,7 +151,7 @@ class Painter : private util::noncopyable { float haloWidth, float haloBlur, std::array translate, - TranslateAnchorType translateAnchor, + style::TranslateAnchorType translateAnchor, float paintSize); void setDepthSublayer(int n); diff --git a/src/mbgl/renderer/painter_background.cpp b/src/mbgl/renderer/painter_background.cpp index bc01d3c32fb..07e5821ce8f 100644 --- a/src/mbgl/renderer/painter_background.cpp +++ b/src/mbgl/renderer/painter_background.cpp @@ -1,14 +1,16 @@ #include -#include -#include +#include +#include #include #include #include #include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderBackground(const BackgroundLayer& layer) { // Note that for bottommost layers without a pattern, the background color is drawn with @@ -107,3 +109,5 @@ void Painter::renderBackground(const BackgroundLayer& layer) { MBGL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)tileStencilBuffer.index())); } } + +} diff --git a/src/mbgl/renderer/painter_circle.cpp b/src/mbgl/renderer/painter_circle.cpp index c371f4debed..9f2cd17f7f8 100644 --- a/src/mbgl/renderer/painter_circle.cpp +++ b/src/mbgl/renderer/painter_circle.cpp @@ -1,12 +1,14 @@ #include #include -#include -#include +#include +#include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderCircle(CircleBucket& bucket, const CircleLayer& layer, @@ -43,3 +45,5 @@ void Painter::renderCircle(CircleBucket& bucket, bucket.drawCircles(*circleShader, store); } + +} diff --git a/src/mbgl/renderer/painter_clipping.cpp b/src/mbgl/renderer/painter_clipping.cpp index f0fd4982674..e6ce1a040e0 100644 --- a/src/mbgl/renderer/painter_clipping.cpp +++ b/src/mbgl/renderer/painter_clipping.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/mbgl/renderer/painter_fill.cpp b/src/mbgl/renderer/painter_fill.cpp index b499d20da39..b89686c8158 100644 --- a/src/mbgl/renderer/painter_fill.cpp +++ b/src/mbgl/renderer/painter_fill.cpp @@ -1,14 +1,16 @@ #include #include -#include -#include +#include +#include #include #include #include #include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderFill(FillBucket& bucket, const FillLayer& layer, @@ -195,3 +197,5 @@ void Painter::renderFill(FillBucket& bucket, bucket.drawVertices(*outlineShader, store); } } + +} diff --git a/src/mbgl/renderer/painter_line.cpp b/src/mbgl/renderer/painter_line.cpp index 3cf1ad41471..26041a8165d 100644 --- a/src/mbgl/renderer/painter_line.cpp +++ b/src/mbgl/renderer/painter_line.cpp @@ -1,7 +1,7 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -9,7 +9,9 @@ #include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderLine(LineBucket& bucket, const LineLayer& layer, @@ -161,3 +163,5 @@ void Painter::renderLine(LineBucket& bucket, bucket.drawLines(*lineShader, store); } } + +} diff --git a/src/mbgl/renderer/painter_raster.cpp b/src/mbgl/renderer/painter_raster.cpp index 511ac963873..cce71e8ce2a 100644 --- a/src/mbgl/renderer/painter_raster.cpp +++ b/src/mbgl/renderer/painter_raster.cpp @@ -1,11 +1,13 @@ #include #include #include -#include -#include +#include +#include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderRaster(RasterBucket& bucket, const RasterLayer& layer, @@ -66,3 +68,5 @@ std::array Painter::spinWeights(float spin) { }}; return spin_weights; } + +} diff --git a/src/mbgl/renderer/painter_symbol.cpp b/src/mbgl/renderer/painter_symbol.cpp index 97745680740..3c453242ae7 100644 --- a/src/mbgl/renderer/painter_symbol.cpp +++ b/src/mbgl/renderer/painter_symbol.cpp @@ -1,6 +1,7 @@ #include #include -#include +#include +#include #include #include #include @@ -10,7 +11,9 @@ #include -using namespace mbgl; +namespace mbgl { + +using namespace style; void Painter::renderSDF(SymbolBucket &bucket, const UnwrappedTileID &tileID, @@ -257,3 +260,5 @@ void Painter::renderSymbol(SymbolBucket& bucket, config.activeTexture = GL_TEXTURE0; } + +} diff --git a/src/mbgl/renderer/raster_bucket.cpp b/src/mbgl/renderer/raster_bucket.cpp index b16d7f8161c..39f8dacd92c 100644 --- a/src/mbgl/renderer/raster_bucket.cpp +++ b/src/mbgl/renderer/raster_bucket.cpp @@ -1,9 +1,11 @@ #include -#include +#include #include #include -using namespace mbgl; +namespace mbgl { + +using namespace style; RasterBucket::RasterBucket(gl::TexturePool& texturePool) : raster(texturePool) { @@ -40,3 +42,5 @@ bool RasterBucket::hasData() const { bool RasterBucket::needsClipping() const { return false; } + +} diff --git a/src/mbgl/renderer/raster_bucket.hpp b/src/mbgl/renderer/raster_bucket.hpp index 9125ef2047c..93331755fb9 100644 --- a/src/mbgl/renderer/raster_bucket.hpp +++ b/src/mbgl/renderer/raster_bucket.hpp @@ -14,7 +14,7 @@ class RasterBucket : public Bucket { RasterBucket(gl::TexturePool&); void upload(gl::ObjectStore&) override; - void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool needsClipping() const override; diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 67c8468ecdd..f4e55432c13 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -31,6 +31,8 @@ namespace mbgl { +using namespace style; + SymbolInstance::SymbolInstance(Anchor& anchor, const GeometryCoordinates& line, const Shaping& shapedText, const PositionedIcon& shapedIcon, const SymbolLayoutProperties& layout, const bool addToBuffers, const uint32_t index_, diff --git a/src/mbgl/renderer/symbol_bucket.hpp b/src/mbgl/renderer/symbol_bucket.hpp index b19a86b2751..314d44bdee6 100644 --- a/src/mbgl/renderer/symbol_bucket.hpp +++ b/src/mbgl/renderer/symbol_bucket.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include @@ -46,7 +46,7 @@ class SymbolInstance { public: explicit SymbolInstance(Anchor& anchor, const GeometryCoordinates& line, const Shaping& shapedText, const PositionedIcon& shapedIcon, - const SymbolLayoutProperties& layout, const bool inside, const uint32_t index, + const style::SymbolLayoutProperties&, const bool inside, const uint32_t index, const float textBoxScale, const float textPadding, const float textAlongLine, const float iconBoxScale, const float iconPadding, const float iconAlongLine, const GlyphPositions& face, const IndexedSubfeature& indexedfeature); @@ -70,7 +70,7 @@ class SymbolBucket : public Bucket { ~SymbolBucket() override; void upload(gl::ObjectStore&) override; - void render(Painter&, const Layer&, const UnwrappedTileID&, const mat4&) override; + void render(Painter&, const style::Layer&, const UnwrappedTileID&, const mat4&) override; bool hasData() const override; bool hasTextData() const; bool hasIconData() const; @@ -87,7 +87,7 @@ class SymbolBucket : public Bucket { void drawIcons(IconShader&, gl::ObjectStore&); void drawCollisionBoxes(CollisionBoxShader&, gl::ObjectStore&); - void parseFeatures(const GeometryTileLayer&, const Filter&); + void parseFeatures(const GeometryTileLayer&, const style::Filter&); bool needsDependencies(GlyphStore&, SpriteStore&); void placeFeatures(CollisionTile&) override; @@ -109,7 +109,7 @@ class SymbolBucket : public Bucket { const bool keepUpright, const bool alongLine, const float placementAngle); public: - SymbolLayoutProperties layout; + style::SymbolLayoutProperties layout; float iconMaxSize = 1.0f; float textMaxSize = 16.0f; diff --git a/src/mbgl/style/style_bucket_parameters.cpp b/src/mbgl/style/bucket_parameters.cpp similarity index 80% rename from src/mbgl/style/style_bucket_parameters.cpp rename to src/mbgl/style/bucket_parameters.cpp index 0b4b2affcde..f3367d57e1e 100644 --- a/src/mbgl/style/style_bucket_parameters.cpp +++ b/src/mbgl/style/bucket_parameters.cpp @@ -1,10 +1,11 @@ -#include +#include #include #include namespace mbgl { +namespace style { -void StyleBucketParameters::eachFilteredFeature(const Filter& filter, +void BucketParameters::eachFilteredFeature(const Filter& filter, std::function function) { auto name = layer.getName(); for (std::size_t i = 0; !cancelled() && i < layer.featureCount(); i++) { @@ -18,4 +19,5 @@ void StyleBucketParameters::eachFilteredFeature(const Filter& filter, } } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_bucket_parameters.hpp b/src/mbgl/style/bucket_parameters.hpp similarity index 93% rename from src/mbgl/style/style_bucket_parameters.hpp rename to src/mbgl/style/bucket_parameters.hpp index 17639afae70..f85e1e17efe 100644 --- a/src/mbgl/style/style_bucket_parameters.hpp +++ b/src/mbgl/style/bucket_parameters.hpp @@ -18,9 +18,11 @@ class GlyphStore; class CollisionTile; class FeatureIndex; -class StyleBucketParameters { +namespace style { + +class BucketParameters { public: - StyleBucketParameters(const OverscaledTileID& tileID_, + BucketParameters(const OverscaledTileID& tileID_, const GeometryTileLayer& layer_, const std::atomic& obsolete_, uintptr_t tileUID_, @@ -59,4 +61,5 @@ class StyleBucketParameters { const MapMode mode; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/calculation_parameters.hpp b/src/mbgl/style/calculation_parameters.hpp new file mode 100644 index 00000000000..2afd7c4b34a --- /dev/null +++ b/src/mbgl/style/calculation_parameters.hpp @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +namespace mbgl { +namespace style { + +class CalculationParameters { +public: + explicit CalculationParameters(float z_) + : z(z_) {} + + CalculationParameters(float z_, + const TimePoint& now_, + const ZoomHistory& zoomHistory_, + const Duration& defaultFadeDuration_) + : z(z_), + now(now_), + zoomHistory(zoomHistory_), + defaultFadeDuration(defaultFadeDuration_) {} + + float z; + TimePoint now; + ZoomHistory zoomHistory; + Duration defaultFadeDuration; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/cascade_parameters.hpp b/src/mbgl/style/cascade_parameters.hpp new file mode 100644 index 00000000000..4ad6da2ce39 --- /dev/null +++ b/src/mbgl/style/cascade_parameters.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include + +#include + +namespace mbgl { +namespace style { + +class TransitionOptions; + +class CascadeParameters { +public: + std::vector classes; + TimePoint now; + TransitionOptions transition; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/style/class_dictionary.cpp b/src/mbgl/style/class_dictionary.cpp index 53ea5c1484b..ec06ee7d9d0 100644 --- a/src/mbgl/style/class_dictionary.cpp +++ b/src/mbgl/style/class_dictionary.cpp @@ -3,6 +3,7 @@ #include namespace mbgl { +namespace style { ClassDictionary::ClassDictionary() {} @@ -46,4 +47,5 @@ ClassID ClassDictionary::normalize(ClassID id) { } } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/class_dictionary.hpp b/src/mbgl/style/class_dictionary.hpp index 703e27b4381..c95773d7c36 100644 --- a/src/mbgl/style/class_dictionary.hpp +++ b/src/mbgl/style/class_dictionary.hpp @@ -5,6 +5,7 @@ #include namespace mbgl { +namespace style { enum class ClassID : uint32_t { Fallback = 0, // These values are from the fallback properties @@ -31,4 +32,5 @@ class ClassDictionary { uint32_t offset = 0; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/filter_evaluator.hpp b/src/mbgl/style/filter_evaluator.hpp index b607a0c6581..e03beaa4d03 100644 --- a/src/mbgl/style/filter_evaluator.hpp +++ b/src/mbgl/style/filter_evaluator.hpp @@ -6,6 +6,7 @@ #include namespace mbgl { +namespace style { class FilterEvaluator { public: @@ -159,3 +160,4 @@ class FilterEvaluator { }; } // namespace mbgl +} // namespace mbgl diff --git a/src/mbgl/layer/layer.cpp b/src/mbgl/style/layer.cpp similarity index 93% rename from src/mbgl/layer/layer.cpp rename to src/mbgl/style/layer.cpp index c26eb9a723d..342699a2c9b 100644 --- a/src/mbgl/layer/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -1,7 +1,8 @@ #include -#include +#include namespace mbgl { +namespace style { Layer::Layer(Type type_, std::unique_ptr baseImpl_) : baseImpl(std::move(baseImpl_)), type(type_) { @@ -45,4 +46,5 @@ std::unique_ptr Layer::copy(const std::string& id, return result; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/layer_impl.cpp b/src/mbgl/style/layer_impl.cpp similarity index 81% rename from src/mbgl/layer/layer_impl.cpp rename to src/mbgl/style/layer_impl.cpp index 315a1cb1b14..74cc80d2531 100644 --- a/src/mbgl/layer/layer_impl.cpp +++ b/src/mbgl/style/layer_impl.cpp @@ -1,6 +1,7 @@ -#include +#include namespace mbgl { +namespace style { const std::string& Layer::Impl::bucketName() const { return ref.empty() ? id : ref; @@ -14,4 +15,5 @@ bool Layer::Impl::needsRendering() const { return passes != RenderPass::None && visibility != VisibilityType::None; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/layer_impl.hpp b/src/mbgl/style/layer_impl.hpp similarity index 89% rename from src/mbgl/layer/layer_impl.hpp rename to src/mbgl/style/layer_impl.hpp index 3d6b5cccfdb..dcd5d9906b7 100644 --- a/src/mbgl/layer/layer_impl.hpp +++ b/src/mbgl/style/layer_impl.hpp @@ -14,11 +14,14 @@ namespace mbgl { -class StyleCascadeParameters; -class StyleCalculationParameters; -class StyleBucketParameters; class Bucket; +namespace style { + +class CascadeParameters; +class CalculationParameters; +class BucketParameters; + /** * `Layer::Impl` contains the internal implementation of `Layer`: the details that need to be accessible to other parts * of the code, but hidden from the public API. Like `Layer`, it is an abstract base class, with derived classes for @@ -44,13 +47,13 @@ class Layer::Impl { const std::string& bucketName() const; // Partially evaluate paint properties based on a set of classes. - virtual void cascade(const StyleCascadeParameters&) = 0; + virtual void cascade(const CascadeParameters&) = 0; // Fully evaluate cascaded paint properties based on a zoom level. // Returns true if any paint properties have active transitions. - virtual bool recalculate(const StyleCalculationParameters&) = 0; + virtual bool recalculate(const CalculationParameters&) = 0; - virtual std::unique_ptr createBucket(StyleBucketParameters&) const = 0; + virtual std::unique_ptr createBucket(BucketParameters&) const = 0; // Checks whether this layer needs to be rendered in the given render pass. bool hasRenderPass(RenderPass) const; @@ -85,4 +88,5 @@ class Layer::Impl { RenderPass passes = RenderPass::None; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp similarity index 90% rename from src/mbgl/layer/background_layer.cpp rename to src/mbgl/style/layers/background_layer.cpp index 36cf6be07cf..aeb40675030 100644 --- a/src/mbgl/layer/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { BackgroundLayer::BackgroundLayer(const std::string& layerID) : Layer(Type::Background, std::make_unique()) @@ -52,4 +53,5 @@ void BackgroundLayer::setBackgroundOpacity(PropertyValue value) { impl->paint.backgroundOpacity.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/background_layer_impl.cpp b/src/mbgl/style/layers/background_layer_impl.cpp similarity index 54% rename from src/mbgl/layer/background_layer_impl.cpp rename to src/mbgl/style/layers/background_layer_impl.cpp index 626c8fc8055..0c09c5d1582 100644 --- a/src/mbgl/layer/background_layer_impl.cpp +++ b/src/mbgl/style/layers/background_layer_impl.cpp @@ -1,17 +1,18 @@ -#include +#include #include namespace mbgl { +namespace style { void BackgroundLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void BackgroundLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void BackgroundLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool BackgroundLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool BackgroundLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); passes = paint.backgroundOpacity > 0 ? RenderPass::Translucent : RenderPass::None; @@ -19,8 +20,9 @@ bool BackgroundLayer::Impl::recalculate(const StyleCalculationParameters& parame return hasTransitions; } -std::unique_ptr BackgroundLayer::Impl::createBucket(StyleBucketParameters&) const { +std::unique_ptr BackgroundLayer::Impl::createBucket(BucketParameters&) const { return nullptr; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/background_layer_impl.hpp b/src/mbgl/style/layers/background_layer_impl.hpp new file mode 100644 index 00000000000..19e2a062a41 --- /dev/null +++ b/src/mbgl/style/layers/background_layer_impl.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + +class BackgroundLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; + + std::unique_ptr createBucket(BucketParameters&) const override; + + BackgroundPaintProperties paint; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.cpp b/src/mbgl/style/layers/background_layer_properties.cpp similarity index 73% rename from src/mbgl/layer/background_layer_properties.cpp rename to src/mbgl/style/layers/background_layer_properties.cpp index d866df7eee8..a20cedf12ce 100644 --- a/src/mbgl/layer/background_layer_properties.cpp +++ b/src/mbgl/style/layers/background_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void BackgroundPaintProperties::parse(const JSValue& value) { backgroundColor.parse("background-color", value); @@ -10,13 +11,13 @@ void BackgroundPaintProperties::parse(const JSValue& value) { backgroundOpacity.parse("background-opacity", value); } -void BackgroundPaintProperties::cascade(const StyleCascadeParameters& parameters) { +void BackgroundPaintProperties::cascade(const CascadeParameters& parameters) { backgroundColor.cascade(parameters); backgroundPattern.cascade(parameters); backgroundOpacity.cascade(parameters); } -bool BackgroundPaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool BackgroundPaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= backgroundColor.calculate(parameters); @@ -26,4 +27,5 @@ bool BackgroundPaintProperties::recalculate(const StyleCalculationParameters& pa return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/background_layer_properties.hpp b/src/mbgl/style/layers/background_layer_properties.hpp similarity index 74% rename from src/mbgl/layer/background_layer_properties.hpp rename to src/mbgl/style/layers/background_layer_properties.hpp index 20db9b22fbf..a1a1a3a5a7e 100644 --- a/src/mbgl/layer/background_layer_properties.hpp +++ b/src/mbgl/style/layers/background_layer_properties.hpp @@ -7,19 +7,21 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class BackgroundPaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty backgroundColor { {{ 0, 0, 0, 1 }} }; PaintProperty backgroundPattern { "" }; PaintProperty backgroundOpacity { 1 }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp similarity index 94% rename from src/mbgl/layer/circle_layer.cpp rename to src/mbgl/style/layers/circle_layer.cpp index efc0e9488d0..bdfbf629e68 100644 --- a/src/mbgl/layer/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { CircleLayer::CircleLayer(const std::string& layerID) : Layer(Type::Circle, std::make_unique()) @@ -100,4 +101,5 @@ void CircleLayer::setCircleTranslateAnchor(PropertyValue va impl->paint.circleTranslateAnchor.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_impl.cpp b/src/mbgl/style/layers/circle_layer_impl.cpp similarity index 82% rename from src/mbgl/layer/circle_layer_impl.cpp rename to src/mbgl/style/layers/circle_layer_impl.cpp index b1ba778cd60..c2efac5cef5 100644 --- a/src/mbgl/layer/circle_layer_impl.cpp +++ b/src/mbgl/style/layers/circle_layer_impl.cpp @@ -1,21 +1,22 @@ -#include -#include +#include +#include #include #include #include #include namespace mbgl { +namespace style { void CircleLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void CircleLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void CircleLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool CircleLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool CircleLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); passes = (paint.circleRadius > 0 && paint.circleColor.value[3] > 0 && paint.circleOpacity > 0) @@ -24,7 +25,7 @@ bool CircleLayer::Impl::recalculate(const StyleCalculationParameters& parameters return hasTransitions; } -std::unique_ptr CircleLayer::Impl::createBucket(StyleBucketParameters& parameters) const { +std::unique_ptr CircleLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique(parameters.mode); auto& name = bucketName(); @@ -57,4 +58,5 @@ bool CircleLayer::Impl::queryIntersectsGeometry( translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_impl.hpp b/src/mbgl/style/layers/circle_layer_impl.hpp similarity index 60% rename from src/mbgl/layer/circle_layer_impl.hpp rename to src/mbgl/style/layers/circle_layer_impl.hpp index 1cb19a62051..463f3ca18d1 100644 --- a/src/mbgl/layer/circle_layer_impl.hpp +++ b/src/mbgl/style/layers/circle_layer_impl.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace mbgl { +namespace style { class CircleLayer::Impl : public Layer::Impl { public: @@ -13,10 +14,10 @@ class CircleLayer::Impl : public Layer::Impl { void parseLayout(const JSValue&) override {}; void parsePaints(const JSValue&) override; - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; - std::unique_ptr createBucket(StyleBucketParameters&) const override; + std::unique_ptr createBucket(BucketParameters&) const override; float getQueryRadius() const override; bool queryIntersectsGeometry( @@ -28,4 +29,5 @@ class CircleLayer::Impl : public Layer::Impl { CirclePaintProperties paint; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_properties.cpp b/src/mbgl/style/layers/circle_layer_properties.cpp similarity index 82% rename from src/mbgl/layer/circle_layer_properties.cpp rename to src/mbgl/style/layers/circle_layer_properties.cpp index 48d99b579ee..b21df1e2d0d 100644 --- a/src/mbgl/layer/circle_layer_properties.cpp +++ b/src/mbgl/style/layers/circle_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void CirclePaintProperties::parse(const JSValue& value) { circleRadius.parse("circle-radius", value); @@ -13,7 +14,7 @@ void CirclePaintProperties::parse(const JSValue& value) { circleTranslateAnchor.parse("circle-translate-anchor", value); } -void CirclePaintProperties::cascade(const StyleCascadeParameters& parameters) { +void CirclePaintProperties::cascade(const CascadeParameters& parameters) { circleRadius.cascade(parameters); circleColor.cascade(parameters); circleBlur.cascade(parameters); @@ -22,7 +23,7 @@ void CirclePaintProperties::cascade(const StyleCascadeParameters& parameters) { circleTranslateAnchor.cascade(parameters); } -bool CirclePaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool CirclePaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= circleRadius.calculate(parameters); @@ -35,4 +36,5 @@ bool CirclePaintProperties::recalculate(const StyleCalculationParameters& parame return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/circle_layer_properties.hpp b/src/mbgl/style/layers/circle_layer_properties.hpp similarity index 78% rename from src/mbgl/layer/circle_layer_properties.hpp rename to src/mbgl/style/layers/circle_layer_properties.hpp index a88db27605b..956e423c45f 100644 --- a/src/mbgl/layer/circle_layer_properties.hpp +++ b/src/mbgl/style/layers/circle_layer_properties.hpp @@ -7,15 +7,16 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class CirclePaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty circleRadius { 5 }; PaintProperty circleColor { {{ 0, 0, 0, 1 }} }; @@ -25,4 +26,5 @@ class CirclePaintProperties { PaintProperty circleTranslateAnchor { TranslateAnchorType::Map }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/custom_layer.cpp b/src/mbgl/style/layers/custom_layer.cpp similarity index 82% rename from src/mbgl/layer/custom_layer.cpp rename to src/mbgl/style/layers/custom_layer.cpp index a33176e7f99..3407a7f5a53 100644 --- a/src/mbgl/layer/custom_layer.cpp +++ b/src/mbgl/style/layers/custom_layer.cpp @@ -1,7 +1,8 @@ -#include -#include +#include +#include namespace mbgl { +namespace style { CustomLayer::CustomLayer(const std::string& layerID, CustomLayerInitializeFunction init, @@ -19,4 +20,5 @@ CustomLayer::CustomLayer(const Impl& other) CustomLayer::~CustomLayer() = default; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/custom_layer_impl.cpp b/src/mbgl/style/layers/custom_layer_impl.cpp similarity index 87% rename from src/mbgl/layer/custom_layer_impl.cpp rename to src/mbgl/style/layers/custom_layer_impl.cpp index 8a08c804ed4..214d4ce663a 100644 --- a/src/mbgl/layer/custom_layer_impl.cpp +++ b/src/mbgl/style/layers/custom_layer_impl.cpp @@ -1,8 +1,9 @@ -#include +#include #include #include namespace mbgl { +namespace style { CustomLayer::Impl::Impl(const std::string& id_, CustomLayerInitializeFunction initializeFn_, @@ -54,13 +55,14 @@ void CustomLayer::Impl::render(const TransformState& state) const { renderFn(context, parameters); } -bool CustomLayer::Impl::recalculate(const StyleCalculationParameters&) { +bool CustomLayer::Impl::recalculate(const CalculationParameters&) { passes = RenderPass::Translucent; return false; } -std::unique_ptr CustomLayer::Impl::createBucket(StyleBucketParameters&) const { +std::unique_ptr CustomLayer::Impl::createBucket(BucketParameters&) const { return nullptr; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/custom_layer_impl.hpp b/src/mbgl/style/layers/custom_layer_impl.hpp similarity index 71% rename from src/mbgl/layer/custom_layer_impl.hpp rename to src/mbgl/style/layers/custom_layer_impl.hpp index 09709a2f9d4..00e576b6a3c 100644 --- a/src/mbgl/layer/custom_layer_impl.hpp +++ b/src/mbgl/style/layers/custom_layer_impl.hpp @@ -1,12 +1,14 @@ #pragma once -#include -#include +#include +#include namespace mbgl { class TransformState; +namespace style { + class CustomLayer::Impl : public Layer::Impl { public: Impl(const std::string& id, @@ -27,10 +29,10 @@ class CustomLayer::Impl : public Layer::Impl { void parseLayout(const JSValue&) final {} void parsePaints(const JSValue&) final {} - void cascade(const StyleCascadeParameters&) final {} - bool recalculate(const StyleCalculationParameters&) final; + void cascade(const CascadeParameters&) final {} + bool recalculate(const CalculationParameters&) final; - std::unique_ptr createBucket(StyleBucketParameters&) const final; + std::unique_ptr createBucket(BucketParameters&) const final; CustomLayerInitializeFunction initializeFn = nullptr; CustomLayerRenderFunction renderFn = nullptr; @@ -38,4 +40,5 @@ class CustomLayer::Impl : public Layer::Impl { void* context = nullptr; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp similarity index 95% rename from src/mbgl/layer/fill_layer.cpp rename to src/mbgl/style/layers/fill_layer.cpp index 77efaa61aa0..1deaabb5ef0 100644 --- a/src/mbgl/layer/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { FillLayer::FillLayer(const std::string& layerID) : Layer(Type::Fill, std::make_unique()) @@ -108,4 +109,5 @@ void FillLayer::setFillPattern(PropertyValue value) { impl->paint.fillPattern.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_impl.cpp b/src/mbgl/style/layers/fill_layer_impl.cpp similarity index 83% rename from src/mbgl/layer/fill_layer_impl.cpp rename to src/mbgl/style/layers/fill_layer_impl.cpp index 21f482922dd..c1836174829 100644 --- a/src/mbgl/layer/fill_layer_impl.cpp +++ b/src/mbgl/style/layers/fill_layer_impl.cpp @@ -1,21 +1,22 @@ -#include -#include +#include +#include #include #include #include #include namespace mbgl { +namespace style { void FillLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void FillLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void FillLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool FillLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool FillLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); passes = RenderPass::None; @@ -33,7 +34,7 @@ bool FillLayer::Impl::recalculate(const StyleCalculationParameters& parameters) return hasTransitions; } -std::unique_ptr FillLayer::Impl::createBucket(StyleBucketParameters& parameters) const { +std::unique_ptr FillLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique(); auto& name = bucketName(); @@ -63,4 +64,5 @@ bool FillLayer::Impl::queryIntersectsGeometry( return util::multiPolygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), geometry); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_impl.hpp b/src/mbgl/style/layers/fill_layer_impl.hpp similarity index 60% rename from src/mbgl/layer/fill_layer_impl.hpp rename to src/mbgl/style/layers/fill_layer_impl.hpp index 2af0d6491d7..a37dd76ace2 100644 --- a/src/mbgl/layer/fill_layer_impl.hpp +++ b/src/mbgl/style/layers/fill_layer_impl.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace mbgl { +namespace style { class FillLayer::Impl : public Layer::Impl { public: @@ -13,10 +14,10 @@ class FillLayer::Impl : public Layer::Impl { void parseLayout(const JSValue&) override {}; void parsePaints(const JSValue&) override; - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; - std::unique_ptr createBucket(StyleBucketParameters&) const override; + std::unique_ptr createBucket(BucketParameters&) const override; float getQueryRadius() const override; bool queryIntersectsGeometry( @@ -28,4 +29,5 @@ class FillLayer::Impl : public Layer::Impl { FillPaintProperties paint; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.cpp b/src/mbgl/style/layers/fill_layer_properties.cpp similarity index 83% rename from src/mbgl/layer/fill_layer_properties.cpp rename to src/mbgl/style/layers/fill_layer_properties.cpp index e0d4f10bc9a..a4714689f9c 100644 --- a/src/mbgl/layer/fill_layer_properties.cpp +++ b/src/mbgl/style/layers/fill_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void FillPaintProperties::parse(const JSValue& value) { fillAntialias.parse("fill-antialias", value); @@ -14,7 +15,7 @@ void FillPaintProperties::parse(const JSValue& value) { fillPattern.parse("fill-pattern", value); } -void FillPaintProperties::cascade(const StyleCascadeParameters& parameters) { +void FillPaintProperties::cascade(const CascadeParameters& parameters) { fillAntialias.cascade(parameters); fillOpacity.cascade(parameters); fillColor.cascade(parameters); @@ -24,7 +25,7 @@ void FillPaintProperties::cascade(const StyleCascadeParameters& parameters) { fillPattern.cascade(parameters); } -bool FillPaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool FillPaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= fillAntialias.calculate(parameters); @@ -38,4 +39,5 @@ bool FillPaintProperties::recalculate(const StyleCalculationParameters& paramete return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/fill_layer_properties.hpp b/src/mbgl/style/layers/fill_layer_properties.hpp similarity index 80% rename from src/mbgl/layer/fill_layer_properties.hpp rename to src/mbgl/style/layers/fill_layer_properties.hpp index 2ae67ef0a09..43396f45d2c 100644 --- a/src/mbgl/layer/fill_layer_properties.hpp +++ b/src/mbgl/style/layers/fill_layer_properties.hpp @@ -7,15 +7,16 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class FillPaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty fillAntialias { true }; PaintProperty fillOpacity { 1 }; @@ -26,4 +27,5 @@ class FillPaintProperties { PaintProperty fillPattern { "" }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp similarity index 96% rename from src/mbgl/layer/line_layer.cpp rename to src/mbgl/style/layers/line_layer.cpp index e1a7d813af0..abe326a672e 100644 --- a/src/mbgl/layer/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { LineLayer::LineLayer(const std::string& layerID) : Layer(Type::Line, std::make_unique()) @@ -160,4 +161,5 @@ void LineLayer::setLinePattern(PropertyValue value) { impl->paint.linePattern.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_impl.cpp b/src/mbgl/style/layers/line_layer_impl.cpp similarity index 87% rename from src/mbgl/layer/line_layer_impl.cpp rename to src/mbgl/style/layers/line_layer_impl.cpp index aee1687046a..b7ee9dc5bf5 100644 --- a/src/mbgl/layer/line_layer_impl.cpp +++ b/src/mbgl/style/layers/line_layer_impl.cpp @@ -1,11 +1,12 @@ -#include -#include +#include +#include #include #include #include #include namespace mbgl { +namespace style { void LineLayer::Impl::parseLayout(const JSValue& value) { layout.parse(value); @@ -15,13 +16,13 @@ void LineLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void LineLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void LineLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool LineLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool LineLayer::Impl::recalculate(const CalculationParameters& parameters) { // for scaling dasharrays - StyleCalculationParameters dashArrayParams = parameters; + CalculationParameters dashArrayParams = parameters; dashArrayParams.z = std::floor(dashArrayParams.z); paint.lineWidth.calculate(dashArrayParams); dashLineWidth = paint.lineWidth; @@ -34,11 +35,11 @@ bool LineLayer::Impl::recalculate(const StyleCalculationParameters& parameters) return hasTransitions; } -std::unique_ptr LineLayer::Impl::createBucket(StyleBucketParameters& parameters) const { +std::unique_ptr LineLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique(parameters.tileID.overscaleFactor()); bucket->layout = layout; - bucket->layout.recalculate(StyleCalculationParameters(parameters.tileID.overscaledZ)); + bucket->layout.recalculate(CalculationParameters(parameters.tileID.overscaledZ)); auto& name = bucketName(); parameters.eachFilteredFeature(filter, [&] (const auto& feature, std::size_t index, const std::string& layerName) { @@ -111,4 +112,5 @@ bool LineLayer::Impl::queryIntersectsGeometry( halfWidth); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_impl.hpp b/src/mbgl/style/layers/line_layer_impl.hpp similarity index 65% rename from src/mbgl/layer/line_layer_impl.hpp rename to src/mbgl/style/layers/line_layer_impl.hpp index b602df52fa1..3356dc2ceb4 100644 --- a/src/mbgl/layer/line_layer_impl.hpp +++ b/src/mbgl/style/layers/line_layer_impl.hpp @@ -1,10 +1,11 @@ #pragma once -#include -#include -#include +#include +#include +#include namespace mbgl { +namespace style { class LineLayer::Impl : public Layer::Impl { public: @@ -13,10 +14,10 @@ class LineLayer::Impl : public Layer::Impl { void parseLayout(const JSValue&) override; void parsePaints(const JSValue&) override; - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; - std::unique_ptr createBucket(StyleBucketParameters&) const override; + std::unique_ptr createBucket(BucketParameters&) const override; float getQueryRadius() const override; bool queryIntersectsGeometry( @@ -35,4 +36,5 @@ class LineLayer::Impl : public Layer::Impl { float getLineWidth() const; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.cpp b/src/mbgl/style/layers/line_layer_properties.cpp similarity index 86% rename from src/mbgl/layer/line_layer_properties.cpp rename to src/mbgl/style/layers/line_layer_properties.cpp index 4941a1ecd2a..7c74f6de04a 100644 --- a/src/mbgl/layer/line_layer_properties.cpp +++ b/src/mbgl/style/layers/line_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void LineLayoutProperties::parse(const JSValue& value) { lineCap.parse("line-cap", value); @@ -11,7 +12,7 @@ void LineLayoutProperties::parse(const JSValue& value) { lineRoundLimit.parse("line-round-limit", value); } -void LineLayoutProperties::recalculate(const StyleCalculationParameters& parameters) { +void LineLayoutProperties::recalculate(const CalculationParameters& parameters) { lineCap.calculate(parameters); lineJoin.calculate(parameters); lineMiterLimit.calculate(parameters); @@ -31,7 +32,7 @@ void LinePaintProperties::parse(const JSValue& value) { linePattern.parse("line-pattern", value); } -void LinePaintProperties::cascade(const StyleCascadeParameters& parameters) { +void LinePaintProperties::cascade(const CascadeParameters& parameters) { lineOpacity.cascade(parameters); lineColor.cascade(parameters); lineTranslate.cascade(parameters); @@ -44,7 +45,7 @@ void LinePaintProperties::cascade(const StyleCascadeParameters& parameters) { linePattern.cascade(parameters); } -bool LinePaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool LinePaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= lineOpacity.calculate(parameters); @@ -61,4 +62,5 @@ bool LinePaintProperties::recalculate(const StyleCalculationParameters& paramete return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/line_layer_properties.hpp b/src/mbgl/style/layers/line_layer_properties.hpp similarity index 83% rename from src/mbgl/layer/line_layer_properties.hpp rename to src/mbgl/style/layers/line_layer_properties.hpp index f4dad055bd6..e0c63b516bf 100644 --- a/src/mbgl/layer/line_layer_properties.hpp +++ b/src/mbgl/style/layers/line_layer_properties.hpp @@ -7,14 +7,15 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class LineLayoutProperties { public: void parse(const JSValue&); - void recalculate(const StyleCalculationParameters&); + void recalculate(const CalculationParameters&); LayoutProperty lineCap { LineCapType::Butt }; LayoutProperty lineJoin { LineJoinType::Miter }; @@ -25,8 +26,8 @@ class LineLayoutProperties { class LinePaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty lineOpacity { 1 }; PaintProperty lineColor { {{ 0, 0, 0, 1 }} }; @@ -40,4 +41,5 @@ class LinePaintProperties { PaintProperty linePattern { "" }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp similarity index 94% rename from src/mbgl/layer/raster_layer.cpp rename to src/mbgl/style/layers/raster_layer.cpp index 661c44b7d5d..fb7f08fbe91 100644 --- a/src/mbgl/layer/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { RasterLayer::RasterLayer(const std::string& layerID) : Layer(Type::Raster, std::make_unique()) @@ -93,4 +94,5 @@ void RasterLayer::setRasterFadeDuration(PropertyValue value) { impl->paint.rasterFadeDuration.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_impl.cpp b/src/mbgl/style/layers/raster_layer_impl.cpp similarity index 54% rename from src/mbgl/layer/raster_layer_impl.cpp rename to src/mbgl/style/layers/raster_layer_impl.cpp index f44a424f995..4854ec041da 100644 --- a/src/mbgl/layer/raster_layer_impl.cpp +++ b/src/mbgl/style/layers/raster_layer_impl.cpp @@ -1,17 +1,18 @@ -#include +#include #include namespace mbgl { +namespace style { void RasterLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void RasterLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void RasterLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool RasterLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool RasterLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); passes = paint.rasterOpacity > 0 ? RenderPass::Translucent : RenderPass::None; @@ -19,8 +20,9 @@ bool RasterLayer::Impl::recalculate(const StyleCalculationParameters& parameters return hasTransitions; } -std::unique_ptr RasterLayer::Impl::createBucket(StyleBucketParameters&) const { +std::unique_ptr RasterLayer::Impl::createBucket(BucketParameters&) const { return nullptr; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layers/raster_layer_impl.hpp b/src/mbgl/style/layers/raster_layer_impl.hpp new file mode 100644 index 00000000000..6812b469a61 --- /dev/null +++ b/src/mbgl/style/layers/raster_layer_impl.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include +#include +#include + +namespace mbgl { +namespace style { + +class RasterLayer::Impl : public Layer::Impl { +public: + std::unique_ptr clone() const override; + + void parseLayout(const JSValue&) override {}; + void parsePaints(const JSValue&) override; + + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; + + std::unique_ptr createBucket(BucketParameters&) const override; + + RasterPaintProperties paint; +}; + +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_properties.cpp b/src/mbgl/style/layers/raster_layer_properties.cpp similarity index 84% rename from src/mbgl/layer/raster_layer_properties.cpp rename to src/mbgl/style/layers/raster_layer_properties.cpp index 898188bc839..0e6afc5e9c9 100644 --- a/src/mbgl/layer/raster_layer_properties.cpp +++ b/src/mbgl/style/layers/raster_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void RasterPaintProperties::parse(const JSValue& value) { rasterOpacity.parse("raster-opacity", value); @@ -14,7 +15,7 @@ void RasterPaintProperties::parse(const JSValue& value) { rasterFadeDuration.parse("raster-fade-duration", value); } -void RasterPaintProperties::cascade(const StyleCascadeParameters& parameters) { +void RasterPaintProperties::cascade(const CascadeParameters& parameters) { rasterOpacity.cascade(parameters); rasterHueRotate.cascade(parameters); rasterBrightnessMin.cascade(parameters); @@ -24,7 +25,7 @@ void RasterPaintProperties::cascade(const StyleCascadeParameters& parameters) { rasterFadeDuration.cascade(parameters); } -bool RasterPaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool RasterPaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= rasterOpacity.calculate(parameters); @@ -38,4 +39,5 @@ bool RasterPaintProperties::recalculate(const StyleCalculationParameters& parame return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/raster_layer_properties.hpp b/src/mbgl/style/layers/raster_layer_properties.hpp similarity index 78% rename from src/mbgl/layer/raster_layer_properties.hpp rename to src/mbgl/style/layers/raster_layer_properties.hpp index 46bd00ff2e8..049da873127 100644 --- a/src/mbgl/layer/raster_layer_properties.hpp +++ b/src/mbgl/style/layers/raster_layer_properties.hpp @@ -7,15 +7,16 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class RasterPaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty rasterOpacity { 1 }; PaintProperty rasterHueRotate { 0 }; @@ -26,4 +27,5 @@ class RasterPaintProperties { PaintProperty rasterFadeDuration { 300 }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp similarity index 98% rename from src/mbgl/layer/symbol_layer.cpp rename to src/mbgl/style/layers/symbol_layer.cpp index 66d018b5813..d7d6a02acee 100644 --- a/src/mbgl/layer/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1,9 +1,10 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include -#include +#include +#include namespace mbgl { +namespace style { SymbolLayer::SymbolLayer(const std::string& layerID) : Layer(Type::Symbol, std::make_unique()) @@ -381,4 +382,5 @@ void SymbolLayer::setTextTranslateAnchor(PropertyValue valu impl->paint.textTranslateAnchor.set(value); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp similarity index 77% rename from src/mbgl/layer/symbol_layer_impl.cpp rename to src/mbgl/style/layers/symbol_layer_impl.cpp index 3a0e0dceca9..a4dc264ed2f 100644 --- a/src/mbgl/layer/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -1,8 +1,9 @@ -#include +#include #include -#include +#include namespace mbgl { +namespace style { void SymbolLayer::Impl::parseLayout(const JSValue& value) { layout.parse(value); @@ -12,11 +13,11 @@ void SymbolLayer::Impl::parsePaints(const JSValue& layer) { paint.parse(layer); } -void SymbolLayer::Impl::cascade(const StyleCascadeParameters& parameters) { +void SymbolLayer::Impl::cascade(const CascadeParameters& parameters) { paint.cascade(parameters); } -bool SymbolLayer::Impl::recalculate(const StyleCalculationParameters& parameters) { +bool SymbolLayer::Impl::recalculate(const CalculationParameters& parameters) { bool hasTransitions = paint.recalculate(parameters); // text-size and icon-size are layout properties but they also need to be evaluated as paint properties: @@ -32,7 +33,7 @@ bool SymbolLayer::Impl::recalculate(const StyleCalculationParameters& parameters return hasTransitions; } -std::unique_ptr SymbolLayer::Impl::createBucket(StyleBucketParameters& parameters) const { +std::unique_ptr SymbolLayer::Impl::createBucket(BucketParameters& parameters) const { auto bucket = std::make_unique(parameters.tileID.overscaleFactor(), parameters.tileID.overscaledZ, parameters.mode, @@ -41,7 +42,7 @@ std::unique_ptr SymbolLayer::Impl::createBucket(StyleBucketParameters& p bucket->layout = layout; - StyleCalculationParameters p(parameters.tileID.overscaledZ); + CalculationParameters p(parameters.tileID.overscaledZ); bucket->layout.symbolPlacement.calculate(p); if (bucket->layout.symbolPlacement.value == SymbolPlacementType::Line) { bucket->layout.iconRotationAlignment.value = RotationAlignmentType::Map; @@ -50,12 +51,12 @@ std::unique_ptr SymbolLayer::Impl::createBucket(StyleBucketParameters& p bucket->layout.recalculate(p); - bucket->layout.iconSize.calculate(StyleCalculationParameters(18)); - bucket->layout.textSize.calculate(StyleCalculationParameters(18)); + bucket->layout.iconSize.calculate(CalculationParameters(18)); + bucket->layout.textSize.calculate(CalculationParameters(18)); bucket->iconMaxSize = bucket->layout.iconSize; bucket->textMaxSize = bucket->layout.textSize; - bucket->layout.iconSize.calculate(StyleCalculationParameters(p.z + 1)); - bucket->layout.textSize.calculate(StyleCalculationParameters(p.z + 1)); + bucket->layout.iconSize.calculate(CalculationParameters(p.z + 1)); + bucket->layout.textSize.calculate(CalculationParameters(p.z + 1)); bucket->parseFeatures(parameters.layer, filter); @@ -77,4 +78,5 @@ std::unique_ptr SymbolLayer::Impl::createBucket(StyleBucketParameters& p return std::move(bucket); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp similarity index 52% rename from src/mbgl/layer/symbol_layer_impl.hpp rename to src/mbgl/style/layers/symbol_layer_impl.hpp index 46503ab916a..9727cc64809 100644 --- a/src/mbgl/layer/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -1,14 +1,15 @@ -#ifndef MBGL_SYMBOL_LAYER -#define MBGL_SYMBOL_LAYER +#pragma once -#include -#include -#include +#include +#include +#include namespace mbgl { class SpriteAtlas; +namespace style { + class SymbolLayer::Impl : public Layer::Impl { public: std::unique_ptr clone() const override; @@ -16,10 +17,10 @@ class SymbolLayer::Impl : public Layer::Impl { void parseLayout(const JSValue&) override; void parsePaints(const JSValue&) override; - void cascade(const StyleCascadeParameters&) override; - bool recalculate(const StyleCalculationParameters&) override; + void cascade(const CascadeParameters&) override; + bool recalculate(const CalculationParameters&) override; - std::unique_ptr createBucket(StyleBucketParameters&) const override; + std::unique_ptr createBucket(BucketParameters&) const override; SymbolLayoutProperties layout; SymbolPaintProperties paint; @@ -30,6 +31,5 @@ class SymbolLayer::Impl : public Layer::Impl { SpriteAtlas* spriteAtlas = nullptr; }; +} // namespace style } // namespace mbgl - -#endif diff --git a/src/mbgl/layer/symbol_layer_properties.cpp b/src/mbgl/style/layers/symbol_layer_properties.cpp similarity index 93% rename from src/mbgl/layer/symbol_layer_properties.cpp rename to src/mbgl/style/layers/symbol_layer_properties.cpp index 4b9e9a5fb6b..ce16ae2e50b 100644 --- a/src/mbgl/layer/symbol_layer_properties.cpp +++ b/src/mbgl/style/layers/symbol_layer_properties.cpp @@ -1,8 +1,9 @@ // This file is generated. Edit scripts/generate-style-code.js, then run `make style-code`. -#include +#include namespace mbgl { +namespace style { void SymbolLayoutProperties::parse(const JSValue& value) { symbolPlacement.parse("symbol-placement", value); @@ -38,7 +39,7 @@ void SymbolLayoutProperties::parse(const JSValue& value) { textOptional.parse("text-optional", value); } -void SymbolLayoutProperties::recalculate(const StyleCalculationParameters& parameters) { +void SymbolLayoutProperties::recalculate(const CalculationParameters& parameters) { symbolPlacement.calculate(parameters); symbolSpacing.calculate(parameters); symbolAvoidEdges.calculate(parameters); @@ -89,7 +90,7 @@ void SymbolPaintProperties::parse(const JSValue& value) { textTranslateAnchor.parse("text-translate-anchor", value); } -void SymbolPaintProperties::cascade(const StyleCascadeParameters& parameters) { +void SymbolPaintProperties::cascade(const CascadeParameters& parameters) { iconOpacity.cascade(parameters); iconColor.cascade(parameters); iconHaloColor.cascade(parameters); @@ -106,7 +107,7 @@ void SymbolPaintProperties::cascade(const StyleCascadeParameters& parameters) { textTranslateAnchor.cascade(parameters); } -bool SymbolPaintProperties::recalculate(const StyleCalculationParameters& parameters) { +bool SymbolPaintProperties::recalculate(const CalculationParameters& parameters) { bool hasTransitions = false; hasTransitions |= iconOpacity.calculate(parameters); @@ -127,4 +128,5 @@ bool SymbolPaintProperties::recalculate(const StyleCalculationParameters& parame return hasTransitions; } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/layer/symbol_layer_properties.hpp b/src/mbgl/style/layers/symbol_layer_properties.hpp similarity index 92% rename from src/mbgl/layer/symbol_layer_properties.hpp rename to src/mbgl/style/layers/symbol_layer_properties.hpp index ccbecef00e5..38455b5cac6 100644 --- a/src/mbgl/layer/symbol_layer_properties.hpp +++ b/src/mbgl/style/layers/symbol_layer_properties.hpp @@ -7,14 +7,15 @@ #include namespace mbgl { +namespace style { -class StyleCascadeParameters; -class StyleCalculationParameters; +class CascadeParameters; +class CalculationParameters; class SymbolLayoutProperties { public: void parse(const JSValue&); - void recalculate(const StyleCalculationParameters&); + void recalculate(const CalculationParameters&); LayoutProperty symbolPlacement { SymbolPlacementType::Point }; LayoutProperty symbolSpacing { 250 }; @@ -52,8 +53,8 @@ class SymbolLayoutProperties { class SymbolPaintProperties { public: void parse(const JSValue&); - void cascade(const StyleCascadeParameters&); - bool recalculate(const StyleCalculationParameters&); + void cascade(const CascadeParameters&); + bool recalculate(const CalculationParameters&); PaintProperty iconOpacity { 1 }; PaintProperty iconColor { {{ 0, 0, 0, 1 }} }; @@ -71,4 +72,5 @@ class SymbolPaintProperties { PaintProperty textTranslateAnchor { TranslateAnchorType::Map }; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/layout_property.hpp b/src/mbgl/style/layout_property.hpp index b4857aeae5a..f5045b47fcb 100644 --- a/src/mbgl/style/layout_property.hpp +++ b/src/mbgl/style/layout_property.hpp @@ -8,6 +8,7 @@ #include namespace mbgl { +namespace style { template class LayoutProperty { @@ -30,7 +31,7 @@ class LayoutProperty { } } - void calculate(const StyleCalculationParameters& parameters) { + void calculate(const CalculationParameters& parameters) { if (currentValue) { PropertyEvaluator evaluator(parameters, defaultValue); value = PropertyValue::visit(currentValue, evaluator); @@ -46,4 +47,5 @@ class LayoutProperty { PropertyValue currentValue; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_observer.hpp b/src/mbgl/style/observer.hpp similarity index 59% rename from src/mbgl/style/style_observer.hpp rename to src/mbgl/style/observer.hpp index 9e2c946f7d0..c19f58904f3 100644 --- a/src/mbgl/style/style_observer.hpp +++ b/src/mbgl/style/observer.hpp @@ -2,22 +2,24 @@ #include #include -#include +#include namespace mbgl { +namespace style { -class StyleObserver : public GlyphStoreObserver, public SpriteStoreObserver, public SourceObserver { +class Observer : public GlyphStoreObserver, + public SpriteStoreObserver, + public SourceObserver { public: - virtual ~StyleObserver() = default; - /** * In addition to the individual glyph, sprite, and source events, the * following "rollup" events are provided for convenience. They are * strictly additive; e.g. when a source is loaded, both `onSourceLoaded` * and `onResourceLoaded` will be called. */ - virtual void onResourceLoaded() {} - virtual void onResourceError(std::exception_ptr) {} + virtual void onResourceLoaded() {}; + virtual void onResourceError(std::exception_ptr) {}; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp index 8428a905331..62fd59684e9 100644 --- a/src/mbgl/style/paint_property.hpp +++ b/src/mbgl/style/paint_property.hpp @@ -3,9 +3,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -14,6 +14,7 @@ #include namespace mbgl { +namespace style { template class Evaluator = PropertyEvaluator> class PaintProperty { @@ -62,14 +63,14 @@ class PaintProperty { } if (it->value.HasMember(transitionName.c_str())) { - if (auto v = parsePropertyTransition(name, it->value[transitionName.c_str()])) { + if (auto v = parseTransitionOptions(name, it->value[transitionName.c_str()])) { transitions.emplace(classID, *v); } } } } - void cascade(const StyleCascadeParameters& params) { + void cascade(const CascadeParameters& params) { const bool overrideTransition = !params.transition.delay && !params.transition.duration; Duration delay = params.transition.delay.value_or(Duration::zero()); Duration duration = params.transition.duration.value_or(Duration::zero()); @@ -79,7 +80,7 @@ class PaintProperty { continue; if (overrideTransition && transitions.find(classID) != transitions.end()) { - const PropertyTransition& transition = transitions[classID]; + const TransitionOptions& transition = transitions[classID]; if (transition.delay) delay = *transition.delay; if (transition.duration) duration = *transition.duration; } @@ -95,7 +96,7 @@ class PaintProperty { assert(cascaded); } - bool calculate(const StyleCalculationParameters& parameters) { + bool calculate(const CalculationParameters& parameters) { assert(cascaded); Evaluator evaluator(parameters, defaultValue); value = cascaded->calculate(evaluator, parameters.now); @@ -109,7 +110,7 @@ class PaintProperty { private: T defaultValue; std::map> values; - std::map transitions; + std::map transitions; struct CascadedValue { CascadedValue(std::unique_ptr prior_, @@ -147,4 +148,5 @@ class PaintProperty { std::unique_ptr cascaded; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_parser.cpp b/src/mbgl/style/parser.cpp similarity index 91% rename from src/mbgl/style/style_parser.cpp rename to src/mbgl/style/parser.cpp index 95ab36498dc..28a7d2e81bb 100644 --- a/src/mbgl/style/style_parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include #include @@ -23,7 +23,7 @@ #include namespace mbgl { - +namespace style { namespace { @@ -102,9 +102,9 @@ void parseTileJSONMember(const JSValue& value, std::array& target, co } // end namespace -StyleParser::~StyleParser() = default; +Parser::~Parser() = default; -void StyleParser::parse(const std::string& json) { +void Parser::parse(const std::string& json) { rapidjson::GenericDocument, rapidjson::CrtAllocator> document; document.Parse<0>(json.c_str()); @@ -143,7 +143,7 @@ void StyleParser::parse(const std::string& json) { } } -void StyleParser::parseSources(const JSValue& value) { +void Parser::parseSources(const JSValue& value) { if (!value.IsObject()) { Log::Warning(Event::ParseStyle, "sources must be an object"); return; @@ -174,7 +174,7 @@ void StyleParser::parseSources(const JSValue& value) { uint16_t tileSize = util::tileSize; - std::unique_ptr info; + std::unique_ptr tileset; std::unique_ptr geojsonvt; switch (type) { @@ -200,12 +200,12 @@ void StyleParser::parseSources(const JSValue& value) { continue; } } else { - info = parseTileJSON(sourceVal); + tileset = parseTileJSON(sourceVal); } break; case SourceType::GeoJSON: - info = std::make_unique(); + tileset = std::make_unique(); // We should probably split this up to have URLs in the url property, and actual data // in the data property. Until then, we're going to detect the content based on the @@ -218,7 +218,7 @@ void StyleParser::parseSources(const JSValue& value) { } else if (dataVal.IsObject()) { // We need to parse dataVal as a GeoJSON object geojsonvt = parseGeoJSON(dataVal); - info->maxZoom = geojsonvt->options.maxZoom; + tileset->maxZoom = geojsonvt->options.maxZoom; } else { Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object"); continue; @@ -236,14 +236,14 @@ void StyleParser::parseSources(const JSValue& value) { } const std::string id { nameVal.GetString(), nameVal.GetStringLength() }; - std::unique_ptr source = std::make_unique(type, id, url, tileSize, std::move(info), std::move(geojsonvt)); + std::unique_ptr source = std::make_unique(type, id, url, tileSize, std::move(tileset), std::move(geojsonvt)); sourcesMap.emplace(id, source.get()); sources.emplace_back(std::move(source)); } } -std::unique_ptr StyleParser::parseGeoJSON(const JSValue& value) { +std::unique_ptr parseGeoJSON(const JSValue& value) { using namespace mapbox::geojsonvt; Options options; @@ -260,7 +260,7 @@ std::unique_ptr StyleParser::parseGeoJSON(const JS } } -std::unique_ptr StyleParser::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) { +std::unique_ptr parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) { rapidjson::GenericDocument, rapidjson::CrtAllocator> document; document.Parse<0>(json.c_str()); @@ -270,7 +270,7 @@ std::unique_ptr StyleParser::parseTileJSON(const std::string& json, throw std::runtime_error(message.str()); } - std::unique_ptr result = StyleParser::parseTileJSON(document); + std::unique_ptr result = parseTileJSON(document); // TODO: Remove this hack by delivering proper URLs in the TileJSON to begin with. if (util::mapbox::isMapboxURL(sourceURL)) { @@ -282,24 +282,24 @@ std::unique_ptr StyleParser::parseTileJSON(const std::string& json, return result; } -std::unique_ptr StyleParser::parseTileJSON(const JSValue& value) { - auto info = std::make_unique(); - parseTileJSONMember(value, info->tiles, "tiles"); - parseTileJSONMember(value, info->minZoom, "minzoom"); - parseTileJSONMember(value, info->maxZoom, "maxzoom"); - parseTileJSONMember(value, info->attribution, "attribution"); +std::unique_ptr parseTileJSON(const JSValue& value) { + auto tileset = std::make_unique(); + parseTileJSONMember(value, tileset->tiles, "tiles"); + parseTileJSONMember(value, tileset->minZoom, "minzoom"); + parseTileJSONMember(value, tileset->maxZoom, "maxzoom"); + parseTileJSONMember(value, tileset->attribution, "attribution"); std::array array; parseTileJSONMember(value, array, "center"); - info->center = { array[0], array[1] }; - info->zoom = array[2]; + tileset->center = { array[0], array[1] }; + tileset->zoom = array[2]; parseTileJSONMember(value, array, "bounds"); - info->bounds = LatLngBounds::hull({ array[0], array[1] }, { array[2], array[3] }); + tileset->bounds = LatLngBounds::hull({ array[0], array[1] }, { array[2], array[3] }); - return info; + return tileset; } -void StyleParser::parseLayers(const JSValue& value) { +void Parser::parseLayers(const JSValue& value) { std::vector ids; if (!value.IsArray()) { @@ -353,7 +353,7 @@ void StyleParser::parseLayers(const JSValue& value) { } } -void StyleParser::parseLayer(const std::string& id, const JSValue& value, std::unique_ptr& layer) { +void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique_ptr& layer) { if (layer) { // Skip parsing this again. We already have a valid layer definition. return; @@ -486,7 +486,7 @@ MBGL_DEFINE_ENUM_CLASS(VisibilityTypeClass, VisibilityType, { { VisibilityType::None, "none" }, }); -void StyleParser::parseVisibility(Layer& layer, const JSValue& value) { +void Parser::parseVisibility(Layer& layer, const JSValue& value) { Layer::Impl& impl = *layer.baseImpl; if (!value.HasMember("visibility")) { return; @@ -664,7 +664,7 @@ Filter parseFilter(const JSValue& value) { } } -std::vector StyleParser::fontStacks() const { +std::vector Parser::fontStacks() const { std::set result; for (const auto& layer : layers) { @@ -685,4 +685,5 @@ std::vector StyleParser::fontStacks() const { return std::vector(result.begin(), result.end()); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_parser.hpp b/src/mbgl/style/parser.hpp similarity index 74% rename from src/mbgl/style/style_parser.hpp rename to src/mbgl/style/parser.hpp index b5445bbfb30..ea821fabde3 100644 --- a/src/mbgl/style/style_parser.hpp +++ b/src/mbgl/style/parser.hpp @@ -1,10 +1,11 @@ #pragma once -#include #include -#include +#include #include + #include +#include #include #include @@ -13,12 +14,18 @@ #include namespace mbgl { +namespace style { + +std::unique_ptr parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize); +std::unique_ptr parseTileJSON(const JSValue&); + +std::unique_ptr parseGeoJSON(const JSValue&); Filter parseFilter(const JSValue&); -class StyleParser { +class Parser { public: - ~StyleParser(); + ~Parser(); void parse(const std::string&); @@ -31,11 +38,6 @@ class StyleParser { // Statically evaluate layer properties to determine what font stacks are used. std::vector fontStacks() const; - static std::unique_ptr parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize); - static std::unique_ptr parseTileJSON(const JSValue&); - - static std::unique_ptr parseGeoJSON(const JSValue&); - private: void parseSources(const JSValue&); void parseLayers(const JSValue&); @@ -49,4 +51,5 @@ class StyleParser { std::forward_list stack; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/property_evaluator.cpp b/src/mbgl/style/property_evaluator.cpp index 08eea899c25..d2e633c7822 100644 --- a/src/mbgl/style/property_evaluator.cpp +++ b/src/mbgl/style/property_evaluator.cpp @@ -1,12 +1,14 @@ #include -#include +#include #include #include #include +#include #include namespace mbgl { +namespace style { template inline T defaultStopsValue(); @@ -140,4 +142,5 @@ Faded CrossFadedPropertyEvaluator::calculate(const T& min, const T& mid, c template class CrossFadedPropertyEvaluator; template class CrossFadedPropertyEvaluator>; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/property_evaluator.hpp b/src/mbgl/style/property_evaluator.hpp index 112c373a44a..77100bda46e 100644 --- a/src/mbgl/style/property_evaluator.hpp +++ b/src/mbgl/style/property_evaluator.hpp @@ -4,15 +4,16 @@ #include namespace mbgl { +namespace style { -class StyleCalculationParameters; +class CalculationParameters; template class PropertyEvaluator { public: using ResultType = T; - PropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + PropertyEvaluator(const CalculationParameters& parameters_, const T& defaultValue_) : parameters(parameters_), defaultValue(defaultValue_) {} @@ -21,7 +22,7 @@ class PropertyEvaluator { T operator()(const Function&) const; private: - const StyleCalculationParameters& parameters; + const CalculationParameters& parameters; T defaultValue; }; @@ -39,7 +40,7 @@ class CrossFadedPropertyEvaluator { public: using ResultType = Faded; - CrossFadedPropertyEvaluator(const StyleCalculationParameters& parameters_, const T& defaultValue_) + CrossFadedPropertyEvaluator(const CalculationParameters& parameters_, const T& defaultValue_) : parameters(parameters_), defaultValue(defaultValue_) {} @@ -50,13 +51,15 @@ class CrossFadedPropertyEvaluator { private: Faded calculate(const T& min, const T& mid, const T& max) const; - const StyleCalculationParameters& parameters; + const CalculationParameters& parameters; T defaultValue; }; +} // namespace style + namespace util { template -struct Interpolator> +struct Interpolator> : Uninterpolated {}; } diff --git a/src/mbgl/style/property_parsing.cpp b/src/mbgl/style/property_parsing.cpp index 67baa3ec8dc..9f60ddf3b63 100644 --- a/src/mbgl/style/property_parsing.cpp +++ b/src/mbgl/style/property_parsing.cpp @@ -1,11 +1,11 @@ #include -#include #include #include namespace mbgl { +namespace style { template <> optional parseConstant(const char* name, const JSValue& value) { @@ -264,7 +264,7 @@ optional> parseConstant(const char* name, const JSValue return result; } -optional parsePropertyTransition(const char *, const JSValue& value) { +optional parseTransitionOptions(const char *, const JSValue& value) { if (!value.IsObject()) { return {}; } @@ -283,7 +283,8 @@ optional parsePropertyTransition(const char *, const JSValue return {}; } - return PropertyTransition(duration, delay); + return TransitionOptions(duration, delay); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/property_parsing.hpp b/src/mbgl/style/property_parsing.hpp index c0fe5ce2bc3..bb894c24078 100644 --- a/src/mbgl/style/property_parsing.hpp +++ b/src/mbgl/style/property_parsing.hpp @@ -2,10 +2,11 @@ #include #include -#include +#include #include #include +#include #include @@ -14,6 +15,7 @@ #include namespace mbgl { +namespace style { template optional parseConstant(const char* name, const JSValue&); @@ -104,6 +106,7 @@ PropertyValue parseProperty(const char* name, const JSValue& value) { return Function(stops, base); } -optional parsePropertyTransition(const char * name, const JSValue&); +optional parseTransitionOptions(const char * name, const JSValue&); +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_query_parameters.hpp b/src/mbgl/style/query_parameters.hpp similarity index 80% rename from src/mbgl/style/style_query_parameters.hpp rename to src/mbgl/style/query_parameters.hpp index 33115bdfb2c..3c1abf3b708 100644 --- a/src/mbgl/style/style_query_parameters.hpp +++ b/src/mbgl/style/query_parameters.hpp @@ -8,11 +8,14 @@ namespace mbgl { class TransformState; -class StyleQueryParameters { +namespace style { + +class QueryParameters { public: const ScreenLineString& geometry; const TransformState& transformState; const optional>& layerIDs; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/render_item.hpp b/src/mbgl/style/render_item.hpp index ebf67998283..da59591c360 100644 --- a/src/mbgl/style/render_item.hpp +++ b/src/mbgl/style/render_item.hpp @@ -2,12 +2,15 @@ namespace mbgl { -class Layer; class Tile; class Bucket; +namespace style { +class Layer; +} + struct RenderItem { - inline RenderItem(const Layer& layer_, + inline RenderItem(const style::Layer& layer_, const Tile* tile_ = nullptr, Bucket* bucket_ = nullptr) : tile(tile_), bucket(bucket_), layer(layer_) { @@ -15,7 +18,7 @@ struct RenderItem { const Tile* const tile; Bucket* const bucket; - const Layer& layer; + const style::Layer& layer; }; } // namespace mbgl diff --git a/src/mbgl/source/source.cpp b/src/mbgl/style/source.cpp similarity index 89% rename from src/mbgl/source/source.cpp rename to src/mbgl/style/source.cpp index 66546909ac3..8e5973f4123 100644 --- a/src/mbgl/source/source.cpp +++ b/src/mbgl/style/source.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -39,6 +39,7 @@ #include namespace mbgl { +namespace style { static SourceObserver nullObserver; @@ -46,13 +47,13 @@ Source::Source(SourceType type_, const std::string& id_, const std::string& url_, uint16_t tileSize_, - std::unique_ptr&& info_, + std::unique_ptr&& tileset_, std::unique_ptr&& geojsonvt_) : type(type_), id(id_), url(url_), tileSize(tileSize_), - info(std::move(info_)), + tileset(std::move(tileset_)), geojsonvt(std::move(geojsonvt_)), observer(&nullObserver) { } @@ -84,7 +85,7 @@ void Source::load(FileSource& fileSource) { } if (req) { - // We don't have a SourceInfo object yet, but there's already a request underway to load + // We don't have a Tileset object yet, but there's already a request underway to load // the data. return; } @@ -101,20 +102,20 @@ void Source::load(FileSource& fileSource) { bool reloadTiles = false; if (type == SourceType::Vector || type == SourceType::Raster) { - std::unique_ptr newInfo; + std::unique_ptr newTileset; - // Create a new copy of the SourceInfo object that holds the base values we've parsed + // Create a new copy of the Tileset object that holds the base values we've parsed // from the stylesheet. Then merge in the values parsed from the TileJSON we retrieved // via the URL. try { - newInfo = StyleParser::parseTileJSON(*res.data, url, type, tileSize); + newTileset = style::parseTileJSON(*res.data, url, type, tileSize); } catch (...) { observer->onSourceError(*this, std::current_exception()); return; } // Check whether previous information specifies different tile - if (info && info->tiles != newInfo->tiles) { + if (tileset && tileset->tiles != newTileset->tiles) { reloadTiles = true; // Tile size changed: We need to recalculate the tiles we need to load because we @@ -132,9 +133,9 @@ void Source::load(FileSource& fileSource) { // Center/bounds changed: We're not using these values currently } - info = std::move(newInfo); + tileset = std::move(newTileset); } else if (type == SourceType::GeoJSON) { - std::unique_ptr newInfo = std::make_unique(); + std::unique_ptr newTileset = std::make_unique(); rapidjson::GenericDocument, rapidjson::CrtAllocator> d; d.Parse<0>(res.data->c_str()); @@ -146,11 +147,11 @@ void Source::load(FileSource& fileSource) { return; } - geojsonvt = StyleParser::parseGeoJSON(d); + geojsonvt = style::parseGeoJSON(d); reloadTiles = true; - newInfo->maxZoom = geojsonvt->options.maxZoom; - info = std::move(newInfo); + newTileset->maxZoom = geojsonvt->options.maxZoom; + tileset = std::move(newTileset); } if (reloadTiles) { @@ -186,7 +187,7 @@ const std::map& Source::getTiles() const { } std::unique_ptr Source::createTile(const OverscaledTileID& overscaledTileID, - const StyleUpdateParameters& parameters) { + const UpdateParameters& parameters) { std::unique_ptr data = cache.get(overscaledTileID); if (data) { return data; @@ -198,13 +199,13 @@ std::unique_ptr Source::createTile(const OverscaledTileID& overscaledT // If we don't find working tile data, we're just going to load it. if (type == SourceType::Raster) { data = std::make_unique(overscaledTileID, parameters.pixelRatio, - info->tiles.at(0), parameters.texturePool, + tileset->tiles.at(0), parameters.texturePool, parameters.worker, parameters.fileSource, callback); } else { std::unique_ptr monitor; if (type == SourceType::Vector) { - monitor = std::make_unique(overscaledTileID, parameters.pixelRatio, info->tiles.at(0), parameters.fileSource); + monitor = std::make_unique(overscaledTileID, parameters.pixelRatio, tileset->tiles.at(0), parameters.fileSource); } else if (type == SourceType::Annotations) { monitor = std::make_unique(overscaledTileID, parameters.annotationManager); } else if (type == SourceType::GeoJSON) { @@ -230,7 +231,7 @@ TileData* Source::getTileData(const OverscaledTileID& overscaledTileID) const { } } -bool Source::update(const StyleUpdateParameters& parameters) { +bool Source::update(const UpdateParameters& parameters) { bool allTilesUpdated = true; if (!loaded || parameters.animationTime <= updated) { @@ -242,8 +243,8 @@ bool Source::update(const StyleUpdateParameters& parameters) { int32_t dataTileZoom = overscaledZoom; std::vector idealTiles; - if (overscaledZoom >= info->minZoom) { - int32_t idealZoom = std::min(info->maxZoom, overscaledZoom); + if (overscaledZoom >= tileset->minZoom) { + int32_t idealZoom = std::min(tileset->maxZoom, overscaledZoom); // Make sure we're not reparsing overzoomed raster tiles. if (type == SourceType::Raster) { @@ -278,7 +279,7 @@ bool Source::update(const StyleUpdateParameters& parameters) { tiles.clear(); algorithm::updateRenderables(getTileDataFn, createTileDataFn, retainTileDataFn, renderTileFn, - idealTiles, *info, dataTileZoom); + idealTiles, *tileset, dataTileZoom); if (type != SourceType::Raster && type != SourceType::Annotations && cache.getSize() == 0) { size_t conservativeCacheSize = @@ -341,7 +342,7 @@ static Point coordinateToTilePoint(const UnwrappedTileID& tileID, const }; } -std::unordered_map> Source::queryRenderedFeatures(const StyleQueryParameters& parameters) const { +std::unordered_map> Source::queryRenderedFeatures(const QueryParameters& parameters) const { LineString queryGeometry; for (const auto& p : parameters.geometry) { @@ -423,4 +424,5 @@ void Source::dumpDebugLogs() const { } } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/source/source.hpp b/src/mbgl/style/source.hpp similarity index 85% rename from src/mbgl/source/source.hpp rename to src/mbgl/style/source.hpp index cbdf4afa151..cadc45c25c2 100644 --- a/src/mbgl/source/source.hpp +++ b/src/mbgl/style/source.hpp @@ -3,12 +3,13 @@ #include #include #include -#include +#include #include #include #include #include +#include #include #include @@ -22,15 +23,18 @@ class GeoJSONVT; namespace mbgl { -class Style; -class StyleUpdateParameters; -class StyleQueryParameters; class Painter; class FileSource; class AsyncRequest; class TransformState; class Tile; struct ClipID; + +namespace style { + +class Style; +class UpdateParameters; +class QueryParameters; class SourceObserver; class Source : private util::noncopyable { @@ -39,7 +43,7 @@ class Source : private util::noncopyable { const std::string& id, const std::string& url, uint16_t tileSize, - std::unique_ptr&&, + std::unique_ptr&&, std::unique_ptr&&); ~Source(); @@ -48,13 +52,13 @@ class Source : private util::noncopyable { bool isLoading() const; bool isLoaded() const; - const SourceInfo* getInfo() const { return info.get(); } + const Tileset* getTileset() const { return tileset.get(); } // Request or parse all the tiles relevant for the "TransformState". This method // will return true if all the tiles were scheduled for updating of false if // they were not. shouldReparsePartialTiles must be set to "true" if there is // new data available that a tile in the "partial" state might be interested at. - bool update(const StyleUpdateParameters&); + bool update(const UpdateParameters&); template void updateClipIDs(ClipIDGenerator& generator) { @@ -69,7 +73,7 @@ class Source : private util::noncopyable { TileData* getTileData(const OverscaledTileID&) const; std::unordered_map> - queryRenderedFeatures(const StyleQueryParameters&) const; + queryRenderedFeatures(const QueryParameters&) const; void setCacheSize(size_t); void onLowMemory(); @@ -86,11 +90,10 @@ class Source : private util::noncopyable { private: void tileLoadingCallback(const OverscaledTileID&, std::exception_ptr, bool isNewTile); - std::unique_ptr createTile(const OverscaledTileID&, - const StyleUpdateParameters& parameters); + std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&); private: - std::unique_ptr info; + std::unique_ptr tileset; std::unique_ptr geojsonvt; @@ -106,4 +109,5 @@ class Source : private util::noncopyable { SourceObserver* observer = nullptr; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/source/source_observer.hpp b/src/mbgl/style/source_observer.hpp similarity index 92% rename from src/mbgl/source/source_observer.hpp rename to src/mbgl/style/source_observer.hpp index 828e562a3e7..a669e8e756a 100644 --- a/src/mbgl/source/source_observer.hpp +++ b/src/mbgl/style/source_observer.hpp @@ -4,9 +4,12 @@ namespace mbgl { -class Source; class OverscaledTileID; +namespace style { + +class Source; + class SourceObserver { public: virtual ~SourceObserver() = default; @@ -18,4 +21,5 @@ class SourceObserver { virtual void onPlacementRedone() {} }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index ee847ccf570..136c98df035 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -1,23 +1,23 @@ #include -#include -#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include +#include +#include +#include #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -30,10 +30,11 @@ #include namespace mbgl { +namespace style { -static StyleObserver nullObserver; +static Observer nullObserver; -bool Style::addClass(const std::string& className, const PropertyTransition& properties) { +bool Style::addClass(const std::string& className, const TransitionOptions& properties) { if (std::find(classes.begin(), classes.end(), className) != classes.end()) return false; classes.push_back(className); transitionProperties = properties; @@ -44,7 +45,7 @@ bool Style::hasClass(const std::string& className) const { return std::find(classes.begin(), classes.end(), className) != classes.end(); } -bool Style::removeClass(const std::string& className, const PropertyTransition& properties) { +bool Style::removeClass(const std::string& className, const TransitionOptions& properties) { const auto it = std::find(classes.begin(), classes.end(), className); if (it != classes.end()) { classes.erase(it); @@ -54,7 +55,7 @@ bool Style::removeClass(const std::string& className, const PropertyTransition& return false; } -void Style::setClasses(const std::vector& classNames, const PropertyTransition& properties) { +void Style::setClasses(const std::vector& classNames, const TransitionOptions& properties) { classes = classNames; transitionProperties = properties; } @@ -81,7 +82,7 @@ void Style::setJSON(const std::string& json, const std::string&) { layers.clear(); classes.clear(); - StyleParser parser; + Parser parser; parser.parse(json); for (auto& source : parser.sources) { @@ -153,7 +154,7 @@ void Style::removeLayer(const std::string& id) { layers.erase(it); } -void Style::update(const StyleUpdateParameters& parameters) { +void Style::update(const UpdateParameters& parameters) { bool allTilesUpdated = true; for (const auto& source : sources) { @@ -172,7 +173,7 @@ void Style::update(const StyleUpdateParameters& parameters) { void Style::cascade(const TimePoint& timePoint, MapMode mode) { // When in continuous mode, we can either have user- or style-defined // transitions. Still mode is always immediate. - static const PropertyTransition immediateTransition; + static const TransitionOptions immediateTransition; std::vector classIDs; for (const auto& className : classes) { @@ -181,7 +182,7 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) { classIDs.push_back(ClassID::Default); classIDs.push_back(ClassID::Fallback); - const StyleCascadeParameters parameters { + const CascadeParameters parameters { classIDs, mode == MapMode::Continuous ? timePoint : Clock::time_point::max(), mode == MapMode::Continuous ? transitionProperties.value_or(immediateTransition) : immediateTransition @@ -201,7 +202,7 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) { zoomHistory.update(z, timePoint); - const StyleCalculationParameters parameters { + const CalculationParameters parameters { z, mode == MapMode::Continuous ? timePoint : Clock::time_point::max(), zoomHistory, @@ -325,7 +326,7 @@ RenderData Style::getRenderData() const { return result; } -std::vector Style::queryRenderedFeatures(const StyleQueryParameters& parameters) const { +std::vector Style::queryRenderedFeatures(const QueryParameters& parameters) const { std::unordered_map> resultsByLayer; for (const auto& source : sources) { @@ -367,7 +368,7 @@ void Style::onLowMemory() { } } -void Style::setObserver(StyleObserver* observer_) { +void Style::setObserver(style::Observer* observer_) { observer = observer_; } @@ -440,4 +441,5 @@ void Style::dumpDebugLogs() const { spriteStore->dumpDebugLogs(); } +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 6892f4967a6..49af6743367 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -1,20 +1,21 @@ #pragma once #include -#include -#include -#include +#include -#include +#include +#include #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -25,20 +26,20 @@ namespace mbgl { class FileSource; class GlyphAtlas; -class GlyphStore; -class SpriteStore; class SpriteAtlas; class LineAtlas; -class StyleUpdateParameters; -class StyleQueryParameters; -class StyleObserver; struct RenderData { Color backgroundColor = {{ 0, 0, 0, 0 }}; - std::set sources; + std::set sources; std::vector order; }; +namespace style { + +class UpdateParameters; +class QueryParameters; + class Style : public GlyphStoreObserver, public SpriteStoreObserver, public SourceObserver, @@ -49,13 +50,13 @@ class Style : public GlyphStoreObserver, void setJSON(const std::string& data, const std::string& base); - void setObserver(StyleObserver*); + void setObserver(Observer*); bool isLoaded() const; // Fetch the tiles needed by the current viewport and emit a signal when // a tile is ready so observers can render the tile. - void update(const StyleUpdateParameters&); + void update(const UpdateParameters&); void cascade(const TimePoint&, MapMode); void recalculate(float z, const TimePoint&, MapMode); @@ -75,15 +76,15 @@ class Style : public GlyphStoreObserver, optional beforeLayerID = {}); void removeLayer(const std::string& layerID); - bool addClass(const std::string&, const PropertyTransition& = {}); - bool removeClass(const std::string&, const PropertyTransition& = {}); + bool addClass(const std::string&, const TransitionOptions& = {}); + bool removeClass(const std::string&, const TransitionOptions& = {}); bool hasClass(const std::string&) const; - void setClasses(const std::vector&, const PropertyTransition& = {}); + void setClasses(const std::vector&, const TransitionOptions& = {}); std::vector getClasses() const; RenderData getRenderData() const; - std::vector queryRenderedFeatures(const StyleQueryParameters&) const; + std::vector queryRenderedFeatures(const QueryParameters&) const; float getQueryRadius() const; @@ -103,7 +104,7 @@ class Style : public GlyphStoreObserver, std::vector> sources; std::vector> layers; std::vector classes; - optional transitionProperties; + optional transitionProperties; std::vector>::const_iterator findLayer(const std::string& layerID) const; @@ -122,7 +123,8 @@ class Style : public GlyphStoreObserver, void onTileError(Source&, const OverscaledTileID&, std::exception_ptr) override; void onPlacementRedone() override; - StyleObserver* observer = nullptr; + Observer nullObserver; + Observer* observer = &nullObserver; std::exception_ptr lastError; @@ -135,4 +137,5 @@ class Style : public GlyphStoreObserver, Worker workers; }; +} // namespace style } // namespace mbgl diff --git a/src/mbgl/style/style_calculation_parameters.hpp b/src/mbgl/style/style_calculation_parameters.hpp deleted file mode 100644 index 1c50bd61283..00000000000 --- a/src/mbgl/style/style_calculation_parameters.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -namespace mbgl { - -class StyleCalculationParameters { -public: - explicit StyleCalculationParameters(float z_) - : z(z_) {} - - StyleCalculationParameters(float z_, - const TimePoint& now_, - const ZoomHistory& zoomHistory_, - const Duration& defaultFadeDuration_) - : z(z_), - now(now_), - zoomHistory(zoomHistory_), - defaultFadeDuration(defaultFadeDuration_) {} - - float z; - TimePoint now; - ZoomHistory zoomHistory; - Duration defaultFadeDuration; -}; - -} // namespace mbgl diff --git a/src/mbgl/style/style_cascade_parameters.hpp b/src/mbgl/style/style_cascade_parameters.hpp deleted file mode 100644 index 569145bd043..00000000000 --- a/src/mbgl/style/style_cascade_parameters.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include -#include -#include - -#include - -namespace mbgl { - -class PropertyTransition; - -class StyleCascadeParameters { -public: - std::vector classes; - TimePoint now; - PropertyTransition transition; -}; - -} // namespace mbgl diff --git a/src/mbgl/style/style_render_parameters.hpp b/src/mbgl/style/style_render_parameters.hpp deleted file mode 100644 index 7347717a1df..00000000000 --- a/src/mbgl/style/style_render_parameters.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -namespace mbgl { - -class TransformState; - -class StyleRenderParameters { -public: - StyleRenderParameters(const TransformState& state_) - : state(state_) {} - - const TransformState& state; -}; - -} diff --git a/src/mbgl/style/style_update_parameters.hpp b/src/mbgl/style/update_parameters.hpp similarity index 92% rename from src/mbgl/style/style_update_parameters.hpp rename to src/mbgl/style/update_parameters.hpp index 73ed500e8e9..9faaa32d6f3 100644 --- a/src/mbgl/style/style_update_parameters.hpp +++ b/src/mbgl/style/update_parameters.hpp @@ -7,13 +7,16 @@ namespace mbgl { class TransformState; class Worker; class FileSource; -class Style; namespace gl { class TexturePool; } class AnnotationManager; -class StyleUpdateParameters { +namespace style { + +class Style; + +class UpdateParameters { public: - StyleUpdateParameters(float pixelRatio_, + UpdateParameters(float pixelRatio_, MapDebugOptions debugOptions_, TimePoint animationTime_, const TransformState& transformState_, @@ -51,4 +54,5 @@ class StyleUpdateParameters { Style& style; }; -} +} // namespace style +} // namespace mbgl diff --git a/src/mbgl/text/glyph_pbf.hpp b/src/mbgl/text/glyph_pbf.hpp index 08616b268b4..85f4b62e6fe 100644 --- a/src/mbgl/text/glyph_pbf.hpp +++ b/src/mbgl/text/glyph_pbf.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index d614a4947f0..edc89b48949 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/mbgl/text/glyph_store_observer.hpp b/src/mbgl/text/glyph_store_observer.hpp index 89650892ea3..39f10cd812e 100644 --- a/src/mbgl/text/glyph_store_observer.hpp +++ b/src/mbgl/text/glyph_store_observer.hpp @@ -2,6 +2,7 @@ #include #include +#include #include diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index 3cb508a1029..ce320791c34 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -2,13 +2,15 @@ #include #include #include -#include +#include #include #include #include namespace mbgl { +using namespace style; + const float globalMinScale = 0.5f; // underscale by 1 zoom level SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, diff --git a/src/mbgl/text/quads.hpp b/src/mbgl/text/quads.hpp index c68ea2fe6a5..0627647f4c0 100644 --- a/src/mbgl/text/quads.hpp +++ b/src/mbgl/text/quads.hpp @@ -7,39 +7,43 @@ namespace mbgl { - struct SymbolQuad { - explicit SymbolQuad(const Point &tl_, const Point &tr_, - const Point &bl_, const Point &br_, - const Rect &tex_, float angle_, const Point &anchorPoint_, - float minScale_, float maxScale_) - : tl(tl_), - tr(tr_), - bl(bl_), - br(br_), - tex(tex_), - angle(angle_), - anchorPoint(anchorPoint_), - minScale(minScale_), - maxScale(maxScale_) {} - - Point tl, tr, bl, br; - Rect tex; - float angle; - Point anchorPoint; - float minScale, maxScale; - }; - - typedef std::vector SymbolQuads; - - struct Anchor; - class SymbolLayoutProperties; - class PositionedIcon; - - SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, - const GeometryCoordinates& line, const SymbolLayoutProperties& layout, - const bool alongLine); - - SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, - const float boxScale, const GeometryCoordinates& line, const SymbolLayoutProperties& layout, - const bool alongLine, const GlyphPositions& face); +struct Anchor; +class PositionedIcon; + +namespace style { +class SymbolLayoutProperties; +} + +struct SymbolQuad { + explicit SymbolQuad(const Point &tl_, const Point &tr_, + const Point &bl_, const Point &br_, + const Rect &tex_, float angle_, const Point &anchorPoint_, + float minScale_, float maxScale_) + : tl(tl_), + tr(tr_), + bl(bl_), + br(br_), + tex(tex_), + angle(angle_), + anchorPoint(anchorPoint_), + minScale(minScale_), + maxScale(maxScale_) {} + + Point tl, tr, bl, br; + Rect tex; + float angle; + Point anchorPoint; + float minScale, maxScale; +}; + +typedef std::vector SymbolQuads; + +SymbolQuads getIconQuads(Anchor& anchor, const PositionedIcon& shapedIcon, + const GeometryCoordinates& line, const style::SymbolLayoutProperties&, + const bool alongLine); + +SymbolQuads getGlyphQuads(Anchor& anchor, const Shaping& shapedText, + const float boxScale, const GeometryCoordinates& line, const style::SymbolLayoutProperties&, + const bool alongLine, const GlyphPositions& face); + } // namespace mbgl diff --git a/src/mbgl/text/shaping.cpp b/src/mbgl/text/shaping.cpp index ce93b4977e0..1091cd6e941 100644 --- a/src/mbgl/text/shaping.cpp +++ b/src/mbgl/text/shaping.cpp @@ -1,9 +1,9 @@ #include -#include +#include namespace mbgl { -PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties& layout) { +PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties& layout) { float dx = layout.iconOffset.value[0]; float dy = layout.iconOffset.value[1]; float x1 = dx - image.spriteImage->getWidth() / 2.0f; diff --git a/src/mbgl/text/shaping.hpp b/src/mbgl/text/shaping.hpp index ea169b8dc63..f81230acec9 100644 --- a/src/mbgl/text/shaping.hpp +++ b/src/mbgl/text/shaping.hpp @@ -7,26 +7,28 @@ namespace mbgl { - struct SpriteAtlasElement; +struct SpriteAtlasElement; - class PositionedIcon { - public: - inline explicit PositionedIcon() {} - inline explicit PositionedIcon(const SpriteAtlasElement& _image, - float _top, float _bottom, float _left, float _right) : - image(_image), top(_top), bottom(_bottom), left(_left), right(_right) {} +namespace style { +class SymbolLayoutProperties; +} - optional image; - float top = 0; - float bottom = 0; - float left = 0; - float right = 0; +class PositionedIcon { + public: + inline explicit PositionedIcon() {} + inline explicit PositionedIcon(const SpriteAtlasElement& _image, + float _top, float _bottom, float _left, float _right) : + image(_image), top(_top), bottom(_bottom), left(_left), right(_right) {} - operator bool() const { return image && (*image).pos.hasArea(); } - }; + optional image; + float top = 0; + float bottom = 0; + float left = 0; + float right = 0; - class SymbolLayoutProperties; + operator bool() const { return image && (*image).pos.hasArea(); } +}; - PositionedIcon shapeIcon(const SpriteAtlasElement& image, const SymbolLayoutProperties&); +PositionedIcon shapeIcon(const SpriteAtlasElement& image, const style::SymbolLayoutProperties&); } // namespace mbgl diff --git a/src/mbgl/tile/raster_tile_data.cpp b/src/mbgl/tile/raster_tile_data.cpp index a5eab3fb236..420cb7055e1 100644 --- a/src/mbgl/tile/raster_tile_data.cpp +++ b/src/mbgl/tile/raster_tile_data.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -61,7 +61,7 @@ RasterTileData::~RasterTileData() { cancel(); } -Bucket* RasterTileData::getBucket(const Layer&) { +Bucket* RasterTileData::getBucket(const style::Layer&) { return bucket.get(); } diff --git a/src/mbgl/tile/raster_tile_data.hpp b/src/mbgl/tile/raster_tile_data.hpp index ea9b144e25b..62d21d28c4f 100644 --- a/src/mbgl/tile/raster_tile_data.hpp +++ b/src/mbgl/tile/raster_tile_data.hpp @@ -7,9 +7,13 @@ namespace mbgl { class FileSource; class AsyncRequest; -class Layer; + namespace gl { class TexturePool; } +namespace style { +class Layer; +} + class RasterTileData : public TileData { public: RasterTileData(const OverscaledTileID&, @@ -22,7 +26,7 @@ class RasterTileData : public TileData { ~RasterTileData(); void cancel() override; - Bucket* getBucket(const Layer&) override; + Bucket* getBucket(const style::Layer&) override; private: gl::TexturePool& texturePool; diff --git a/src/mbgl/tile/tile_data.hpp b/src/mbgl/tile/tile_data.hpp index 035a7ed319e..5b6583faf8d 100644 --- a/src/mbgl/tile/tile_data.hpp +++ b/src/mbgl/tile/tile_data.hpp @@ -16,11 +16,14 @@ namespace mbgl { -class Layer; class Worker; class DebugBucket; class TransformState; +namespace style { +class Layer; +} + class TileData : private util::noncopyable { public: TileData(const OverscaledTileID&); @@ -29,7 +32,7 @@ class TileData : private util::noncopyable { // Mark this tile as no longer needed and cancel any pending work. virtual void cancel() = 0; - virtual Bucket* getBucket(const Layer&) = 0; + virtual Bucket* getBucket(const style::Layer&) = 0; virtual bool parsePending(std::function) { return true; } virtual void redoPlacement(PlacementConfig, const std::function&) {} diff --git a/src/mbgl/tile/tile_worker.cpp b/src/mbgl/tile/tile_worker.cpp index 9076684a2d4..b2283043da1 100644 --- a/src/mbgl/tile/tile_worker.cpp +++ b/src/mbgl/tile/tile_worker.cpp @@ -1,11 +1,11 @@ #include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #include #include @@ -15,7 +15,9 @@ #include #include -using namespace mbgl; +namespace mbgl { + +using namespace mbgl::style; TileWorker::TileWorker(const OverscaledTileID& id_, std::string sourceID_, @@ -155,7 +157,7 @@ void TileWorker::parseLayer(const Layer* layer) { return; } - StyleBucketParameters parameters(id, + BucketParameters parameters(id, *geometryLayer, obsolete, reinterpret_cast(this), @@ -185,3 +187,5 @@ void TileWorker::insertBucket(const std::string& name, std::unique_ptr b result.buckets.emplace(name, std::move(bucket)); } } + +} diff --git a/src/mbgl/tile/tile_worker.hpp b/src/mbgl/tile/tile_worker.hpp index a04ef6a78f4..2757c0f9ba3 100644 --- a/src/mbgl/tile/tile_worker.hpp +++ b/src/mbgl/tile/tile_worker.hpp @@ -23,8 +23,11 @@ class SpriteStore; class GlyphAtlas; class GlyphStore; class Bucket; + +namespace style { class Layer; class SymbolLayer; +} // We're using this class to shuttle the resulting buckets from the worker thread to the MapContext // thread. This class is movable-only because the vector contains movable-only value elements. @@ -51,7 +54,7 @@ class TileWorker : public util::noncopyable { const MapMode); ~TileWorker(); - TileParseResult parseAllLayers(std::vector>, + TileParseResult parseAllLayers(std::vector>, std::unique_ptr geometryTile, PlacementConfig); @@ -62,7 +65,7 @@ class TileWorker : public util::noncopyable { private: TileParseResult prepareResult(const PlacementConfig& config); - void parseLayer(const Layer*); + void parseLayer(const style::Layer*); void insertBucket(const std::string& name, std::unique_ptr); std::unique_ptr placeLayers(PlacementConfig); @@ -77,14 +80,14 @@ class TileWorker : public util::noncopyable { bool partialParse = false; - std::vector> layers; + std::vector> layers; std::unique_ptr featureIndex; std::unique_ptr geometryTile; // Contains buckets that we couldn't parse so far due to missing resources. // They will be attempted on subsequent parses. - std::list>> pending; + std::list>> pending; // Contains buckets that have been parsed, but still need placement. // They will be placed when all buckets have been parsed. diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp index 8a69a823141..5126d0ce83a 100644 --- a/src/mbgl/tile/vector_tile.cpp +++ b/src/mbgl/tile/vector_tile.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index db0ec8029e1..1ab2566a25a 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -14,7 +14,7 @@ namespace mbgl { VectorTileData::VectorTileData(const OverscaledTileID& id_, std::unique_ptr monitor_, std::string sourceID, - Style& style_, + style::Style& style_, const MapMode mode_, const std::function& callback) : TileData(id_), @@ -139,7 +139,7 @@ bool VectorTileData::parsePending(std::function callba return true; } -Bucket* VectorTileData::getBucket(const Layer& layer) { +Bucket* VectorTileData::getBucket(const style::Layer& layer) { const auto it = buckets.find(layer.baseImpl->bucketName()); if (it == buckets.end()) { return nullptr; diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp index 4695338e1e2..e7de39e0389 100644 --- a/src/mbgl/tile/vector_tile_data.hpp +++ b/src/mbgl/tile/vector_tile_data.hpp @@ -11,23 +11,26 @@ namespace mbgl { -class Style; class AsyncRequest; class GeometryTileMonitor; class FeatureIndex; +namespace style { +class Style; +} + class VectorTileData : public TileData { public: VectorTileData(const OverscaledTileID&, std::unique_ptr monitor, std::string sourceID, - Style&, + style::Style&, const MapMode, const std::function& callback); ~VectorTileData(); - Bucket* getBucket(const Layer&) override; + Bucket* getBucket(const style::Layer&) override; bool parsePending(std::function callback) override; @@ -43,7 +46,7 @@ class VectorTileData : public TileData { void cancel() override; private: - Style& style; + style::Style& style; Worker& worker; TileWorker tileWorker; diff --git a/src/mbgl/style/types.cpp b/src/mbgl/util/font_stack.cpp similarity index 91% rename from src/mbgl/style/types.cpp rename to src/mbgl/util/font_stack.cpp index 27574afa939..fb3b1b60a26 100644 --- a/src/mbgl/style/types.cpp +++ b/src/mbgl/util/font_stack.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/mbgl/source/source_info.hpp b/src/mbgl/util/tileset.hpp similarity index 86% rename from src/mbgl/source/source_info.hpp rename to src/mbgl/util/tileset.hpp index dc79695dc9e..972fc51f8c5 100644 --- a/src/mbgl/source/source_info.hpp +++ b/src/mbgl/util/tileset.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -11,9 +10,7 @@ namespace mbgl { -class TileID; - -class SourceInfo { +class Tileset { public: std::vector tiles; uint8_t minZoom = 0; diff --git a/src/mbgl/util/worker.cpp b/src/mbgl/util/worker.cpp index 43abe6792a3..2bc545c704a 100644 --- a/src/mbgl/util/worker.cpp +++ b/src/mbgl/util/worker.cpp @@ -30,7 +30,7 @@ class Worker::Impl { } void parseGeometryTile(TileWorker* worker, - std::vector> layers, + std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { @@ -79,7 +79,7 @@ Worker::parseRasterTile(std::unique_ptr bucket, std::unique_ptr Worker::parseGeometryTile(TileWorker& worker, - std::vector> layers, + std::vector> layers, std::unique_ptr tile, PlacementConfig config, std::function callback) { diff --git a/src/mbgl/util/worker.hpp b/src/mbgl/util/worker.hpp index 68625f42bf4..678dfaedb31 100644 --- a/src/mbgl/util/worker.hpp +++ b/src/mbgl/util/worker.hpp @@ -40,7 +40,7 @@ class Worker : public mbgl::util::noncopyable { std::function callback); Request parseGeometryTile(TileWorker&, - std::vector>, + std::vector>, std::unique_ptr, PlacementConfig, std::function callback); diff --git a/test/api/custom_layer.cpp b/test/api/custom_layer.cpp index b3ff335d4e8..c805df5566c 100644 --- a/test/api/custom_layer.cpp +++ b/test/api/custom_layer.cpp @@ -4,12 +4,13 @@ #include #include #include -#include +#include #include #include #include using namespace mbgl; +using namespace mbgl::style; static const GLchar * vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 0, 1); }"; static const GLchar * fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 1, 0, 1); }"; diff --git a/test/map/map.cpp b/test/map/map.cpp index c6f6843a0d8..7cafe563b4c 100644 --- a/test/map/map.cpp +++ b/test/map/map.cpp @@ -8,9 +8,10 @@ #include #include #include -#include +#include using namespace mbgl; +using namespace mbgl::style; using namespace std::literals::string_literals; struct MapTest { diff --git a/test/src/mbgl/test/stub_style_observer.hpp b/test/src/mbgl/test/stub_style_observer.hpp index 45af1edf9db..d70fc5e44cd 100644 --- a/test/src/mbgl/test/stub_style_observer.hpp +++ b/test/src/mbgl/test/stub_style_observer.hpp @@ -1,13 +1,14 @@ #pragma once -#include +#include -namespace mbgl { +using namespace mbgl; +using namespace mbgl::style; /** - * An implementation of StyleObserver that forwards all methods to dynamically-settable lambas. + * An implementation of style::Observer that forwards all methods to dynamically-settable lambas. */ -class StubStyleObserver : public StyleObserver { +class StubStyleObserver : public style::Observer { public: void onGlyphsLoaded(const FontStack& fontStack, const GlyphRange& glyphRange) override { if (glyphsLoaded) glyphsLoaded(fontStack, glyphRange); @@ -61,5 +62,3 @@ class StubStyleObserver : public StyleObserver { std::function resourceLoaded; std::function resourceError; }; - -} // namespace mbgl diff --git a/test/storage/offline.cpp b/test/storage/offline.cpp index 3b64c0f50ea..06789cd8285 100644 --- a/test/storage/offline.cpp +++ b/test/storage/offline.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -14,49 +14,49 @@ static const LatLngBounds sanFranciscoWrapped = TEST(OfflineTilePyramidRegionDefinition, TileCoverEmpty) { OfflineTilePyramidRegionDefinition region("", LatLngBounds::empty(), 0, 20, 1.0); - SourceInfo info; + Tileset tileset; - EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, info)); + EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, tileset)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomIntersection) { OfflineTilePyramidRegionDefinition region("", sanFrancisco, 2, 2, 1.0); - SourceInfo info; + Tileset tileset; - info.minZoom = 0; + tileset.minZoom = 0; EXPECT_EQ((std::vector{ { 2, 0, 1 } }), - region.tileCover(SourceType::Vector, 512, info)); + region.tileCover(SourceType::Vector, 512, tileset)); - info.minZoom = 3; - EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, info)); + tileset.minZoom = 3; + EXPECT_EQ((std::vector{}), region.tileCover(SourceType::Vector, 512, tileset)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverTileSize) { OfflineTilePyramidRegionDefinition region("", LatLngBounds::world(), 0, 0, 1.0); - SourceInfo info; + Tileset tileset; EXPECT_EQ((std::vector{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, info)); + region.tileCover(SourceType::Vector, 512, tileset)); EXPECT_EQ((std::vector{ { 1, 0, 0 }, { 1, 0, 1 }, { 1, 1, 0 }, { 1, 1, 1 } }), - region.tileCover(SourceType::Vector, 256, info)); + region.tileCover(SourceType::Vector, 256, tileset)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverZoomRounding) { OfflineTilePyramidRegionDefinition region("", sanFrancisco, 0.6, 0.7, 1.0); - SourceInfo info; + Tileset tileset; EXPECT_EQ((std::vector{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, info)); + region.tileCover(SourceType::Vector, 512, tileset)); EXPECT_EQ((std::vector{ { 1, 0, 0 } }), - region.tileCover(SourceType::Raster, 512, info)); + region.tileCover(SourceType::Raster, 512, tileset)); } TEST(OfflineTilePyramidRegionDefinition, TileCoverWrapped) { OfflineTilePyramidRegionDefinition region("", sanFranciscoWrapped, 0, 0, 1.0); - SourceInfo info; + Tileset tileset; EXPECT_EQ((std::vector{ { 0, 0, 0 } }), - region.tileCover(SourceType::Vector, 512, info)); + region.tileCover(SourceType::Vector, 512, tileset)); } diff --git a/test/style/filter.cpp b/test/style/filter.cpp index f258c31492e..6e7f62db1b2 100644 --- a/test/style/filter.cpp +++ b/test/style/filter.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -10,6 +10,7 @@ #include using namespace mbgl; +using namespace mbgl::style; typedef std::multimap Properties; diff --git a/test/style/functions.cpp b/test/style/functions.cpp index 8812c77b559..5406320e4c9 100644 --- a/test/style/functions.cpp +++ b/test/style/functions.cpp @@ -2,12 +2,13 @@ #include #include -#include +#include using namespace mbgl; +using namespace mbgl::style; float evaluate(PropertyValue value, float zoom) { - return PropertyValue::visit(value, PropertyEvaluator(StyleCalculationParameters(zoom), 0)); + return PropertyValue::visit(value, PropertyEvaluator(CalculationParameters(zoom), 0)); } TEST(Function, Constant) { diff --git a/test/style/source.cpp b/test/style/source.cpp index b9eb1bc4345..ae8fb54d2f2 100644 --- a/test/style/source.cpp +++ b/test/style/source.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include @@ -12,8 +12,8 @@ #include #include #include -#include -#include +#include +#include #include #include @@ -30,9 +30,9 @@ class SourceTest { Worker worker { 1 }; gl::TexturePool texturePool; AnnotationManager annotationManager { 1.0 }; - Style style { fileSource, 1.0 }; + style::Style style { fileSource, 1.0 }; - StyleUpdateParameters updateParameters { + style::UpdateParameters updateParameters { 1.0, MapDebugOptions(), TimePoint(), @@ -131,10 +131,10 @@ TEST(Source, RasterTileEmpty) { FAIL() << "Should never be called"; }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Raster, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -160,10 +160,10 @@ TEST(Source, VectorTileEmpty) { FAIL() << "Should never be called"; }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Vector, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -189,10 +189,10 @@ TEST(Source, RasterTileFail) { test.end(); }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Raster, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -218,10 +218,10 @@ TEST(Source, VectorTileFail) { test.end(); }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Vector, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -246,10 +246,10 @@ TEST(Source, RasterTileCorrupt) { test.end(); }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Raster, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -278,10 +278,10 @@ TEST(Source, VectorTileCorrupt) { layer->setSource("source", "water"); test.style.addLayer(std::move(layer)); - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Vector, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -305,10 +305,10 @@ TEST(Source, RasterTileCancel) { FAIL() << "Should never be called"; }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Raster, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Raster, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); @@ -332,10 +332,10 @@ TEST(Source, VectorTileCancel) { FAIL() << "Should never be called"; }; - auto info = std::make_unique(); - info->tiles = { "tiles" }; + auto tileset = std::make_unique(); + tileset->tiles = { "tiles" }; - Source source(SourceType::Vector, "source", "", 512, std::move(info), nullptr); + Source source(SourceType::Vector, "source", "", 512, std::move(tileset), nullptr); source.setObserver(&test.observer); source.load(test.fileSource); source.update(test.updateParameters); diff --git a/test/style/style.cpp b/test/style/style.cpp index 916e1121c65..931867978e6 100644 --- a/test/style/style.cpp +++ b/test/style/style.cpp @@ -2,10 +2,11 @@ #include #include -#include +#include #include using namespace mbgl; +using namespace mbgl::style; TEST(Style, UnusedSource) { util::RunLoop loop; diff --git a/test/style/style_layer.cpp b/test/style/style_layer.cpp index 3274fe33775..ed8904dabd5 100644 --- a/test/style/style_layer.cpp +++ b/test/style/style_layer.cpp @@ -1,8 +1,9 @@ #include -#include -#include +#include +#include using namespace mbgl; +using namespace mbgl::style; TEST(Layer, Clone) { std::unique_ptr layer = std::make_unique("id"); diff --git a/test/style/style_parser.cpp b/test/style/style_parser.cpp index 6245c326a5e..5f730a8373d 100644 --- a/test/style/style_parser.cpp +++ b/test/style/style_parser.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include #include #include @@ -29,7 +29,7 @@ TEST_P(StyleParserTest, ParseStyle) { FixtureLogObserver* observer = new FixtureLogObserver(); Log::setObserver(std::unique_ptr(observer)); - StyleParser parser; + style::Parser parser; parser.parse(util::read_file(base + ".style.json")); for (auto it = infoDoc.MemberBegin(), end = infoDoc.MemberEnd(); it != end; it++) { @@ -86,7 +86,7 @@ INSTANTIATE_TEST_CASE_P(StyleParser, StyleParserTest, ::testing::ValuesIn([] { }())); TEST(StyleParser, ParseTileJSONRaster) { - auto result = StyleParser::parseTileJSON( + auto result = style::parseTileJSON( util::read_file("test/fixtures/style_parser/tilejson.raster.json"), "mapbox://mapbox.satellite", SourceType::Raster, @@ -103,7 +103,7 @@ TEST(StyleParser, ParseTileJSONRaster) { } TEST(StyleParser, ParseTileJSONVector) { - auto result = StyleParser::parseTileJSON( + auto result = style::parseTileJSON( util::read_file("test/fixtures/style_parser/tilejson.vector.json"), "mapbox://mapbox.streets", SourceType::Vector, @@ -116,7 +116,7 @@ TEST(StyleParser, ParseTileJSONVector) { } TEST(StyleParser, FontStacks) { - StyleParser parser; + style::Parser parser; parser.parse(util::read_file("test/fixtures/style_parser/font_stacks.json")); auto result = parser.fontStacks(); ASSERT_EQ(3, result.size()); From e1a58565c88a80e5b68181e69fd3a8b4bfe3e85c Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 2 Jun 2016 15:44:39 -0700 Subject: [PATCH 8/8] [core] Move RenderData alongside RenderItem --- src/mbgl/renderer/painter.hpp | 5 ++-- src/mbgl/renderer/render_item.hpp | 38 +++++++++++++++++++++++++++++++ src/mbgl/style/render_item.hpp | 24 ------------------- src/mbgl/style/style.cpp | 1 + src/mbgl/style/style.hpp | 11 +-------- 5 files changed, 42 insertions(+), 37 deletions(-) create mode 100644 src/mbgl/renderer/render_item.hpp delete mode 100644 src/mbgl/style/render_item.hpp diff --git a/src/mbgl/renderer/painter.hpp b/src/mbgl/renderer/painter.hpp index f040fee67f3..25627a8d7a3 100644 --- a/src/mbgl/renderer/painter.hpp +++ b/src/mbgl/renderer/painter.hpp @@ -5,18 +5,17 @@ #include #include +#include #include #include #include #include +#include -#include #include -#include - #include #include #include diff --git a/src/mbgl/renderer/render_item.hpp b/src/mbgl/renderer/render_item.hpp new file mode 100644 index 00000000000..6c97b66bd1a --- /dev/null +++ b/src/mbgl/renderer/render_item.hpp @@ -0,0 +1,38 @@ +#pragma once + +#include + +#include +#include + +namespace mbgl { + +class Tile; +class Bucket; + +namespace style { +class Layer; +class Source; +} + +class RenderItem { +public: + RenderItem(const style::Layer& layer_, + const Tile* tile_ = nullptr, + Bucket* bucket_ = nullptr) + : tile(tile_), bucket(bucket_), layer(layer_) { + } + + const Tile* const tile; + Bucket* const bucket; + const style::Layer& layer; +}; + +class RenderData { +public: + Color backgroundColor = {{ 0, 0, 0, 0 }}; + std::set sources; + std::vector order; +}; + +} // namespace mbgl diff --git a/src/mbgl/style/render_item.hpp b/src/mbgl/style/render_item.hpp deleted file mode 100644 index da59591c360..00000000000 --- a/src/mbgl/style/render_item.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -namespace mbgl { - -class Tile; -class Bucket; - -namespace style { -class Layer; -} - -struct RenderItem { - inline RenderItem(const style::Layer& layer_, - const Tile* tile_ = nullptr, - Bucket* bucket_ = nullptr) - : tile(tile_), bucket(bucket_), layer(layer_) { - } - - const Tile* const tile; - Bucket* const bucket; - const style::Layer& layer; -}; - -} // namespace mbgl diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 136c98df035..b86845154c3 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/src/mbgl/style/style.hpp b/src/mbgl/style/style.hpp index 49af6743367..a679681f417 100644 --- a/src/mbgl/style/style.hpp +++ b/src/mbgl/style/style.hpp @@ -1,8 +1,6 @@ #pragma once -#include #include - #include #include #include @@ -15,12 +13,10 @@ #include #include #include -#include #include #include #include -#include namespace mbgl { @@ -28,12 +24,7 @@ class FileSource; class GlyphAtlas; class SpriteAtlas; class LineAtlas; - -struct RenderData { - Color backgroundColor = {{ 0, 0, 0, 0 }}; - std::set sources; - std::vector order; -}; +class RenderData; namespace style {