• 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_ANIMATION_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_H
18 
19 #include <memory>
20 #include <unistd.h>
21 
22 #include "animation/rs_animation_common.h"
23 #include "animation/rs_animation_timing_protocol.h"
24 #include "common/rs_common_def.h"
25 #include "modifier/rs_modifier_type.h"
26 #include "modifier/rs_property.h"
27 
28 #ifdef _WIN32
29 #include <windows.h>
30 #define gettid GetCurrentThreadId
31 #endif
32 
33 #ifdef __APPLE__
34 #define gettid getpid
35 #endif
36 
37 #ifdef __gnu_linux__
38 #include <sys/types.h>
39 #include <sys/syscall.h>
40 #define gettid []() -> int32_t { return static_cast<int32_t>(syscall(SYS_gettid)); }
41 #endif
42 
43 namespace OHOS {
44 namespace Rosen {
45 class RSNode;
46 class AnimationFinishCallback;
47 class AnimationRepeatCallback;
48 class RSRenderAnimation;
49 
50 class RSC_EXPORT RSAnimation : public RSAnimationTimingProtocol, public std::enable_shared_from_this<RSAnimation> {
51 public:
52     virtual ~RSAnimation();
53 
54     AnimationId GetId() const;
55 
56     void SetFinishCallback(const std::function<void()>& finishCallback);
57 
58     void Start(const std::shared_ptr<RSNode>& target);
59 
60     const std::weak_ptr<RSNode> GetTarget() const;
61 
62     void Pause();
63 
64     void Resume();
65 
66     void Finish();
67 
68     void Reverse();
69 
70     void SetFraction(float fraction);
71 
72     bool IsStarted() const;
73 
74     bool IsRunning() const;
75 
76     bool IsPaused() const;
77 
78     bool IsFinished() const;
79 
80     bool IsUiAnimation() const;
81 
82     void InteractivePause();
83 
84     void InteractiveContinue();
85 
86     void InteractiveFinish(RSInteractiveAnimationPosition pos);
87 
88     void InteractiveReverse();
89 
90     void InteractiveSetFraction(float fraction);
91 
IsSupportInteractiveAnimator()92     virtual bool IsSupportInteractiveAnimator() { return true; }
93 
94     std::string DumpAnimation() const;
DumpAnimationInfo(std::string & dumpInfo)95     virtual void DumpAnimationInfo(std::string& dumpInfo) const {}
96 protected:
97     enum class AnimationState {
98         INITIALIZED,
99         RUNNING,
100         PAUSED,
101         FINISHED,
102     };
103 
104     RSAnimation();
105 
OnStart()106     virtual void OnStart() {}
107     virtual void OnReverse();
108     virtual void OnPause();
109     virtual void OnResume();
110     virtual void OnFinish();
111     virtual void OnSetFraction(float fraction);
OnUpdateStagingValue(bool isFirstStart)112     virtual void OnUpdateStagingValue(bool isFirstStart) {};
UpdateStagingValueOnInteractiveFinish(RSInteractiveAnimationPosition pos)113     virtual void UpdateStagingValueOnInteractiveFinish(RSInteractiveAnimationPosition pos) {};
114     virtual PropertyId GetPropertyId() const;
115 
116     void StartInner(const std::shared_ptr<RSNode>& target);
117     bool IsReversed() const;
118     void UpdateParamToRenderAnimation(const std::shared_ptr<RSRenderAnimation>& animation);
OnCallFinishCallback()119     virtual void OnCallFinishCallback() {}
SetPropertyOnAllAnimationFinish()120     virtual void SetPropertyOnAllAnimationFinish() {}
121 
122     void StartCustomAnimation(const std::shared_ptr<RSRenderAnimation>& animation);
SetInitialVelocity(const std::shared_ptr<RSPropertyBase> & velocity)123     virtual void SetInitialVelocity(const std::shared_ptr<RSPropertyBase>& velocity) {};
124 
125 private:
126     static AnimationId GenerateId();
127     const AnimationId id_;
128 
129     void SetFinishCallback(const std::shared_ptr<AnimationFinishCallback>& finishCallback);
130     void SetRepeatCallback(const std::shared_ptr<AnimationRepeatCallback>& repeatCallback);
131     void SetInteractiveFinishCallback(const std::shared_ptr<InteractiveAnimatorFinishCallback>& finishCallback);
132     void UpdateStagingValue(bool isFirstStart);
133     void CallFinishCallback();
134     void CallRepeatCallback();
135     void CallLogicallyFinishCallback();
SetZeroThreshold(const float zeroThreshold)136     virtual void SetZeroThreshold(const float zeroThreshold) {};
137 
138     bool isReversed_ { false };
139     AnimationState state_ { AnimationState::INITIALIZED };
140     std::weak_ptr<RSNode> target_;
141     std::shared_ptr<AnimationFinishCallback> finishCallback_;
142     std::shared_ptr<AnimationRepeatCallback> repeatCallback_;
143     std::shared_ptr<InteractiveAnimatorFinishCallback> interactiveFinishCallback_;
144     std::shared_ptr<RSRenderAnimation> uiAnimation_;
145 
146     friend class RSCurveImplicitAnimParam;
147     friend class RSAnimationGroup;
148     friend class RSNode;
149     friend class RSImplicitAnimator;
150     friend class RSInteractiveImplictAnimator;
151     friend class RSUIContext;
152 };
153 } // namespace Rosen
154 } // namespace OHOS
155 
156 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_H
157