[core] Unify {Paint,Layout,Light}Properties

This commit is contained in:
John Firebaugh
2017-05-10 11:34:00 -07:00
parent 2690a65f8d
commit da4d735e2c
66 changed files with 493 additions and 575 deletions

View File

@@ -192,7 +192,6 @@ set(MBGL_CORE_FILES
src/mbgl/renderer/tile_parameters.hpp
src/mbgl/renderer/tile_pyramid.cpp
src/mbgl/renderer/tile_pyramid.hpp
src/mbgl/renderer/transitioning_property.hpp
src/mbgl/renderer/update_parameters.hpp
# renderer/buckets
@@ -343,11 +342,11 @@ set(MBGL_CORE_FILES
src/mbgl/style/light_impl.cpp
src/mbgl/style/light_impl.hpp
src/mbgl/style/light_observer.hpp
src/mbgl/style/light_properties.hpp
src/mbgl/style/observer.hpp
src/mbgl/style/paint_property.hpp
src/mbgl/style/parser.cpp
src/mbgl/style/parser.hpp
src/mbgl/style/properties.hpp
src/mbgl/style/rapidjson_conversion.hpp
src/mbgl/style/source.cpp
src/mbgl/style/source_impl.cpp

View File

@@ -97,7 +97,7 @@ set(MBGL_TEST_FILES
test/style/function/source_function.test.cpp
# style
test/style/paint_property.test.cpp
test/style/properties.test.cpp
test/style/source.test.cpp
test/style/style.test.cpp
test/style/style_image.test.cpp

View File

@@ -56,7 +56,7 @@ public:
}
template <typename Evaluator>
auto evaluate(const Evaluator& evaluator) const {
auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
return Value::visit(value, evaluator);
}
};

View File

@@ -35,7 +35,7 @@ public:
const CameraFunction<T>& asCameraFunction() const { return value.template get<CameraFunction<T>>(); }
template <typename Evaluator>
auto evaluate(const Evaluator& evaluator) const {
auto evaluate(const Evaluator& evaluator, TimePoint = {}) const {
return Value::visit(value, evaluator);
}
};

View File

@@ -50,8 +50,8 @@ SymbolLayout::SymbolLayout(const BucketParameters& parameters,
mode(parameters.mode),
tileSize(util::tileSize * overscaling),
tilePixelRatio(float(util::EXTENT) / tileSize),
textSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.unevaluated.get<TextSize>()),
iconSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.unevaluated.get<IconSize>())
textSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.get<TextSize>()),
iconSize(layers.at(0)->as<RenderSymbolLayer>()->impl().layout.get<IconSize>())
{
const SymbolLayer::Impl& leader = layers.at(0)->as<RenderSymbolLayer>()->impl();

View File

@@ -47,7 +47,7 @@ public:
State state = Pending;
std::map<std::string,
std::pair<style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>> layerPaintProperties;
std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>> layerPaintProperties;
private:
void addFeature(const size_t,

View File

@@ -4,6 +4,7 @@
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/collision_box.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/util/geometry.hpp>
#include <cmath>
@@ -29,7 +30,7 @@ class CollisionBoxProgram : public Program<
uniforms::u_scale,
uniforms::u_zoom,
uniforms::u_maxzoom>,
style::PaintProperties<>>
style::Properties<>>
{
public:
using Program::Program;

View File

@@ -4,6 +4,7 @@
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/debug.hpp>
#include <mbgl/style/properties.hpp>
namespace mbgl {
@@ -15,7 +16,7 @@ class DebugProgram : public Program<
gl::Uniforms<
uniforms::u_matrix,
uniforms::u_color>,
style::PaintProperties<>>
style::Properties<>>
{
public:
using Program::Program;

View File

@@ -4,6 +4,7 @@
#include <mbgl/programs/attributes.hpp>
#include <mbgl/programs/uniforms.hpp>
#include <mbgl/shaders/extrusion_texture.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/util/geometry.hpp>
namespace mbgl {
@@ -17,7 +18,7 @@ class ExtrusionTextureProgram : public Program<
uniforms::u_world,
uniforms::u_image,
uniforms::u_opacity>,
style::PaintProperties<>> {
style::Properties<>> {
public:
using Program::Program;

View File

@@ -13,7 +13,7 @@ using namespace style;
static_assert(sizeof(LineLayoutVertex) == 8, "expected LineLayoutVertex size");
template <class Values, class...Args>
Values makeValues(const LinePaintProperties::Evaluated& properties,
Values makeValues(const LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,
@@ -33,7 +33,7 @@ Values makeValues(const LinePaintProperties::Evaluated& properties,
}
LineProgram::UniformValues
LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
LineProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits) {
@@ -46,7 +46,7 @@ LineProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
}
LineSDFProgram::UniformValues
LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
LineSDFProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
float pixelRatio,
const RenderTile& tile,
const TransformState& state,
@@ -84,7 +84,7 @@ LineSDFProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
}
LinePatternProgram::UniformValues
LinePatternProgram::uniformValues(const LinePaintProperties::Evaluated& properties,
LinePatternProgram::uniformValues(const LinePaintProperties::PossiblyEvaluated& properties,
const RenderTile& tile,
const TransformState& state,
const std::array<float, 2>& pixelsToGLUnits,

View File

@@ -91,7 +91,7 @@ public:
*/
static const int8_t extrudeScale = 63;
static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&,
const RenderTile&,
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits);
@@ -119,7 +119,7 @@ class LinePatternProgram : public Program<
public:
using Program::Program;
static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&,
const RenderTile&,
const TransformState&,
const std::array<float, 2>& pixelsToGLUnits,
@@ -148,7 +148,7 @@ class LineSDFProgram : public Program<
public:
using Program::Program;
static UniformValues uniformValues(const style::LinePaintProperties::Evaluated&,
static UniformValues uniformValues(const style::LinePaintProperties::PossiblyEvaluated&,
float pixelRatio,
const RenderTile&,
const TransformState&,

View File

@@ -53,7 +53,7 @@ public:
const gl::IndexBuffer<DrawMode>& indexBuffer,
const gl::SegmentVector<Attributes>& segments,
const PaintPropertyBinders& paintPropertyBinders,
const typename PaintProperties::Evaluated& currentProperties,
const typename PaintProperties::PossiblyEvaluated& currentProperties,
float currentZoom) {
program.draw(
context,

View File

@@ -365,7 +365,7 @@ public:
const gl::IndexBuffer<DrawMode>& indexBuffer,
const gl::SegmentVector<Attributes>& segments,
const PaintPropertyBinders& paintPropertyBinders,
const typename PaintProperties::Evaluated& currentProperties,
const typename PaintProperties::PossiblyEvaluated& currentProperties,
float currentZoom) {
program.draw(
context,

View File

@@ -14,7 +14,7 @@ using namespace style;
LineBucket::LineBucket(const BucketParameters& parameters,
const std::vector<const RenderLayer*>& layers,
const style::LineLayoutProperties& layout_)
const style::LineLayoutProperties::Unevaluated& layout_)
: layout(layout_.evaluate(PropertyEvaluationParameters(parameters.tileID.overscaledZ))),
overscaling(parameters.tileID.overscaleFactor()) {
for (const auto& layer : layers) {

View File

@@ -19,7 +19,7 @@ class LineBucket : public Bucket {
public:
LineBucket(const BucketParameters&,
const std::vector<const RenderLayer*>&,
const style::LineLayoutProperties&);
const style::LineLayoutProperties::Unevaluated&);
void addFeature(const GeometryTileFeature&,
const GeometryCollection&) override;

View File

@@ -10,7 +10,8 @@ using namespace style;
SymbolBucket::SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated layout_,
const std::map<std::string, std::pair<
style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>& layerPaintProperties,
style::IconPaintProperties::PossiblyEvaluated,
style::TextPaintProperties::PossiblyEvaluated>>& layerPaintProperties,
const style::DataDrivenPropertyValue<float>& textSize,
const style::DataDrivenPropertyValue<float>& iconSize,
float zoom,

View File

@@ -18,7 +18,7 @@ namespace mbgl {
class SymbolBucket : public Bucket {
public:
SymbolBucket(style::SymbolLayoutProperties::PossiblyEvaluated,
const std::map<std::string, std::pair<style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>&,
const std::map<std::string, std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>>&,
const style::DataDrivenPropertyValue<float>& textSize,
const style::DataDrivenPropertyValue<float>& iconSize,
float zoom,

View File

@@ -19,7 +19,7 @@ public:
// Paint properties
style::BackgroundPaintProperties::Unevaluated unevaluated;
style::BackgroundPaintProperties::Evaluated evaluated;
style::BackgroundPaintProperties::PossiblyEvaluated evaluated;
const style::BackgroundLayer::Impl& impl() const;
};

View File

@@ -26,7 +26,7 @@ public:
// Paint properties
style::CirclePaintProperties::Unevaluated unevaluated;
style::CirclePaintProperties::Evaluated evaluated;
style::CirclePaintProperties::PossiblyEvaluated evaluated;
const style::CircleLayer::Impl& impl() const;
};

View File

@@ -26,7 +26,7 @@ public:
// Paint properties
style::FillExtrusionPaintProperties::Unevaluated unevaluated;
style::FillExtrusionPaintProperties::Evaluated evaluated;
style::FillExtrusionPaintProperties::PossiblyEvaluated evaluated;
const style::FillExtrusionLayer::Impl& impl() const;
};

View File

@@ -26,7 +26,7 @@ public:
// Paint properties
style::FillPaintProperties::Unevaluated unevaluated;
style::FillPaintProperties::Evaluated evaluated;
style::FillPaintProperties::PossiblyEvaluated evaluated;
const style::FillLayer::Impl& impl() const;
};

View File

@@ -26,7 +26,7 @@ public:
// Paint properties
style::LinePaintProperties::Unevaluated unevaluated;
style::LinePaintProperties::Evaluated evaluated;
style::LinePaintProperties::PossiblyEvaluated evaluated;
const style::LineLayer::Impl& impl() const;

View File

@@ -19,7 +19,7 @@ public:
// Paint properties
style::RasterPaintProperties::Unevaluated unevaluated;
style::RasterPaintProperties::Evaluated evaluated;
style::RasterPaintProperties::PossiblyEvaluated evaluated;
const style::RasterLayer::Impl& impl() const;
};

View File

@@ -54,8 +54,8 @@ bool RenderSymbolLayer::hasTransition() const {
return unevaluated.hasTransition();
}
style::IconPaintProperties::Evaluated RenderSymbolLayer::iconPaintProperties() const {
return style::IconPaintProperties::Evaluated {
style::IconPaintProperties::PossiblyEvaluated RenderSymbolLayer::iconPaintProperties() const {
return style::IconPaintProperties::PossiblyEvaluated {
evaluated.get<style::IconOpacity>(),
evaluated.get<style::IconColor>(),
evaluated.get<style::IconHaloColor>(),
@@ -66,8 +66,8 @@ style::IconPaintProperties::Evaluated RenderSymbolLayer::iconPaintProperties() c
};
}
style::TextPaintProperties::Evaluated RenderSymbolLayer::textPaintProperties() const {
return style::TextPaintProperties::Evaluated {
style::TextPaintProperties::PossiblyEvaluated RenderSymbolLayer::textPaintProperties() const {
return style::TextPaintProperties::PossiblyEvaluated {
evaluated.get<style::TextOpacity>(),
evaluated.get<style::TextColor>(),
evaluated.get<style::TextHaloColor>(),

View File

@@ -13,7 +13,7 @@ namespace style {
// {icon,text}-specific paint-property packs for use in the symbol Programs.
// Since each program deals either with icons or text, using a smaller property set
// lets us avoid unnecessarily binding attributes for properties the program wouldn't use.
class IconPaintProperties : public PaintProperties<
class IconPaintProperties : public Properties<
IconOpacity,
IconColor,
IconHaloColor,
@@ -23,7 +23,7 @@ class IconPaintProperties : public PaintProperties<
IconTranslateAnchor
> {};
class TextPaintProperties : public PaintProperties<
class TextPaintProperties : public Properties<
TextOpacity,
TextColor,
TextHaloColor,
@@ -68,8 +68,8 @@ public:
void evaluate(const PropertyEvaluationParameters&) override;
bool hasTransition() const override;
style::IconPaintProperties::Evaluated iconPaintProperties() const;
style::TextPaintProperties::Evaluated textPaintProperties() const;
style::IconPaintProperties::PossiblyEvaluated iconPaintProperties() const;
style::TextPaintProperties::PossiblyEvaluated textPaintProperties() const;
style::SymbolPropertyValues iconPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const;
style::SymbolPropertyValues textPropertyValues(const style::SymbolLayoutProperties::PossiblyEvaluated&) const;
@@ -80,7 +80,7 @@ public:
// Paint properties
style::SymbolPaintProperties::Unevaluated unevaluated;
style::SymbolPaintProperties::Evaluated evaluated;
style::SymbolPaintProperties::PossiblyEvaluated evaluated;
float iconSize = 1.0f;
float textSize = 16.0f;

View File

@@ -4,6 +4,7 @@
#include <mbgl/gl/attribute.hpp>
#include <mbgl/gl/uniform.hpp>
#include <mbgl/util/type_list.hpp>
#include <mbgl/renderer/possibly_evaluated_property_value.hpp>
#include <mbgl/renderer/paint_property_statistics.hpp>
namespace mbgl {

View File

@@ -350,7 +350,7 @@ void Painter::renderPass(PaintParameters& parameters,
mat4 viewportMat;
matrix::ortho(viewportMat, 0, size.width, size.height, 0, 0, 1);
const PaintProperties<>::Evaluated properties{};
const Properties<>::PossiblyEvaluated properties{};
parameters.programs.extrusionTexture.draw(
context, gl::Triangles(), gl::DepthMode::disabled(), gl::StencilMode::disabled(),

View File

@@ -14,9 +14,9 @@ using namespace style;
void Painter::renderBackground(PaintParameters& parameters, const RenderBackgroundLayer& layer) {
// Note that for bottommost layers without a pattern, the background color is drawn with
// glClear rather than this method.
const BackgroundPaintProperties::Evaluated& background = layer.evaluated;
const BackgroundPaintProperties::PossiblyEvaluated& background = layer.evaluated;
style::FillPaintProperties::Evaluated properties;
style::FillPaintProperties::PossiblyEvaluated properties;
properties.get<FillPattern>() = background.get<BackgroundPattern>();
properties.get<FillOpacity>() = { background.get<BackgroundOpacity>() };
properties.get<FillColor>() = { background.get<BackgroundColor>() };

View File

@@ -20,7 +20,7 @@ void Painter::renderCircle(PaintParameters& parameters,
return;
}
const CirclePaintProperties::Evaluated& properties = layer.evaluated;
const CirclePaintProperties::PossiblyEvaluated& properties = layer.evaluated;
const bool scaleWithMap = properties.get<CirclePitchScale>() == CirclePitchScaleType::Map;
parameters.programs.circle.draw(

View File

@@ -6,7 +6,7 @@
namespace mbgl {
void Painter::renderClippingMask(const UnwrappedTileID& tileID, const ClipID& clip) {
static const style::FillPaintProperties::Evaluated properties {};
static const style::FillPaintProperties::PossiblyEvaluated properties {};
static const FillProgram::PaintPropertyBinders paintAttibuteData(properties, 0);
programs->fill.draw(
context,

View File

@@ -20,7 +20,7 @@ void Painter::renderTileDebug(const RenderTile& renderTile) {
MBGL_DEBUG_GROUP(context, std::string { "debug " } + util::toString(renderTile.id));
static const style::PaintProperties<>::Evaluated properties {};
static const style::Properties<>::PossiblyEvaluated properties {};
static const DebugProgram::PaintPropertyBinders paintAttibuteData(properties, 0);
auto draw = [&] (Color color, const auto& vertexBuffer, const auto& indexBuffer, const auto& segments, auto drawMode) {

View File

@@ -17,7 +17,7 @@ void Painter::renderFill(PaintParameters& parameters,
FillBucket& bucket,
const RenderFillLayer& layer,
const RenderTile& tile) {
const FillPaintProperties::Evaluated& properties = layer.evaluated;
const FillPaintProperties::PossiblyEvaluated& properties = layer.evaluated;
if (!properties.get<FillPattern>().from.empty()) {
if (pass != RenderPass::Translucent) {

View File

@@ -18,7 +18,7 @@ void Painter::renderFillExtrusion(PaintParameters& parameters,
FillExtrusionBucket& bucket,
const RenderFillExtrusionLayer& layer,
const RenderTile& tile) {
const FillExtrusionPaintProperties::Evaluated& properties = layer.evaluated;
const FillExtrusionPaintProperties::PossiblyEvaluated& properties = layer.evaluated;
if (pass == RenderPass::Opaque) {
return;

View File

@@ -21,7 +21,7 @@ void Painter::renderLine(PaintParameters& parameters,
return;
}
const LinePaintProperties::Evaluated& properties = layer.evaluated;
const LinePaintProperties::PossiblyEvaluated& properties = layer.evaluated;
auto draw = [&] (auto& program, auto&& uniformValues) {
program.draw(

View File

@@ -48,7 +48,7 @@ void Painter::renderRaster(PaintParameters& parameters,
if (!bucket.hasData())
return;
const RasterPaintProperties::Evaluated& properties = layer.evaluated;
const RasterPaintProperties::PossiblyEvaluated& properties = layer.evaluated;
const RasterProgram::PaintPropertyBinders paintAttributeData(properties, 0);
assert(bucket.texture);

View File

@@ -137,7 +137,7 @@ void Painter::renderSymbol(PaintParameters& parameters,
}
if (bucket.hasCollisionBoxData()) {
static const style::PaintProperties<>::Evaluated properties {};
static const style::Properties<>::PossiblyEvaluated properties {};
static const CollisionBoxProgram::PaintPropertyBinders paintAttributeData(properties, 0);
programs->collisionBox.draw(

View File

@@ -7,11 +7,11 @@ RenderLight::RenderLight(Immutable<style::Light::Impl> impl_)
}
void RenderLight::transition(const CascadeParameters& parameters) {
transitioning = TransitioningLight(impl->properties, std::move(transitioning), parameters);
transitioning = impl->properties.cascade(parameters, std::move(transitioning));
}
void RenderLight::evaluate(const PropertyEvaluationParameters& parameters) {
evaluated = EvaluatedLight(transitioning, parameters);
evaluated = transitioning.evaluate(parameters);
}
bool RenderLight::hasTransition() const {

View File

@@ -1,75 +1,15 @@
#pragma once
#include <mbgl/style/light_impl.hpp>
#include <mbgl/renderer/transitioning_property.hpp>
#include <mbgl/renderer/cascade_parameters.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/util/ignore.hpp>
#include <memory>
#include <mbgl/util/immutable.hpp>
namespace mbgl {
template <class TypeList>
class Transitioning;
class CascadeParameters;
class PropertyEvaluationParameters;
template <class... Ps>
class Transitioning<TypeList<Ps...>> : public IndexedTuple<
TypeList<Ps...>,
TypeList<TransitioningProperty<typename Ps::ValueType>...>>
{
private:
using Properties = TypeList<Ps...>;
using Raw = IndexedTuple<Properties, Properties>;
using Super = IndexedTuple<
TypeList<Ps...>,
TypeList<TransitioningProperty<typename Ps::ValueType>...>>;
public:
Transitioning() = default;
Transitioning(const Raw& raw, Transitioning&& prior, const CascadeParameters& params)
: Super {
TransitioningProperty<typename Ps::ValueType>(
raw.template get<Ps>().value,
std::move(prior.template get<Ps>()),
raw.template get<Ps>().transition.reverseMerge(params.transition),
params.now)...
} {}
bool hasTransition() const {
bool result = false;
util::ignore({ result |= this->template get<Ps>().hasTransition()... });
return result;
}
};
template <class TypeList>
class Evaluated;
template <class... Ps>
class Evaluated<TypeList<Ps...>> : public IndexedTuple<
TypeList<Ps...>,
TypeList<typename Ps::Type...>>
{
private:
using Properties = TypeList<Ps...>;
using TransitioningPs = Transitioning<Properties>;
using Super = IndexedTuple<
TypeList<Ps...>,
TypeList<typename Ps::Type...>>;
public:
Evaluated() = default;
Evaluated(TransitioningPs& transitioning, const PropertyEvaluationParameters& params)
: Super {
transitioning.template get<Ps>()
.evaluate(PropertyEvaluator<typename Ps::Type>(params, Ps::defaultValue()), params.now)...
} {}
};
using TransitioningLight = Transitioning<style::LightProperties>;
using EvaluatedLight = Evaluated<style::LightProperties>;
using TransitioningLight = style::LightProperties::Unevaluated;
using EvaluatedLight = style::LightProperties::PossiblyEvaluated;
class RenderLight {
public:

View File

@@ -1,75 +0,0 @@
#pragma once
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/util/interpolate.hpp>
#include <utility>
namespace mbgl {
template <class Value>
class TransitioningProperty {
public:
TransitioningProperty() = default;
TransitioningProperty(Value value_,
TransitioningProperty<Value> prior_,
style::TransitionOptions transition,
TimePoint now)
: begin(now + transition.delay.value_or(Duration::zero())),
end(begin + transition.duration.value_or(Duration::zero())),
value(std::move(value_)) {
if (transition.isDefined()) {
prior = { std::move(prior_) };
}
}
template <class Evaluator>
auto evaluate(const Evaluator& evaluator, TimePoint now) {
auto finalValue = value.evaluate(evaluator);
if (!prior) {
// No prior value.
return finalValue;
} else if (now >= end) {
// Transition from prior value is now complete.
prior = {};
return finalValue;
} else if (value.isDataDriven()) {
// Transitions to data-driven properties are not supported.
// We snap immediately to the data-driven value so that, when we perform layout,
// we see the data-driven function and can use it to populate vertex buffers.
prior = {};
return finalValue;
} else if (now < begin) {
// Transition hasn't started yet.
return prior->get().evaluate(evaluator, now);
} else {
// Interpolate between recursively-calculated prior value and final.
float t = std::chrono::duration<float>(now - begin) / (end - begin);
return util::interpolate(prior->get().evaluate(evaluator, now), finalValue,
util::DEFAULT_TRANSITION_EASE.solve(t, 0.001));
}
}
bool hasTransition() const {
return bool(prior);
}
bool isUndefined() const {
return value.isUndefined();
}
const Value& getValue() const {
return value;
}
private:
optional<mapbox::util::recursive_wrapper<TransitioningProperty<Value>>> prior;
TimePoint begin;
TimePoint end;
Value value;
};
} // namespace mbgl

View File

@@ -2,7 +2,7 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/util/enum.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/feature.hpp>
@@ -446,13 +446,6 @@ void stringify(Writer& writer, const DataDrivenPropertyValue<T>& value) {
}
}
template <class Writer, class... Ps>
void stringify(Writer& writer, const LayoutProperties<Ps...>& ps) {
writer.StartObject();
util::ignore({ (stringify<Ps>(writer, ps.unevaluated.template get<Ps>()), 0)... });
writer.EndObject();
}
} // namespace conversion
} // namespace style
} // namespace mbgl

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/background_layer.hpp>
#include <mbgl/style/layers/background_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -22,7 +23,7 @@ struct BackgroundOpacity : PaintProperty<float> {
static float defaultValue() { return 1; }
};
class BackgroundPaintProperties : public PaintProperties<
class BackgroundPaintProperties : public Properties<
BackgroundColor,
BackgroundPattern,
BackgroundOpacity

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/circle_layer.hpp>
#include <mbgl/style/layers/circle_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -50,7 +51,7 @@ struct CircleStrokeOpacity : DataDrivenPaintProperty<float, attributes::a_stroke
static float defaultValue() { return 1; }
};
class CirclePaintProperties : public PaintProperties<
class CirclePaintProperties : public Properties<
CircleRadius,
CircleColor,
CircleBlur,

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/fill_extrusion_layer.hpp>
#include <mbgl/style/layers/fill_extrusion_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -38,7 +39,7 @@ struct FillExtrusionBase : DataDrivenPaintProperty<float, attributes::a_base> {
static float defaultValue() { return 0; }
};
class FillExtrusionPaintProperties : public PaintProperties<
class FillExtrusionPaintProperties : public Properties<
FillExtrusionOpacity,
FillExtrusionColor,
FillExtrusionTranslate,

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/fill_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -38,7 +39,7 @@ struct FillPattern : CrossFadedPaintProperty<std::string> {
static std::string defaultValue() { return ""; }
};
class FillPaintProperties : public PaintProperties<
class FillPaintProperties : public Properties<
FillAntialias,
FillOpacity,
FillColor,

View File

@@ -7,7 +7,6 @@
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer.hpp>
#include <mbgl/style/layers/<%- type.replace('-', '_') %>_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
@@ -46,7 +45,7 @@ std::unique_ptr<Layer> <%- camelize(type) %>Layer::cloneRef(const std::string& i
<% if (layoutProperties.length) { -%>
void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
conversion::stringify(writer, layout);
layout.stringify(writer);
}
<% } else { -%>
void <%- camelize(type) %>Layer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const {
@@ -119,14 +118,14 @@ void <%- camelize(type) %>Layer::setMaxZoom(float maxZoom) {
}
<%- propertyValueType(property) %> <%- camelize(type) %>Layer::get<%- camelize(property.name) %>() const {
return impl().layout.unevaluated.get<<%- camelize(property.name) %>>();
return impl().layout.get<<%- camelize(property.name) %>>();
}
void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(<%- propertyValueType(property) %> value) {
if (value == get<%- camelize(property.name) %>())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<<%- camelize(property.name) %>>() = value;
impl_->layout.get<<%- camelize(property.name) %>>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>");
}

View File

@@ -10,6 +10,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -29,7 +30,7 @@ struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %>
<% } -%>
<% if (layoutProperties.length) { -%>
class <%- camelize(type) %>LayoutProperties : public LayoutProperties<
class <%- camelize(type) %>LayoutProperties : public Properties<
<% for (const property of layoutProperties.slice(0, -1)) { -%>
<%- camelize(property.name) %>,
<% } -%>
@@ -37,7 +38,7 @@ class <%- camelize(type) %>LayoutProperties : public LayoutProperties<
> {};
<% } -%>
class <%- camelize(type) %>PaintProperties : public PaintProperties<
class <%- camelize(type) %>PaintProperties : public Properties<
<% for (const property of paintProperties.slice(0, -1)) { -%>
<%- camelize(property.name) %>,
<% } -%>

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/line_layer.hpp>
#include <mbgl/style/layers/line_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
@@ -34,7 +33,7 @@ std::unique_ptr<Layer> LineLayer::cloneRef(const std::string& id_) const {
}
void LineLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
conversion::stringify(writer, layout);
layout.stringify(writer);
}
// Source
@@ -98,14 +97,14 @@ PropertyValue<LineCapType> LineLayer::getDefaultLineCap() {
}
PropertyValue<LineCapType> LineLayer::getLineCap() const {
return impl().layout.unevaluated.get<LineCap>();
return impl().layout.get<LineCap>();
}
void LineLayer::setLineCap(PropertyValue<LineCapType> value) {
if (value == getLineCap())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineCap>() = value;
impl_->layout.get<LineCap>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-cap");
}
@@ -114,14 +113,14 @@ PropertyValue<LineJoinType> LineLayer::getDefaultLineJoin() {
}
PropertyValue<LineJoinType> LineLayer::getLineJoin() const {
return impl().layout.unevaluated.get<LineJoin>();
return impl().layout.get<LineJoin>();
}
void LineLayer::setLineJoin(PropertyValue<LineJoinType> value) {
if (value == getLineJoin())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineJoin>() = value;
impl_->layout.get<LineJoin>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-join");
}
@@ -130,14 +129,14 @@ PropertyValue<float> LineLayer::getDefaultLineMiterLimit() {
}
PropertyValue<float> LineLayer::getLineMiterLimit() const {
return impl().layout.unevaluated.get<LineMiterLimit>();
return impl().layout.get<LineMiterLimit>();
}
void LineLayer::setLineMiterLimit(PropertyValue<float> value) {
if (value == getLineMiterLimit())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineMiterLimit>() = value;
impl_->layout.get<LineMiterLimit>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit");
}
@@ -146,14 +145,14 @@ PropertyValue<float> LineLayer::getDefaultLineRoundLimit() {
}
PropertyValue<float> LineLayer::getLineRoundLimit() const {
return impl().layout.unevaluated.get<LineRoundLimit>();
return impl().layout.get<LineRoundLimit>();
}
void LineLayer::setLineRoundLimit(PropertyValue<float> value) {
if (value == getLineRoundLimit())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<LineRoundLimit>() = value;
impl_->layout.get<LineRoundLimit>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "line-round-limit");
}

View File

@@ -13,7 +13,7 @@ public:
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
LineLayoutProperties layout;
LineLayoutProperties::Unevaluated layout;
LinePaintProperties::Cascading paint;
};

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -70,14 +71,14 @@ struct LinePattern : CrossFadedPaintProperty<std::string> {
static std::string defaultValue() { return ""; }
};
class LineLayoutProperties : public LayoutProperties<
class LineLayoutProperties : public Properties<
LineCap,
LineJoin,
LineMiterLimit,
LineRoundLimit
> {};
class LinePaintProperties : public PaintProperties<
class LinePaintProperties : public Properties<
LineOpacity,
LineColor,
LineTranslate,

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/raster_layer.hpp>
#include <mbgl/style/layers/raster_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -38,7 +39,7 @@ struct RasterFadeDuration : PaintProperty<float> {
static float defaultValue() { return 300; }
};
class RasterPaintProperties : public PaintProperties<
class RasterPaintProperties : public Properties<
RasterOpacity,
RasterHueRotate,
RasterBrightnessMin,

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/style/layer_observer.hpp>
namespace mbgl {
@@ -34,7 +33,7 @@ std::unique_ptr<Layer> SymbolLayer::cloneRef(const std::string& id_) const {
}
void SymbolLayer::Impl::stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>& writer) const {
conversion::stringify(writer, layout);
layout.stringify(writer);
}
// Source
@@ -98,14 +97,14 @@ PropertyValue<SymbolPlacementType> SymbolLayer::getDefaultSymbolPlacement() {
}
PropertyValue<SymbolPlacementType> SymbolLayer::getSymbolPlacement() const {
return impl().layout.unevaluated.get<SymbolPlacement>();
return impl().layout.get<SymbolPlacement>();
}
void SymbolLayer::setSymbolPlacement(PropertyValue<SymbolPlacementType> value) {
if (value == getSymbolPlacement())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<SymbolPlacement>() = value;
impl_->layout.get<SymbolPlacement>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "symbol-placement");
}
@@ -114,14 +113,14 @@ PropertyValue<float> SymbolLayer::getDefaultSymbolSpacing() {
}
PropertyValue<float> SymbolLayer::getSymbolSpacing() const {
return impl().layout.unevaluated.get<SymbolSpacing>();
return impl().layout.get<SymbolSpacing>();
}
void SymbolLayer::setSymbolSpacing(PropertyValue<float> value) {
if (value == getSymbolSpacing())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<SymbolSpacing>() = value;
impl_->layout.get<SymbolSpacing>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "symbol-spacing");
}
@@ -130,14 +129,14 @@ PropertyValue<bool> SymbolLayer::getDefaultSymbolAvoidEdges() {
}
PropertyValue<bool> SymbolLayer::getSymbolAvoidEdges() const {
return impl().layout.unevaluated.get<SymbolAvoidEdges>();
return impl().layout.get<SymbolAvoidEdges>();
}
void SymbolLayer::setSymbolAvoidEdges(PropertyValue<bool> value) {
if (value == getSymbolAvoidEdges())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<SymbolAvoidEdges>() = value;
impl_->layout.get<SymbolAvoidEdges>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "symbol-avoid-edges");
}
@@ -146,14 +145,14 @@ PropertyValue<bool> SymbolLayer::getDefaultIconAllowOverlap() {
}
PropertyValue<bool> SymbolLayer::getIconAllowOverlap() const {
return impl().layout.unevaluated.get<IconAllowOverlap>();
return impl().layout.get<IconAllowOverlap>();
}
void SymbolLayer::setIconAllowOverlap(PropertyValue<bool> value) {
if (value == getIconAllowOverlap())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconAllowOverlap>() = value;
impl_->layout.get<IconAllowOverlap>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-allow-overlap");
}
@@ -162,14 +161,14 @@ PropertyValue<bool> SymbolLayer::getDefaultIconIgnorePlacement() {
}
PropertyValue<bool> SymbolLayer::getIconIgnorePlacement() const {
return impl().layout.unevaluated.get<IconIgnorePlacement>();
return impl().layout.get<IconIgnorePlacement>();
}
void SymbolLayer::setIconIgnorePlacement(PropertyValue<bool> value) {
if (value == getIconIgnorePlacement())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconIgnorePlacement>() = value;
impl_->layout.get<IconIgnorePlacement>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-ignore-placement");
}
@@ -178,14 +177,14 @@ PropertyValue<bool> SymbolLayer::getDefaultIconOptional() {
}
PropertyValue<bool> SymbolLayer::getIconOptional() const {
return impl().layout.unevaluated.get<IconOptional>();
return impl().layout.get<IconOptional>();
}
void SymbolLayer::setIconOptional(PropertyValue<bool> value) {
if (value == getIconOptional())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconOptional>() = value;
impl_->layout.get<IconOptional>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-optional");
}
@@ -194,14 +193,14 @@ PropertyValue<AlignmentType> SymbolLayer::getDefaultIconRotationAlignment() {
}
PropertyValue<AlignmentType> SymbolLayer::getIconRotationAlignment() const {
return impl().layout.unevaluated.get<IconRotationAlignment>();
return impl().layout.get<IconRotationAlignment>();
}
void SymbolLayer::setIconRotationAlignment(PropertyValue<AlignmentType> value) {
if (value == getIconRotationAlignment())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconRotationAlignment>() = value;
impl_->layout.get<IconRotationAlignment>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-rotation-alignment");
}
@@ -210,14 +209,14 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconSize() {
}
DataDrivenPropertyValue<float> SymbolLayer::getIconSize() const {
return impl().layout.unevaluated.get<IconSize>();
return impl().layout.get<IconSize>();
}
void SymbolLayer::setIconSize(DataDrivenPropertyValue<float> value) {
if (value == getIconSize())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconSize>() = value;
impl_->layout.get<IconSize>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-size");
}
@@ -226,14 +225,14 @@ PropertyValue<IconTextFitType> SymbolLayer::getDefaultIconTextFit() {
}
PropertyValue<IconTextFitType> SymbolLayer::getIconTextFit() const {
return impl().layout.unevaluated.get<IconTextFit>();
return impl().layout.get<IconTextFit>();
}
void SymbolLayer::setIconTextFit(PropertyValue<IconTextFitType> value) {
if (value == getIconTextFit())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconTextFit>() = value;
impl_->layout.get<IconTextFit>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit");
}
@@ -242,14 +241,14 @@ PropertyValue<std::array<float, 4>> SymbolLayer::getDefaultIconTextFitPadding()
}
PropertyValue<std::array<float, 4>> SymbolLayer::getIconTextFitPadding() const {
return impl().layout.unevaluated.get<IconTextFitPadding>();
return impl().layout.get<IconTextFitPadding>();
}
void SymbolLayer::setIconTextFitPadding(PropertyValue<std::array<float, 4>> value) {
if (value == getIconTextFitPadding())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconTextFitPadding>() = value;
impl_->layout.get<IconTextFitPadding>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding");
}
@@ -258,14 +257,14 @@ DataDrivenPropertyValue<std::string> SymbolLayer::getDefaultIconImage() {
}
DataDrivenPropertyValue<std::string> SymbolLayer::getIconImage() const {
return impl().layout.unevaluated.get<IconImage>();
return impl().layout.get<IconImage>();
}
void SymbolLayer::setIconImage(DataDrivenPropertyValue<std::string> value) {
if (value == getIconImage())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconImage>() = value;
impl_->layout.get<IconImage>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-image");
}
@@ -274,14 +273,14 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultIconRotate() {
}
DataDrivenPropertyValue<float> SymbolLayer::getIconRotate() const {
return impl().layout.unevaluated.get<IconRotate>();
return impl().layout.get<IconRotate>();
}
void SymbolLayer::setIconRotate(DataDrivenPropertyValue<float> value) {
if (value == getIconRotate())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconRotate>() = value;
impl_->layout.get<IconRotate>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-rotate");
}
@@ -290,14 +289,14 @@ PropertyValue<float> SymbolLayer::getDefaultIconPadding() {
}
PropertyValue<float> SymbolLayer::getIconPadding() const {
return impl().layout.unevaluated.get<IconPadding>();
return impl().layout.get<IconPadding>();
}
void SymbolLayer::setIconPadding(PropertyValue<float> value) {
if (value == getIconPadding())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconPadding>() = value;
impl_->layout.get<IconPadding>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-padding");
}
@@ -306,14 +305,14 @@ PropertyValue<bool> SymbolLayer::getDefaultIconKeepUpright() {
}
PropertyValue<bool> SymbolLayer::getIconKeepUpright() const {
return impl().layout.unevaluated.get<IconKeepUpright>();
return impl().layout.get<IconKeepUpright>();
}
void SymbolLayer::setIconKeepUpright(PropertyValue<bool> value) {
if (value == getIconKeepUpright())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconKeepUpright>() = value;
impl_->layout.get<IconKeepUpright>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright");
}
@@ -322,14 +321,14 @@ DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconOffset(
}
DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getIconOffset() const {
return impl().layout.unevaluated.get<IconOffset>();
return impl().layout.get<IconOffset>();
}
void SymbolLayer::setIconOffset(DataDrivenPropertyValue<std::array<float, 2>> value) {
if (value == getIconOffset())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<IconOffset>() = value;
impl_->layout.get<IconOffset>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "icon-offset");
}
@@ -338,14 +337,14 @@ PropertyValue<AlignmentType> SymbolLayer::getDefaultTextPitchAlignment() {
}
PropertyValue<AlignmentType> SymbolLayer::getTextPitchAlignment() const {
return impl().layout.unevaluated.get<TextPitchAlignment>();
return impl().layout.get<TextPitchAlignment>();
}
void SymbolLayer::setTextPitchAlignment(PropertyValue<AlignmentType> value) {
if (value == getTextPitchAlignment())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextPitchAlignment>() = value;
impl_->layout.get<TextPitchAlignment>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-pitch-alignment");
}
@@ -354,14 +353,14 @@ PropertyValue<AlignmentType> SymbolLayer::getDefaultTextRotationAlignment() {
}
PropertyValue<AlignmentType> SymbolLayer::getTextRotationAlignment() const {
return impl().layout.unevaluated.get<TextRotationAlignment>();
return impl().layout.get<TextRotationAlignment>();
}
void SymbolLayer::setTextRotationAlignment(PropertyValue<AlignmentType> value) {
if (value == getTextRotationAlignment())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextRotationAlignment>() = value;
impl_->layout.get<TextRotationAlignment>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment");
}
@@ -370,14 +369,14 @@ DataDrivenPropertyValue<std::string> SymbolLayer::getDefaultTextField() {
}
DataDrivenPropertyValue<std::string> SymbolLayer::getTextField() const {
return impl().layout.unevaluated.get<TextField>();
return impl().layout.get<TextField>();
}
void SymbolLayer::setTextField(DataDrivenPropertyValue<std::string> value) {
if (value == getTextField())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextField>() = value;
impl_->layout.get<TextField>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-field");
}
@@ -386,14 +385,14 @@ PropertyValue<std::vector<std::string>> SymbolLayer::getDefaultTextFont() {
}
PropertyValue<std::vector<std::string>> SymbolLayer::getTextFont() const {
return impl().layout.unevaluated.get<TextFont>();
return impl().layout.get<TextFont>();
}
void SymbolLayer::setTextFont(PropertyValue<std::vector<std::string>> value) {
if (value == getTextFont())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextFont>() = value;
impl_->layout.get<TextFont>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-font");
}
@@ -402,14 +401,14 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextSize() {
}
DataDrivenPropertyValue<float> SymbolLayer::getTextSize() const {
return impl().layout.unevaluated.get<TextSize>();
return impl().layout.get<TextSize>();
}
void SymbolLayer::setTextSize(DataDrivenPropertyValue<float> value) {
if (value == getTextSize())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextSize>() = value;
impl_->layout.get<TextSize>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-size");
}
@@ -418,14 +417,14 @@ PropertyValue<float> SymbolLayer::getDefaultTextMaxWidth() {
}
PropertyValue<float> SymbolLayer::getTextMaxWidth() const {
return impl().layout.unevaluated.get<TextMaxWidth>();
return impl().layout.get<TextMaxWidth>();
}
void SymbolLayer::setTextMaxWidth(PropertyValue<float> value) {
if (value == getTextMaxWidth())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextMaxWidth>() = value;
impl_->layout.get<TextMaxWidth>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-max-width");
}
@@ -434,14 +433,14 @@ PropertyValue<float> SymbolLayer::getDefaultTextLineHeight() {
}
PropertyValue<float> SymbolLayer::getTextLineHeight() const {
return impl().layout.unevaluated.get<TextLineHeight>();
return impl().layout.get<TextLineHeight>();
}
void SymbolLayer::setTextLineHeight(PropertyValue<float> value) {
if (value == getTextLineHeight())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextLineHeight>() = value;
impl_->layout.get<TextLineHeight>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-line-height");
}
@@ -450,14 +449,14 @@ PropertyValue<float> SymbolLayer::getDefaultTextLetterSpacing() {
}
PropertyValue<float> SymbolLayer::getTextLetterSpacing() const {
return impl().layout.unevaluated.get<TextLetterSpacing>();
return impl().layout.get<TextLetterSpacing>();
}
void SymbolLayer::setTextLetterSpacing(PropertyValue<float> value) {
if (value == getTextLetterSpacing())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextLetterSpacing>() = value;
impl_->layout.get<TextLetterSpacing>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-letter-spacing");
}
@@ -466,14 +465,14 @@ PropertyValue<TextJustifyType> SymbolLayer::getDefaultTextJustify() {
}
PropertyValue<TextJustifyType> SymbolLayer::getTextJustify() const {
return impl().layout.unevaluated.get<TextJustify>();
return impl().layout.get<TextJustify>();
}
void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) {
if (value == getTextJustify())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextJustify>() = value;
impl_->layout.get<TextJustify>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-justify");
}
@@ -482,14 +481,14 @@ PropertyValue<TextAnchorType> SymbolLayer::getDefaultTextAnchor() {
}
PropertyValue<TextAnchorType> SymbolLayer::getTextAnchor() const {
return impl().layout.unevaluated.get<TextAnchor>();
return impl().layout.get<TextAnchor>();
}
void SymbolLayer::setTextAnchor(PropertyValue<TextAnchorType> value) {
if (value == getTextAnchor())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextAnchor>() = value;
impl_->layout.get<TextAnchor>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-anchor");
}
@@ -498,14 +497,14 @@ PropertyValue<float> SymbolLayer::getDefaultTextMaxAngle() {
}
PropertyValue<float> SymbolLayer::getTextMaxAngle() const {
return impl().layout.unevaluated.get<TextMaxAngle>();
return impl().layout.get<TextMaxAngle>();
}
void SymbolLayer::setTextMaxAngle(PropertyValue<float> value) {
if (value == getTextMaxAngle())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextMaxAngle>() = value;
impl_->layout.get<TextMaxAngle>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-max-angle");
}
@@ -514,14 +513,14 @@ DataDrivenPropertyValue<float> SymbolLayer::getDefaultTextRotate() {
}
DataDrivenPropertyValue<float> SymbolLayer::getTextRotate() const {
return impl().layout.unevaluated.get<TextRotate>();
return impl().layout.get<TextRotate>();
}
void SymbolLayer::setTextRotate(DataDrivenPropertyValue<float> value) {
if (value == getTextRotate())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextRotate>() = value;
impl_->layout.get<TextRotate>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-rotate");
}
@@ -530,14 +529,14 @@ PropertyValue<float> SymbolLayer::getDefaultTextPadding() {
}
PropertyValue<float> SymbolLayer::getTextPadding() const {
return impl().layout.unevaluated.get<TextPadding>();
return impl().layout.get<TextPadding>();
}
void SymbolLayer::setTextPadding(PropertyValue<float> value) {
if (value == getTextPadding())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextPadding>() = value;
impl_->layout.get<TextPadding>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-padding");
}
@@ -546,14 +545,14 @@ PropertyValue<bool> SymbolLayer::getDefaultTextKeepUpright() {
}
PropertyValue<bool> SymbolLayer::getTextKeepUpright() const {
return impl().layout.unevaluated.get<TextKeepUpright>();
return impl().layout.get<TextKeepUpright>();
}
void SymbolLayer::setTextKeepUpright(PropertyValue<bool> value) {
if (value == getTextKeepUpright())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextKeepUpright>() = value;
impl_->layout.get<TextKeepUpright>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright");
}
@@ -562,14 +561,14 @@ DataDrivenPropertyValue<TextTransformType> SymbolLayer::getDefaultTextTransform(
}
DataDrivenPropertyValue<TextTransformType> SymbolLayer::getTextTransform() const {
return impl().layout.unevaluated.get<TextTransform>();
return impl().layout.get<TextTransform>();
}
void SymbolLayer::setTextTransform(DataDrivenPropertyValue<TextTransformType> value) {
if (value == getTextTransform())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextTransform>() = value;
impl_->layout.get<TextTransform>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-transform");
}
@@ -578,14 +577,14 @@ DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextOffset(
}
DataDrivenPropertyValue<std::array<float, 2>> SymbolLayer::getTextOffset() const {
return impl().layout.unevaluated.get<TextOffset>();
return impl().layout.get<TextOffset>();
}
void SymbolLayer::setTextOffset(DataDrivenPropertyValue<std::array<float, 2>> value) {
if (value == getTextOffset())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextOffset>() = value;
impl_->layout.get<TextOffset>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-offset");
}
@@ -594,14 +593,14 @@ PropertyValue<bool> SymbolLayer::getDefaultTextAllowOverlap() {
}
PropertyValue<bool> SymbolLayer::getTextAllowOverlap() const {
return impl().layout.unevaluated.get<TextAllowOverlap>();
return impl().layout.get<TextAllowOverlap>();
}
void SymbolLayer::setTextAllowOverlap(PropertyValue<bool> value) {
if (value == getTextAllowOverlap())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextAllowOverlap>() = value;
impl_->layout.get<TextAllowOverlap>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-allow-overlap");
}
@@ -610,14 +609,14 @@ PropertyValue<bool> SymbolLayer::getDefaultTextIgnorePlacement() {
}
PropertyValue<bool> SymbolLayer::getTextIgnorePlacement() const {
return impl().layout.unevaluated.get<TextIgnorePlacement>();
return impl().layout.get<TextIgnorePlacement>();
}
void SymbolLayer::setTextIgnorePlacement(PropertyValue<bool> value) {
if (value == getTextIgnorePlacement())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextIgnorePlacement>() = value;
impl_->layout.get<TextIgnorePlacement>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-ignore-placement");
}
@@ -626,14 +625,14 @@ PropertyValue<bool> SymbolLayer::getDefaultTextOptional() {
}
PropertyValue<bool> SymbolLayer::getTextOptional() const {
return impl().layout.unevaluated.get<TextOptional>();
return impl().layout.get<TextOptional>();
}
void SymbolLayer::setTextOptional(PropertyValue<bool> value) {
if (value == getTextOptional())
return;
auto impl_ = mutableImpl();
impl_->layout.unevaluated.get<TextOptional>() = value;
impl_->layout.get<TextOptional>() = value;
baseImpl = std::move(impl_);
observer->onLayerLayoutPropertyChanged(*this, "text-optional");
}

View File

@@ -13,7 +13,7 @@ public:
void stringifyLayout(rapidjson::Writer<rapidjson::StringBuffer>&) const override;
SymbolLayoutProperties layout;
SymbolLayoutProperties::Unevaluated layout;
SymbolPaintProperties::Cascading paint;
};

View File

@@ -5,6 +5,7 @@
#include <mbgl/style/types.hpp>
#include <mbgl/style/layout_property.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/programs/attributes.hpp>
namespace mbgl {
@@ -236,7 +237,7 @@ struct TextTranslateAnchor : PaintProperty<TranslateAnchorType> {
static TranslateAnchorType defaultValue() { return TranslateAnchorType::Map; }
};
class SymbolLayoutProperties : public LayoutProperties<
class SymbolLayoutProperties : public Properties<
SymbolPlacement,
SymbolSpacing,
SymbolAvoidEdges,
@@ -273,7 +274,7 @@ class SymbolLayoutProperties : public LayoutProperties<
TextOptional
> {};
class SymbolPaintProperties : public PaintProperties<
class SymbolPaintProperties : public Properties<
IconOpacity,
IconColor,
IconHaloColor,

View File

@@ -4,117 +4,30 @@
#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/data_driven_property_evaluator.hpp>
#include <mbgl/util/indexed_tuple.hpp>
namespace mbgl {
class PropertyEvaluationParameters;
namespace style {
template <class T>
class LayoutProperty {
public:
using CascadingType = std::nullptr_t;
using UnevaluatedType = PropertyValue<T>;
using EvaluatorType = PropertyEvaluator<T>;
using PossiblyEvaluatedType = T;
using Type = T;
static constexpr bool IsDataDriven = false;
};
template <class T>
class DataDrivenLayoutProperty {
public:
using CascadingType = std::nullptr_t;
using UnevaluatedType = DataDrivenPropertyValue<T>;
using EvaluatorType = DataDrivenPropertyEvaluator<T>;
using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>;
using Type = T;
};
template <class... Ps>
class LayoutProperties {
public:
using Properties = TypeList<Ps...>;
template <class TypeList>
using Tuple = IndexedTuple<Properties, TypeList>;
/*
For layout properties we implement a two step evaluation process: if you have a zoom level,
you can evaluate a set of unevaluated property values, producing a set of possibly evaluated
values, where undefined, constant, or camera function values have been fully evaluated, and
source or composite function values have not.
Once you also have a particular feature, you can evaluate that set of possibly evaluated values
fully, producing a set of fully evaluated values.
This is in theory maximally efficient in terms of avoiding repeated evaluation of camera
functions, though it's more of a historical accident than a purposeful optimization.
*/
using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
using PossiblyEvaluatedTypes = TypeList<typename Ps::PossiblyEvaluatedType...>;
using EvaluatedTypes = TypeList<typename Ps::Type...>;
class Evaluated : public Tuple<EvaluatedTypes> {
public:
using Tuple<EvaluatedTypes>::Tuple;
};
class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> {
public:
using Tuple<PossiblyEvaluatedTypes>::Tuple;
template <class T>
static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) {
return t;
}
template <class T>
static T evaluate(float z, const GeometryTileFeature& feature,
const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
return v.match(
[&] (const T& t) {
return t;
},
[&] (const SourceFunction<T>& t) {
return t.evaluate(feature, defaultValue);
},
[&] (const CompositeFunction<T>& t) {
return t.evaluate(z, feature, defaultValue);
});
}
template <class P>
auto evaluate(float z, const GeometryTileFeature& feature) const {
return evaluate(z, feature, this->template get<P>(), P::defaultValue());
}
Evaluated evaluate(float z, const GeometryTileFeature& feature) const {
return Evaluated {
evaluate<Ps>(z, feature)...
};
}
};
class Unevaluated : public Tuple<UnevaluatedTypes> {
public:
using Tuple<UnevaluatedTypes>::Tuple;
};
template <class P>
auto evaluate(const PropertyEvaluationParameters& parameters) const {
using Evaluator = typename P::EvaluatorType;
return unevaluated.template get<P>()
.evaluate(Evaluator(parameters, P::defaultValue()));
}
PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const {
return PossiblyEvaluated {
evaluate<Ps>(parameters)...
};
}
Unevaluated unevaluated;
static constexpr bool IsDataDriven = true;
};
} // namespace style

View File

@@ -2,9 +2,10 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/style/position.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/indexed_tuple.hpp>
@@ -14,11 +15,12 @@ namespace style {
template <class T>
class LightProperty {
public:
using CascadingType = Transitionable<PropertyValue<T>>;
using UnevaluatedType = Transitioning<PropertyValue<T>>;
using EvaluatorType = PropertyEvaluator<T>;
using PossiblyEvaluatedType = T;
using Type = T;
using ValueType = PropertyValue<T>;
PropertyValue<T> value;
TransitionOptions transition;
static constexpr bool IsDataDriven = false;
};
struct LightAnchor : LightProperty<LightAnchorType> {
@@ -46,11 +48,11 @@ struct LightIntensity : LightProperty<float> {
}
};
using LightProperties = TypeList<LightAnchor, LightPosition, LightColor, LightIntensity>;
using LightProperties = Properties<LightAnchor, LightPosition, LightColor, LightIntensity>;
class Light::Impl {
public:
IndexedTuple<LightProperties, LightProperties> properties;
LightProperties::Cascading properties;
};
} // namespace style

View File

@@ -1,186 +1,51 @@
#pragma once
#include <mbgl/style/class_dictionary.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/style/property_value.hpp>
#include <mbgl/style/data_driven_property_value.hpp>
#include <mbgl/style/transition_options.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/cross_faded_property_evaluator.hpp>
#include <mbgl/renderer/data_driven_property_evaluator.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/renderer/cascade_parameters.hpp>
#include <mbgl/renderer/transitioning_property.hpp>
#include <mbgl/renderer/paint_property_binder.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/interpolate.hpp>
#include <mbgl/util/indexed_tuple.hpp>
#include <mbgl/util/ignore.hpp>
#include <utility>
namespace mbgl {
class GeometryTileFeature;
namespace style {
template <class Value>
class CascadingPaintProperty {
public:
bool isUndefined() const {
return values.find(ClassID::Default) == values.end();
}
const Value& get(const optional<std::string>& klass) const {
static const Value staticValue{};
const auto it = values.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default);
return it == values.end() ? staticValue : it->second;
}
void set(const Value& value_, const optional<std::string>& klass) {
values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_;
}
const TransitionOptions& getTransition(const optional<std::string>& klass) const {
static const TransitionOptions staticValue{};
const auto it = transitions.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default);
return it == transitions.end() ? staticValue : it->second;
}
void setTransition(const TransitionOptions& transition, const optional<std::string>& klass) {
transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition;
}
template <class TransitioningProperty>
TransitioningProperty cascade(const CascadeParameters& params, TransitioningProperty prior) const {
TransitionOptions transition;
Value value;
for (const auto classID : params.classes) {
if (values.find(classID) != values.end()) {
value = values.at(classID);
break;
}
}
for (const auto classID : params.classes) {
if (transitions.find(classID) != transitions.end()) {
transition = transitions.at(classID).reverseMerge(transition);
break;
}
}
return TransitioningProperty(std::move(value),
std::move(prior),
transition.reverseMerge(params.transition),
params.now);
}
private:
std::map<ClassID, Value> values;
std::map<ClassID, TransitionOptions> transitions;
};
template <class T>
class PaintProperty {
public:
using ValueType = PropertyValue<T>;
using CascadingType = CascadingPaintProperty<ValueType>;
using UnevaluatedType = TransitioningProperty<ValueType>;
using CascadingType = Cascading<PropertyValue<T>>;
using UnevaluatedType = Transitioning<PropertyValue<T>>;
using EvaluatorType = PropertyEvaluator<T>;
using EvaluatedType = T;
using PossiblyEvaluatedType = T;
using Type = T;
static constexpr bool IsDataDriven = false;
};
template <class T, class A>
class DataDrivenPaintProperty {
public:
using ValueType = DataDrivenPropertyValue<T>;
using CascadingType = CascadingPaintProperty<ValueType>;
using UnevaluatedType = TransitioningProperty<ValueType>;
using CascadingType = Cascading<DataDrivenPropertyValue<T>>;
using UnevaluatedType = Transitioning<DataDrivenPropertyValue<T>>;
using EvaluatorType = DataDrivenPropertyEvaluator<T>;
using EvaluatedType = PossiblyEvaluatedPropertyValue<T>;
using PossiblyEvaluatedType = PossiblyEvaluatedPropertyValue<T>;
using Type = T;
static constexpr bool IsDataDriven = true;
using Type = T;
using Attribute = A;
};
template <class T>
class CrossFadedPaintProperty {
public:
using ValueType = PropertyValue<T>;
using CascadingType = CascadingPaintProperty<ValueType>;
using UnevaluatedType = TransitioningProperty<ValueType>;
using CascadingType = Cascading<PropertyValue<T>>;
using UnevaluatedType = Transitioning<PropertyValue<T>>;
using EvaluatorType = CrossFadedPropertyEvaluator<T>;
using EvaluatedType = Faded<T>;
using PossiblyEvaluatedType = Faded<T>;
using Type = T;
static constexpr bool IsDataDriven = false;
};
template <class P>
struct IsDataDriven : std::integral_constant<bool, P::IsDataDriven> {};
template <class... Ps>
class PaintProperties {
public:
using Properties = TypeList<Ps...>;
using DataDrivenProperties = FilteredTypeList<Properties, IsDataDriven>;
using Binders = PaintPropertyBinders<DataDrivenProperties>;
using EvaluatedTypes = TypeList<typename Ps::EvaluatedType...>;
using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
using CascadingTypes = TypeList<typename Ps::CascadingType...>;
template <class TypeList>
using Tuple = IndexedTuple<Properties, TypeList>;
class Evaluated : public Tuple<EvaluatedTypes> {
public:
using Tuple<EvaluatedTypes>::Tuple;
};
class Unevaluated : public Tuple<UnevaluatedTypes> {
public:
using Tuple<UnevaluatedTypes>::Tuple;
bool hasTransition() const {
bool result = false;
util::ignore({ result |= this->template get<Ps>().hasTransition()... });
return result;
}
template <class P>
auto evaluate(const PropertyEvaluationParameters& parameters) {
using Evaluator = typename P::EvaluatorType;
return this->template get<P>().evaluate(
Evaluator(parameters, P::defaultValue()),
parameters.now
);
}
Evaluated evaluate(const PropertyEvaluationParameters& parameters) {
return Evaluated {
evaluate<Ps>(parameters)...
};
}
};
class Cascading : public Tuple<CascadingTypes> {
public:
using Tuple<CascadingTypes>::Tuple;
Unevaluated cascade(const CascadeParameters& parameters, Unevaluated&& prior) const {
return Unevaluated {
this->template get<Ps>().cascade(
parameters,
std::move(prior.template get<Ps>())
)...
};
}
};
};
} // namespace style
} // namespace mbgl

View File

@@ -0,0 +1,268 @@
#pragma once
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion/stringify.hpp>
#include <mbgl/renderer/cascade_parameters.hpp>
#include <mbgl/renderer/paint_property_binder.hpp>
#include <mbgl/renderer/property_evaluation_parameters.hpp>
#include <mbgl/renderer/cascade_parameters.hpp>
#include <mbgl/util/indexed_tuple.hpp>
#include <mbgl/util/ignore.hpp>
namespace mbgl {
class GeometryTileFeature;
namespace style {
template <class Value>
class Transitioning {
public:
Transitioning() = default;
Transitioning(Value value_,
Transitioning<Value> prior_,
TransitionOptions transition,
TimePoint now)
: begin(now + transition.delay.value_or(Duration::zero())),
end(begin + transition.duration.value_or(Duration::zero())),
value(std::move(value_)) {
if (transition.isDefined()) {
prior = { std::move(prior_) };
}
}
template <class Evaluator>
auto evaluate(const Evaluator& evaluator, TimePoint now) const {
auto finalValue = value.evaluate(evaluator);
if (!prior) {
// No prior value.
return finalValue;
} else if (now >= end) {
// Transition from prior value is now complete.
prior = {};
return finalValue;
} else if (value.isDataDriven()) {
// Transitions to data-driven properties are not supported.
// We snap immediately to the data-driven value so that, when we perform layout,
// we see the data-driven function and can use it to populate vertex buffers.
prior = {};
return finalValue;
} else if (now < begin) {
// Transition hasn't started yet.
return prior->get().evaluate(evaluator, now);
} else {
// Interpolate between recursively-calculated prior value and final.
float t = std::chrono::duration<float>(now - begin) / (end - begin);
return util::interpolate(prior->get().evaluate(evaluator, now), finalValue,
util::DEFAULT_TRANSITION_EASE.solve(t, 0.001));
}
}
bool hasTransition() const {
return bool(prior);
}
bool isUndefined() const {
return value.isUndefined();
}
const Value& getValue() const {
return value;
}
private:
mutable optional<mapbox::util::recursive_wrapper<Transitioning<Value>>> prior;
TimePoint begin;
TimePoint end;
Value value;
};
template <class Value>
class Transitionable {
public:
Value value;
TransitionOptions transition;
Transitioning<Value> cascade(const CascadeParameters& params, Transitioning<Value> prior) const {
return Transitioning<Value>(value,
std::move(prior),
transition.reverseMerge(params.transition),
params.now);
}
};
template <class Value>
class Cascading {
public:
bool isUndefined() const {
return values.find(ClassID::Default) == values.end();
}
const Value& get(const optional<std::string>& klass) const {
static const Value staticValue{};
const auto it = values.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default);
return it == values.end() ? staticValue : it->second;
}
void set(const Value& value_, const optional<std::string>& klass) {
values[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = value_;
}
const TransitionOptions& getTransition(const optional<std::string>& klass) const {
static const TransitionOptions staticValue{};
const auto it = transitions.find(klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default);
return it == transitions.end() ? staticValue : it->second;
}
void setTransition(const TransitionOptions& transition, const optional<std::string>& klass) {
transitions[klass ? ClassDictionary::Get().lookup(*klass) : ClassID::Default] = transition;
}
Transitioning<Value> cascade(const CascadeParameters& params, Transitioning<Value> prior) const {
TransitionOptions transition;
Value value;
for (const auto classID : params.classes) {
if (values.find(classID) != values.end()) {
value = values.at(classID);
break;
}
}
for (const auto classID : params.classes) {
if (transitions.find(classID) != transitions.end()) {
transition = transitions.at(classID).reverseMerge(transition);
break;
}
}
return Transitioning<Value>(std::move(value),
std::move(prior),
transition.reverseMerge(params.transition),
params.now);
}
private:
std::map<ClassID, Value> values;
std::map<ClassID, TransitionOptions> transitions;
};
template <class P>
struct IsDataDriven : std::integral_constant<bool, P::IsDataDriven> {};
template <class... Ps>
class Properties {
public:
/*
For style properties we implement a two step evaluation process: if you have a zoom level,
you can evaluate a set of unevaluated property values, producing a set of possibly evaluated
values, where undefined, constant, or camera function values have been fully evaluated, and
source or composite function values have not.
Once you also have a particular feature, you can evaluate that set of possibly evaluated values
fully, producing a set of fully evaluated values.
This is in theory maximally efficient in terms of avoiding repeated evaluation of camera
functions, though it's more of a historical accident than a purposeful optimization.
*/
using PropertyTypes = TypeList<Ps...>;
using CascadingTypes = TypeList<typename Ps::CascadingType...>;
using UnevaluatedTypes = TypeList<typename Ps::UnevaluatedType...>;
using PossiblyEvaluatedTypes = TypeList<typename Ps::PossiblyEvaluatedType...>;
using EvaluatedTypes = TypeList<typename Ps::Type...>;
using DataDrivenProperties = FilteredTypeList<PropertyTypes, IsDataDriven>;
using Binders = PaintPropertyBinders<DataDrivenProperties>;
template <class TypeList>
using Tuple = IndexedTuple<PropertyTypes, TypeList>;
class Evaluated : public Tuple<EvaluatedTypes> {
public:
using Tuple<EvaluatedTypes>::Tuple;
};
class PossiblyEvaluated : public Tuple<PossiblyEvaluatedTypes> {
public:
using Tuple<PossiblyEvaluatedTypes>::Tuple;
template <class T>
static T evaluate(float, const GeometryTileFeature&, const T& t, const T&) {
return t;
}
template <class T>
static T evaluate(float z, const GeometryTileFeature& feature,
const PossiblyEvaluatedPropertyValue<T>& v, const T& defaultValue) {
return v.match(
[&] (const T& t) {
return t;
},
[&] (const SourceFunction<T>& t) {
return t.evaluate(feature, defaultValue);
},
[&] (const CompositeFunction<T>& t) {
return t.evaluate(z, feature, defaultValue);
});
}
template <class P>
auto evaluate(float z, const GeometryTileFeature& feature) const {
return evaluate(z, feature, this->template get<P>(), P::defaultValue());
}
Evaluated evaluate(float z, const GeometryTileFeature& feature) const {
return Evaluated {
evaluate<Ps>(z, feature)...
};
}
};
class Unevaluated : public Tuple<UnevaluatedTypes> {
public:
using Tuple<UnevaluatedTypes>::Tuple;
bool hasTransition() const {
bool result = false;
util::ignore({ result |= this->template get<Ps>().hasTransition()... });
return result;
}
template <class P>
auto evaluate(const PropertyEvaluationParameters& parameters) const {
using Evaluator = typename P::EvaluatorType;
return this->template get<P>()
.evaluate(Evaluator(parameters, P::defaultValue()), parameters.now);
}
PossiblyEvaluated evaluate(const PropertyEvaluationParameters& parameters) const {
return PossiblyEvaluated {
evaluate<Ps>(parameters)...
};
}
template <class Writer>
void stringify(Writer& writer) const {
writer.StartObject();
util::ignore({ (conversion::stringify<Ps>(writer, this->template get<Ps>()), 0)... });
writer.EndObject();
}
};
class Cascading : public Tuple<CascadingTypes> {
public:
using Tuple<CascadingTypes>::Tuple;
Unevaluated cascade(const CascadeParameters& parameters, Unevaluated&& prior) const {
return Unevaluated {
this->template get<Ps>()
.cascade(parameters, std::move(prior.template get<Ps>()))...
};
}
};
};
} // namespace style
} // namespace mbgl

View File

@@ -584,7 +584,7 @@ RenderData Style::getRenderData(MapDebugOptions debugOptions, float angle) const
result.order.emplace_back(*layer);
continue;
}
const BackgroundPaintProperties::Evaluated& paint = background->evaluated;
const BackgroundPaintProperties::PossiblyEvaluated& paint = background->evaluated;
if (layerImpl.get() == layerImpls[0].get() && paint.get<BackgroundPattern>().from.empty()) {
// This is a solid background. We can use glClear().
result.backgroundColor = paint.get<BackgroundColor>() * paint.get<BackgroundOpacity>();

View File

@@ -121,10 +121,17 @@ TEST(Stringify, PropertyValue) {
}
TEST(Stringify, Layout) {
ASSERT_EQ(stringify(SymbolLayoutProperties()), "{}");
auto stringify = [] (const SymbolLayoutProperties::Unevaluated& layout) {
rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s);
layout.stringify(writer);
return std::string(s.GetString());
};
SymbolLayoutProperties layout;
layout.unevaluated.get<SymbolAvoidEdges>() = true;
layout.unevaluated.get<IconPadding>() = 2.0;
ASSERT_EQ(stringify(SymbolLayoutProperties::Unevaluated()), "{}");
SymbolLayoutProperties::Unevaluated layout;
layout.get<SymbolAvoidEdges>() = true;
layout.get<IconPadding>() = 2.0;
ASSERT_EQ(stringify(layout), "{\"symbol-avoid-edges\":true,\"icon-padding\":2.0}");
}

View File

@@ -1,13 +1,14 @@
#include <mbgl/test/util.hpp>
#include <mbgl/style/paint_property.hpp>
#include <mbgl/renderer/transitioning_property.hpp>
#include <mbgl/style/properties.hpp>
#include <mbgl/renderer/property_evaluator.hpp>
#include <mbgl/renderer/data_driven_property_evaluator.hpp>
using namespace mbgl;
using namespace mbgl::style;
using namespace std::literals::chrono_literals;
float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
float evaluate(Transitioning<PropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
@@ -25,7 +26,7 @@ float evaluate(TransitioningProperty<PropertyValue<float>>& property, Duration d
return property.evaluate(evaluator, parameters.now);
}
PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
PossiblyEvaluatedPropertyValue<float> evaluate(Transitioning<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
ZoomHistory zoomHistory;
zoomHistory.update(0, TimePoint::min() + delta);
@@ -43,15 +44,15 @@ PossiblyEvaluatedPropertyValue<float> evaluate(TransitioningProperty<DataDrivenP
return property.evaluate(evaluator, parameters.now);
}
TEST(TransitioningProperty, EvaluateDefaultValue) {
TransitioningProperty<PropertyValue<float>> property;
TEST(TransitioningPropertyValue, EvaluateDefaultValue) {
Transitioning<PropertyValue<float>> property;
ASSERT_EQ(0.0f, evaluate(property));
}
TEST(TransitioningProperty, EvaluateUntransitionedConstant) {
TransitioningProperty<PropertyValue<float>> property {
TEST(TransitioningPropertyValue, EvaluateUntransitionedConstant) {
Transitioning<PropertyValue<float>> property {
PropertyValue<float>(1.0f),
TransitioningProperty<PropertyValue<float>>(),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
@@ -59,18 +60,18 @@ TEST(TransitioningProperty, EvaluateUntransitionedConstant) {
ASSERT_EQ(1.0f, evaluate(property));
}
TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) {
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithoutDelay) {
TransitionOptions transition;
transition.duration = { 1000ms };
TransitioningProperty<PropertyValue<float>> t0 {
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
TransitioningProperty<PropertyValue<float>>(),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
TransitioningProperty<PropertyValue<float>> t1 {
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
@@ -82,19 +83,19 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithoutDelay) {
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 1500ms));
}
TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) {
TEST(TransitioningPropertyValue, EvaluateTransitionedConstantWithDelay) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
TransitioningProperty<PropertyValue<float>> t0 {
Transitioning<PropertyValue<float>> t0 {
PropertyValue<float>(0.0f),
TransitioningProperty<PropertyValue<float>>(),
Transitioning<PropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
TransitioningProperty<PropertyValue<float>> t1 {
Transitioning<PropertyValue<float>> t1 {
PropertyValue<float>(1.0f),
t0,
transition,
@@ -108,14 +109,14 @@ TEST(TransitioningProperty, EvaluateTransitionedConstantWithDelay) {
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms));
}
TEST(TransitioningProperty, EvaluateDataDrivenValue) {
TEST(TransitioningDataDrivenPropertyValue, Evaluate) {
TransitionOptions transition;
transition.delay = { 1000ms };
transition.duration = { 1000ms };
TransitioningProperty<DataDrivenPropertyValue<float>> t0 {
Transitioning<DataDrivenPropertyValue<float>> t0 {
DataDrivenPropertyValue<float>(0.0f),
TransitioningProperty<DataDrivenPropertyValue<float>>(),
Transitioning<DataDrivenPropertyValue<float>>(),
TransitionOptions(),
TimePoint::min()
};
@@ -125,7 +126,7 @@ TEST(TransitioningProperty, EvaluateDataDrivenValue) {
IdentityStops<float>()
};
TransitioningProperty<DataDrivenPropertyValue<float>> t1 {
Transitioning<DataDrivenPropertyValue<float>> t1 {
DataDrivenPropertyValue<float>(sourceFunction),
t0,
transition,

View File

@@ -68,7 +68,7 @@ TEST(VectorTile, Issue7615) {
style::SymbolLayoutProperties::PossiblyEvaluated(),
std::map<
std::string,
std::pair<style::IconPaintProperties::Evaluated, style::TextPaintProperties::Evaluated>>(),
std::pair<style::IconPaintProperties::PossiblyEvaluated, style::TextPaintProperties::PossiblyEvaluated>>(),
16.0f, 1.0f, 0.0f, false, false);
// Simulate placement of a symbol layer.