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