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 #ifndef RENDER_SERVICE_CLIENT_CORE_UI_RS_FRAME_RATE_POLICY_H
16 #define RENDER_SERVICE_CLIENT_CORE_UI_RS_FRAME_RATE_POLICY_H
17 
18 #include <mutex>
19 #include <unordered_map>
20 #include <memory>
21 #include "transaction/rs_hgm_config_data.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 enum class RSPropertyUnit : int16_t;
26 struct AnimDynamicAttribute {
27     int32_t minSpeed = 0;
28     int32_t maxSpeed = 0;
29     int32_t preferredFps = 0;
30 };
31 
32 class RSFrameRatePolicy {
33 public:
34     static RSFrameRatePolicy* GetInstance();
35 
36     void RegisterHgmConfigChangeCallback();
37 
38     int32_t GetPreferredFps(const std::string& scene, float speed);
39     int32_t GetRefreshRateModeName() const;
40     int32_t GetExpectedFrameRate(const RSPropertyUnit unit, float velocity);
41 
42 private:
43     RSFrameRatePolicy() = default;
44     ~RSFrameRatePolicy();
45 
46     void HgmConfigChangeCallback(std::shared_ptr<RSHgmConfigData> configData);
47     void HgmRefreshRateModeChangeCallback(int32_t refreshRateMode);
48 
49     float ppi_ = 1.0f;
50     float xDpi_ = 1.0f;
51     float yDpi_ = 1.0f;
52     int32_t currentRefreshRateModeName_ = -1;
53     std::unordered_map<std::string, std::unordered_map<std::string, AnimDynamicAttribute>> animAttributes_;
54     std::mutex mutex_;
55 };
56 } // namespace Rosen
57 } // namespace OHOS
58 #endif // RENDER_SERVICE_CLIENT_CORE_UI_RS_FRAME_RATE_POLICY_H
59