• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_animatable_property.h"
24 #include "animation/rs_animation_timing_protocol.h"
25 #include "common/rs_common_def.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class RSNode;
30 class AnimationFinishCallback;
31 
32 class RS_EXPORT RSAnimation : public RSAnimationTimingProtocol, public std::enable_shared_from_this<RSAnimation> {
33 public:
34     virtual ~RSAnimation() = default;
35 
36     AnimationId GetId() const;
37 
38     void SetFinishCallback(const std::function<void()>& finishCallback);
39 
40     void Start(const std::shared_ptr<RSNode>& target);
41 
42     const std::weak_ptr<RSNode> GetTarget() const;
43 
44     void Pause();
45 
46     void Resume();
47 
48     void Finish();
49 
50     void Reverse();
51 
52     void SetFraction(float fraction);
53 
54     bool IsStarted() const;
55 
56     bool IsRunning() const;
57 
58     bool IsPaused() const;
59 
60     bool IsFinished() const;
61 
62 protected:
63     enum class AnimationState {
64         INITIALIZED,
65         RUNNING,
66         PAUSED,
67         FINISHED,
68     };
69 
70     RSAnimation();
71 
OnStart()72     virtual void OnStart() {}
73     virtual void OnReverse();
74     virtual void OnPause();
75     virtual void OnResume();
76     virtual void OnFinish();
77     virtual void OnSetFraction(float fraction);
OnUpdateStagingValue(bool isFirstStart)78     virtual void OnUpdateStagingValue(bool isFirstStart) {};
79     virtual RSAnimatableProperty GetProperty() const;
80 
81     void StartInner(const std::shared_ptr<RSNode>& target);
82     bool IsReversed() const;
83     void CallFinishCallback();
84 
85 private:
86     static AnimationId GenerateId();
87     const AnimationId id_;
88 
89     void SetFinishCallback(const std::shared_ptr<AnimationFinishCallback>& finishCallback);
90     void UpdateStagingValue(bool isFirstStart);
91 
92     bool isReversed_ { false };
93     AnimationState state_ { AnimationState::INITIALIZED };
94     std::weak_ptr<RSNode> target_;
95     std::shared_ptr<AnimationFinishCallback> finishCallback_;
96 
97     friend class RSCurveImplicitAnimParam;
98     friend class RSAnimationGroup;
99     friend class RSNode;
100     friend class RSImplicitAnimator;
101 };
102 } // namespace Rosen
103 } // namespace OHOS
104 
105 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_H
106