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 33 enum OledRefreshRate { 34 OLED_NULL_HZ = 0, 35 OLED_MIN_HZ = 1, 36 OLED_1_HZ = 1, 37 OLED_10_HZ = 10, 38 OLED_20_HZ = 20, 39 OLED_30_HZ = 30, 40 OLED_40_HZ = 40, 41 OLED_60_HZ = 60, 42 OLED_90_HZ = 90, 43 OLED_120_HZ = 120, 44 OLED_144_HZ = 144, 45 OLED_MAX_HZ = 1000, 46 }; 47 48 enum HgmErrCode { 49 HGM_ERROR = -1, 50 51 EXEC_SUCCESS = 0, 52 53 HGM_NO_SCREEN = 100, 54 HGM_BASE_REMOVE_FAILED, 55 56 XML_PARSER_CREATE_FAIL = 200, 57 XML_FILE_LOAD_FAIL, 58 XML_GET_ROOT_FAIL, 59 XML_PARSE_INTERNAL_FAIL, 60 61 HGM_SCREEN_MODE_EXIST, 62 HGM_SCREEN_PARAM_ERROR, 63 FINAL_RANGE_NOT_VALID, 64 }; 65 66 enum HgmXmlNode { 67 HGM_XML_UNDEFINED = 0, 68 HGM_XML_PARAM, 69 HGM_XML_PARAMS, 70 }; 71 72 enum class SceneType { 73 SCREEN_RECORD, 74 }; 75 76 enum DynamicModeType : int32_t { 77 TOUCH_DISENABLED = 0, 78 TOUCH_ENABLED = 1, 79 TOUCH_EXT_ENABLED = 2, // touch extend program 80 }; 81 82 enum MultiAppStrategyType { 83 USE_MAX, 84 FOLLOW_FOCUS, 85 USE_STRATEGY_NUM, 86 }; 87 88 class PolicyConfigData { 89 public: 90 PolicyConfigData() = default; 91 ~PolicyConfigData() = default; 92 93 struct StrategyConfig { 94 int32_t min; 95 int32_t max; 96 DynamicModeType dynamicMode; 97 bool isFactor; 98 int32_t drawMin; 99 int32_t drawMax; 100 int32_t down; 101 // <bufferName, fps> 102 std::vector<std::pair<std::string, int32_t>> appBufferList; 103 std::vector<std::string> appBufferBlackList; 104 }; 105 // <"1", StrategyConfig> 106 using StrategyConfigMap = std::unordered_map<std::string, StrategyConfig>; 107 108 struct SceneConfig { 109 std::string strategy; 110 std::string priority; 111 }; 112 // <"SCENE_APP_START_ANIMATION", SceneConfig> 113 using SceneConfigMap = std::unordered_map<std::string, SceneConfig>; 114 115 struct DynamicConfig { 116 int32_t min; 117 int32_t max; 118 int32_t preferred_fps; 119 }; 120 // <"1", DynamicConfig> 121 using DynamicSetting = std::unordered_map<std::string, DynamicConfig>; 122 // <"translate", DynamicSetting> 123 using DynamicSettingMap = std::unordered_map<std::string, DynamicSetting>; 124 125 struct ScreenSetting { 126 std::string strategy; 127 // <"switch", "1"> 128 std::unordered_map<std::string, std::string> ltpoConfig; 129 // <"pkgName", "4"> 130 std::unordered_map<std::string, std::string> appList; 131 MultiAppStrategyType multiAppStrategyType; 132 std::string multiAppStrategyName; 133 // <appType, strategyName> 134 std::unordered_map<int32_t, std::string> appTypes; 135 SceneConfigMap sceneList; 136 // <SCENE_APP_START_ANIMATION, placeholder> 137 std::unordered_map<std::string, std::string> gameSceneList; 138 DynamicSettingMap animationDynamicSettings; 139 DynamicSettingMap aceSceneDynamicSettings; 140 // <CONFIG_NAME, VALUE> 141 std::unordered_map<std::string, std::string> animationPowerConfig; 142 // <rateTypeName, idleFps> 143 std::unordered_map<std::string, std::string> uiPowerConfig; 144 // <SCENE_APP_START_ANIMATION, placeholder> 145 SceneConfigMap ancoSceneList; 146 }; 147 // <"-1", ScreenSetting> 148 using ScreenConfig = std::unordered_map<std::string, ScreenSetting>; 149 // <"LTPO-DEFAULT", ScreenConfig> 150 using ScreenConfigMap = std::unordered_map<std::string, ScreenConfig>; 151 152 std::string defaultRefreshRateMode_ = "-1"; 153 // <"120", "1"> 154 std::vector<std::pair<int32_t, int32_t>> refreshRateForSettings_; 155 std::vector<std::string> appBufferList_; 156 bool xmlCompatibleMode_ = false; 157 bool safeVoteEnabled = true; 158 // <"VIRTUAL_AXX", "4"> 159 std::unordered_map<std::string, std::string> virtualDisplayConfigs_; 160 bool virtualDisplaySwitch_; 161 // <"screen0_LTPO", "LTPO-DEFAULT"> 162 std::unordered_map<std::string, std::string> screenStrategyConfigs_; 163 std::unordered_map<std::string, std::string> sourceTuningConfig_; 164 std::unordered_map<std::string, std::string> solidLayerConfig_; 165 StrategyConfigMap strategyConfigs_; 166 ScreenConfigMap screenConfigs_; 167 bool videoFrameRateVoteSwitch_ = false; 168 // <"pkgName", "1"> 169 std::unordered_map<std::string, std::string> videoFrameRateList_; 170 GetAceSceneDynamicSettingMap(const std::string & screenType,const std::string & settingMode)171 DynamicSettingMap GetAceSceneDynamicSettingMap(const std::string& screenType, const std::string& settingMode) 172 { 173 if (screenConfigs_.count(screenType) && screenConfigs_[screenType].count(settingMode)) { 174 return screenConfigs_[screenType][settingMode].aceSceneDynamicSettings; 175 } else { 176 return {}; 177 } 178 } 179 SettingModeId2XmlModeId(int32_t settingModeId)180 int32_t SettingModeId2XmlModeId(int32_t settingModeId) 181 { 182 if (settingModeId < 0 || settingModeId >= static_cast<int32_t>(refreshRateForSettings_.size())) { 183 return 0; 184 } 185 return refreshRateForSettings_[settingModeId].second; 186 } 187 XmlModeId2SettingModeId(int32_t xmlModeId)188 int32_t XmlModeId2SettingModeId(int32_t xmlModeId) 189 { 190 auto iter = std::find_if(refreshRateForSettings_.begin(), refreshRateForSettings_.end(), 191 [=] (auto nameModeId) { return nameModeId.second == xmlModeId; }); 192 if (iter != refreshRateForSettings_.end()) { 193 return static_cast<int32_t>(iter - refreshRateForSettings_.begin()); 194 } 195 return 0; 196 } 197 GetRefreshRateModeName(int32_t refreshRateModeId)198 int32_t GetRefreshRateModeName(int32_t refreshRateModeId) 199 { 200 auto iter = std::find_if(refreshRateForSettings_.begin(), refreshRateForSettings_.end(), 201 [=] (auto nameModeId) { return nameModeId.second == refreshRateModeId; }); 202 if (iter != refreshRateForSettings_.end()) { 203 return iter->first; 204 } 205 return 0; 206 } 207 }; 208 } // namespace OHOS 209 #endif // HGM_COMMAND_H