• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace {
26 constexpr float SECOND_TO_MILLISECOND = 1e3;
27 constexpr float MILLISECOND_TO_SECOND = 1e-3;
28 } // namespace
29 
30 class RSB_EXPORT RSRenderSpringAnimation : public RSRenderPropertyAnimation,
31     public RSSpringModel<std::shared_ptr<RSRenderPropertyBase>> {
32 public:
33     explicit RSRenderSpringAnimation(AnimationId id, const PropertyId& propertyId,
34         const std::shared_ptr<RSRenderPropertyBase>& originValue,
35         const std::shared_ptr<RSRenderPropertyBase>& startValue,
36         const std::shared_ptr<RSRenderPropertyBase>& endValue);
37 
38     void SetSpringParameters(float response, float dampingRatio);
39 
40     ~RSRenderSpringAnimation() override = default;
41 
42 #ifdef ROSEN_OHOS
43     bool Marshalling(Parcel& parcel) const override;
44     static RSRenderSpringAnimation* Unmarshalling(Parcel& parcel);
45 #endif
46 protected:
47     void OnSetFraction(float fraction) override;
48     void OnAnimate(float fraction) override;
49 
50     void OnAttach() override;
51     void OnDetach() override;
52     void OnInitialize() override;
53 
54 private:
55 #ifdef ROSEN_OHOS
56     bool ParseParam(Parcel& parcel) override;
57 #endif
58     RSRenderSpringAnimation() = default;
59 
60     std::tuple<std::shared_ptr<RSRenderPropertyBase>, std::shared_ptr<RSRenderPropertyBase>> GetSpringStatus();
61 
62     float prevMappedTime_ = 0.0f;
63     std::shared_ptr<RSRenderPropertyBase> startValue_;
64     std::shared_ptr<RSRenderPropertyBase> endValue_;
65 };
66 } // namespace Rosen
67 } // namespace OHOS
68 
69 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_SPRING_ANIMATION_H
70