1 /* 2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_VALUE_ESTIMATOR_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_VALUE_ESTIMATOR_H 18 19 #include <memory> 20 21 #include "rs_spring_model.h" 22 23 #include "animation/rs_animation_common.h" 24 #include "animation/rs_interpolator.h" 25 #include "common/rs_color.h" 26 #include "common/rs_macros.h" 27 #include "common/rs_matrix3.h" 28 #include "common/rs_vector2.h" 29 #include "common/rs_vector4.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 class RSRenderPropertyBase; 34 template<typename T> 35 class RSRenderAnimatableProperty; 36 37 class RSB_EXPORT RSValueEstimator { 38 public: 39 template<typename T> Estimate(float fraction,const T & startValue,const T & endValue)40 T Estimate(float fraction, const T& startValue, const T& endValue) 41 { 42 return startValue * (1.0f - fraction) + endValue * fraction; 43 } 44 45 Quaternion Estimate(float fraction, const Quaternion& startValue, const Quaternion& endValue); 46 EstimateFraction(const std::shared_ptr<RSInterpolator> & interpolator)47 virtual float EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator) 48 { 49 return 0.0f; 50 } 51 EstimateFraction(const std::shared_ptr<RSInterpolator> & interpolator,float targetFraction,int duration)52 virtual float EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator, 53 float targetFraction, int duration) 54 { 55 return 0.0f; 56 } 57 InitCurveAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & endValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)58 virtual void InitCurveAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 59 const std::shared_ptr<RSRenderPropertyBase>& startValue, 60 const std::shared_ptr<RSRenderPropertyBase>& endValue, 61 const std::shared_ptr<RSRenderPropertyBase>& lastValue) {} 62 InitKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,std::vector<std::tuple<float,std::shared_ptr<RSRenderPropertyBase>,std::shared_ptr<RSInterpolator>>> & keyframes,const std::shared_ptr<RSRenderPropertyBase> & lastValue)63 virtual void InitKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 64 std::vector<std::tuple<float, std::shared_ptr<RSRenderPropertyBase>, 65 std::shared_ptr<RSInterpolator>>>& keyframes, 66 const std::shared_ptr<RSRenderPropertyBase>& lastValue) {} 67 InitDurationKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,std::vector<std::tuple<float,float,std::shared_ptr<RSRenderPropertyBase>,std::shared_ptr<RSInterpolator>>> & keyframes,const std::shared_ptr<RSRenderPropertyBase> & lastValue)68 virtual void InitDurationKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 69 std::vector<std::tuple<float, float, std::shared_ptr<RSRenderPropertyBase>, 70 std::shared_ptr<RSInterpolator>>>& keyframes, 71 const std::shared_ptr<RSRenderPropertyBase>& lastValue) {} 72 73 virtual void UpdateAnimationValue(const float fraction, const bool isAdditive) = 0; 74 }; 75 76 template<typename T> 77 class RSB_EXPORT_TMP RSCurveValueEstimator : public RSValueEstimator { 78 public: 79 RSCurveValueEstimator() = default; 80 virtual ~RSCurveValueEstimator() = default; 81 InitCurveAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & endValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)82 void InitCurveAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 83 const std::shared_ptr<RSRenderPropertyBase>& startValue, 84 const std::shared_ptr<RSRenderPropertyBase>& endValue, 85 const std::shared_ptr<RSRenderPropertyBase>& lastValue) override 86 { 87 auto animatableProperty = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(property); 88 auto animatableStartValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(startValue); 89 auto animatableEndValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(endValue); 90 auto animatableLastValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(lastValue); 91 if (animatableProperty && animatableStartValue && animatableEndValue && animatableLastValue) { 92 property_ = animatableProperty; 93 startValue_ = animatableStartValue->Get(); 94 endValue_ = animatableEndValue->Get(); 95 lastValue_ = animatableLastValue->Get(); 96 } 97 } 98 UpdateAnimationValue(const float fraction,const bool isAdditive)99 void UpdateAnimationValue(const float fraction, const bool isAdditive) override 100 { 101 auto animationValue = GetAnimationValue(fraction, isAdditive); 102 if (property_ != nullptr) { 103 property_->Set(animationValue); 104 } 105 } 106 GetAnimationValue(const float fraction,const bool isAdditive)107 T GetAnimationValue(const float fraction, const bool isAdditive) 108 { 109 auto interpolationValue = RSValueEstimator::Estimate(fraction, startValue_, endValue_); 110 auto animationValue = interpolationValue; 111 if (isAdditive && property_ != nullptr) { 112 animationValue = property_->Get() + (interpolationValue - lastValue_); 113 } 114 lastValue_ = interpolationValue; 115 return animationValue; 116 } 117 EstimateFraction(const std::shared_ptr<RSInterpolator> & interpolator)118 float EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator) override 119 { 120 return 0.0f; 121 } 122 EstimateFraction(const std::shared_ptr<RSInterpolator> & interpolator,float targetFraction,int duration)123 float EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator, 124 float targetFraction, int duration) override 125 { 126 if (interpolator == nullptr || duration <= 0) { 127 return FRACTION_MIN; 128 } 129 int secondTime = std::ceil(static_cast<float>(duration) / SECOND_TO_MS); 130 if (secondTime <= 0) { 131 return FRACTION_MIN; 132 } 133 auto frameTimes = MAX_FRAME_TIME_FRACTION * secondTime; 134 float lastFraction = FRACTION_MIN; 135 for (int time = 1; time <= frameTimes; time++) { 136 float frameFraction = static_cast<float>(time) / frameTimes; 137 frameFraction = std::clamp(frameFraction, 0.0f, 1.0f); 138 float fraction = interpolator->Interpolate(frameFraction); 139 if (lastFraction <= targetFraction && fraction >= targetFraction) { 140 return frameFraction; 141 } 142 lastFraction = fraction; 143 } 144 return FRACTION_MIN; 145 } 146 private: 147 T startValue_ {}; 148 T endValue_ {}; 149 T lastValue_ {}; 150 std::shared_ptr<RSRenderAnimatableProperty<T>> property_; 151 }; 152 153 template<> 154 float RSCurveValueEstimator<float>::EstimateFraction(const std::shared_ptr<RSInterpolator>& interpolator); 155 156 extern template class RSCurveValueEstimator<float>; 157 158 template<typename T> 159 class RSKeyframeValueEstimator : public RSValueEstimator { 160 public: 161 RSKeyframeValueEstimator() = default; 162 virtual ~RSKeyframeValueEstimator() = default; 163 InitKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,std::vector<std::tuple<float,std::shared_ptr<RSRenderPropertyBase>,std::shared_ptr<RSInterpolator>>> & keyframes,const std::shared_ptr<RSRenderPropertyBase> & lastValue)164 void InitKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 165 std::vector<std::tuple<float, std::shared_ptr<RSRenderPropertyBase>, 166 std::shared_ptr<RSInterpolator>>>& keyframes, 167 const std::shared_ptr<RSRenderPropertyBase>& lastValue) override 168 { 169 auto animatableProperty = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(property); 170 auto animatableLastValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(lastValue); 171 if (animatableProperty && animatableLastValue) { 172 property_ = animatableProperty; 173 lastValue_ = animatableLastValue->Get(); 174 } 175 for (const auto& keyframe : keyframes) { 176 auto keyframeValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(std::get<1>(keyframe)); 177 if (keyframeValue != nullptr) { 178 keyframes_.push_back({ std::get<0>(keyframe), keyframeValue->Get(), std::get<2>(keyframe) }); 179 } 180 } 181 } 182 InitDurationKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase> & property,std::vector<std::tuple<float,float,std::shared_ptr<RSRenderPropertyBase>,std::shared_ptr<RSInterpolator>>> & keyframes,const std::shared_ptr<RSRenderPropertyBase> & lastValue)183 void InitDurationKeyframeAnimationValue(const std::shared_ptr<RSRenderPropertyBase>& property, 184 std::vector<std::tuple<float, float, std::shared_ptr<RSRenderPropertyBase>, 185 std::shared_ptr<RSInterpolator>>>& keyframes, 186 const std::shared_ptr<RSRenderPropertyBase>& lastValue) override 187 { 188 auto animatableProperty = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(property); 189 auto animatableLastValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(lastValue); 190 if (animatableProperty && animatableLastValue) { 191 property_ = animatableProperty; 192 lastValue_ = animatableLastValue->Get(); 193 } 194 for (const auto& keyframe : keyframes) { 195 auto keyframeValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(std::get<2>(keyframe)); 196 if (keyframeValue != nullptr) { 197 durationKeyframes_.push_back( 198 { std::get<0>(keyframe), std::get<1>(keyframe), keyframeValue->Get(), std::get<3>(keyframe) }); 199 } 200 } 201 } 202 UpdateAnimationValue(const float fraction,const bool isAdditive)203 void UpdateAnimationValue(const float fraction, const bool isAdditive) override 204 { 205 auto animationValue = GetAnimationValue(fraction, isAdditive); 206 if (property_ != nullptr) { 207 property_->Set(animationValue); 208 } 209 } 210 GetAnimationValue(const float fraction,const bool isAdditive)211 T GetAnimationValue(const float fraction, const bool isAdditive) 212 { 213 if (!(durationKeyframes_.empty())) { 214 return GetDurationKeyframeAnimationValue(fraction, isAdditive); 215 } 216 float preKeyframeFraction = std::get<0>(keyframes_.front()); 217 auto preKeyframeValue = std::get<1>(keyframes_.front()); 218 for (const auto& keyframe : keyframes_) { 219 // the index of tuple 220 float keyframeFraction = std::get<0>(keyframe); 221 auto keyframeValue = std::get<1>(keyframe); 222 auto keyframeInterpolator = std::get<2>(keyframe); 223 if (fraction <= keyframeFraction) { 224 if (ROSEN_EQ(keyframeFraction, preKeyframeFraction)) { 225 continue; 226 } 227 228 float intervalFraction = (fraction - preKeyframeFraction) / (keyframeFraction - preKeyframeFraction); 229 auto interpolationValue = RSValueEstimator::Estimate( 230 keyframeInterpolator->Interpolate(intervalFraction), preKeyframeValue, keyframeValue); 231 auto animationValue = interpolationValue; 232 if (isAdditive && property_ != nullptr) { 233 animationValue = property_->Get() + (interpolationValue - lastValue_); 234 } 235 lastValue_ = interpolationValue; 236 return animationValue; 237 } 238 239 preKeyframeFraction = keyframeFraction; 240 preKeyframeValue = keyframeValue; 241 } 242 return preKeyframeValue; 243 } 244 GetDurationKeyframeAnimationValue(const float fraction,const bool isAdditive)245 T GetDurationKeyframeAnimationValue(const float fraction, const bool isAdditive) 246 { 247 auto preKeyframeValue = std::get<2>(durationKeyframes_.front()); 248 auto animationValue = preKeyframeValue; 249 bool bInFraction = false; 250 for (const auto& keyframe : durationKeyframes_) { 251 float startFraction = std::get<0>(keyframe); 252 float endFraction = std::get<1>(keyframe); 253 auto keyframeValue = std::get<2>(keyframe); 254 auto keyframeInterpolator = std::get<3>(keyframe); 255 if (fraction < startFraction) { 256 break; 257 } 258 if ((fraction > startFraction) && (fraction <= endFraction)) { 259 bInFraction = true; 260 float intervalFraction = (fraction - startFraction) / (endFraction - startFraction); 261 auto interpolationValue = RSValueEstimator::Estimate( 262 keyframeInterpolator->Interpolate(intervalFraction), preKeyframeValue, keyframeValue); 263 animationValue = interpolationValue; 264 if (isAdditive && property_ != nullptr) { 265 animationValue = property_->Get() + (interpolationValue - lastValue_); 266 } 267 lastValue_ = interpolationValue; 268 preKeyframeValue = animationValue; 269 continue; 270 } 271 if (ROSEN_EQ(fraction, startFraction) && ROSEN_EQ(startFraction, endFraction)) { 272 bInFraction = true; 273 animationValue = keyframeValue; 274 preKeyframeValue = keyframeValue; 275 lastValue_ = keyframeValue; 276 continue; 277 } 278 preKeyframeValue = keyframeValue; 279 } 280 if (!bInFraction) { 281 animationValue = preKeyframeValue; 282 lastValue_ = preKeyframeValue; 283 } 284 return animationValue; 285 } 286 287 private: 288 std::vector<std::tuple<float, T, std::shared_ptr<RSInterpolator>>> keyframes_; 289 std::vector<std::tuple<float, float, T, std::shared_ptr<RSInterpolator>>> durationKeyframes_; 290 T lastValue_ {}; 291 std::shared_ptr<RSRenderAnimatableProperty<T>> property_; 292 }; 293 294 enum class RSValueEstimatorType : int16_t { 295 INVALID = 0, 296 CURVE_VALUE_ESTIMATOR, 297 KEYFRAME_VALUE_ESTIMATOR, 298 PATH_VALUE_ESTIMATOR, 299 }; 300 301 class RSB_EXPORT RSSpringValueEstimatorBase { 302 public: 303 RSSpringValueEstimatorBase() = default; 304 virtual ~RSSpringValueEstimatorBase() = default; 305 SetResponse(const float response)306 virtual void SetResponse(const float response) {} SetMinimumAmplitudeRatio(const float minimumAmplitudeRatio)307 virtual void SetMinimumAmplitudeRatio(const float minimumAmplitudeRatio) {} SetDampingRatio(const float dampingRatio)308 virtual void SetDampingRatio(const float dampingRatio) {} GetResponse()309 virtual float GetResponse() const 310 { 311 return 0.0f; 312 } GetDampingRatio()313 virtual float GetDampingRatio() const 314 { 315 return 0.0f; 316 } SetInitialVelocity(const std::shared_ptr<RSRenderPropertyBase> & initialVelocity)317 virtual void SetInitialVelocity(const std::shared_ptr<RSRenderPropertyBase>& initialVelocity) {} InitRSSpringValueEstimator(const std::shared_ptr<RSRenderPropertyBase> & property,const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & endValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)318 virtual void InitRSSpringValueEstimator(const std::shared_ptr<RSRenderPropertyBase>& property, 319 const std::shared_ptr<RSRenderPropertyBase>& startValue, const std::shared_ptr<RSRenderPropertyBase>& endValue, 320 const std::shared_ptr<RSRenderPropertyBase>& lastValue) 321 {} UpdateStartValueAndLastValue(const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)322 virtual void UpdateStartValueAndLastValue( 323 const std::shared_ptr<RSRenderPropertyBase>& startValue, const std::shared_ptr<RSRenderPropertyBase>& lastValue) 324 {} UpdateAnimationValue(const float time,const bool isAdditive)325 virtual void UpdateAnimationValue(const float time, const bool isAdditive) {} GetAnimationProperty()326 virtual std::shared_ptr<RSRenderPropertyBase> GetAnimationProperty() const 327 { 328 return nullptr; 329 } GetPropertyVelocity(float time)330 virtual std::shared_ptr<RSRenderPropertyBase> GetPropertyVelocity(float time) const 331 { 332 return nullptr; 333 } UpdateDuration()334 virtual float UpdateDuration() 335 { 336 return 0.0f; 337 } UpdateSpringParameters()338 virtual void UpdateSpringParameters() {} 339 }; 340 341 template<typename T> 342 class RSSpringValueEstimator : public RSSpringValueEstimatorBase { 343 public: RSSpringValueEstimator()344 RSSpringValueEstimator() : RSSpringValueEstimatorBase() 345 { 346 InitSpringModel(); 347 } 348 349 ~RSSpringValueEstimator() override = default; 350 InitSpringModel()351 void InitSpringModel() 352 { 353 if (!springModel_) { 354 springModel_ = std::make_shared<RSSpringModel<T>>(); 355 } 356 } 357 SetResponse(const float response)358 void SetResponse(const float response) override 359 { 360 if (springModel_) { 361 springModel_->response_ = response; 362 } 363 } 364 SetMinimumAmplitudeRatio(const float minimumAmplitudeRatio)365 void SetMinimumAmplitudeRatio(const float minimumAmplitudeRatio) override 366 { 367 if (springModel_) { 368 springModel_->minimumAmplitudeRatio_ = minimumAmplitudeRatio; 369 } 370 } 371 SetDampingRatio(const float dampingRatio)372 void SetDampingRatio(const float dampingRatio) override 373 { 374 if (springModel_) { 375 springModel_->dampingRatio_ = std::clamp(dampingRatio, SPRING_MIN_DAMPING_RATIO, SPRING_MAX_DAMPING_RATIO); 376 } 377 } 378 GetResponse()379 float GetResponse() const override 380 { 381 if (springModel_) { 382 return springModel_->response_; 383 } 384 return 0.0f; 385 } 386 GetDampingRatio()387 float GetDampingRatio() const override 388 { 389 if (springModel_) { 390 return springModel_->dampingRatio_; 391 } 392 return 0.0f; 393 } 394 SetInitialVelocity(const std::shared_ptr<RSRenderPropertyBase> & initialVelocity)395 void SetInitialVelocity(const std::shared_ptr<RSRenderPropertyBase>& initialVelocity) override 396 { 397 auto animatableInitialVelocity = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(initialVelocity); 398 if (animatableInitialVelocity != nullptr && springModel_ != nullptr) { 399 springModel_->initialVelocity_ = animatableInitialVelocity->Get(); 400 } 401 } 402 InitRSSpringValueEstimator(const std::shared_ptr<RSRenderPropertyBase> & property,const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & endValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)403 void InitRSSpringValueEstimator(const std::shared_ptr<RSRenderPropertyBase>& property, 404 const std::shared_ptr<RSRenderPropertyBase>& startValue, const std::shared_ptr<RSRenderPropertyBase>& endValue, 405 const std::shared_ptr<RSRenderPropertyBase>& lastValue) override 406 { 407 auto animatableProperty = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(property); 408 auto animatableStartValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(startValue); 409 auto animatableEndValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(endValue); 410 auto animatableLastValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(lastValue); 411 if (animatableProperty && animatableStartValue && animatableEndValue && animatableLastValue) { 412 property_ = animatableProperty; 413 startValue_ = animatableStartValue->Get(); 414 endValue_ = animatableEndValue->Get(); 415 lastValue_ = animatableLastValue->Get(); 416 if (springModel_) { 417 springModel_->initialOffset_ = startValue_ - endValue_; 418 } 419 } 420 } 421 UpdateStartValueAndLastValue(const std::shared_ptr<RSRenderPropertyBase> & startValue,const std::shared_ptr<RSRenderPropertyBase> & lastValue)422 void UpdateStartValueAndLastValue(const std::shared_ptr<RSRenderPropertyBase>& startValue, 423 const std::shared_ptr<RSRenderPropertyBase>& lastValue) override 424 { 425 auto animatableStartValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(startValue); 426 auto animatableLastValue = std::static_pointer_cast<RSRenderAnimatableProperty<T>>(lastValue); 427 if (animatableStartValue && animatableLastValue) { 428 startValue_ = animatableStartValue->Get(); 429 lastValue_ = animatableLastValue->Get(); 430 if (springModel_) { 431 springModel_->initialOffset_ = startValue_ - endValue_; 432 } 433 } 434 } 435 UpdateAnimationValue(const float time,const bool isAdditive)436 void UpdateAnimationValue(const float time, const bool isAdditive) override 437 { 438 auto animationValue = GetAnimationValue(time, isAdditive); 439 if (property_ != nullptr) { 440 property_->Set(animationValue); 441 } 442 } 443 GetAnimationValue(const float time,const bool isAdditive)444 T GetAnimationValue(const float time, const bool isAdditive) 445 { 446 T currentValue = startValue_; 447 constexpr static float TIME_THRESHOLD = 1e-3f; 448 if (ROSEN_EQ(time, duration_, TIME_THRESHOLD)) { 449 currentValue = endValue_; 450 } else if (springModel_) { 451 currentValue = springModel_->CalculateDisplacement(time) + endValue_; 452 } 453 454 auto animationValue = currentValue; 455 if (isAdditive && property_) { 456 animationValue = property_->Get() + currentValue - lastValue_; 457 } 458 lastValue_ = currentValue; 459 return animationValue; 460 } 461 GetAnimationProperty()462 std::shared_ptr<RSRenderPropertyBase> GetAnimationProperty() const override 463 { 464 return std::make_shared<RSRenderAnimatableProperty<T>>(lastValue_); 465 } 466 GetPropertyVelocity(float time)467 std::shared_ptr<RSRenderPropertyBase> GetPropertyVelocity(float time) const override 468 { 469 if (!springModel_) { 470 return nullptr; 471 } 472 constexpr float TIME_INTERVAL = 1e-6f; // 1 microsecond 473 T velocity = (springModel_->CalculateDisplacement(time + TIME_INTERVAL) - 474 springModel_->CalculateDisplacement(time)) * (1 / TIME_INTERVAL); 475 return std::make_shared<RSRenderAnimatableProperty<T>>(velocity); 476 } 477 UpdateDuration()478 float UpdateDuration() override 479 { 480 if (springModel_) { 481 duration_ = springModel_->EstimateDuration(); 482 } 483 return duration_; 484 } 485 UpdateSpringParameters()486 void UpdateSpringParameters() override 487 { 488 if (springModel_) { 489 springModel_->CalculateSpringParameters(); 490 } 491 } 492 493 private: 494 T startValue_ {}; 495 T endValue_ {}; 496 T lastValue_ {}; 497 float duration_ = 0.3f; 498 std::shared_ptr<RSSpringModel<T>> springModel_; 499 std::shared_ptr<RSRenderAnimatableProperty<T>> property_; 500 }; 501 } // namespace Rosen 502 } // namespace OHOS 503 504 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_VALUE_ESTIMATOR_H 505