Merge branch 'master' of gitee.com:openharmony/window_window_manager into dev-compress

Signed-off-by: X PN <pengxin33@huawei.com>
Change-Id: I2c7f87a301f17f7383731b0c452e76addb2b73af
This commit is contained in:
X PN 2022-09-01 12:11:48 +00:00 committed by xpeng
commit 90b514df7d
12 changed files with 103 additions and 42 deletions

View File

@ -33,8 +33,7 @@ public:
constexpr static int32_t DEFAULT_HIGHT = 1280;
constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0;
constexpr static uint32_t DEFAULT_FRESH_RATE = 60;
AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
ScreenId screenGroupId, sptr<SupportedScreenModes> info);
AbstractDisplay(DisplayId id, std::string name, sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen);
WM_DISALLOW_COPY_AND_MOVE(AbstractDisplay);
~AbstractDisplay() = default;
static inline bool IsVertical(Rotation rotation)
@ -70,9 +69,9 @@ public:
private:
DisplayId id_ { DISPLAY_ID_INVALID };
std::string name_ { "" };
ScreenId screenId_ { SCREEN_ID_INVALID };
ScreenId screenGroupId_ { SCREEN_ID_INVALID };
std::string name_ { "" };
int32_t offsetX_ { 0 };
int32_t offsetY_ { 0 };
int32_t width_ { 0 };

View File

@ -67,6 +67,7 @@ private:
sptr<AbstractScreen> absScreen, sptr<AbstractScreenGroup> screenGroup, sptr<AbstractDisplay>& absDisplay);
bool UpdateDisplaySize(sptr<AbstractDisplay> absDisplay, sptr<SupportedScreenModes> info);
void SetDisplayStateChangeListener(sptr<AbstractDisplay> abstractDisplay, DisplayStateChangeType type);
DisplayId GetDefaultDisplayId();
std::recursive_mutex& mutex_;
std::atomic<DisplayId> displayCount_ { 0 };

View File

@ -63,6 +63,7 @@ public:
ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent);
DMError DestroyVirtualScreen(ScreenId screenId);
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
void SetBuildInDefaultOrientation(Orientation orientation);
bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow);
bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow);
@ -148,6 +149,7 @@ private:
sptr<IRSScreenChangeListener> rSScreenChangeListener_;
std::shared_ptr<AppExecFwk::EventHandler> controllerHandler_;
std::atomic<ScreenId> defaultRsScreenId_ {SCREEN_ID_INVALID };
Orientation buildInDefaultOrientation_ { Orientation::UNSPECIFIED };
bool isExpandCombination_ = false;
};
} // namespace OHOS::Rosen

View File

@ -119,6 +119,7 @@ private:
ScreenId GetScreenIdByDisplayId(DisplayId displayId) const;
std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByDisplayId(DisplayId displayId) const;
void ConfigureDisplayManagerService();
void ConfigureWaterfallDisplayCompressionParams();
std::recursive_mutex mutex_;
static inline SingletonDelegator<DisplayManagerService> delegator_;

View File

@ -26,23 +26,25 @@ namespace {
constexpr int32_t PHONE_SCREEN_WIDTH = 2160;
}
AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, std::string name,
ScreenId screenGroupId, sptr<SupportedScreenModes> info)
AbstractDisplay::AbstractDisplay(DisplayId id, std::string name,
sptr<SupportedScreenModes>& info, sptr<AbstractScreen>& absScreen)
: id_(id),
screenId_(screenId),
screenGroupId_(screenGroupId),
name_(name),
screenId_(absScreen->dmsId_),
screenGroupId_(absScreen->groupDmsId_),
width_(info->width_),
height_(info->height_),
refreshRate_(info->refreshRate_)
refreshRate_(info->refreshRate_),
orientation_(absScreen->orientation_)
{
RequestRotation(absScreen->rotation_);
if (DisplayManagerService::GetCustomVirtualPixelRatio() &&
fabs(DisplayManagerService::GetCustomVirtualPixelRatio() + 1) > 1e-6) {
virtualPixelRatio_ = DisplayManagerService::GetCustomVirtualPixelRatio();
return;
}
if ((width_ >= PHONE_SCREEN_WIDTH) || (height_ >= PHONE_SCREEN_WIDTH)) {
if ((width_ == PAD_SCREEN_WIDTH) || (height_ == PAD_SCREEN_WIDTH)) {
if ((info->width_ >= PHONE_SCREEN_WIDTH) || (info->height_ >= PHONE_SCREEN_WIDTH)) {
if ((info->width_ == PAD_SCREEN_WIDTH) || (info->height_ == PAD_SCREEN_WIDTH)) {
virtualPixelRatio_ = 2.0f; // Pad is 2.0
} else {
virtualPixelRatio_ = 3.0f; // Phone is 3.0

View File

@ -294,12 +294,17 @@ void AbstractDisplayController::ProcessDisplayRotationChange(sptr<AbstractScreen
void AbstractDisplayController::ProcessDefaultDisplayLayoutCompression(sptr<AbstractScreen> absScreen)
{
WLOGFI("Enter ProcessDefaultDisplayLayoutCompression");
auto absDisplay = GetAbstractDisplayByAbsScreen(absScreen);
DisplayId defaultDisplayId = GetDefaultDisplayId();
if (absDisplay->GetDisplayId() == defaultDisplayId) {
return;
}
if (!DisplayCutoutController::IsWaterfallCurvedAreaLayoutCompressionEnable() ||
DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal() == 0) {
WLOGFI("Not enable waterfall display area compression.");
return;
}
auto absDisplay = GetAbstractDisplayByAbsScreen(absScreen);
Rotation rotation = absDisplay->GetRotation();
if (ScreenRotationController::IsDisplayRotationHorizontal(rotation)) {
uint32_t offsetY = DisplayCutoutController::GetWaterfallAreaCompressionSizeWhenHorizontal();
@ -500,8 +505,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr<AbstractScreen> realA
std::ostringstream buffer;
buffer<<"display_"<<displayId;
std::string name = buffer.str();
sptr<AbstractDisplay> display = new(std::nothrow) AbstractDisplay(displayId, realAbsScreen->dmsId_,
name, realAbsScreen->groupDmsId_, info);
sptr<AbstractDisplay> display = new(std::nothrow) AbstractDisplay(displayId, name, info, realAbsScreen);
if (display == nullptr) {
WLOGFE("create display failed");
return;
@ -570,8 +574,7 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr<AbstractScreen> abs
std::ostringstream buffer;
buffer<<"display_"<<displayId;
std::string name = buffer.str();
sptr<AbstractDisplay> display = new AbstractDisplay(displayId,
absScreen->dmsId_, name, absScreen->groupDmsId_, info);
sptr<AbstractDisplay> display = new AbstractDisplay(displayId, name, info, absScreen);
Point point = abstractScreenController_->GetAbstractScreenGroup(absScreen->groupDmsId_)->
GetChildPosition(absScreen->dmsId_);
display->SetOffset(point.posX_, point.posY_);
@ -635,14 +638,20 @@ std::map<DisplayId, sptr<DisplayInfo>> AbstractDisplayController::GetAllDisplayI
void AbstractDisplayController::SetDisplayStateChangeListener(
sptr<AbstractDisplay> abstractDisplay, DisplayStateChangeType type)
{
ScreenId defaultDisplayId = DISPLAY_ID_INVALID;
ScreenId defaultDisplayId = GetDefaultDisplayId();
std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap = GetAllDisplayInfoOfGroup(
abstractDisplay->ConvertToDisplayInfo());
displayStateChangeListener_(defaultDisplayId, abstractDisplay->ConvertToDisplayInfo(), displayInfoMap, type);
}
DisplayId AbstractDisplayController::GetDefaultDisplayId()
{
DisplayId defaultDisplayId = DISPLAY_ID_INVALID;
ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId();
sptr<AbstractDisplay> defaultDisplay = GetAbstractDisplayByScreen(defaultScreenId);
if (defaultDisplay != nullptr) {
defaultDisplayId = defaultDisplay->GetId();
}
std::map<DisplayId, sptr<DisplayInfo>> displayInfoMap = GetAllDisplayInfoOfGroup(
abstractDisplay->ConvertToDisplayInfo());
displayStateChangeListener_(defaultDisplayId, abstractDisplay->ConvertToDisplayInfo(), displayInfoMap, type);
return defaultDisplayId;
}
} // namespace OHOS::Rosen

View File

@ -282,25 +282,48 @@ void AbstractScreenController::ScreenConnectionInDisplayInit(sptr<AbstractScreen
void AbstractScreenController::ProcessScreenConnected(ScreenId rsScreenId)
{
std::lock_guard<std::recursive_mutex> lock(mutex_);
if (!screenIdManager_.HasRsScreenId(rsScreenId)) {
WLOGFD("connect new screen");
auto absScreen = InitAndGetScreen(rsScreenId);
if (absScreen == nullptr) {
return;
}
sptr<AbstractScreenGroup> screenGroup = AddToGroupLocked(absScreen);
if (screenGroup == nullptr) {
return;
}
NotifyScreenGroupChanged(absScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onConnect_(absScreen);
}
if (rSScreenChangeListener_ != nullptr) {
rSScreenChangeListener_->onConnected_();
}
} else {
if (screenIdManager_.HasRsScreenId(rsScreenId)) {
WLOGE("reconnect screen, screenId=%{public}" PRIu64"", rsScreenId);
return;
}
WLOGFD("connect new screen");
auto absScreen = InitAndGetScreen(rsScreenId);
if (absScreen == nullptr) {
return;
}
sptr<AbstractScreenGroup> screenGroup = AddToGroupLocked(absScreen);
if (screenGroup == nullptr) {
return;
}
if (rsScreenId == rsInterface_.GetDefaultScreenId() && absScreen->rsDisplayNode_ != nullptr) {
absScreen->screenRequestedOrientation_ = buildInDefaultOrientation_;
Rotation rotationAfter = absScreen->CalcRotation(absScreen->screenRequestedOrientation_);
WLOGFD("set default rotation to %{public}d for buildin screen", rotationAfter);
sptr<SupportedScreenModes> abstractScreenModes = absScreen->GetActiveScreenMode();
if (abstractScreenModes != nullptr) {
float w = abstractScreenModes->width_;
float h = abstractScreenModes->height_;
float x = 0;
float y = 0;
if (!IsVertical(rotationAfter)) {
std::swap(w, h);
x = (h - w) / 2; // 2: used to calculate offset to center display node
y = (w - h) / 2; // 2: used to calculate offset to center display node
}
// 90.f is base degree
absScreen->rsDisplayNode_->SetRotation(-90.0f * static_cast<uint32_t>(rotationAfter));
absScreen->rsDisplayNode_->SetFrame(x, y, w, h);
absScreen->rotation_ = rotationAfter;
absScreen->SetOrientation(absScreen->screenRequestedOrientation_);
}
}
NotifyScreenConnected(absScreen->ConvertToScreenInfo());
NotifyScreenGroupChanged(absScreen->ConvertToScreenInfo(), ScreenGroupChangeEvent::ADD_TO_GROUP);
if (abstractScreenCallback_ != nullptr) {
abstractScreenCallback_->onConnect_(absScreen);
}
if (rSScreenChangeListener_ != nullptr) {
rSScreenChangeListener_->onConnected_();
}
}
@ -323,7 +346,6 @@ sptr<AbstractScreen> AbstractScreenController::InitAndGetScreen(ScreenId rsScree
return nullptr;
}
dmsScreenMap_.insert(std::make_pair(dmsScreenId, absScreen));
NotifyScreenConnected(absScreen->ConvertToScreenInfo());
return absScreen;
}
@ -635,6 +657,13 @@ DMError AbstractScreenController::SetVirtualScreenSurface(ScreenId screenId, spt
return DMError::DM_OK;
}
void AbstractScreenController::SetBuildInDefaultOrientation(Orientation orientation)
{
if (orientation >= Orientation::BEGIN && orientation <= Orientation::END) {
buildInDefaultOrientation_ = orientation;
}
}
bool AbstractScreenController::SetOrientation(ScreenId screenId, Orientation newOrientation, bool isFromWindow)
{
WLOGD("set orientation. screen %{public}" PRIu64" orientation %{public}u", screenId, newOrientation);

View File

@ -110,7 +110,8 @@ bool DisplayManagerConfig::LoadConfigXml()
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("defaultDeviceRotationOffset")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("cutoutArea")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("curvedScreenBoundary")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("waterfallAreaCompressionSizeWhenHorzontal"))) {
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("waterfallAreaCompressionSizeWhenHorzontal")) ||
!xmlStrcmp(nodeName, reinterpret_cast<const xmlChar*>("buildInDefaultOrientation"))) {
ReadIntNumbersConfigInfo(curNodePtr);
continue;
}

View File

@ -130,6 +130,17 @@ void DisplayManagerService::ConfigureDisplayManagerService()
displayCutoutController_->SetBuiltInDisplayCutoutSvgPath(
static_cast<std::string>(stringConfig["defaultDisplayCutoutPath"]));
}
ConfigureWaterfallDisplayCompressionParams();
if (numbersConfig.count("buildInDefaultOrientation") != 0) {
Orientation orientation = static_cast<Orientation>(numbersConfig["buildInDefaultOrientation"][0]);
abstractScreenController_->SetBuildInDefaultOrientation(orientation);
}
}
void DisplayManagerService::ConfigureWaterfallDisplayCompressionParams()
{
auto numbersConfig = DisplayManagerConfig::GetIntNumbersConfig();
auto enableConfig = DisplayManagerConfig::GetEnableConfig();
if (enableConfig.count("isWaterfallAreaCompressionEnableWhenHorizontal") != 0) {
DisplayCutoutController::SetWaterfallCurvedAreaLayoutCompressionEnable(
static_cast<bool>(enableConfig["isWaterfallAreaCompressionEnableWhenHorizontal"]));

View File

@ -50,4 +50,10 @@
<!-- format: uint32_t, the unit is vp. -->
<!-- default value: 0 -->
<waterfallAreaCompressionSizeWhenHorzontal>0</waterfallAreaCompressionSizeWhenHorzontal>
<!-- Indicates orientation of the built-in screen -->
<!-- 0: Orientation::UNSPECIFIED -->
<!-- 1: Orientation::VERTICAL 2: Orientation::HORIZONTAL-->
<!-- 3: Orientation::REVERSE_VERTICAL 4: Orientation::REVERSE_HORIZONTAL -->
<buildInDefaultOrientation>0</buildInDefaultOrientation>
</Configs>

View File

@ -52,7 +52,6 @@ public:
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, OffsetY, offsetY, 0);
DEFINE_VAR_DEFAULT_FUNC_GET(DisplayState, DisplayState, displayState, DisplayState::UNKNOWN);
DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, WaterfallDisplayCompressionStatus, waterfallDisplayCompressionStatus, false);
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, WaterfallDisplayCompressionSize, waterfallDisplayCompressionSize, 0);
};
} // namespace OHOS::Rosen
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H

View File

@ -29,7 +29,8 @@ bool DisplayInfo::Marshalling(Parcel &parcel) const
parcel.WriteUint32(static_cast<uint32_t>(rotation_)) &&
parcel.WriteUint32(static_cast<uint32_t>(orientation_)) &&
parcel.WriteInt32(offsetX_) && parcel.WriteInt32(offsetY_) &&
parcel.WriteUint32(static_cast<uint32_t>(displayState_));
parcel.WriteUint32(static_cast<uint32_t>(displayState_)) &&
parcel.WriteBool(waterfallDisplayCompressionStatus_);
}
DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
@ -50,7 +51,7 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel)
parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) &&
parcel.ReadUint32(rotation) && parcel.ReadUint32(orientation) &&
parcel.ReadInt32(displayInfo->offsetX_) && parcel.ReadInt32(displayInfo->offsetY_) &&
parcel.ReadUint32(displayState);
parcel.ReadUint32(displayState) && parcel.ReadBool(waterfallDisplayCompressionStatus_);
if (!res) {
delete displayInfo;
return nullptr;