summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnand Thakker <anandthakker@users.noreply.github.com>2017-03-08 11:53:44 -0500
committerGitHub <noreply@github.com>2017-03-08 11:53:44 -0500
commitbb846fd6cdff84e71741de9428a00137fd5f73a8 (patch)
tree915421863f2d6468ad537113566ae609ff0a94be
parentf591421aaaf698c23ccff37a03d03c87eaa0d988 (diff)
downloadqtlocation-mapboxgl-bb846fd6cdff84e71741de9428a00137fd5f73a8.tar.gz
For data-driven paint setters, transition immediately to target value (#8306)
Closes #8237
-rw-r--r--include/mbgl/style/property_value.hpp1
-rw-r--r--src/mbgl/style/paint_property.hpp6
-rw-r--r--test/style/paint_property.test.cpp45
3 files changed, 52 insertions, 0 deletions
diff --git a/include/mbgl/style/property_value.hpp b/include/mbgl/style/property_value.hpp
index e784633aa7..1b7429dae6 100644
--- a/include/mbgl/style/property_value.hpp
+++ b/include/mbgl/style/property_value.hpp
@@ -29,6 +29,7 @@ public:
bool isUndefined() const { return value.which() == 0; }
bool isConstant() const { return value.which() == 1; }
bool isCameraFunction() const { return value.which() == 2; }
+ bool isDataDriven() const { return false; }
const T & asConstant() const { return value.template get< T >(); }
const CameraFunction<T>& asCameraFunction() const { return value.template get<CameraFunction<T>>(); }
diff --git a/src/mbgl/style/paint_property.hpp b/src/mbgl/style/paint_property.hpp
index 1fa2390f33..599bbef1f4 100644
--- a/src/mbgl/style/paint_property.hpp
+++ b/src/mbgl/style/paint_property.hpp
@@ -51,6 +51,12 @@ public:
// 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);
diff --git a/test/style/paint_property.test.cpp b/test/style/paint_property.test.cpp
index c70fa101ca..39d31068c1 100644
--- a/test/style/paint_property.test.cpp
+++ b/test/style/paint_property.test.cpp
@@ -22,6 +22,22 @@ float evaluate(UnevaluatedPaintProperty<PropertyValue<float>>& property, Duratio
return property.evaluate(evaluator, parameters.now);
}
+PossiblyEvaluatedPropertyValue<float> evaluate(UnevaluatedPaintProperty<DataDrivenPropertyValue<float>>& property, Duration delta = Duration::zero()) {
+ PropertyEvaluationParameters parameters {
+ 0,
+ TimePoint::min() + delta,
+ ZoomHistory(),
+ Duration::zero()
+ };
+
+ DataDrivenPropertyEvaluator<float> evaluator {
+ parameters,
+ 0.0f
+ };
+
+ return property.evaluate(evaluator, parameters.now);
+}
+
TEST(UnevaluatedPaintProperty, EvaluateDefaultValue) {
UnevaluatedPaintProperty<PropertyValue<float>> property;
ASSERT_EQ(0.0f, evaluate(property));
@@ -86,3 +102,32 @@ TEST(UnevaluatedPaintProperty, EvaluateTransitionedConstantWithDelay) {
ASSERT_FLOAT_EQ(0.823099f, evaluate(t1, 1500ms));
ASSERT_FLOAT_EQ(1.0f, evaluate(t1, 2500ms));
}
+
+TEST(UnevaluatedPaintProperty, EvaluateDataDrivenValue) {
+ TransitionOptions transition;
+ transition.delay = { 1000ms };
+ transition.duration = { 1000ms };
+
+ UnevaluatedPaintProperty<DataDrivenPropertyValue<float>> t0 {
+ DataDrivenPropertyValue<float>(0.0f),
+ UnevaluatedPaintProperty<DataDrivenPropertyValue<float>>(),
+ TransitionOptions(),
+ TimePoint::min()
+ };
+
+ SourceFunction<float> sourceFunction = {
+ "property_name",
+ IdentityStops<float>()
+ };
+
+ UnevaluatedPaintProperty<DataDrivenPropertyValue<float>> t1 {
+ DataDrivenPropertyValue<float>(sourceFunction),
+ t0,
+ transition,
+ TimePoint::min()
+ };
+
+ ASSERT_TRUE(evaluate(t0, 0ms).isConstant());
+ ASSERT_FALSE(evaluate(t1, 0ms).isConstant()) <<
+ "A paint property transition to a data-driven evaluates immediately to the final value (see https://github.com/mapbox/mapbox-gl-native/issues/8237).";
+}