1 /*
2  * Copyright (c) 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_FRAME_RATE_FRAME_RATE_MANAGER_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_FRAME_RATE_FRAME_RATE_MANAGER_H
18 
19 #include <unordered_map>
20 #include <algorithm>
21 
22 #include "base/memory/ace_type.h"
23 #include "base/utils/noncopyable.h"
24 
25 namespace OHOS::Ace::NG {
26 constexpr int32_t UI_ANIMATION_FRAME_RATE_TYPE = 2;
27 constexpr int32_t DISPLAY_SYNC_FRAME_RATE_TYPE = 3;
28 constexpr int32_t ACE_COMPONENT_FRAME_RATE_TYPE = 4;
29 
30 class FrameRateManager : public virtual AceType {
31     DECLARE_ACE_TYPE(FrameRateManager, AceType);
32 
33 public:
34     FrameRateManager() = default;
35     ~FrameRateManager() override = default;
36 
37     bool IsRateChanged();
38 
39     void SetIsRateChanged(bool isChanged);
40 
41     void AddNodeRate(int32_t nodeId, int32_t rate = 0);
42 
43     void RemoveNodeRate(int32_t nodeId);
44 
45     void UpdateNodeRate(int32_t nodeId, int32_t rate);
46 
47     void SetAnimateRate(int32_t rate);
48 
49     void SetDisplaySyncRate(int32_t displaySyncRate);
50 
51     int32_t GetDisplaySyncRate() const;
52 
53     std::pair<int32_t, int32_t> GetExpectedRate();
54 
55 private:
56     std::unordered_map<int32_t, int32_t> nodeRateMap_;
57     bool isRateChanged_ = false;
58     int32_t displaySyncRate_ = 0;
59     int32_t animateRate_ = 0;
60 
61     ACE_DISALLOW_COPY_AND_MOVE(FrameRateManager);
62 };
63 } // namespace OHOS::Ace::NG
64 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MANAGER_FRAME_RATE_FRAME_RATE_MANAGER_H
65