[core] Introduce style::LayerProperties interface and its implementations

This commit is contained in:
Mikhail Pozdnyakov
2019-01-24 10:40:50 +02:00
parent cd5f87e9d2
commit 1a66a02097
23 changed files with 389 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
#pragma once
#include <mbgl/style/layer_impl.hpp>
namespace mbgl {
namespace style {
/**
* @brief An interface, wrapping evaluated layer properties.
*
* It is an abstract base class; concrete derived classes that hold the actual data are provided for each layer type.
*/
class LayerProperties {
public:
virtual ~LayerProperties() = default;
Immutable<Layer::Impl> baseImpl;
protected:
LayerProperties(Immutable<Layer::Impl> impl) : baseImpl(std::move(impl)) {}
};
template <class Derived>
inline const auto& getEvaluated(const Immutable<LayerProperties>& properties) {
return static_cast<const Derived&>(*properties).evaluated;
}
} // namespace style
} // namespace mbgl

View File

@@ -420,6 +420,7 @@
"mbgl/style/filter.hpp": "include/mbgl/style/filter.hpp",
"mbgl/style/image.hpp": "include/mbgl/style/image.hpp",
"mbgl/style/layer.hpp": "include/mbgl/style/layer.hpp",
"mbgl/style/layer_properties.hpp": "include/mbgl/style/layer_properties.hpp",
"mbgl/style/layers/background_layer.hpp": "include/mbgl/style/layers/background_layer.hpp",
"mbgl/style/layers/circle_layer.hpp": "include/mbgl/style/layers/circle_layer.hpp",
"mbgl/style/layers/custom_layer.hpp": "include/mbgl/style/layers/custom_layer.hpp",

View File

@@ -12,8 +12,6 @@
namespace mbgl {
class RenderLayer;
namespace style {
/**
@@ -65,4 +63,4 @@ const LayerTypeInfo* getTypeInfo() const noexcept final { return staticTypeInfo(
static const LayerTypeInfo* staticTypeInfo() noexcept
} // namespace style
} // namespace mbgl
} // namespace mbgl

View File

@@ -2,8 +2,28 @@
#include <mbgl/style/layers/background_layer_properties.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
namespace mbgl {
namespace style {
BackgroundLayerProperties::BackgroundLayerProperties(
Immutable<BackgroundLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
BackgroundLayerProperties::BackgroundLayerProperties(
Immutable<BackgroundLayer::Impl> impl_,
CrossfadeParameters crossfade_,
BackgroundPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
crossfade(std::move(crossfade_)),
evaluated(std::move(evaluated_)) {}
BackgroundLayerProperties::~BackgroundLayerProperties() = default;
const BackgroundLayer::Impl& BackgroundLayerProperties::layerImpl() const {
return static_cast<const BackgroundLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -30,5 +32,20 @@ class BackgroundPaintProperties : public Properties<
BackgroundOpacity
> {};
class BackgroundLayerProperties final : public LayerProperties {
public:
explicit BackgroundLayerProperties(Immutable<BackgroundLayer::Impl>);
BackgroundLayerProperties(
Immutable<BackgroundLayer::Impl>,
CrossfadeParameters,
BackgroundPaintProperties::PossiblyEvaluated);
~BackgroundLayerProperties() override;
const BackgroundLayer::Impl& layerImpl() const;
// Data members.
CrossfadeParameters crossfade;
BackgroundPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,26 @@
#include <mbgl/style/layers/circle_layer_properties.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
namespace mbgl {
namespace style {
CircleLayerProperties::CircleLayerProperties(
Immutable<CircleLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
CircleLayerProperties::CircleLayerProperties(
Immutable<CircleLayer::Impl> impl_,
CirclePaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
evaluated(std::move(evaluated_)) {}
CircleLayerProperties::~CircleLayerProperties() = default;
const CircleLayer::Impl& CircleLayerProperties::layerImpl() const {
return static_cast<const CircleLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -70,5 +72,18 @@ class CirclePaintProperties : public Properties<
CircleStrokeOpacity
> {};
class CircleLayerProperties final : public LayerProperties {
public:
explicit CircleLayerProperties(Immutable<CircleLayer::Impl>);
CircleLayerProperties(
Immutable<CircleLayer::Impl>,
CirclePaintProperties::PossiblyEvaluated);
~CircleLayerProperties() override;
const CircleLayer::Impl& layerImpl() const;
// Data members.
CirclePaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,28 @@
#include <mbgl/style/layers/fill_extrusion_layer_properties.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp>
namespace mbgl {
namespace style {
FillExtrusionLayerProperties::FillExtrusionLayerProperties(
Immutable<FillExtrusionLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
FillExtrusionLayerProperties::FillExtrusionLayerProperties(
Immutable<FillExtrusionLayer::Impl> impl_,
CrossfadeParameters crossfade_,
FillExtrusionPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
crossfade(std::move(crossfade_)),
evaluated(std::move(evaluated_)) {}
FillExtrusionLayerProperties::~FillExtrusionLayerProperties() = default;
const FillExtrusionLayer::Impl& FillExtrusionLayerProperties::layerImpl() const {
return static_cast<const FillExtrusionLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -55,5 +57,20 @@ class FillExtrusionPaintProperties : public Properties<
FillExtrusionVerticalGradient
> {};
class FillExtrusionLayerProperties final : public LayerProperties {
public:
explicit FillExtrusionLayerProperties(Immutable<FillExtrusionLayer::Impl>);
FillExtrusionLayerProperties(
Immutable<FillExtrusionLayer::Impl>,
CrossfadeParameters,
FillExtrusionPaintProperties::PossiblyEvaluated);
~FillExtrusionLayerProperties() override;
const FillExtrusionLayer::Impl& layerImpl() const;
// Data members.
CrossfadeParameters crossfade;
FillExtrusionPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,28 @@
#include <mbgl/style/layers/fill_layer_properties.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
namespace mbgl {
namespace style {
FillLayerProperties::FillLayerProperties(
Immutable<FillLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
FillLayerProperties::FillLayerProperties(
Immutable<FillLayer::Impl> impl_,
CrossfadeParameters crossfade_,
FillPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
crossfade(std::move(crossfade_)),
evaluated(std::move(evaluated_)) {}
FillLayerProperties::~FillLayerProperties() = default;
const FillLayer::Impl& FillLayerProperties::layerImpl() const {
return static_cast<const FillLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -50,5 +52,20 @@ class FillPaintProperties : public Properties<
FillPattern
> {};
class FillLayerProperties final : public LayerProperties {
public:
explicit FillLayerProperties(Immutable<FillLayer::Impl>);
FillLayerProperties(
Immutable<FillLayer::Impl>,
CrossfadeParameters,
FillPaintProperties::PossiblyEvaluated);
~FillLayerProperties() override;
const FillLayer::Impl& layerImpl() const;
// Data members.
CrossfadeParameters crossfade;
FillPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,26 @@
#include <mbgl/style/layers/heatmap_layer_properties.hpp>
#include <mbgl/style/layers/heatmap_layer_impl.hpp>
namespace mbgl {
namespace style {
HeatmapLayerProperties::HeatmapLayerProperties(
Immutable<HeatmapLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
HeatmapLayerProperties::HeatmapLayerProperties(
Immutable<HeatmapLayer::Impl> impl_,
HeatmapPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
evaluated(std::move(evaluated_)) {}
HeatmapLayerProperties::~HeatmapLayerProperties() = default;
const HeatmapLayer::Impl& HeatmapLayerProperties::layerImpl() const {
return static_cast<const HeatmapLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/heatmap_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -39,5 +41,18 @@ class HeatmapPaintProperties : public Properties<
HeatmapOpacity
> {};
class HeatmapLayerProperties final : public LayerProperties {
public:
explicit HeatmapLayerProperties(Immutable<HeatmapLayer::Impl>);
HeatmapLayerProperties(
Immutable<HeatmapLayer::Impl>,
HeatmapPaintProperties::PossiblyEvaluated);
~HeatmapLayerProperties() override;
const HeatmapLayer::Impl& layerImpl() const;
// Data members.
HeatmapPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,26 @@
#include <mbgl/style/layers/hillshade_layer_properties.hpp>
#include <mbgl/style/layers/hillshade_layer_impl.hpp>
namespace mbgl {
namespace style {
HillshadeLayerProperties::HillshadeLayerProperties(
Immutable<HillshadeLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
HillshadeLayerProperties::HillshadeLayerProperties(
Immutable<HillshadeLayer::Impl> impl_,
HillshadePaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
evaluated(std::move(evaluated_)) {}
HillshadeLayerProperties::~HillshadeLayerProperties() = default;
const HillshadeLayer::Impl& HillshadeLayerProperties::layerImpl() const {
return static_cast<const HillshadeLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/hillshade_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -45,5 +47,18 @@ class HillshadePaintProperties : public Properties<
HillshadeAccentColor
> {};
class HillshadeLayerProperties final : public LayerProperties {
public:
explicit HillshadeLayerProperties(Immutable<HillshadeLayer::Impl>);
HillshadeLayerProperties(
Immutable<HillshadeLayer::Impl>,
HillshadePaintProperties::PossiblyEvaluated);
~HillshadeLayerProperties() override;
const HillshadeLayer::Impl& layerImpl() const;
// Data members.
HillshadePaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -7,8 +7,32 @@
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer_properties.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer_impl.hpp>
namespace mbgl {
namespace style {
<%- camelize(type) %>LayerProperties::<%- camelize(type) %>LayerProperties(
Immutable<<%- camelize(type) %>Layer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
<%- camelize(type) %>LayerProperties::<%- camelize(type) %>LayerProperties(
Immutable<<%- camelize(type) %>Layer::Impl> impl_,
<% if (type === 'background' || type === 'fill' || type === 'line' || type === 'fill-extrusion') { -%>
CrossfadeParameters crossfade_,
<% } -%>
<%- camelize(type) %>PaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
<% if (type === 'background' || type === 'fill' || type === 'line' || type === 'fill-extrusion') { -%>
crossfade(std::move(crossfade_)),
<% } -%>
evaluated(std::move(evaluated_)) {}
<%- camelize(type) %>LayerProperties::~<%- camelize(type) %>LayerProperties() = default;
const <%- camelize(type) %>Layer::Impl& <%- camelize(type) %>LayerProperties::layerImpl() const {
return static_cast<const <%- camelize(type) %>Layer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -8,6 +8,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -66,5 +68,24 @@ class <%- camelize(type) %>PaintProperties : public Properties<
<%- camelize(paintProperties.slice(-1)[0].name) %>
> {};
class <%- camelize(type) %>LayerProperties final : public LayerProperties {
public:
explicit <%- camelize(type) %>LayerProperties(Immutable<<%- camelize(type) %>Layer::Impl>);
<%- camelize(type) %>LayerProperties(
Immutable<<%- camelize(type) %>Layer::Impl>,
<% if (type === 'background' || type === 'fill' || type === 'line' || type === 'fill-extrusion') { -%>
CrossfadeParameters,
<% } -%>
<%- camelize(type) %>PaintProperties::PossiblyEvaluated);
~<%- camelize(type) %>LayerProperties() override;
const <%- camelize(type) %>Layer::Impl& layerImpl() const;
// Data members.
<% if (type === 'background' || type === 'fill' || type === 'line' || type === 'fill-extrusion') { -%>
CrossfadeParameters crossfade;
<% } -%>
<%- camelize(type) %>PaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,28 @@
#include <mbgl/style/layers/line_layer_properties.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
namespace mbgl {
namespace style {
LineLayerProperties::LineLayerProperties(
Immutable<LineLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
LineLayerProperties::LineLayerProperties(
Immutable<LineLayer::Impl> impl_,
CrossfadeParameters crossfade_,
LinePaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
crossfade(std::move(crossfade_)),
evaluated(std::move(evaluated_)) {}
LineLayerProperties::~LineLayerProperties() = default;
const LineLayer::Impl& LineLayerProperties::layerImpl() const {
return static_cast<const LineLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -102,5 +104,20 @@ class LinePaintProperties : public Properties<
LineGradient
> {};
class LineLayerProperties final : public LayerProperties {
public:
explicit LineLayerProperties(Immutable<LineLayer::Impl>);
LineLayerProperties(
Immutable<LineLayer::Impl>,
CrossfadeParameters,
LinePaintProperties::PossiblyEvaluated);
~LineLayerProperties() override;
const LineLayer::Impl& layerImpl() const;
// Data members.
CrossfadeParameters crossfade;
LinePaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,26 @@
#include <mbgl/style/layers/raster_layer_properties.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
namespace mbgl {
namespace style {
RasterLayerProperties::RasterLayerProperties(
Immutable<RasterLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
RasterLayerProperties::RasterLayerProperties(
Immutable<RasterLayer::Impl> impl_,
RasterPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
evaluated(std::move(evaluated_)) {}
RasterLayerProperties::~RasterLayerProperties() = default;
const RasterLayer::Impl& RasterLayerProperties::layerImpl() const {
return static_cast<const RasterLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -55,5 +57,18 @@ class RasterPaintProperties : public Properties<
RasterFadeDuration
> {};
class RasterLayerProperties final : public LayerProperties {
public:
explicit RasterLayerProperties(Immutable<RasterLayer::Impl>);
RasterLayerProperties(
Immutable<RasterLayer::Impl>,
RasterPaintProperties::PossiblyEvaluated);
~RasterLayerProperties() override;
const RasterLayer::Impl& layerImpl() const;
// Data members.
RasterPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl

View File

@@ -2,8 +2,26 @@
#include <mbgl/style/layers/symbol_layer_properties.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
namespace mbgl {
namespace style {
SymbolLayerProperties::SymbolLayerProperties(
Immutable<SymbolLayer::Impl> impl_)
: LayerProperties(std::move(impl_)) {}
SymbolLayerProperties::SymbolLayerProperties(
Immutable<SymbolLayer::Impl> impl_,
SymbolPaintProperties::PossiblyEvaluated evaluated_)
: LayerProperties(std::move(impl_)),
evaluated(std::move(evaluated_)) {}
SymbolLayerProperties::~SymbolLayerProperties() = default;
const SymbolLayer::Impl& SymbolLayerProperties::layerImpl() const {
return static_cast<const SymbolLayer::Impl&>(*baseImpl);
}
} // namespace style
} // namespace mbgl

View File

@@ -3,6 +3,8 @@
#pragma once
#include <mbgl/style/types.hpp>
#include <mbgl/style/layer_properties.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
@@ -331,5 +333,18 @@ class SymbolPaintProperties : public Properties<
TextTranslateAnchor
> {};
class SymbolLayerProperties final : public LayerProperties {
public:
explicit SymbolLayerProperties(Immutable<SymbolLayer::Impl>);
SymbolLayerProperties(
Immutable<SymbolLayer::Impl>,
SymbolPaintProperties::PossiblyEvaluated);
~SymbolLayerProperties() override;
const SymbolLayer::Impl& layerImpl() const;
// Data members.
SymbolPaintProperties::PossiblyEvaluated evaluated;
};
} // namespace style
} // namespace mbgl