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