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_TIMING_PROTOCOL_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_TIMING_PROTOCOL_H
18 
19 #include "common/rs_common_def.h"
20 #include "rs_frame_rate_range.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 enum class FillMode {
25     NONE,
26     FORWARDS,
27     BACKWARDS,
28     BOTH,
29 };
30 
31 enum class FinishCallbackType {
32     TIME_SENSITIVE,
33     TIME_INSENSITIVE,
34     LOGICALLY,
35 };
36 
37 class RSB_EXPORT RSAnimationTimingProtocol {
38 public:
39     RSAnimationTimingProtocol() = default;
RSAnimationTimingProtocol(int duration)40     RSAnimationTimingProtocol(int duration) : duration_(duration) {}
41     virtual ~RSAnimationTimingProtocol() = default;
42 
SetDuration(int duration)43     void SetDuration(int duration)
44     {
45         duration_ = duration;
46     }
47 
SetStartDelay(int startDelay)48     void SetStartDelay(int startDelay)
49     {
50         startDelay_ = startDelay;
51     }
52 
SetSpeed(float speed)53     void SetSpeed(float speed)
54     {
55         speed_ = speed;
56     }
57 
SetRepeatCount(int repeatCount)58     void SetRepeatCount(int repeatCount)
59     {
60         repeatCount_ = repeatCount;
61     }
62 
SetAutoReverse(bool autoReverse)63     void SetAutoReverse(bool autoReverse)
64     {
65         autoReverse_ = autoReverse;
66     }
67 
SetFillMode(const FillMode & fillMode)68     void SetFillMode(const FillMode& fillMode)
69     {
70         fillMode_ = fillMode;
71     }
72 
SetDirection(bool isForward)73     void SetDirection(bool isForward)
74     {
75         isForward_ = isForward;
76     }
77 
SetFrameRateRange(FrameRateRange range)78     void SetFrameRateRange(FrameRateRange range)
79     {
80         range_ = range;
81     }
82 
SetFinishCallbackType(FinishCallbackType finishCallbackType)83     void SetFinishCallbackType(FinishCallbackType finishCallbackType)
84     {
85         finishCallbackType_ = finishCallbackType;
86     }
87 
GetDuration()88     int GetDuration() const
89     {
90         return duration_;
91     }
92 
GetStartDelay()93     int GetStartDelay() const
94     {
95         return startDelay_;
96     }
97 
GetSpeed()98     float GetSpeed() const
99     {
100         return speed_;
101     }
102 
GetRepeatCount()103     int GetRepeatCount() const
104     {
105         return repeatCount_;
106     }
107 
GetAutoReverse()108     bool GetAutoReverse() const
109     {
110         return autoReverse_;
111     }
112 
GetFillMode()113     const FillMode& GetFillMode() const
114     {
115         return fillMode_;
116     }
117 
GetDirection()118     bool GetDirection() const
119     {
120         return isForward_;
121     }
122 
GetFrameRateRange()123     FrameRateRange GetFrameRateRange() const
124     {
125         return range_;
126     }
127 
GetFinishCallbackType()128     FinishCallbackType GetFinishCallbackType() const
129     {
130         return finishCallbackType_;
131     }
132 
133     static const RSAnimationTimingProtocol DEFAULT;
134     static const RSAnimationTimingProtocol IMMEDIATE;
135 
136 protected:
137     int duration_ { 300 };
138     int startDelay_ { 0 };
139     float speed_ { 1.0f };
140     int repeatCount_ { 1 };
141     bool autoReverse_ { false };
142     FillMode fillMode_ { FillMode::FORWARDS };
143     bool isForward_ { true };
144     FrameRateRange range_ = {0, 0, 0};
145     FinishCallbackType finishCallbackType_ { FinishCallbackType::TIME_SENSITIVE };
146 };
147 } // namespace Rosen
148 } // namespace OHOS
149 
150 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_TIMING_PROTOCOL_H
151