• 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 class RSUIContext;
38 
39 class RSC_EXPORT RSImplicitAnimator {
40 public:
41     RSImplicitAnimator() = default;
42     virtual ~RSImplicitAnimator() = default;
43 
44     // open implicit animation with given animation options, finish callback and repeatcallback
45     int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
46         const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback,
47         std::shared_ptr<AnimationRepeatCallback>&& repeatCallback);
48     // open implicit animation with given animation options and finish callback
49     int OpenImplicitAnimation(const RSAnimationTimingProtocol& timingProtocol,
50         const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback);
51     // open implicit animation with current options and given finish callback
52     int OpenImplicitAnimation(std::shared_ptr<AnimationFinishCallback>&& finishCallback);
53     // open implicit animation with current callback and given timing protocol & curve
54     int OpenImplicitAnimation(
55         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
56 
57     // close implicit animation and return all animations
58     std::vector<std::shared_ptr<RSAnimation>> CloseImplicitAnimation();
59     // close implicit cancel animation and return whether the synchronization was successful
60     bool CloseImplicitCancelAnimation();
61 
62     // open implicit animation with given animation options and finish callback
63     int OpenInterActiveImplicitAnimation(bool isAddImplictAnimation, const RSAnimationTimingProtocol& timingProtocol,
64         const RSAnimationTimingCurve& timingCurve, std::shared_ptr<AnimationFinishCallback>&& finishCallback);
65     // interactive animator close implicit animation and return all animations
66     std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>> CloseInterActiveImplicitAnimation(
67         bool isAddImplictAnimation);
68 
69     void BeginImplicitKeyFrameAnimation(float fraction, const RSAnimationTimingCurve& timingCurve);
70     void BeginImplicitKeyFrameAnimation(float fraction);
71     void EndImplicitKeyFrameAnimation();
72 
73     void BeginImplicitDurationKeyFrameAnimation(int duration, const RSAnimationTimingCurve& timingCurve);
74     void EndImplicitDurationKeyFrameAnimation();
75 
76     void BeginImplicitTransition(const std::shared_ptr<const RSTransitionEffect>& effect, bool isTransitionIn);
77     void EndImplicitTransition();
78 
79     void BeginImplicitPathAnimation(const std::shared_ptr<RSMotionPathOption>& motionPathOption);
80     void EndImplicitPathAnimation();
81 
82     bool NeedImplicitAnimation();
83 
84     void CreateImplicitAnimation(const std::shared_ptr<RSNode>& target, std::shared_ptr<RSPropertyBase> property,
85         const std::shared_ptr<RSPropertyBase>& startValue, const std::shared_ptr<RSPropertyBase>& endValue);
86 
87     void CreateImplicitAnimationWithInitialVelocity(const std::shared_ptr<RSNode>& target,
88         const std::shared_ptr<RSPropertyBase>& property, const std::shared_ptr<RSPropertyBase>& startValue,
89         const std::shared_ptr<RSPropertyBase>& endValue, const std::shared_ptr<RSPropertyBase>& velocity);
90 
91     void CreateImplicitTransition(RSNode& target);
92     void CancelImplicitAnimation(
93         const std::shared_ptr<RSNode>& target, const std::shared_ptr<RSPropertyBase>& property);
94 
95 private:
96     void EndImplicitAnimation();
97     void BeginImplicitCurveAnimation();
98     void BeginImplicitSpringAnimation();
99     void BeginImplicitInterpolatingSpringAnimation();
100     void BeginImplicitCancelAnimation();
101 
102     void CloseImplicitAnimationInner();
103     void ProcessEmptyAnimations(const std::shared_ptr<AnimationFinishCallback>& finishCallback);
104     void ProcessAnimationFinishCallbackGuaranteeTask();
105 
106     void PushImplicitParam(const std::shared_ptr<RSImplicitAnimationParam>& implicitParam);
107     void PopImplicitParam();
108 
109     void SetPropertyValue(std::shared_ptr<RSPropertyBase> property, const std::shared_ptr<RSPropertyBase>& value);
110 
111     void ExecuteWithoutAnimation(const std::function<void()>& callback);
112 
SetRSUIContext(std::weak_ptr<RSUIContext> rsUIContext)113     void SetRSUIContext(std::weak_ptr<RSUIContext> rsUIContext)
114     {
115         rsUIContext_ = rsUIContext;
116     }
117 
118     std::stack<std::tuple<RSAnimationTimingProtocol, RSAnimationTimingCurve,
119         const std::shared_ptr<AnimationFinishCallback>, std::shared_ptr<AnimationRepeatCallback>>>
120         globalImplicitParams_;
121     std::stack<std::shared_ptr<RSImplicitAnimationParam>> implicitAnimationParams_;
122     std::stack<std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>>> implicitAnimations_;
123     std::stack<std::map<std::pair<NodeId, PropertyId>, std::shared_ptr<RSAnimation>>> keyframeAnimations_;
124     std::stack<std::tuple<bool, int, int>> durationKeyframeParams_;
125 
126     bool implicitAnimationDisabled_ { false };
127 
128     std::stack<std::vector<std::pair<std::shared_ptr<RSAnimation>, NodeId>>> interactiveImplicitAnimations_;
129     bool isAddInteractiveAnimator_ { false };
130     std::weak_ptr<RSUIContext> rsUIContext_;
131     friend class RSImplicitAnimatorMap;
132     friend class RSNode;
133     friend class RSUIContext;
134 };
135 } // namespace Rosen
136 } // namespace OHOS
137 
138 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_IMPLICIT_ANIMATOR_H
139