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