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 #include "screen_scene_config.h"
17
18 #include <climits>
19 #include <cstdint>
20 #include <cstdlib>
21 #include <libxml/globals.h>
22 #include <libxml/xmlstring.h>
23 #include <map>
24 #include <string>
25 #include <utility>
26 #include <vector>
27
28 #include "config_policy_utils.h"
29 #include "fold_screen_state_internel.h"
30 #include "include/core/SkMatrix.h"
31 #include "include/core/SkPath.h"
32 #include "include/core/SkPathMeasure.h"
33 #include "include/utils/SkParsePath.h"
34 #include "window_manager_hilog.h"
35
36 namespace OHOS::Rosen {
37 namespace {
38 constexpr uint32_t NO_WATERFALL_DISPLAY_COMPRESSION_SIZE = 0;
39 constexpr uint32_t DISPLAY_PHYSICAL_SIZE = 2;
40 constexpr uint32_t SCROLLABLE_PARAM_SIZE = 2;
41 enum XmlNodeElement {
42 DPI = 0,
43 SUB_DPI,
44 IS_WATERFALL_DISPLAY,
45 CURVED_SCREEN_BOUNDARY,
46 CURVED_AREA_IN_LANDSCAPE,
47 IS_CURVED_COMPRESS_ENABLED,
48 BUILD_IN_DEFAULT_ORIENTATION,
49 DEFAULT_DEVICE_ROTATION_OFFSET,
50 DEFAULT_DISPLAY_CUTOUT_PATH,
51 SUB_DISPLAY_CUTOUT_PATH,
52 HALL_SWITCH_APP,
53 PACKAGE_NAME,
54 ROTATION_POLICY,
55 DEFAULT_ROTATION_POLICY,
56 SCREEN_SNAPSHOT_BUNDLE_NAME,
57 SCREEN_SNAPSHOT_ABILITY_NAME,
58 IS_RIGHT_POWER_BUTTON,
59 SUPPORT_ROTATE_WITH_SCREEN,
60 EXTERNAL_SCREEN_DEFAULT_MODE,
61 CAST_BUNDLE_NAME,
62 CAST_ABILITY_NAME,
63 PHYSICAL_DISPLAY_RESOLUTION,
64 SCROLLABLE_PARAM,
65 IS_SUPPORT_CAPTURE,
66 IS_SUPPORT_OFFSCREEN_RENDERING,
67 OFF_SCREEN_PPI_THRESHOLD,
68 PC_MODE_DPI,
69 SUPPORT_DURING_CALL
70 };
71 }
72
73 std::map<std::string, bool> ScreenSceneConfig::enableConfig_;
74 std::map<std::string, std::vector<int>> ScreenSceneConfig::intNumbersConfig_;
75 std::map<std::string, std::string> ScreenSceneConfig::stringConfig_;
76 std::map<std::string, std::vector<std::string>> ScreenSceneConfig::stringListConfig_;
77 std::map<uint64_t, std::vector<DMRect>> ScreenSceneConfig::cutoutBoundaryRectMap_;
78 std::vector<DisplayPhysicalResolution> ScreenSceneConfig::displayPhysicalResolution_;
79 std::map<FoldDisplayMode, ScrollableParam> ScreenSceneConfig::scrollableParams_;
80 std::vector<DMRect> ScreenSceneConfig::subCutoutBoundaryRect_;
81 bool ScreenSceneConfig::isWaterfallDisplay_ = false;
82 bool ScreenSceneConfig::isSupportCapture_ = false;
83 bool ScreenSceneConfig::isScreenCompressionEnableInLandscape_ = false;
84 bool ScreenSceneConfig::isSupportOffScreenRendering_ = false;
85 uint32_t ScreenSceneConfig::curvedAreaInLandscape_ = 0;
86 uint32_t ScreenSceneConfig::offScreenPPIThreshold_ = 0;
87 std::map<int32_t, std::string> ScreenSceneConfig::xmlNodeMap_ = {
88 {DPI, "dpi"},
89 {SUB_DPI, "subDpi"},
90 {IS_WATERFALL_DISPLAY, "isWaterfallDisplay"},
91 {CURVED_SCREEN_BOUNDARY, "curvedScreenBoundary"},
92 {CURVED_AREA_IN_LANDSCAPE, "waterfallAreaCompressionSizeWhenHorzontal"},
93 {IS_CURVED_COMPRESS_ENABLED, "isWaterfallAreaCompressionEnableWhenHorizontal"},
94 {BUILD_IN_DEFAULT_ORIENTATION, "buildInDefaultOrientation"},
95 {DEFAULT_DEVICE_ROTATION_OFFSET, "defaultDeviceRotationOffset"},
96 {DEFAULT_DISPLAY_CUTOUT_PATH, "defaultDisplayCutoutPath"},
97 {SUB_DISPLAY_CUTOUT_PATH, "subDisplayCutoutPath"},
98 {HALL_SWITCH_APP, "hallSwitchApp"},
99 {PACKAGE_NAME, "packageName"},
100 {ROTATION_POLICY, "rotationPolicy"},
101 {DEFAULT_ROTATION_POLICY, "defaultRotationPolicy"},
102 {SCREEN_SNAPSHOT_BUNDLE_NAME, "screenSnapshotBundleName"},
103 {SCREEN_SNAPSHOT_ABILITY_NAME, "screenSnapshotAbilityName"},
104 {IS_RIGHT_POWER_BUTTON, "isRightPowerButton"},
105 {SUPPORT_ROTATE_WITH_SCREEN, "supportRotateWithSensor"},
106 {EXTERNAL_SCREEN_DEFAULT_MODE, "externalScreenDefaultMode"},
107 {CAST_BUNDLE_NAME, "castBundleName"},
108 {CAST_ABILITY_NAME, "castAbilityName"},
109 {PHYSICAL_DISPLAY_RESOLUTION, "physicalDisplayResolution"},
110 {SCROLLABLE_PARAM, "scrollableParam"},
111 {IS_SUPPORT_CAPTURE, "isSupportCapture"},
112 {IS_SUPPORT_OFFSCREEN_RENDERING, "isSupportOffScreenRendering"},
113 {OFF_SCREEN_PPI_THRESHOLD, "offScreenPPIThreshold"},
114 {PC_MODE_DPI, "pcModeDpi"},
115 {SUPPORT_DURING_CALL, "supportDuringCall"}
116 };
117
118
Split(std::string str,std::string pattern)119 std::vector<std::string> ScreenSceneConfig::Split(std::string str, std::string pattern)
120 {
121 std::vector<std::string> result;
122 str += pattern;
123 int32_t length = static_cast<int32_t>(str.size());
124 for (int32_t i = 0; i < length; i++) {
125 int32_t position = static_cast<int32_t>(str.find(pattern, i));
126 if (position < length) {
127 std::string tmp = str.substr(i, position - i);
128 result.push_back(tmp);
129 i = position + static_cast<int32_t>(pattern.size()) - 1;
130 }
131 }
132 return result;
133 }
134
IsNumber(std::string str)135 bool ScreenSceneConfig::IsNumber(std::string str)
136 {
137 if (str.size() == 0) {
138 return false;
139 }
140 for (int32_t i = 0; i < static_cast<int32_t>(str.size()); i++) {
141 if (str.at(i) < '0' || str.at(i) > '9') {
142 return false;
143 }
144 }
145 return true;
146 }
147
GetConfigPath(const std::string & configFileName)148 std::string ScreenSceneConfig::GetConfigPath(const std::string& configFileName)
149 {
150 char buf[PATH_MAX + 1];
151 char* configPath = GetOneCfgFile(configFileName.c_str(), buf, PATH_MAX + 1);
152 char tmpPath[PATH_MAX + 1] = { 0 };
153 if (!configPath || strlen(configPath) == 0 || strlen(configPath) > PATH_MAX || !realpath(configPath, tmpPath)) {
154 TLOGI(WmsLogTag::DMS, "can not get customization config file");
155 return "/system/" + configFileName;
156 }
157 return std::string(tmpPath);
158 }
159
LoadConfigXml()160 bool ScreenSceneConfig::LoadConfigXml()
161 {
162 auto configFilePath = GetConfigPath("etc/window/resources/display_manager_config.xml");
163 xmlDocPtr docPtr = nullptr;
164 {
165 std::lock_guard<std::recursive_mutex> lock(mutex_);
166 docPtr = xmlReadFile(configFilePath.c_str(), nullptr, XML_PARSE_NOBLANKS);
167 }
168 TLOGI(WmsLogTag::DMS, "filePath: %{public}s", configFilePath.c_str());
169 if (docPtr == nullptr) {
170 TLOGE(WmsLogTag::DMS, "load xml error!");
171 return false;
172 }
173 xmlNodePtr rootPtr = xmlDocGetRootElement(docPtr);
174 if (rootPtr == nullptr || rootPtr->name == nullptr ||
175 xmlStrcmp(rootPtr->name, reinterpret_cast<const xmlChar*>("Configs"))) {
176 TLOGE(WmsLogTag::DMS, "get root element failed!");
177 xmlFreeDoc(docPtr);
178 return false;
179 }
180 for (xmlNodePtr curNodePtr = rootPtr->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
181 if (!IsValidNode(*curNodePtr)) {
182 TLOGE(WmsLogTag::DMS, ":invalid node!");
183 continue;
184 }
185 ParseNodeConfig(curNodePtr);
186 }
187 xmlFreeDoc(docPtr);
188 return true;
189 }
190
ParseNodeConfig(const xmlNodePtr & currNode)191 void ScreenSceneConfig::ParseNodeConfig(const xmlNodePtr& currNode)
192 {
193 std::string nodeName(reinterpret_cast<const char*>(currNode->name));
194 bool enableConfigCheck = (xmlNodeMap_[IS_WATERFALL_DISPLAY] == nodeName) ||
195 (xmlNodeMap_[IS_CURVED_COMPRESS_ENABLED] == nodeName) ||
196 (xmlNodeMap_[IS_RIGHT_POWER_BUTTON] == nodeName) ||
197 (xmlNodeMap_[IS_SUPPORT_CAPTURE] == nodeName) ||
198 (xmlNodeMap_[SUPPORT_ROTATE_WITH_SCREEN] == nodeName)||
199 (xmlNodeMap_[IS_SUPPORT_OFFSCREEN_RENDERING] == nodeName) ||
200 (xmlNodeMap_[SUPPORT_DURING_CALL] == nodeName);
201 bool numberConfigCheck = (xmlNodeMap_[DPI] == nodeName) ||
202 (xmlNodeMap_[SUB_DPI] == nodeName) ||
203 (xmlNodeMap_[CURVED_SCREEN_BOUNDARY] == nodeName) ||
204 (xmlNodeMap_[CURVED_AREA_IN_LANDSCAPE] == nodeName) ||
205 (xmlNodeMap_[BUILD_IN_DEFAULT_ORIENTATION] == nodeName) ||
206 (xmlNodeMap_[DEFAULT_DEVICE_ROTATION_OFFSET] == nodeName) ||
207 (xmlNodeMap_[OFF_SCREEN_PPI_THRESHOLD] == nodeName) ||
208 (xmlNodeMap_[PC_MODE_DPI] == nodeName);
209 bool stringConfigCheck = (xmlNodeMap_[DEFAULT_DISPLAY_CUTOUT_PATH] == nodeName) ||
210 (xmlNodeMap_[SUB_DISPLAY_CUTOUT_PATH] == nodeName) ||
211 (xmlNodeMap_[ROTATION_POLICY] == nodeName) ||
212 (xmlNodeMap_[DEFAULT_ROTATION_POLICY] == nodeName) ||
213 (xmlNodeMap_[SCREEN_SNAPSHOT_BUNDLE_NAME] == nodeName) ||
214 (xmlNodeMap_[SCREEN_SNAPSHOT_ABILITY_NAME] == nodeName) ||
215 (xmlNodeMap_[EXTERNAL_SCREEN_DEFAULT_MODE] == nodeName) ||
216 (xmlNodeMap_[CAST_BUNDLE_NAME] == nodeName) ||
217 (xmlNodeMap_[CAST_ABILITY_NAME] == nodeName);
218 if (enableConfigCheck) {
219 ReadEnableConfigInfo(currNode);
220 } else if (numberConfigCheck) {
221 ReadIntNumbersConfigInfo(currNode);
222 } else if (stringConfigCheck) {
223 ReadStringConfigInfo(currNode);
224 } else if (xmlNodeMap_[HALL_SWITCH_APP] == nodeName) {
225 ReadStringListConfigInfo(currNode, nodeName);
226 } else if (xmlNodeMap_[PHYSICAL_DISPLAY_RESOLUTION] == nodeName) {
227 ReadPhysicalDisplayConfigInfo(currNode);
228 } else if (xmlNodeMap_[SCROLLABLE_PARAM] == nodeName) {
229 ReadScrollableParam(currNode);
230 } else {
231 TLOGI(WmsLogTag::DMS, "xml config node name is not match, nodeName:%{public}s", nodeName.c_str());
232 }
233 }
234
IsValidNode(const xmlNode & currNode)235 bool ScreenSceneConfig::IsValidNode(const xmlNode& currNode)
236 {
237 if (currNode.name == nullptr || currNode.type == XML_COMMENT_NODE) {
238 return false;
239 }
240 return true;
241 }
242
ReadIntNumbersConfigInfo(const xmlNodePtr & currNode)243 void ScreenSceneConfig::ReadIntNumbersConfigInfo(const xmlNodePtr& currNode)
244 {
245 xmlChar* context = xmlNodeGetContent(currNode);
246 if (context == nullptr) {
247 TLOGE(WmsLogTag::DMS, "read xml node error: nodeName:(%{public}s)", currNode->name);
248 return;
249 }
250
251 std::vector<int> numbersVec;
252 std::string numbersStr = reinterpret_cast<const char*>(context);
253 if (numbersStr.empty()) {
254 xmlFree(context);
255 return;
256 }
257 auto numbers = Split(numbersStr, " ");
258 for (auto& num : numbers) {
259 if (!IsNumber(num)) {
260 TLOGE(WmsLogTag::DMS, "read number error: nodeName:(%{public}s)", currNode->name);
261 xmlFree(context);
262 return;
263 }
264 numbersVec.emplace_back(std::stoi(num));
265 }
266
267 std::string nodeName = reinterpret_cast<const char *>(currNode->name);
268 intNumbersConfig_[nodeName] = numbersVec;
269 xmlFree(context);
270 }
271
272 // LCOV_EXCL_START
ReadPhysicalDisplayConfigInfo(const xmlNodePtr & currNode)273 void ScreenSceneConfig::ReadPhysicalDisplayConfigInfo(const xmlNodePtr& currNode)
274 {
275 xmlChar* displayMode = xmlGetProp(currNode, reinterpret_cast<const xmlChar*>("displayMode"));
276 if (displayMode == nullptr) {
277 TLOGE(WmsLogTag::DMS, "read xml node error: nodeName:(%{public}s)", currNode->name);
278 return;
279 }
280 xmlChar* displayModeContext = xmlNodeGetContent(currNode);
281 if (displayModeContext == nullptr) {
282 TLOGE(WmsLogTag::DMS, "read xml nodeName:(%{public}s) context null", currNode->name);
283 xmlFree(displayMode);
284 return;
285 }
286 std::string displaySizeStr = reinterpret_cast<const char*>(displayModeContext);
287 if (displaySizeStr.empty()) {
288 xmlFree(displayModeContext);
289 xmlFree(displayMode);
290 return;
291 }
292 auto displaySizeArray = Split(displaySizeStr, ":");
293 if (displaySizeArray.size() != DISPLAY_PHYSICAL_SIZE) {
294 xmlFree(displayModeContext);
295 xmlFree(displayMode);
296 return;
297 }
298 DisplayPhysicalResolution physicalSize;
299 if (!xmlStrcmp(displayMode, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_FULL"))) {
300 physicalSize.foldDisplayMode_ = FoldDisplayMode::FULL;
301 } else if (!xmlStrcmp(displayMode, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_MAIN"))) {
302 physicalSize.foldDisplayMode_ = FoldDisplayMode::MAIN;
303 } else if (!xmlStrcmp(displayMode, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_SUB"))) {
304 physicalSize.foldDisplayMode_ = FoldDisplayMode::SUB;
305 } else if (!xmlStrcmp(displayMode, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_GLOBAL_FULL"))) {
306 physicalSize.foldDisplayMode_ = FoldDisplayMode::GLOBAL_FULL;
307 } else {
308 physicalSize.foldDisplayMode_ = FoldDisplayMode::UNKNOWN;
309 }
310 if (IsNumber(displaySizeArray[0]) && IsNumber(displaySizeArray[1])) {
311 physicalSize.physicalWidth_ = static_cast<uint32_t>(std::stoi(displaySizeArray[0]));
312 physicalSize.physicalHeight_ = static_cast<uint32_t>(std::stoi(displaySizeArray[1]));
313 }
314 displayPhysicalResolution_.emplace_back(physicalSize);
315 xmlFree(displayModeContext);
316 xmlFree(displayMode);
317 }
318 // LCOV_EXCL_STOP
319
GetAllDisplayPhysicalConfig()320 std::vector<DisplayPhysicalResolution> ScreenSceneConfig::GetAllDisplayPhysicalConfig()
321 {
322 return displayPhysicalResolution_;
323 }
324
325 // LCOV_EXCL_START
GetFoldDisplayMode(uint32_t width,uint32_t height)326 FoldDisplayMode ScreenSceneConfig::GetFoldDisplayMode(uint32_t width, uint32_t height)
327 {
328 // Due to incorrect configuration files, custom processing is required.
329 if (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice()) {
330 return (width == height) ? FoldDisplayMode::MAIN : FoldDisplayMode::FULL;
331 }
332
333 for (const DisplayPhysicalResolution& resolution : displayPhysicalResolution_) {
334 if ((resolution.physicalWidth_ == width && resolution.physicalHeight_ == height) ||
335 (resolution.physicalWidth_ == height && resolution.physicalHeight_ == width)) {
336 return resolution.foldDisplayMode_;
337 }
338 }
339 return FoldDisplayMode::UNKNOWN;
340 }
341
ReadScrollableParam(const xmlNodePtr & currNode)342 void ScreenSceneConfig::ReadScrollableParam(const xmlNodePtr& currNode)
343 {
344 xmlChar* displayModeXml = xmlGetProp(currNode, reinterpret_cast<const xmlChar*>("displayMode"));
345 if (displayModeXml == nullptr) {
346 TLOGE(WmsLogTag::DMS, "read xml node error: nodeName:(%{public}s)", currNode->name);
347 return;
348 }
349 xmlChar* displayModeContext = xmlNodeGetContent(currNode);
350 if (displayModeContext == nullptr) {
351 TLOGE(WmsLogTag::DMS, "read xml nodeName:(%{public}s) context null", currNode->name);
352 xmlFree(displayModeXml);
353 return;
354 }
355 std::string scrollableParamStr = reinterpret_cast<const char*>(displayModeContext);
356 if (scrollableParamStr.empty()) {
357 xmlFree(displayModeContext);
358 xmlFree(displayModeXml);
359 return;
360 }
361 auto scrollableParamArray = Split(scrollableParamStr, ":");
362 if (scrollableParamArray.size() != SCROLLABLE_PARAM_SIZE) {
363 xmlFree(displayModeContext);
364 xmlFree(displayModeXml);
365 return;
366 }
367 FoldDisplayMode foldDisplayMode;
368 if (!xmlStrcmp(displayModeXml, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_FULL"))) {
369 foldDisplayMode = FoldDisplayMode::FULL;
370 } else if (!xmlStrcmp(displayModeXml, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_MAIN"))) {
371 foldDisplayMode = FoldDisplayMode::MAIN;
372 } else if (!xmlStrcmp(displayModeXml, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_SUB"))) {
373 foldDisplayMode = FoldDisplayMode::SUB;
374 } else if (!xmlStrcmp(displayModeXml, reinterpret_cast<const xmlChar*>("FOLD_DISPLAY_MODE_COORDINATION"))) {
375 foldDisplayMode = FoldDisplayMode::COORDINATION;
376 } else {
377 foldDisplayMode = FoldDisplayMode::UNKNOWN;
378 }
379 ScrollableParam scrollableParam;
380 scrollableParam.velocityScale_ = scrollableParamArray[0];
381 scrollableParam.friction_ = scrollableParamArray[1];
382 scrollableParams_[foldDisplayMode] = scrollableParam;
383 xmlFree(displayModeContext);
384 xmlFree(displayModeXml);
385 }
386
GetAllScrollableParam()387 std::map<FoldDisplayMode, ScrollableParam> ScreenSceneConfig::GetAllScrollableParam()
388 {
389 return scrollableParams_;
390 }
391 // LCOV_EXCL_STOP
392
ReadEnableConfigInfo(const xmlNodePtr & currNode)393 void ScreenSceneConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode)
394 {
395 xmlChar* enable = xmlGetProp(currNode, reinterpret_cast<const xmlChar*>("enable"));
396 if (enable == nullptr) {
397 TLOGE(WmsLogTag::DMS, "read xml node error: nodeName:(%{public}s)", currNode->name);
398 return;
399 }
400
401 std::string nodeName = reinterpret_cast<const char *>(currNode->name);
402 if (!xmlStrcmp(enable, reinterpret_cast<const xmlChar*>("true"))) {
403 enableConfig_[nodeName] = true;
404 if (xmlNodeMap_[IS_WATERFALL_DISPLAY] == nodeName) {
405 isWaterfallDisplay_ = true;
406 } else if (xmlNodeMap_[IS_CURVED_COMPRESS_ENABLED] == nodeName) {
407 isScreenCompressionEnableInLandscape_ = true;
408 } else if (xmlNodeMap_[IS_SUPPORT_CAPTURE] == nodeName) {
409 isSupportCapture_ = true;
410 } else if (xmlNodeMap_[IS_SUPPORT_OFFSCREEN_RENDERING] == nodeName) {
411 isSupportOffScreenRendering_ = true;
412 }
413 } else {
414 enableConfig_[nodeName] = false;
415 }
416 xmlFree(enable);
417 }
418
ReadStringConfigInfo(const xmlNodePtr & currNode)419 void ScreenSceneConfig::ReadStringConfigInfo(const xmlNodePtr& currNode)
420 {
421 xmlChar* context = xmlNodeGetContent(currNode);
422 if (context == nullptr) {
423 TLOGE(WmsLogTag::DMS, "read xml node error: nodeName:(%{public}s)", currNode->name);
424 return;
425 }
426
427 std::string inputString = reinterpret_cast<const char*>(context);
428 std::string nodeName = reinterpret_cast<const char*>(currNode->name);
429 stringConfig_[nodeName] = inputString;
430 xmlFree(context);
431 }
432
433 // LCOV_EXCL_START
ReadStringListConfigInfo(const xmlNodePtr & rootNode,std::string name)434 void ScreenSceneConfig::ReadStringListConfigInfo(const xmlNodePtr& rootNode, std::string name)
435 {
436 if (rootNode == nullptr || rootNode->name == nullptr) {
437 TLOGE(WmsLogTag::DMS, "get root element failed!");
438 return;
439 }
440 xmlChar* rootContext = xmlNodeGetContent(rootNode);
441 if (rootContext == nullptr) {
442 TLOGE(WmsLogTag::DMS, "rootContext is null");
443 return;
444 }
445 std::vector<std::string> stringVec;
446 for (xmlNodePtr curNodePtr = rootNode->xmlChildrenNode; curNodePtr != nullptr; curNodePtr = curNodePtr->next) {
447 if (!IsValidNode(*curNodePtr)) {
448 TLOGE(WmsLogTag::DMS, "invalid node!");
449 continue;
450 }
451 xmlChar* context = xmlNodeGetContent(curNodePtr);
452 std::string str = reinterpret_cast<const char*>(context);
453 stringVec.emplace_back(str);
454 xmlFree(context);
455 }
456 stringListConfig_[name] = stringVec;
457 xmlFree(rootContext);
458 }
459 // LCOV_EXCL_STOP
460
GetEnableConfig()461 const std::map<std::string, bool>& ScreenSceneConfig::GetEnableConfig()
462 {
463 return enableConfig_;
464 }
465
GetIntNumbersConfig()466 const std::map<std::string, std::vector<int>>& ScreenSceneConfig::GetIntNumbersConfig()
467 {
468 return intNumbersConfig_;
469 }
470
GetStringConfig()471 const std::map<std::string, std::string>& ScreenSceneConfig::GetStringConfig()
472 {
473 return stringConfig_;
474 }
475
GetStringListConfig()476 const std::map<std::string, std::vector<std::string>>& ScreenSceneConfig::GetStringListConfig()
477 {
478 return stringListConfig_;
479 }
480
DumpConfig()481 void ScreenSceneConfig::DumpConfig()
482 {
483 for (auto& enable : enableConfig_) {
484 TLOGI(WmsLogTag::DMS, "Enable: %{public}s %{public}u", enable.first.c_str(), enable.second);
485 }
486 for (auto& numbers : intNumbersConfig_) {
487 TLOGI(WmsLogTag::DMS, "Numbers: %{public}s %{public}zu",
488 numbers.first.c_str(), numbers.second.size());
489 for (auto& num : numbers.second) {
490 TLOGI(WmsLogTag::DMS, "Num: %{public}d", num);
491 }
492 }
493 for (auto& string : stringConfig_) {
494 TLOGI(WmsLogTag::DMS, "String: %{public}s", string.first.c_str());
495 }
496 }
497
498 // LCOV_EXCL_START
SetCutoutSvgPath(uint64_t displayId,const std::string & svgPath)499 void ScreenSceneConfig::SetCutoutSvgPath(uint64_t displayId, const std::string& svgPath)
500 {
501 if (svgPath.empty()) {
502 return;
503 }
504 cutoutBoundaryRectMap_.clear();
505 cutoutBoundaryRectMap_[displayId].emplace_back(CalcCutoutBoundaryRect(svgPath));
506 }
507
SetSubCutoutSvgPath(const std::string & svgPath)508 void ScreenSceneConfig::SetSubCutoutSvgPath(const std::string& svgPath)
509 {
510 if (svgPath.empty()) {
511 return;
512 }
513 subCutoutBoundaryRect_.clear();
514 subCutoutBoundaryRect_.emplace_back(CalcCutoutBoundaryRect(svgPath));
515 }
516
CalcCutoutBoundaryRect(std::string svgPath)517 DMRect ScreenSceneConfig::CalcCutoutBoundaryRect(std::string svgPath)
518 {
519 DMRect emptyRect = { 0, 0, 0, 0 };
520 SkPath skCutoutSvgPath;
521 if (!SkParsePath::FromSVGString(svgPath.c_str(), &skCutoutSvgPath)) {
522 TLOGE(WmsLogTag::DMS, "Parse svg string path failed.");
523 return emptyRect;
524 }
525 SkRect skRect = skCutoutSvgPath.computeTightBounds();
526 if (skRect.isEmpty()) {
527 TLOGW(WmsLogTag::DMS, "Get empty skRect");
528 return emptyRect;
529 }
530 SkIRect skiRect = skRect.roundOut();
531 if (skiRect.isEmpty()) {
532 TLOGW(WmsLogTag::DMS, "Get empty skiRect");
533 return emptyRect;
534 }
535 int32_t left = static_cast<int32_t>(skiRect.left());
536 int32_t top = static_cast<int32_t>(skiRect.top());
537 uint32_t width = static_cast<uint32_t>(skiRect.width());
538 uint32_t height = static_cast<uint32_t>(skiRect.height());
539 TLOGI(WmsLogTag::DMS,
540 "calc cutout boundary rect - left: [%{public}d top: %{public}d width: %{public}u height: %{public}u]",
541 left, top, width, height);
542 DMRect cutoutMinOuterRect = {
543 .posX_ = left,
544 .posY_ = top,
545 .width_ = width,
546 .height_ = height
547 };
548 return cutoutMinOuterRect;
549 }
550
GetCutoutBoundaryRect(uint64_t displayId)551 std::vector<DMRect> ScreenSceneConfig::GetCutoutBoundaryRect(uint64_t displayId)
552 {
553 if (cutoutBoundaryRectMap_.count(displayId) == 0) {
554 return {};
555 }
556 return cutoutBoundaryRectMap_[displayId];
557 }
558
GetSubCutoutBoundaryRect()559 std::vector<DMRect> ScreenSceneConfig::GetSubCutoutBoundaryRect()
560 {
561 return subCutoutBoundaryRect_;
562 }
563
IsWaterfallDisplay()564 bool ScreenSceneConfig::IsWaterfallDisplay()
565 {
566 return isWaterfallDisplay_;
567 }
568
IsSupportCapture()569 bool ScreenSceneConfig::IsSupportCapture()
570 {
571 return isSupportCapture_;
572 }
573
SetCurvedCompressionAreaInLandscape()574 void ScreenSceneConfig::SetCurvedCompressionAreaInLandscape()
575 {
576 if (intNumbersConfig_[xmlNodeMap_[CURVED_AREA_IN_LANDSCAPE]].size() > 0) {
577 curvedAreaInLandscape_ = static_cast<uint32_t>(intNumbersConfig_[xmlNodeMap_[CURVED_AREA_IN_LANDSCAPE]][0]);
578 } else {
579 TLOGW(WmsLogTag::DMS, "waterfallAreaCompressionSizeWhenHorzontal value is not exist");
580 }
581 }
582
GetCurvedScreenBoundaryConfig()583 std::vector<int> ScreenSceneConfig::GetCurvedScreenBoundaryConfig()
584 {
585 return intNumbersConfig_[xmlNodeMap_[CURVED_SCREEN_BOUNDARY]];
586 }
587
GetCurvedCompressionAreaInLandscape()588 uint32_t ScreenSceneConfig::GetCurvedCompressionAreaInLandscape()
589 {
590 if (!isWaterfallDisplay_ || !isScreenCompressionEnableInLandscape_) {
591 TLOGW(WmsLogTag::DMS, "not waterfall screen or waterfall compression is not enabled");
592 return NO_WATERFALL_DISPLAY_COMPRESSION_SIZE;
593 }
594 return curvedAreaInLandscape_;
595 }
596
IsSupportRotateWithSensor()597 bool ScreenSceneConfig::IsSupportRotateWithSensor()
598 {
599 if (enableConfig_.count("supportRotateWithSensor") != 0) {
600 return static_cast<bool>(enableConfig_["supportRotateWithSensor"]);
601 }
602 return false;
603 }
GetExternalScreenDefaultMode()604 std::string ScreenSceneConfig::GetExternalScreenDefaultMode()
605 {
606 if (stringConfig_.count("externalScreenDefaultMode") != 0) {
607 return static_cast<std::string>(stringConfig_["externalScreenDefaultMode"]);
608 }
609 return "";
610 }
611
GetOffScreenPPIThreshold()612 uint32_t ScreenSceneConfig::GetOffScreenPPIThreshold()
613 {
614 if (intNumbersConfig_[xmlNodeMap_[OFF_SCREEN_PPI_THRESHOLD]].size() != 0) {
615 return static_cast<uint32_t>(intNumbersConfig_[xmlNodeMap_[OFF_SCREEN_PPI_THRESHOLD]][0]);
616 }
617 return offScreenPPIThreshold_;
618 }
619
IsSupportOffScreenRendering()620 bool ScreenSceneConfig::IsSupportOffScreenRendering()
621 {
622 if (enableConfig_.count("isSupportOffScreenRendering") != 0) {
623 return static_cast<bool>(enableConfig_["isSupportOffScreenRendering"]);
624 }
625 return false;
626 }
627
IsSupportDuringCall()628 bool ScreenSceneConfig::IsSupportDuringCall()
629 {
630 if (enableConfig_.count("supportDuringCall") != 0) {
631 return static_cast<bool>(enableConfig_["supportDuringCall"]);
632 }
633 return false;
634 }
635 // LCOV_EXCL_STOP
636 } // namespace OHOS::Rosen
637