• 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 
27 #ifdef _WIN32
28 #include <windows.h>
29 #define gettid GetCurrentThreadId
30 #endif
31 
32 #ifdef __APPLE__
33 #define gettid getpid
34 #endif
35 
36 #ifdef __gnu_linux__
37 #include <sys/types.h>
38 #include <sys/syscall.h>
39 #define gettid []() -> int32_t { return static_cast<int32_t>(syscall(SYS_gettid)); }
40 #endif
41 
42 namespace OHOS {
43 namespace Rosen {
44 class RSNode;
45 class AnimationFinishCallback;
46 class RSRenderAnimation;
47 
48 class RSC_EXPORT RSAnimation : public RSAnimationTimingProtocol, public std::enable_shared_from_this<RSAnimation> {
49 public:
50     virtual ~RSAnimation() = default;
51 
52     AnimationId GetId() const;
53 
54     void SetFinishCallback(const std::function<void()>& finishCallback);
55 
56     void Start(const std::shared_ptr<RSNode>& target);
57 
58     const std::weak_ptr<RSNode> GetTarget() const;
59 
60     void Pause();
61 
62     void Resume();
63 
64     void Finish();
65 
66     void Reverse();
67 
68     void SetFraction(float fraction);
69 
70     bool IsStarted() const;
71 
72     bool IsRunning() const;
73 
74     bool IsPaused() const;
75 
76     bool IsFinished() const;
77 
78 protected:
79     enum class AnimationState {
80         INITIALIZED,
81         RUNNING,
82         PAUSED,
83         FINISHED,
84     };
85 
86     RSAnimation();
87 
OnStart()88     virtual void OnStart() {}
89     virtual void OnReverse();
90     virtual void OnPause();
91     virtual void OnResume();
92     virtual void OnFinish();
93     virtual void OnSetFraction(float fraction);
OnUpdateStagingValue(bool isFirstStart)94     virtual void OnUpdateStagingValue(bool isFirstStart) {};
95     virtual PropertyId GetPropertyId() const;
96 
97     void StartInner(const std::shared_ptr<RSNode>& target);
98     bool IsReversed() const;
99     void CallFinishCallback();
100     void UpdateParamToRenderAnimation(const std::shared_ptr<RSRenderAnimation>& animation);
OnCallFinishCallback()101     virtual void OnCallFinishCallback() {}
SetPropertyOnAllAnimationFinish()102     virtual void SetPropertyOnAllAnimationFinish() {}
103 
104 private:
105     static AnimationId GenerateId();
106     const AnimationId id_;
107 
108     void SetFinishCallback(const std::shared_ptr<AnimationFinishCallback>& finishCallback);
109     void UpdateStagingValue(bool isFirstStart);
110     void UIAnimationFinish();
111 
112     bool isReversed_ { false };
113     AnimationState state_ { AnimationState::INITIALIZED };
114     std::weak_ptr<RSNode> target_;
115     std::shared_ptr<AnimationFinishCallback> finishCallback_;
116 
117     friend class RSCurveImplicitAnimParam;
118     friend class RSAnimationGroup;
119     friend class RSNode;
120     friend class RSImplicitAnimator;
121     friend class RSUIAnimationManager;
122 };
123 } // namespace Rosen
124 } // namespace OHOS
125 
126 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_H
127