• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_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, INTERPOLATING_SPRING, TRANSITION };
29 
30 class RSAnimation;
31 class RSPropertyBase;
32 class RSMotionPathOption;
33 class RSTransition;
34 class RSTransitionEffect;
35 
36 class RSImplicitAnimationParam {
37 public:
38     explicit RSImplicitAnimationParam(const RSAnimationTimingProtocol& timingProtocol);
39     virtual ~RSImplicitAnimationParam() = default;
40     ImplicitAnimationParamType GetType() const;
41 
CreateAnimation(std::shared_ptr<RSPropertyBase> property,const std::shared_ptr<RSPropertyBase> & startValue,const std::shared_ptr<RSPropertyBase> & endValue)42     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
43         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const
44     {
45         return nullptr;
46     }
47 
48 protected:
49     void ApplyTimingProtocol(const std::shared_ptr<RSAnimation>& animation) const;
50     ImplicitAnimationParamType animationType_ { ImplicitAnimationParamType::NONE };
51 
52 private:
53     RSAnimationTimingProtocol timingProtocol_;
54 };
55 
56 class RSImplicitCurveAnimationParam : public RSImplicitAnimationParam {
57 public:
58     RSImplicitCurveAnimationParam(
59         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
60 
61     virtual ~RSImplicitCurveAnimationParam() = default;
62 
63     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
64         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
65 
66 private:
67     RSAnimationTimingCurve timingCurve_;
68 };
69 
70 class RSImplicitKeyframeAnimationParam : public RSImplicitAnimationParam {
71 public:
72     RSImplicitKeyframeAnimationParam(
73         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve, float fraction);
74 
75     virtual ~RSImplicitKeyframeAnimationParam() = default;
76 
77     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
78         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
79 
80     void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const std::shared_ptr<RSPropertyBase>& startValue,
81         const std::shared_ptr<RSPropertyBase>& endValue) const;
82 
83 private:
84     RSAnimationTimingCurve timingCurve_;
85     float fraction_;
86 };
87 
88 class RSImplicitPathAnimationParam : public RSImplicitAnimationParam {
89 public:
90     RSImplicitPathAnimationParam(const RSAnimationTimingProtocol& timingProtocol,
91         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<RSMotionPathOption>& motionPathOption);
92 
93     virtual ~RSImplicitPathAnimationParam() = default;
94 
95     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
96         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
97 
98 private:
99     RSAnimationTimingCurve timingCurve_;
100     std::shared_ptr<RSMotionPathOption> motionPathOption_;
101 };
102 
103 class RSImplicitSpringAnimationParam : public RSImplicitAnimationParam {
104 public:
105     RSImplicitSpringAnimationParam(
106         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
107     virtual ~RSImplicitSpringAnimationParam() = default;
108 
109     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
110         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
111 
112 private:
113     RSAnimationTimingCurve timingCurve_;
114 };
115 
116 class RSImplicitInterpolatingSpringAnimationParam : public RSImplicitAnimationParam {
117 public:
118     RSImplicitInterpolatingSpringAnimationParam(
119         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
120     virtual ~RSImplicitInterpolatingSpringAnimationParam() = default;
121 
122     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
123         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
124 
125 private:
126     RSAnimationTimingCurve timingCurve_;
127 };
128 
129 class RSImplicitTransitionParam : public RSImplicitAnimationParam {
130 public:
131     RSImplicitTransitionParam(const RSAnimationTimingProtocol& timingProtocol,
132         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<const RSTransitionEffect>& effect,
133         bool isTransitionIn);
134     virtual ~RSImplicitTransitionParam() = default;
135 
136     std::shared_ptr<RSAnimation> CreateAnimation();
137 
138     std::shared_ptr<RSAnimation> CreateAnimation(const std::shared_ptr<RSPropertyBase>& property,
139         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue);
140 
141 private:
142     RSAnimationTimingCurve timingCurve_;
143 
144     bool isTransitionIn_;
145     std::shared_ptr<RSTransition> transition_;
146     const std::shared_ptr<const RSTransitionEffect> effect_;
147 };
148 } // namespace Rosen
149 } // namespace OHOS
150 
151 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H
152