• 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_FRACTION_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_FRACTION_H
18 
19 #include "atomic"
20 
21 #include "animation/rs_animation_timing_protocol.h"
22 #include "common/rs_macros.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 enum class ForwardDirection {
27     NORMAL = 0,
28     REVERSE,
29 };
30 
31 class RSB_EXPORT RSAnimationFraction : public RSAnimationTimingProtocol {
32 public:
33     RSAnimationFraction();
34     ~RSAnimationFraction() = default;
35 
36     static void Init();
37     static float GetAnimationScale();
38     static void SetAnimationScale(float animationScale);
39     static void OnAnimationScaleChangedCallback(const char *key, const char *value, void *context);
40 
41     // return <fraction, isInStartDelay, isFinished, isRepeatFinished> as tuple
42     std::tuple<float, bool, bool, bool> GetAnimationFraction(int64_t time);
43     void UpdateRemainTimeFraction(float fraction, int remainTime = 0);
44     float GetStartFraction() const;
45     float GetEndFraction() const;
46     void SetDirectionAfterStart(const ForwardDirection& direction);
47     void SetLastFrameTime(int64_t lastFrameTime);
48     int64_t GetLastFrameTime() const;
49     void ResetFraction();
50 
SetRepeatCallbackEnable(bool isEnable)51     void SetRepeatCallbackEnable(bool isEnable)
52     {
53         isRepeatCallbackEnable_ = isEnable;
54     }
55 
GetRepeatCallbackEnable()56     bool GetRepeatCallbackEnable() const
57     {
58         return isRepeatCallbackEnable_;
59     }
60 
61 private:
62     bool IsInRepeat() const;
63     bool IsFinished() const;
64     void UpdateReverseState(bool finish);
65 
66     static std::atomic<float> animationScale_;
67     static bool isInitialized_;
68 
69     ForwardDirection direction_ { ForwardDirection::NORMAL };
70     int64_t playTime_ { 0 };
71     float currentTimeFraction_ { 0.0f };
72     int currentRepeatCount_ { 0 };
73     int64_t runningTime_ { 0 };
74     bool currentIsReverseCycle_ { false };
75     int64_t lastFrameTime_ { -1 };
76     bool isRepeatCallbackEnable_ {false};
77 };
78 } // namespace Rosen
79 } // namespace OHOS
80 
81 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_FRACTION_H
82