• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HGM_COMMAND_H
17 #define HGM_COMMAND_H
18 
19 #include <inttypes.h>
20 #include <string>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "screen_manager/screen_types.h"
25 #include "animation/rs_frame_rate_range.h"
26 
27 namespace OHOS::Rosen {
28 
29 constexpr int UNI_APP_PID = -1;
30 constexpr int32_t HGM_REFRESHRATE_MODE_AUTO = -1;
31 constexpr pid_t DEFAULT_PID = 0;
32 constexpr int ADAPTIVE_SYNC_ENABLED = 1;
33 constexpr int32_t SWITCH_SCREEN_SCENE = 1;
34 constexpr int32_t STRING_BUFFER_MAX_SIZE = 256;
35 constexpr int64_t IDEAL_PULSE = 2777778; // 2.777778ms
36 const std::string HGM_CONFIG_TYPE_THERMAL_SUFFIX = "_THERMAL";
37 
38 enum OledRefreshRate {
39     OLED_NULL_HZ = 0,
40     OLED_MIN_HZ = 1,
41     OLED_1_HZ = 1,
42     OLED_10_HZ = 10,
43     OLED_20_HZ = 20,
44     OLED_30_HZ = 30,
45     OLED_40_HZ = 40,
46     OLED_60_HZ = 60,
47     OLED_90_HZ = 90,
48     OLED_120_HZ = 120,
49     OLED_144_HZ = 144,
50     OLED_MAX_HZ = 1000,
51 };
52 
53 enum HgmErrCode {
54     HGM_ERROR = -1,
55 
56     EXEC_SUCCESS = 0,
57 
58     HGM_NO_SCREEN = 100,
59     HGM_BASE_REMOVE_FAILED,
60 
61     XML_PARSER_CREATE_FAIL = 200,
62     XML_FILE_LOAD_FAIL,
63     XML_GET_ROOT_FAIL,
64     XML_PARSE_INTERNAL_FAIL,
65 
66     HGM_SCREEN_MODE_EXIST,
67     HGM_SCREEN_PARAM_ERROR,
68     FINAL_RANGE_NOT_VALID,
69 };
70 
71 enum HgmXmlNode {
72     HGM_XML_UNDEFINED = 0,
73     HGM_XML_PARAM,
74     HGM_XML_PARAMS,
75 };
76 
77 enum class SceneType {
78     SCREEN_RECORD,
79 };
80 
81 enum PointerModeType : int32_t {
82     POINTER_DISENABLED = 0,
83     POINTER_ENABLED = 1,
84 };
85 
86 enum DynamicModeType : int32_t {
87     TOUCH_DISENABLED = 0,
88     TOUCH_ENABLED = 1,
89     TOUCH_EXT_ENABLED = 2, // touch extend program
90 };
91 
92 enum MultiAppStrategyType {
93     USE_MAX,
94     FOLLOW_FOCUS,
95     USE_STRATEGY_NUM,
96 };
97 
98 class PolicyConfigData {
99 public:
100     PolicyConfigData() = default;
101     ~PolicyConfigData() = default;
102 
103     struct StrategyConfig {
104         int32_t min;
105         int32_t max;
106         DynamicModeType dynamicMode;
107         PointerModeType pointerMode;
108         int32_t idleFps;
109         bool isFactor;
110         int32_t drawMin;
111         int32_t drawMax;
112         int32_t down;
113         // Does this game app require Adaptive Sync?
114         int32_t supportAS;
115         // <bufferName, fps>
116         std::unordered_map<std::string, int32_t> bufferFpsMap;
117     };
118     // <"1", StrategyConfig>
119     using StrategyConfigMap = std::unordered_map<std::string, StrategyConfig>;
120 
121     struct SceneConfig {
122         std::string strategy;
123         std::string priority;
124         bool doNotAutoClear;
125         bool disableSafeVote;
126     };
127     // <"SCENE_APP_START_ANIMATION", SceneConfig>
128     using SceneConfigMap = std::unordered_map<std::string, SceneConfig>;
129 
130     // <"LowBright", <30, 60, 120>>
131     using SupportedModeConfig = std::unordered_map<std::string, std::vector<uint32_t>>;
132     // <"LTPO-DEFAULT", SupportedModeConfig>
133     using SupportedModeMap = std::unordered_map<std::string, SupportedModeConfig>;
134 
135     struct DynamicConfig {
136         int32_t min;
137         int32_t max;
138         int32_t preferred_fps;
139     };
140     // <"1", DynamicConfig>
141     using DynamicSetting = std::unordered_map<std::string, DynamicConfig>;
142     // <"translate", DynamicSetting>
143     using DynamicSettingMap = std::unordered_map<std::string, DynamicSetting>;
144 
145     using PageUrlConfig = std::unordered_map<std::string, std::string>;
146     using PageUrlConfigMap = std::unordered_map<std::string, PageUrlConfig>;
147     std::vector<std::string> pageNameList_;
148 
149     struct ScreenSetting {
150         std::string strategy;
151         // <"switch", "1">
152         std::unordered_map<std::string, std::string> ltpoConfig;
153         // <"pkgName", "4">
154         std::unordered_map<std::string, std::string> appList;
155         MultiAppStrategyType multiAppStrategyType;
156         std::string multiAppStrategyName;
157         // <appType, strategyName>
158         std::unordered_map<int32_t, std::string> appTypes;
159         SceneConfigMap sceneList;
160         // <SCENE_APP_START_ANIMATION, placeholder>
161         std::unordered_map<std::string, std::string> gameSceneList;
162         DynamicSettingMap animationDynamicSettings;
163         DynamicSettingMap aceSceneDynamicSettings;
164         int32_t smallSizeArea = -1;
165         int32_t smallSizeLength = -1;
166         DynamicSettingMap smallSizeAnimationDynamicSettings;
167         // <CONFIG_NAME, VALUE>
168         std::unordered_map<std::string, std::string> animationPowerConfig;
169         // <rateTypeName, idleFps>
170         std::unordered_map<std::string, std::string> uiPowerConfig;
171         // <SCENE_APP_START_ANIMATION, placeholder>
172         SceneConfigMap ancoSceneList;
173         // <componentCode, idleFps>
174         std::unordered_map<std::string, int32_t> componentPowerConfig;
175         // <"pkgName", "UnityPlayerSurface">
176         std::unordered_map<std::string, std::string> gameAppNodeList;
177         // <"pageName", min, max>
178         PageUrlConfigMap pageUrlConfig;
179         std::unordered_map<std::string, std::string> performanceConfig;
180     };
181     // <"-1", ScreenSetting>
182     using ScreenConfig = std::unordered_map<std::string, ScreenSetting>;
183     // <"LTPO-DEFAULT", ScreenConfig>
184     using ScreenConfigMap = std::unordered_map<std::string, ScreenConfig>;
185 
186     std::string defaultRefreshRateMode_ = "-1";
187     // <"120", "1">
188     std::vector<std::pair<int32_t, int32_t>> refreshRateForSettings_;
189     std::vector<std::string> appBufferList_;
190     bool xmlCompatibleMode_ = false;
191     bool safeVoteEnabled = true;
192     // <"VIRTUAL_AXX", "4">
193     std::unordered_map<std::string, std::string> virtualDisplayConfigs_;
194     bool virtualDisplaySwitch_;
195     // <"screen0_LTPO", "LTPO-DEFAULT">
196     std::unordered_map<std::string, std::string> screenStrategyConfigs_;
197     std::unordered_map<std::string, std::string> sourceTuningConfig_;
198     std::unordered_map<std::string, std::string> solidLayerConfig_;
199     std::unordered_map<std::string, std::string> hwcSourceTuningConfig_;
200     std::unordered_map<std::string, std::string> hwcSolidLayerConfig_;
201     std::unordered_map<std::string, std::string> videoCallLayerConfig_;
202     // <"pkgName", "1">
203     std::unordered_map<std::string, std::string> hfbcConfig_;
204     StrategyConfigMap strategyConfigs_;
205     ScreenConfigMap screenConfigs_;
206     SupportedModeMap supportedModeConfigs_;
207     bool videoFrameRateVoteSwitch_ = false;
208     // <"pkgName", "1">
209     std::unordered_map<std::string, std::string> videoFrameRateList_;
210 
GetAceSceneDynamicSettingMap(const std::string & screenType,const std::string & settingMode)211     DynamicSettingMap GetAceSceneDynamicSettingMap(const std::string& screenType, const std::string& settingMode)
212     {
213         if (screenConfigs_.count(screenType) && screenConfigs_[screenType].count(settingMode)) {
214             return screenConfigs_[screenType][settingMode].aceSceneDynamicSettings;
215         } else {
216             return {};
217         }
218     }
219 
SettingModeId2XmlModeId(int32_t settingModeId)220     int32_t SettingModeId2XmlModeId(int32_t settingModeId)
221     {
222         if (settingModeId < 0 || settingModeId >= static_cast<int32_t>(refreshRateForSettings_.size())) {
223             return 0;
224         }
225         return refreshRateForSettings_[settingModeId].second;
226     }
227 
XmlModeId2SettingModeId(int32_t xmlModeId)228     int32_t XmlModeId2SettingModeId(int32_t xmlModeId)
229     {
230         auto iter = std::find_if(refreshRateForSettings_.begin(), refreshRateForSettings_.end(),
231             [=] (auto nameModeId) { return nameModeId.second == xmlModeId; });
232         if (iter != refreshRateForSettings_.end()) {
233             return static_cast<int32_t>(iter - refreshRateForSettings_.begin());
234         }
235         return 0;
236     }
237 
GetRefreshRateModeName(int32_t refreshRateModeId)238     int32_t GetRefreshRateModeName(int32_t refreshRateModeId)
239     {
240         auto iter = std::find_if(refreshRateForSettings_.begin(), refreshRateForSettings_.end(),
241             [=] (auto nameModeId) { return nameModeId.second == refreshRateModeId; });
242         if (iter != refreshRateForSettings_.end()) {
243             return iter->first;
244         }
245         return 0;
246     }
247 };
248 } // namespace OHOS
249 #endif // HGM_COMMAND_H