• 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 #include <vector>
22 
23 #include "animation/rs_animation_timing_curve.h"
24 #include "animation/rs_animation_timing_protocol.h"
25 #include "modifier/rs_property.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 enum class ImplicitAnimationParamType {
30     INVALID,
31     CURVE,
32     KEYFRAME,
33     PATH,
34     SPRING,
35     INTERPOLATING_SPRING,
36     TRANSITION,
37     CANCEL
38 };
39 class RSAnimation;
40 class RSPropertyBase;
41 class RSMotionPathOption;
42 class RSTransition;
43 class RSTransitionEffect;
44 class RSUIContext;
45 
46 class RSImplicitAnimationParam {
47 public:
48     virtual ~RSImplicitAnimationParam() = default;
49     ImplicitAnimationParamType GetType() const;
50 
51 protected:
52     explicit RSImplicitAnimationParam(const RSAnimationTimingProtocol& timingProtocol, ImplicitAnimationParamType type);
53     void ApplyTimingProtocol(const std::shared_ptr<RSAnimation>& animation) const;
54     ImplicitAnimationParamType animationType_ { ImplicitAnimationParamType::INVALID };
55 
56 private:
57     RSAnimationTimingProtocol timingProtocol_;
58 };
59 
60 class RSImplicitCancelAnimationParam : public RSImplicitAnimationParam {
61 public:
62     RSImplicitCancelAnimationParam(const RSAnimationTimingProtocol& timingProtocol);
63 
64     ~RSImplicitCancelAnimationParam() override = default;
65 
66     void AddPropertyToPendingSyncList(const std::shared_ptr<RSPropertyBase>& property);
67     bool SyncProperties(const std::shared_ptr<RSUIContext>& rsUIContext);
68 
69     std::shared_ptr<RSAnimation> CreateEmptyAnimation(std::shared_ptr<RSPropertyBase> property,
70         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
71 
72 private:
73     bool ExecuteSyncPropertiesTask(
74         RSNodeGetShowingPropertiesAndCancelAnimation::PropertiesMap&& propertiesMap, bool isRenderService,
75         const std::shared_ptr<RSUIContext>& rsUIContext);
76     std::vector<std::shared_ptr<RSPropertyBase>> pendingSyncList_;
77 };
78 
79 class RSImplicitCurveAnimationParam : public RSImplicitAnimationParam {
80 public:
81     RSImplicitCurveAnimationParam(
82         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
83 
84     ~RSImplicitCurveAnimationParam() override = default;
85 
86     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
87         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
88 
89 private:
90     RSAnimationTimingCurve timingCurve_;
91 };
92 
93 class RSImplicitKeyframeAnimationParam : public RSImplicitAnimationParam {
94 public:
95     RSImplicitKeyframeAnimationParam(
96         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve,
97         float fraction, int duration);
98 
99     ~RSImplicitKeyframeAnimationParam() override = default;
100 
101     std::shared_ptr<RSAnimation> CreateAnimation(
102         std::shared_ptr<RSPropertyBase> property, const bool& isCreateDurationKeyframe, const int& startDuration,
103         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
104 
105     void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const std::shared_ptr<RSPropertyBase>& startValue,
106         const std::shared_ptr<RSPropertyBase>& endValue) const;
107 
108     void AddKeyframe(std::shared_ptr<RSAnimation>& animation, const int startDuration,
109         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
110 
111 private:
112     RSAnimationTimingCurve timingCurve_;
113     float fraction_;
114     int duration_;
115 };
116 
117 class RSImplicitPathAnimationParam : public RSImplicitAnimationParam {
118 public:
119     RSImplicitPathAnimationParam(const RSAnimationTimingProtocol& timingProtocol,
120         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<RSMotionPathOption>& motionPathOption);
121 
122     ~RSImplicitPathAnimationParam() override = default;
123 
124     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
125         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
126 
127 private:
128     RSAnimationTimingCurve timingCurve_;
129     std::shared_ptr<RSMotionPathOption> motionPathOption_;
130 };
131 
132 class RSImplicitSpringAnimationParam : public RSImplicitAnimationParam {
133 public:
134     RSImplicitSpringAnimationParam(
135         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
136     ~RSImplicitSpringAnimationParam() override = default;
137 
138     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
139         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
140 
141 private:
142     RSAnimationTimingCurve timingCurve_;
143 };
144 
145 class RSImplicitInterpolatingSpringAnimationParam : public RSImplicitAnimationParam {
146 public:
147     RSImplicitInterpolatingSpringAnimationParam(
148         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
149     ~RSImplicitInterpolatingSpringAnimationParam() override = default;
150 
151     std::shared_ptr<RSAnimation> CreateAnimation(std::shared_ptr<RSPropertyBase> property,
152         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue) const;
153 
154 private:
155     RSAnimationTimingCurve timingCurve_;
156 };
157 
158 class RSImplicitTransitionParam : public RSImplicitAnimationParam {
159 public:
160     RSImplicitTransitionParam(const RSAnimationTimingProtocol& timingProtocol,
161         const RSAnimationTimingCurve& timingCurve, const std::shared_ptr<const RSTransitionEffect>& effect,
162         bool isTransitionIn);
163     ~RSImplicitTransitionParam() override = default;
164 
165     std::shared_ptr<RSAnimation> CreateAnimation();
166 
167     std::shared_ptr<RSAnimation> CreateAnimation(const std::shared_ptr<RSPropertyBase>& property,
168         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue);
169 
170 private:
171     RSAnimationTimingCurve timingCurve_;
172 
173     bool isTransitionIn_;
174     std::shared_ptr<RSTransition> transition_;
175     const std::shared_ptr<const RSTransitionEffect> effect_;
176 };
177 } // namespace Rosen
178 } // namespace OHOS
179 
180 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATION_PARAM_H
181