From 3e57e78e47ead7976860ee84f1e167f8bfeac494 Mon Sep 17 00:00:00 2001 From: xpeng Date: Mon, 1 Aug 2022 14:44:33 +0800 Subject: [PATCH] add cutout_info, update dms_config functions, and configs Signed-off-by: xpeng Change-Id: I48a0528b519516f2b094f237e02960bcd82c9057 --- dmserver/include/display_manager_config.h | 6 + dmserver/src/display_manager_config.cpp | 60 +++++++++- .../js/declaration/api/@ohos.display.d.ts | 38 +++++- .../napi/screen_runtime/api/@ohos.screen.d.ts | 5 + .../config/rk3568/display_manager_config.xml | 15 +++ utils/BUILD.gn | 1 + utils/include/cutout_info.h | 85 +++++++++++++ utils/src/cutout_info.cpp | 113 ++++++++++++++++++ 8 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 utils/include/cutout_info.h create mode 100644 utils/src/cutout_info.cpp diff --git a/dmserver/include/display_manager_config.h b/dmserver/include/display_manager_config.h index 5ae86ffc..6ad5109a 100644 --- a/dmserver/include/display_manager_config.h +++ b/dmserver/include/display_manager_config.h @@ -30,14 +30,20 @@ public: ~DisplayManagerConfig() = default; static bool LoadConfigXml(); + static const std::map& GetEnableConfig(); static const std::map>& GetIntNumbersConfig(); + static const std::map& GetStringConfig(); static void DumpConfig(); private: + static std::map enableConfig_; static std::map> intNumbersConfig_; + static std::map stringConfig_; static bool IsValidNode(const xmlNode& currNode); + static void ReadEnableConfigInfo(const xmlNodePtr& currNode); static void ReadIntNumbersConfigInfo(const xmlNodePtr& currNode); + static void ReadStringConfigInfo(const xmlNodePtr& currNode); static std::string GetConfigPath(const std::string& configFileName); static std::vector Split(std::string str, std::string pattern); diff --git a/dmserver/src/display_manager_config.cpp b/dmserver/src/display_manager_config.cpp index b12fe946..2aa31d74 100644 --- a/dmserver/src/display_manager_config.cpp +++ b/dmserver/src/display_manager_config.cpp @@ -33,7 +33,9 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerConfig"}; } +std::map DisplayManagerConfig::enableConfig_; std::map> DisplayManagerConfig::intNumbersConfig_; +std::map DisplayManagerConfig::stringConfig_; std::vector DisplayManagerConfig::Split(std::string str, std::string pattern) { @@ -99,12 +101,21 @@ bool DisplayManagerConfig::LoadConfigXml() } auto nodeName = curNodePtr->name; + if (!xmlStrcmp(nodeName, reinterpret_cast("isWaterfallDisplay"))) { + ReadEnableConfigInfo(curNodePtr); + continue; + } if (!xmlStrcmp(nodeName, reinterpret_cast("dpi")) || !xmlStrcmp(nodeName, reinterpret_cast("defaultDeviceRotationOffset")) || - !xmlStrcmp(nodeName, reinterpret_cast("cutoutArea"))) { + !xmlStrcmp(nodeName, reinterpret_cast("cutoutArea")) || + !xmlStrcmp(nodeName, reinterpret_cast("curvedScreenBoundary"))) { ReadIntNumbersConfigInfo(curNodePtr); continue; } + if (!xmlStrcmp(nodeName, reinterpret_cast("defaultDisplayCutoutPath"))) { + ReadStringConfigInfo(curNodePtr); + continue; + } } xmlFreeDoc(docPtr); return true; @@ -143,18 +154,65 @@ void DisplayManagerConfig::ReadIntNumbersConfigInfo(const xmlNodePtr& currNode) xmlFree(context); } +void DisplayManagerConfig::ReadEnableConfigInfo(const xmlNodePtr& currNode) +{ + xmlChar* enable = xmlGetProp(currNode, reinterpret_cast("enable")); + if (enable == nullptr) { + WLOGFE("[DmConfig] read xml node error: nodeName:(%{public}s)", currNode->name); + return; + } + + std::string nodeName = reinterpret_cast(currNode->name); + if (!xmlStrcmp(enable, reinterpret_cast("true"))) { + enableConfig_[nodeName] = true; + } else if (!xmlStrcmp(enable, reinterpret_cast("false"))) { + enableConfig_[nodeName] = false; + } + xmlFree(enable); +} + +void DisplayManagerConfig::ReadStringConfigInfo(const xmlNodePtr& currNode) +{ + xmlChar* context = xmlNodeGetContent(currNode); + if (context == nullptr) { + WLOGFE("[DmConfig] read xml node error: nodeName:(%{public}s)", currNode->name); + return; + } + + std::string inputString = reinterpret_cast(context); + std::string nodeName = reinterpret_cast(currNode->name); + stringConfig_[nodeName] = inputString; + xmlFree(context); +} + +const std::map& DisplayManagerConfig::GetEnableConfig() +{ + return enableConfig_; +} + const std::map>& DisplayManagerConfig::GetIntNumbersConfig() { return intNumbersConfig_; } +const std::map& DisplayManagerConfig::GetStringConfig() +{ + return stringConfig_; +} + void DisplayManagerConfig::DumpConfig() { + for (auto& enable : enableConfig_) { + WLOGFI("[DmConfig] Enable: %{public}s %{public}u", enable.first.c_str(), enable.second); + } for (auto& numbers : intNumbersConfig_) { WLOGFI("[DmConfig] Numbers: %{public}s %{public}zu", numbers.first.c_str(), numbers.second.size()); for (auto& num : numbers.second) { WLOGFI("[DmConfig] Num: %{public}d", num); } } + for (auto& string : stringConfig_) { + WLOGFI("[DmConfig] String: %{public}s", string.first.c_str()); + } } } // namespace OHOS::Rosen diff --git a/interfaces/kits/js/declaration/api/@ohos.display.d.ts b/interfaces/kits/js/declaration/api/@ohos.display.d.ts index 5f19d35d..445c526f 100644 --- a/interfaces/kits/js/declaration/api/@ohos.display.d.ts +++ b/interfaces/kits/js/declaration/api/@ohos.display.d.ts @@ -173,7 +173,43 @@ declare namespace display { * DPI on the y-axis. */ yDPI: number; + + /** + * Obtain the cutout info of the display. + * @devices tv, phone, tablet, wearable + */ + getCutoutInfo(callback: AsyncCallback): void; + + /** + * Obtain the cutout info of the display. + * @devices tv, phone, tablet, wearable + */ + getCutoutInfo(): Promise; + } + + /** + * cutout information of the display. + * @syscap SystemCapability.WindowManager.WindowManager.Core + * @since 9 + */ + interface CutoutInfo { + BoundingRects: Array; + waterfallDisplayAreaRects: WaterfallDisplayAreaRects; + } + + interface WaterfallDisplayAreaRects { + left: Rect; + right: Rect; + top: Rect; + bottom: Rect; + } + + interface Rect { + left: number; + top: number; + width: number; + height: number; } } -export default display; +export default display; \ No newline at end of file diff --git a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts index bf3812dc..65b0450c 100644 --- a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts +++ b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts @@ -191,10 +191,15 @@ declare namespace screen { /** * active the mode + * @since 9 */ setScreenActiveMode(modeIndex: number, callback: AsyncCallback): void; setScreenActiveMode(modeIndex: number): Promise; + /** + * set density of the screen. + * @Since 9 + */ setDensityDpi(densityDpi: number, callback: AsyncCallback): void; setDensityDpi(densityDpi: number): Promise; } diff --git a/resources/config/rk3568/display_manager_config.xml b/resources/config/rk3568/display_manager_config.xml index 7933d38e..d16f9aa5 100644 --- a/resources/config/rk3568/display_manager_config.xml +++ b/resources/config/rk3568/display_manager_config.xml @@ -21,4 +21,19 @@ 0 10 10 100 20 + + + + + M 100,100 m -75,0 a 75,75 0 1,0 150,0 a 75,75 0 1,0 -150,0 z + + + + + 100 0 100 0 + + + + + true diff --git a/utils/BUILD.gn b/utils/BUILD.gn index f65e5d84..3e01a53b 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -29,6 +29,7 @@ config("libwmutil_public_config") { ohos_shared_library("libwmutil") { sources = [ "src/agent_death_recipient.cpp", + "src/cutout_info.cpp", "src/display_info.cpp", "src/permission.cpp", "src/screen_group_info.cpp", diff --git a/utils/include/cutout_info.h b/utils/include/cutout_info.h new file mode 100644 index 00000000..a28821d9 --- /dev/null +++ b/utils/include/cutout_info.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FOUNDATION_DMSERVER_CUTOUT_INFO_H +#define FOUNDATION_DMSERVER_CUTOUT_INFO_H + +#include + +#include "class_var_definition.h" +#include "display.h" +#include "dm_common.h" + +namespace OHOS::Rosen { +struct Rect { + int32_t posX_; + int32_t posY_; + uint32_t width_; + uint32_t height_; + + bool operator==(const Rect& a) const + { + return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); + } + + bool operator!=(const Rect& a) const + { + return !this->operator==(a); + } + + bool isUninitializedRect() const + { + return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); + } + + bool IsInsideOf(const Rect& a) const + { + return (posX_ >= a.posX_ && posY_ >= a.posY_ && + posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); + } +}; + +struct WaterfallDisplayAreaRects { + Rect left; + Rect top; + Rect right; + Rect bottom; + + bool isUninitialized() const + { + return (left.isUninitializedRect() && top.isUninitializedRect() && right.isUninitializedRect() && + bottom.isUninitializedRect()); + } +}; + +class CutoutInfo : public Parcelable { +public: + CutoutInfo() = default; + CutoutInfo(const std::vector& boudingRects, WaterfallDisplayAreaRects waterfallDisplayAreaRects); + ~CutoutInfo() = default; + WM_DISALLOW_COPY_AND_MOVE(CutoutInfo); + + virtual bool Marshalling(Parcel& parcel) const override; + static CutoutInfo *Unmarshalling(Parcel& parcel); + + DEFINE_VAR_FUNC_GET_SET(WaterfallDisplayAreaRects, WaterfallDisplayAreaRects, waterfallDisplayAreaRects); + DEFINE_VAR_FUNC_GET_SET(std::vector, BoundingRects, boundingRects); +private: + bool WriteBoundingRectsVector(const std::vector& boundingRects, Parcel &parcel) const; + static bool ReadBoundingRectsVector(std::vector& unmarBoundingRects, Parcel &parcel); + static bool ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel); +}; +} // namespace OHOS::Rosen +#endif // FOUNDATION_DMSERVER_CUTOUT_INFO_H \ No newline at end of file diff --git a/utils/src/cutout_info.cpp b/utils/src/cutout_info.cpp new file mode 100644 index 00000000..948c73e0 --- /dev/null +++ b/utils/src/cutout_info.cpp @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "cutout_info.h" + +namespace OHOS::Rosen { +CutoutInfo::CutoutInfo(const std::vector& boundingRects, + WaterfallDisplayAreaRects waterfallDisplayAreaRects) : waterfallDisplayAreaRects_(waterfallDisplayAreaRects), + boundingRects_(boundingRects) +{ +} + +bool CutoutInfo::Marshalling(Parcel &parcel) const +{ + return parcel.WriteInt32(waterfallDisplayAreaRects_.left.posX_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.left.posY_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.left.width_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.left.height_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.top.posX_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.top.posY_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.top.width_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.top.height_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.right.posX_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.right.posY_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.right.width_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.right.height_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.bottom.posX_) && + parcel.WriteInt32(waterfallDisplayAreaRects_.bottom.posY_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.bottom.width_) && + parcel.WriteUint32(waterfallDisplayAreaRects_.bottom.height_) && + WriteBoundingRectsVector(boundingRects_, parcel); +} + +CutoutInfo *CutoutInfo::Unmarshalling(Parcel &parcel) +{ + WaterfallDisplayAreaRects waterfallDisplayAreaRects; + std::vector boundingRects; + ReadWaterfallDisplayAreaRects(waterfallDisplayAreaRects, parcel); + ReadBoundingRectsVector(boundingRects, parcel); + CutoutInfo *cutoutInfo = new CutoutInfo(boundingRects, waterfallDisplayAreaRects); + return cutoutInfo; +} + +bool CutoutInfo::WriteBoundingRectsVector(const std::vector& boundingRects, Parcel &parcel) const +{ + if (!parcel.WriteUint32(static_cast(boundingRects.size()))) { + return false; + } + for (Rect rect : boundingRects) { + if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) && + parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) { + return false; + } + } + return true; +} + +bool CutoutInfo::ReadBoundingRectsVector(std::vector& unmarBoundingRects, Parcel &parcel) +{ + uint32_t size; + if (!parcel.ReadUint32(size)) { + return false; + } + for (uint32_t index = 0; index < size; index++) { + int32_t posX; + int32_t posY; + uint32_t width; + uint32_t height; + if (!(parcel.ReadInt32(posX) && parcel.ReadInt32(posY) && + parcel.ReadUint32(width) && parcel.ReadUint32(height))) { + return false; + } + Rect rect = {posX, posY, width, height}; + unmarBoundingRects.push_back(rect); + } + return true; +} + +bool CutoutInfo::ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel) +{ + if (!(parcel.ReadInt32(waterfallDisplayAreaRects.left.posX_) && + parcel.ReadInt32(waterfallDisplayAreaRects.left.posY_) && + parcel.ReadUint32(waterfallDisplayAreaRects.left.width_) && + parcel.ReadUint32(waterfallDisplayAreaRects.left.height_) && + parcel.ReadInt32(waterfallDisplayAreaRects.top.posX_) && + parcel.ReadInt32(waterfallDisplayAreaRects.top.posY_) && + parcel.ReadUint32(waterfallDisplayAreaRects.top.width_) && + parcel.ReadUint32(waterfallDisplayAreaRects.top.height_) && + parcel.ReadInt32(waterfallDisplayAreaRects.right.posX_) && + parcel.ReadInt32(waterfallDisplayAreaRects.right.posY_) && + parcel.ReadUint32(waterfallDisplayAreaRects.right.width_) && + parcel.ReadUint32(waterfallDisplayAreaRects.right.height_) && + parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posX_) && + parcel.ReadInt32(waterfallDisplayAreaRects.bottom.posY_) && + parcel.ReadUint32(waterfallDisplayAreaRects.bottom.width_) && + parcel.ReadUint32(waterfallDisplayAreaRects.bottom.height_))) { + return false; + } + return true; +} +} // namespace OHOS::Rosen \ No newline at end of file