• 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_RENDER_ANIMATION_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_ANIMATION_H
18 
19 #ifdef ROSEN_OHOS
20 #include <parcel.h>
21 #include <refbase.h>
22 #endif
23 #include "animation/rs_animatable_property.h"
24 #include "animation/rs_animation_common.h"
25 #include "animation/rs_animation_fraction.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 class RSRenderNode;
30 
31 enum class AnimationState {
32     INITIALIZED,
33     RUNNING,
34     PAUSED,
35     FINISHED,
36 };
37 
38 #ifdef ROSEN_OHOS
39 class RSRenderAnimation : public Parcelable {
40 #else
41 class RSRenderAnimation {
42 #endif
43 public:
44     virtual ~RSRenderAnimation() = default;
45     AnimationId GetAnimationId() const;
46     void Start();
47     void Finish();
48     void Pause();
49     void Resume();
50     void SetFraction(float fraction);
51     void SetReversed(bool isReversed);
52 #ifdef ROSEN_OHOS
53     virtual bool Marshalling(Parcel& parcel) const override;
54 #endif
55     bool Animate(int64_t time);
56 
57     bool IsStarted() const;
58     bool IsRunning() const;
59     bool IsPaused() const;
60     bool IsFinished() const;
61 
SetDuration(int value)62     void SetDuration(int value)
63     {
64         animationFraction_.SetDuration(value);
65     }
66 
GetDuration()67     int GetDuration() const
68     {
69         return animationFraction_.GetDuration();
70     }
71 
SetStartDelay(int value)72     void SetStartDelay(int value)
73     {
74         animationFraction_.SetStartDelay(value);
75     }
76 
GetStartDelay()77     int GetStartDelay() const
78     {
79         return animationFraction_.GetStartDelay();
80     }
81 
SetRepeatCount(int value)82     void SetRepeatCount(int value)
83     {
84         animationFraction_.SetRepeatCount(value);
85     }
86 
GetRepeatCount()87     int GetRepeatCount() const
88     {
89         return animationFraction_.GetRepeatCount();
90     }
91 
SetSpeed(float value)92     void SetSpeed(float value)
93     {
94         animationFraction_.SetSpeed(value);
95     }
96 
GetSpeed()97     float GetSpeed() const
98     {
99         return animationFraction_.GetSpeed();
100     }
101 
SetAutoReverse(bool value)102     void SetAutoReverse(bool value)
103     {
104         animationFraction_.SetAutoReverse(value);
105     }
106 
GetAutoReverse()107     bool GetAutoReverse() const
108     {
109         return animationFraction_.GetAutoReverse();
110     }
111 
SetFillMode(const FillMode & value)112     void SetFillMode(const FillMode& value)
113     {
114         animationFraction_.SetFillMode(value);
115     }
116 
GetFillMode()117     const FillMode& GetFillMode() const
118     {
119         return animationFraction_.GetFillMode();
120     }
121 
SetDirection(bool isForward)122     void SetDirection(bool isForward)
123     {
124         animationFraction_.SetDirection(isForward);
125     }
126 
GetDirection()127     bool GetDirection() const
128     {
129         return animationFraction_.GetDirection();
130     }
131 
132     void Attach(RSRenderNode* renderNode);
133     void Detach();
134     RSRenderNode* GetTarget() const;
135 
136     virtual RSAnimatableProperty GetProperty() const;
137 
138 protected:
139     explicit RSRenderAnimation(AnimationId id);
140     RSRenderAnimation() = default;
141 #ifdef ROSEN_OHOS
142     virtual bool ParseParam(Parcel& parcel);
143 #endif
144     void SetFractionInner(float fraction);
145 
146     virtual void OnSetFraction(float fraction);
147 
OnAttach()148     virtual void OnAttach() {}
149 
OnDetach()150     virtual void OnDetach() {}
151 
OnAnimate(float fraction)152     virtual void OnAnimate(float fraction) {}
153 
OnRemoveOnCompletion()154     virtual void OnRemoveOnCompletion() {}
155 
156 private:
157     void ProcessFillModeOnStart(float startFraction);
158 
159     void ProcessFillModeOnFinish(float endFraction);
160 
161     AnimationId id_ = 0;
162     RSAnimationFraction animationFraction_;
163     AnimationState state_ { AnimationState::INITIALIZED };
164     bool firstToRunning_ { false };
165     RSRenderNode* target_ { nullptr };
166 };
167 } // namespace Rosen
168 } // namespace OHOS
169 
170 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_RENDER_ANIMATION_H
171