• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_IMPLICIT_ANIMATION_PARAM_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H
18 
19 #include <functional>
20 #include <memory>
21 
22 #include "animation/rs_animation_timing_curve.h"
23 #include "animation/rs_animation_timing_protocol.h"
24 #include "modifier/rs_property.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 enum class ImplicitAnimationParamType { NONE, CURVE, KEYFRAME, PATH, SPRING, TRANSITION };
29 
30 class RSAnimation;
31 class RSPropertyBase;
32 class RSMotionPathOption;
33 class RSTransitionEffect;
34 
35 class RSImplicitAnimationParam {
36 public:
37     explicit RSImplicitAnimationParam(const RSAnimationTimingProtocol& timingProtocol);
38     virtual ~RSImplicitAnimationParam() = default;
39     ImplicitAnimationParamType GetType() const;
40 
CreateAnimation(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & startValue,const std::shared_ptr<RSPropertyBase> & endValue)41     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
42         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const
43     {
44         return nullptr;
45     }
46 
47 protected:
48     void ApplyTimingProtocol(const std::shared_ptr<RSAnimation>& animation) const;
49     ImplicitAnimationParamType animationType_ { ImplicitAnimationParamType::NONE };
50 
51 private:
52     RSAnimationTimingProtocol timingProtocol_;
53 };
54 
55 class RSImplicitCurveAnimationParam : public RSImplicitAnimationParam {
56 public:
57     RSImplicitCurveAnimationParam(
58         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
59 
60     virtual ~RSImplicitCurveAnimationParam() = default;
61 
62     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
63         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
64 
65 private:
66     RSAnimationTimingCurve timingCurve_;
67 };
68 
69 class RSImplicitKeyframeAnimationParam : public RSImplicitAnimationParam {
70 public:
71     RSImplicitKeyframeAnimationParam(
72         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve, float fraction);
73 
74     virtual ~RSImplicitKeyframeAnimationParam() = default;
75 
76     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
77         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
78 
79     void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const std::shared_ptr<RSPropertyBase>& startValue,
80         const std::shared_ptr<RSPropertyBase>& endValue) const;
81 
82 private:
83     RSAnimationTimingCurve timingCurve_;
84     float fraction_;
85 };
86 
87 class RSImplicitPathAnimationParam : public RSImplicitAnimationParam {
88 public:
89     RSImplicitPathAnimationParam(const RSAnimationTimingProtocol& timingProtocol,
90         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<RSMotionPathOption>& motionPathOption);
91 
92     virtual ~RSImplicitPathAnimationParam() = default;
93 
94     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
95         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
96 
97 private:
98     RSAnimationTimingCurve timingCurve_;
99     std::shared_ptr<RSMotionPathOption> motionPathOption_;
100 };
101 
102 class RSImplicitSpringAnimationParam : public RSImplicitAnimationParam {
103 public:
104     RSImplicitSpringAnimationParam(
105         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
106     virtual ~RSImplicitSpringAnimationParam() = default;
107 
108     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
109         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
110 
111 private:
112     RSAnimationTimingCurve timingCurve_;
113 };
114 
115 class RSImplicitTransitionParam : public RSImplicitAnimationParam {
116 public:
117     RSImplicitTransitionParam(const RSAnimationTimingProtocol& timingProtocol,
118         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<const RSTransitionEffect>& effect);
119     virtual ~RSImplicitTransitionParam() = default;
120 
121     std::shared_ptr<RSAnimation> CreateAnimation(bool isTransitionIn);
122 
123 private:
124     RSAnimationTimingCurve timingCurve_;
125     const std::shared_ptr<const RSTransitionEffect> effect_;
126 };
127 } // namespace Rosen
128 } // namespace OHOS
129 
130 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H
131