!1277 Add interface to get cutout info

Merge pull request !1277 from X PN/dev-cutout
This commit is contained in:
openharmony_ci
2022-08-01 07:49:04 +00:00
committed by Gitee
8 changed files with 321 additions and 2 deletions
@@ -30,14 +30,20 @@ public:
~DisplayManagerConfig() = default;
static bool LoadConfigXml();
static const std::map<std::string, bool>& GetEnableConfig();
static const std::map<std::string, std::vector<int>>& GetIntNumbersConfig();
static const std::map<std::string, std::string>& GetStringConfig();
static void DumpConfig();
private:
static std::map<std::string, bool> enableConfig_;
static std::map<std::string, std::vector<int>> intNumbersConfig_;
static std::map<std::string, std::string> 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<std::string> Split(std::string str, std::string pattern);
+59 -1
View File
@@ -33,7 +33,9 @@ namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerConfig"};
}
std::map<std::string, bool> DisplayManagerConfig::enableConfig_;
std::map<std::string, std::vector<int>> DisplayManagerConfig::intNumbersConfig_;
std::map<std::string, std::string> DisplayManagerConfig::stringConfig_;
std::vector<std::string> DisplayManagerConfig::Split(std::string str, std::string pattern)
{
@@ -99,12 +101,21 @@ bool DisplayManagerConfig::LoadConfigXml()
}
auto nodeName = curNodePtr->name;
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("isWaterfallDisplay"))) {
ReadEnableConfigInfo(curNodePtr);
continue;
}
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("dpi")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea"))) {
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("curvedScreenBoundary"))) {
ReadIntNumbersConfigInfo(curNodePtr);
continue;
}
if (!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("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<const xmlChar*>("enable"));
if (enable == nullptr) {
WLOGFE("[DmConfig] read xml node error: nodeName:(%{public}s)", currNode->name);
return;
}
std::string nodeName = reinterpret_cast<const char *>(currNode->name);
if (!xmlStrcmp(enable, reinterpret_cast<const xmlChar*>("true"))) {
enableConfig_[nodeName] = true;
} else if (!xmlStrcmp(enable, reinterpret_cast<const xmlChar*>("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<const char*>(context);
std::string nodeName = reinterpret_cast<const char*>(currNode->name);
stringConfig_[nodeName] = inputString;
xmlFree(context);
}
const std::map<std::string, bool>& DisplayManagerConfig::GetEnableConfig()
{
return enableConfig_;
}
const std::map<std::string, std::vector<int>>& DisplayManagerConfig::GetIntNumbersConfig()
{
return intNumbersConfig_;
}
const std::map<std::string, std::string>& 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
+37 -1
View File
@@ -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>): void;
/**
* Obtain the cutout info of the display.
* @devices tv, phone, tablet, wearable
*/
getCutoutInfo(): Promise<CutoutInfo>;
}
/**
* cutout information of the display.
* @syscap SystemCapability.WindowManager.WindowManager.Core
* @since 9
*/
interface CutoutInfo {
BoundingRects: Array<Rect>;
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;
@@ -191,10 +191,15 @@ declare namespace screen {
/**
* active the mode
* @since 9
*/
setScreenActiveMode(modeIndex: number, callback: AsyncCallback<void>): void;
setScreenActiveMode(modeIndex: number): Promise<void>;
/**
* set density of the screen.
* @Since 9
*/
setDensityDpi(densityDpi: number, callback: AsyncCallback<void>): void;
setDensityDpi(densityDpi: number): Promise<void>;
}
@@ -21,4 +21,19 @@
<defaultDeviceRotationOffset>0</defaultDeviceRotationOffset>
<!--Cutout area Rect. This is temporary config. To delete when Rs cutout area interface is ready.-->
<cutoutArea>10 10 100 20</cutoutArea>
<!-- format: string -->
<!-- default value is an empty string -->
<!-- sample: M 205,5 L 795,5 L 595,295 L 5,295 L 205,5 z -->
<!-- mandatory: no -->
<defaultDisplayCutoutPath>M 100,100 m -75,0 a 75,75 0 1,0 150,0 a 75,75 0 1,0 -150,0 z</defaultDisplayCutoutPath>
<!-- format: number(left) number(top) number(right) number(bottom) -->
<!-- default value: 0 0 0 0 -->
<!-- sample: 150 150 0 0 -->
<!-- mandatory: no -->
<curvedScreenBoundary>100 0 100 0</curvedScreenBoundary>
<!-- format: boolean -->
<!-- default value: false -->
<!-- sample: false -->
<!-- mandatory: no -->
<isWaterfallDisplay>true</isWaterfallDisplay>
</Configs>
+1
View File
@@ -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",
+85
View File
@@ -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 <parcel.h>
#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<Rect>& 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<Rect>, BoundingRects, boundingRects);
private:
bool WriteBoundingRectsVector(const std::vector<Rect>& boundingRects, Parcel &parcel) const;
static bool ReadBoundingRectsVector(std::vector<Rect>& unmarBoundingRects, Parcel &parcel);
static bool ReadWaterfallDisplayAreaRects(WaterfallDisplayAreaRects& waterfallDisplayAreaRects, Parcel &parcel);
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_CUTOUT_INFO_H
+113
View File
@@ -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<Rect>& 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<Rect> boundingRects;
ReadWaterfallDisplayAreaRects(waterfallDisplayAreaRects, parcel);
ReadBoundingRectsVector(boundingRects, parcel);
CutoutInfo *cutoutInfo = new CutoutInfo(boundingRects, waterfallDisplayAreaRects);
return cutoutInfo;
}
bool CutoutInfo::WriteBoundingRectsVector(const std::vector<Rect>& boundingRects, Parcel &parcel) const
{
if (!parcel.WriteUint32(static_cast<uint32_t>(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<Rect>& 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