• 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_ANIMATOR_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H
18 
19 #include <stack>
20 #include <utility>
21 #include <vector>
22 
23 #include "animation/rs_animation_timing_curve.h"
24 #include "animation/rs_animation_timing_protocol.h"
25 #include "common/rs_macros.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class AnimationFinishCallback;
30 class AnimationRepeatCallback;
31 class RSAnimation;
32 class RSPropertyBase;
33 class RSImplicitAnimationParam;
34 class RSTransitionEffect;
35 class RSMotionPathOption;
36 class RSNode;
37 
38 class RSC_EXPORT RSImplicitAnimator {
39 public:
40     RSImplicitAnimator() = default;
41     virtual ~RSImplicitAnimator() = default;
42 
43     // open implicit animation with given animation options, finish callback and repeatcallback
44     int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
45         const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback,
46         std::shared_ptr<AnimationRepeatCallback>&& repeatCallback);
47     // open implicit animation with given animation options and finish callback
48     int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
49         const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback);
50     // open implicit animation with current options and given finish callback
51     int OpenImplicitAnimation(std::shared_ptr<AnimationFinishCallback>&& finishCallback);
52     // open implicit animation with current callback and given timing protocol & curve
53     int OpenImplicitAnimation(
54         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
55 
56     // close implicit animation and return all animations
57     std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation();
58 
59     void BeginImplicitKeyFrameAnimation(float fraction, const RSAnimationTimingCurve& timingCurve);
60     void BeginImplicitKeyFrameAnimation(float fraction);
61     void EndImplicitKeyFrameAnimation();
62 
63     void BeginImplicitTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn);
64     void EndImplicitTransition();
65 
66     void BeginImplicitPathAnimation(const std::shared_ptr<RSMotionPathOption>& motionPathOption);
67     void EndImplicitPathAnimation();
68 
69     bool NeedImplicitAnimation();
70 
71     void CreateImplicitAnimation(const std::shared_ptr<RSNode>& target,
72         std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& startValue,
73         const std::shared_ptr<RSPropertyBase>& endValue);
74 
75     void CreateImplicitTransition(RSNode& target);
76 
77 private:
78     void EndImplicitAnimation();
79     void BeginImplicitCurveAnimation();
80     void BeginImplicitSpringAnimation();
81     void BeginImplicitInterpolatingSpringAnimation();
82 
83     void PushImplicitParam(const std::shared_ptr<RSImplicitAnimationParam>& implicitParam);
84     void PopImplicitParam();
85     void CreateEmptyAnimation();
86 
87     void SetPropertyValue(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& value);
88 
89     void ExecuteWithoutAnimation(const std::function<void()>& callback);
90 
91     std::stack<std::tuple<RSAnimationTimingProtocol, RSAnimationTimingCurve,
92         const std::shared_ptr<AnimationFinishCallback>, std::shared_ptr<AnimationRepeatCallback>>>
93         globalImplicitParams_;
94     std::stack<std::shared_ptr<RSImplicitAnimationParam>> implicitAnimationParams_;
95     std::stack<std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>>> implicitAnimations_;
96     std::stack<std::map<std::pair<NodeId, PropertyId>, std::shared_ptr<RSAnimation>>> keyframeAnimations_;
97 
98     bool implicitAnimationDisabled_ { false };
99     friend class RSNode;
100 };
101 } // namespace Rosen
102 } // namespace OHOS
103 
104 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H
105