• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_INTERACTIVE_IMPLICT_ANIMATOR_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_INTERACTIVE_IMPLICT_ANIMATOR_H
18 
19 #include <vector>
20 
21 #include "animation/rs_animation.h"
22 #include "animation/rs_animation_timing_curve.h"
23 #include "animation/rs_animation_timing_protocol.h"
24 #include "common/rs_macros.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 
29 enum class RSInteractiveAnimationState {
30     INACTIVE,
31     ACTIVE,
32     RUNNING,
33     PAUSED,
34 };
35 
36 class RSC_EXPORT RSInteractiveImplictAnimator : public std::enable_shared_from_this<RSInteractiveImplictAnimator> {
37 public:
38     virtual ~RSInteractiveImplictAnimator();
39     static std::shared_ptr<RSInteractiveImplictAnimator> Create(
40         const RSAnimationTimingProtocol& timingProtocol, const RSAnimationTimingCurve& timingCurve);
41     static std::shared_ptr<RSInteractiveImplictAnimator> Create(
42         const std::shared_ptr<RSUIContext> rsUIContext, const RSAnimationTimingProtocol& timingProtocol,
43         const RSAnimationTimingCurve& timingCurve);
44     /*
45      * @brief add animations form callback
46      * @param callback use property set change or RSNode::Animate to create aniamtion
47      *                 property set use animator protocal and curve create animation
48      *                 RSNode::Animate use self Animate protocal and curve crate aniamtion
49      *
50      */
51     size_t AddImplictAnimation(std::function<void()> callback);
52     /*
53      * @brief add animations form callback
54      * @param callback use RSNode::Animate to create aniamtion
55      *                 just use RSNode::Animate can create animation
56      *                 RSNode::Animate use self Animate protocal and curve crate aniamtion
57      *
58      */
59     size_t AddAnimation(std::function<void()> callback);
60 
61     // aniamtor operation
62     int32_t StartAnimation();
63     void PauseAnimation();
64     void ContinueAnimation();
65 
66     /*
67      * @brief finsih all animation in animator
68      * @param position position is START or CURRENT or END
69      *                  START all animaton in animator finish on startvalue and sync stagevalue
70      *                  CURRENT all animaton in animator finish on currentvalue and sync stagevalue
71      *                  START all animaton in animator finish on endvalue and sync stagevalue
72      */
73     void FinishAnimation(RSInteractiveAnimationPosition position);
74     void ReverseAnimation();
75 
76     /*
77      * @brief set value fraction for all animations
78      *          but just support curve animation and interpolating spring aniamtion
79      *          curve animation not support step interpolater and custom interpolater
80      * @param fraction animation value faraction
81      */
82     void SetFraction(float fraction);
83     float GetFraction();
84 
GetStatus()85     RSInteractiveAnimationState GetStatus() const
86     {
87         return state_;
88     }
89 
90     /*
91      * @brief set callback of all animation finish
92      * @param finishCallback all animations in animator use this finishcallback, just one
93      */
94     void SetFinishCallBack(const std::function<void()>& finishCallback);
95 protected:
96     explicit RSInteractiveImplictAnimator(
97         const std::shared_ptr<RSUIContext> rsUIContext, const RSAnimationTimingProtocol& timingProtocol,
98         const RSAnimationTimingCurve& timingCurve);
99 private:
100     static InteractiveImplictAnimatorId GenerateId();
101     const InteractiveImplictAnimatorId id_;
102 
103     static void InitUniRenderEnabled();
104     bool IsUniRenderEnabled() const;
105     void FinishOnCurrent();
106     void CallFinishCallback();
107     void AddCommand(std::unique_ptr<RSCommand>& command, bool isRenderServiceCommand = false,
108         FollowType followType = FollowType::NONE, NodeId nodeId = 0) const;
109     std::shared_ptr<InteractiveAnimatorFinishCallback> GetAnimatorFinishCallback();
110 
111     RSInteractiveAnimationState state_ { RSInteractiveAnimationState::INACTIVE };
112     std::weak_ptr<RSUIContext> rsUIContext_;
113     RSAnimationTimingProtocol timingProtocol_;
114     RSAnimationTimingCurve timingCurve_;
115 
116     std::vector<std::pair<std::weak_ptr<RSAnimation>, NodeId>> animations_;
117     std::function<void()> finishCallback_;
118     std::weak_ptr<InteractiveAnimatorFinishCallback> animatorCallback_;
119     AnimationId fractionAnimationId_ { 0 };
120     NodeId fractionNodeId_ { 0 };
121 };
122 } // namespace Rosen
123 } // namespace OHOS
124 
125 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_INTERACTIVE_IMPLICT_ANIMATOR_H
126