diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-02-01 20:24:49 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-02-04 13:30:21 +0200 |
commit | e45c3926c26884aceca5789837e1c1b31a51154e (patch) | |
tree | 2c954fb953e70b7a670b7c879b67f8bf50ef6471 | |
parent | b56a7181afc40029d4280d60489d989b5dddf304 (diff) | |
download | qtlocation-mapboxgl-e45c3926c26884aceca5789837e1c1b31a51154e.tar.gz |
[core] Reduce presence of the 'useIntegerZoom' option
The `useIntegerZoom` presence is now limited: it is removed
from `PossiblyEvaluatedPropertyValue` class specializations
(was never used there!) and from the `PropertyEvaluationParameters`
class, so we do not have to copy `PropertyEvaluationParameters`
instance at `RenderLineLayer::evaluate`.
5 files changed, 23 insertions, 36 deletions
diff --git a/src/mbgl/renderer/data_driven_property_evaluator.hpp b/src/mbgl/renderer/data_driven_property_evaluator.hpp index d65ac36713..efac9e4532 100644 --- a/src/mbgl/renderer/data_driven_property_evaluator.hpp +++ b/src/mbgl/renderer/data_driven_property_evaluator.hpp @@ -7,7 +7,7 @@ namespace mbgl { -template <typename T> +template <typename T, bool useIntegerZoom = false> class DataDrivenPropertyEvaluator { public: using ResultType = PossiblyEvaluatedPropertyValue<T>; @@ -25,14 +25,18 @@ public: } ResultType operator()(const style::PropertyExpression<T>& expression) const { - if (!expression.isFeatureConstant()) { - auto returnExpression = expression; - returnExpression.useIntegerZoom = parameters.useIntegerZoom; - return ResultType(returnExpression); - } else if (!parameters.useIntegerZoom) { - return ResultType(expression.evaluate(parameters.z)); - } else { + if (useIntegerZoom) { // Compiler will optimize out the unused branch. + if (!expression.isFeatureConstant()) { + auto returnExpression = expression; + returnExpression.useIntegerZoom = true; + return ResultType(returnExpression); + } return ResultType(expression.evaluate(floor(parameters.z))); + } else { + if (!expression.isFeatureConstant()) { + return ResultType(expression); + } + return ResultType(expression.evaluate(parameters.z)); } } diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index b7785d1cb7..7026175bfc 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -47,12 +47,8 @@ void RenderLineLayer::transition(const TransitionParameters& parameters) { void RenderLineLayer::evaluate(const PropertyEvaluationParameters& parameters) { style::Properties<LineFloorwidth>::Unevaluated extra(unevaluated.get<style::LineWidth>()); - - auto dashArrayParams = parameters; - dashArrayParams.useIntegerZoom = true; - evaluated = RenderLinePaintProperties::PossiblyEvaluated( - unevaluated.evaluate(parameters).concat(extra.evaluate(dashArrayParams))); + unevaluated.evaluate(parameters).concat(extra.evaluate(parameters))); crossfade = parameters.getCrossfadeParameters(); diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index 3d050528c4..d586725f54 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -10,7 +10,8 @@ namespace mbgl { struct LineFloorwidth : style::DataDrivenPaintProperty<float, attributes::a_floorwidth, uniforms::u_floorwidth> { - static float defaultValue() { return 1; } + using EvaluatorType = DataDrivenPropertyEvaluator<float, true>; + static float defaultValue() { return 1.0; } }; class RenderLinePaintProperties : public style::ConcatenateProperties< diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index 353df2ab90..625235011c 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -18,9 +18,8 @@ private: public: PossiblyEvaluatedPropertyValue() = default; - PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false) - : value(std::move(v)), - useIntegerZoom(useIntegerZoom_) {} + PossiblyEvaluatedPropertyValue(Value v) + : value(std::move(v)) {} bool isConstant() const { return value.template is<T>(); @@ -46,16 +45,10 @@ public: return this->match( [&] (const T& constant_) { return constant_; }, [&] (const style::PropertyExpression<T>& expression) { - if (useIntegerZoom) { - return expression.evaluate(floor(zoom), feature, defaultValue); - } else { - return expression.evaluate(zoom, feature, defaultValue); - } + return expression.evaluate(zoom, feature, defaultValue); } ); } - - bool useIntegerZoom; }; template <class T> @@ -69,9 +62,8 @@ private: public: PossiblyEvaluatedPropertyValue() = default; - PossiblyEvaluatedPropertyValue(Value v, bool useIntegerZoom_ = false) - : value(std::move(v)), - useIntegerZoom(useIntegerZoom_) {} + PossiblyEvaluatedPropertyValue(Value v) + : value(std::move(v)) {} bool isConstant() const { return value.template is<Faded<T>>(); @@ -108,8 +100,6 @@ public: } ); } - - bool useIntegerZoom; }; diff --git a/src/mbgl/renderer/property_evaluation_parameters.hpp b/src/mbgl/renderer/property_evaluation_parameters.hpp index 0e1c317294..7c0d4e0fe2 100644 --- a/src/mbgl/renderer/property_evaluation_parameters.hpp +++ b/src/mbgl/renderer/property_evaluation_parameters.hpp @@ -18,18 +18,15 @@ public: : z(z_), now(Clock::time_point::max()), zoomHistory(), - defaultFadeDuration(0), - useIntegerZoom(false) {} + defaultFadeDuration(0) {} PropertyEvaluationParameters(ZoomHistory zoomHistory_, TimePoint now_, - Duration defaultFadeDuration_, - bool useIntegerZoom_ = false) + Duration defaultFadeDuration_) : z(zoomHistory_.lastZoom), now(std::move(now_)), zoomHistory(std::move(zoomHistory_)), - defaultFadeDuration(std::move(defaultFadeDuration_)), - useIntegerZoom(useIntegerZoom_) {} + defaultFadeDuration(std::move(defaultFadeDuration_)) {} CrossfadeParameters getCrossfadeParameters() const { const float fraction = z - std::floor(z); @@ -47,7 +44,6 @@ public: TimePoint now; ZoomHistory zoomHistory; Duration defaultFadeDuration; - bool useIntegerZoom; }; } // namespace mbgl |