1 /* 2 * Copyright (c) 2022-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_RENDER_SPRING_ANIMATION_H 17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_SPRING_ANIMATION_H 18 19 #include "animation/rs_render_property_animation.h" 20 #include "animation/rs_spring_model.h" 21 #include "common/rs_macros.h" 22 23 namespace OHOS { 24 namespace Rosen { 25 class RSB_EXPORT RSRenderSpringAnimation : public RSRenderPropertyAnimation, 26 public RSSpringModel<std::shared_ptr<RSRenderPropertyBase>> { 27 public: 28 explicit RSRenderSpringAnimation(AnimationId id, const PropertyId& propertyId, 29 const std::shared_ptr<RSRenderPropertyBase>& originValue, 30 const std::shared_ptr<RSRenderPropertyBase>& startValue, 31 const std::shared_ptr<RSRenderPropertyBase>& endValue); 32 33 void SetSpringParameters(float response, float dampingRatio, float blendDuration = 0.0f); 34 35 ~RSRenderSpringAnimation() override = default; 36 37 #ifdef ROSEN_OHOS 38 bool Marshalling(Parcel& parcel) const override; 39 [[nodiscard]] static RSRenderSpringAnimation* Unmarshalling(Parcel& parcel); 40 #endif 41 protected: 42 void OnSetFraction(float fraction) override; 43 void OnAnimate(float fraction) override; 44 45 void OnAttach() override; 46 void OnDetach() override; 47 void OnInitialize(int64_t time) override; 48 49 private: 50 #ifdef ROSEN_OHOS 51 bool ParseParam(Parcel& parcel) override; 52 #endif 53 RSRenderSpringAnimation() = default; 54 55 // status inherited related 56 float prevMappedTime_ = 0.0f; 57 // return current <value, velocity> as a tuple 58 std::tuple<std::shared_ptr<RSRenderPropertyBase>, std::shared_ptr<RSRenderPropertyBase>> GetSpringStatus() const; 59 void InheritSpringStatus(const RSRenderSpringAnimation* from); 60 61 // blend related 62 uint64_t blendDuration_ = 0; 63 float finalResponse_ = 0.0f; 64 65 std::shared_ptr<RSRenderPropertyBase> startValue_; 66 std::shared_ptr<RSRenderPropertyBase> endValue_; 67 }; 68 } // namespace Rosen 69 } // namespace OHOS 70 71 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_SPRING_ANIMATION_H 72