diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index aa129871..19fe9849 100644 --- a/dm/include/display_manager_adapter.h +++ b/dm/include/display_manager_adapter.h @@ -28,35 +28,34 @@ #include "singleton_delegator.h" namespace OHOS::Rosen { -class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +class BaseAdapter { public: - virtual void OnRemoteDied(const wptr& wptrDeath) override; -}; - -class DisplayManagerAdapter { -WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); -public: - virtual DisplayId GetDefaultDisplayId(); - virtual sptr GetDisplayById(DisplayId displayId); - - virtual ScreenId CreateVirtualScreen(VirtualScreenOption option); - virtual DMError DestroyVirtualScreen(ScreenId screenId); - virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); - virtual bool RequestRotation(ScreenId screenId, Rotation rotation); - virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId); - - // colorspace, gamut - virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts); - virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); - virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); - virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); - virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); - virtual DMError SetScreenColorTransform(ScreenId screenId); - virtual bool RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); virtual bool UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type); + virtual void Clear(); +protected: + bool InitDMSProxyLocked(); + std::recursive_mutex mutex_; + sptr displayManagerServiceProxy_ = nullptr; + sptr dmsDeath_ = nullptr; +}; + +class DMSDeathRecipient : public IRemoteObject::DeathRecipient { +public: + DMSDeathRecipient(BaseAdapter& adapter); + virtual void OnRemoteDied(const wptr& wptrDeath) override; +private: + BaseAdapter& adapter_; +}; + +class DisplayManagerAdapter : public BaseAdapter { +WM_DECLARE_SINGLE_INSTANCE(DisplayManagerAdapter); +public: + virtual DisplayId GetDefaultDisplayId(); + virtual sptr GetDisplayById(DisplayId displayId); + virtual std::shared_ptr GetDisplaySnapshot(DisplayId displayId); virtual bool WakeUpBegin(PowerStateChangeReason reason); virtual bool WakeUpEnd(); virtual bool SuspendBegin(PowerStateChangeReason reason); @@ -65,28 +64,45 @@ public: virtual bool SetDisplayState(DisplayState state); virtual DisplayState GetDisplayState(DisplayId displayId); virtual void NotifyDisplayEvent(DisplayEvent event); - virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); - virtual void Clear(); - virtual DisplayInfo GetDisplayInfo(DisplayId displayId); - virtual sptr GetScreenInfo(ScreenId screenId); - virtual sptr GetScreenById(ScreenId screenId); - virtual sptr GetScreenGroupById(ScreenId screenId); - virtual std::vector> GetAllScreens(); - virtual DMError MakeExpand(std::vector screenId, std::vector startPoint); - virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); - + virtual void UpdateDisplayInfo(DisplayId); private: - bool InitDMSProxyLocked(); + sptr GetDisplayInfo(DisplayId displayId); static inline SingletonDelegator delegator; - std::recursive_mutex mutex_; - sptr displayManagerServiceProxy_ = nullptr; - sptr dmsDeath_ = nullptr; std::map> displayMap_; + DisplayId defaultDisplayId_; +}; + +class ScreenManagerAdapter : public BaseAdapter { +WM_DECLARE_SINGLE_INSTANCE(ScreenManagerAdapter); +public: + virtual bool RequestRotation(ScreenId screenId, Rotation rotation); + virtual ScreenId CreateVirtualScreen(VirtualScreenOption option); + virtual DMError DestroyVirtualScreen(ScreenId screenId); + virtual DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface); + virtual sptr GetScreenById(ScreenId screenId); + virtual sptr GetScreenGroupById(ScreenId screenId); + virtual std::vector> GetAllScreens(); + virtual DMError MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId); + virtual DMError MakeExpand(std::vector screenId, std::vector startPoint); + virtual bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); + virtual void UpdateScreenInfo(ScreenId); + + // colorspace, gamut + virtual DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts); + virtual DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); + virtual DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); + virtual DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); + virtual DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); + virtual DMError SetScreenColorTransform(ScreenId screenId); +private: + sptr GetScreenInfo(ScreenId screenId); + + static inline SingletonDelegator delegator; + std::map> screenMap_; std::map> screenGroupMap_; - DisplayId defaultDisplayId_; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DM_DISPLAY_MANAGER_ADAPTER_H diff --git a/dm/src/display.cpp b/dm/src/display.cpp index 4b354442..6f3465d4 100644 --- a/dm/src/display.cpp +++ b/dm/src/display.cpp @@ -23,90 +23,61 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "Display"}; } class Display::Impl : public RefBase { -friend class Display; -private: - void UpdateDisplay(sptr info); - - std::string name_; - DisplayId id_ { DISPLAY_ID_INVALD }; - int32_t width_ { 0 }; - int32_t height_ { 0 }; - uint32_t freshRate_ { 0 }; - ScreenId screenId_ {SCREEN_ID_INVALID}; - Rotation rotation_ { Rotation::ROTATION_0 }; +public: + Impl(const std::string& name, sptr info) + { + name_= name; + if (info == nullptr) { + WLOGFE("DisplayInfo is nullptr."); + } + displayInfo_ = info; + } + ~Impl() = default; + DEFINE_VAR_FUNC_GET_SET(std::string, Name, name); + DEFINE_VAR_FUNC_GET_SET(sptr, DisplayInfo, displayInfo); }; -void Display::Impl::UpdateDisplay(sptr info) +Display::Display(const std::string& name, sptr info) + : pImpl_(new Impl(name, info)) { - if (info == nullptr) { - WLOGFE("info is nullptr."); - return; - } - width_ = info->width_; - height_ = info->height_; - freshRate_ = info->freshRate_; - screenId_ = info->screenId_; - rotation_ = info->rotation_; -} - -Display::Display(const std::string& name, DisplayInfo* info) - : pImpl_(new Impl()) -{ - pImpl_->name_ = name; - pImpl_->id_ = info->id_; - pImpl_->width_ = info->width_; - pImpl_->height_ = info->height_; - pImpl_->freshRate_ = info->freshRate_; - pImpl_->screenId_ = info->screenId_; - pImpl_->rotation_ = info->rotation_; } DisplayId Display::GetId() const { - return pImpl_->id_; + return pImpl_->GetDisplayInfo()->GetDisplayId(); } int32_t Display::GetWidth() const { - DisplayInfo info = SingletonContainer::Get().GetDisplayInfo(pImpl_->id_); - pImpl_->UpdateDisplay(&info); - return pImpl_->width_; + SingletonContainer::Get().UpdateDisplayInfo(GetId()); + return pImpl_->GetDisplayInfo()->GetWidth(); } int32_t Display::GetHeight() const { - DisplayInfo info = SingletonContainer::Get().GetDisplayInfo(pImpl_->id_); - pImpl_->UpdateDisplay(&info); - return pImpl_->height_; + SingletonContainer::Get().UpdateDisplayInfo(GetId()); + return pImpl_->GetDisplayInfo()->GetHeight(); } uint32_t Display::GetFreshRate() const { - DisplayInfo info = SingletonContainer::Get().GetDisplayInfo(pImpl_->id_); - pImpl_->UpdateDisplay(&info); - return pImpl_->freshRate_; + SingletonContainer::Get().UpdateDisplayInfo(GetId()); + return pImpl_->GetDisplayInfo()->GetFreshRate(); } ScreenId Display::GetScreenId() const { - DisplayInfo info = SingletonContainer::Get().GetDisplayInfo(pImpl_->id_); - pImpl_->UpdateDisplay(&info); - return pImpl_->screenId_; + SingletonContainer::Get().UpdateDisplayInfo(GetId()); + return pImpl_->GetDisplayInfo()->GetScreenId(); } -void Display::SetWidth(int32_t width) +void Display::UpdateDisplayInfo(sptr displayInfo) { - pImpl_->width_ = width; -} - -void Display::SetHeight(int32_t height) -{ - pImpl_->height_ = height; -} - -void Display::SetFreshRate(uint32_t freshRate) -{ - pImpl_->freshRate_ = freshRate; + if (displayInfo == nullptr) { + WLOGFE("displayInfo is invalid"); + return; + } + pImpl_->SetDisplayInfo(displayInfo); } float Display::GetVirtualPixelRatio() const @@ -118,9 +89,4 @@ float Display::GetVirtualPixelRatio() const return 2.0f; #endif } - -void Display::SetId(DisplayId id) -{ - pImpl_->id_ = id; -} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/display_manager.cpp b/dm/src/display_manager.cpp index 096078c0..3bf45203 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -54,7 +54,7 @@ public: void OnDisplayCreate(sptr displayInfo) override { - if (displayInfo == nullptr || displayInfo->id_ == DISPLAY_ID_INVALD) { + if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALD) { WLOGFE("OnDisplayCreate, displayInfo is invalid."); return; } @@ -63,7 +63,7 @@ public: return; } for (auto listener : pImpl_->displayListeners_) { - listener->OnCreate(displayInfo->id_); + listener->OnCreate(displayInfo->GetDisplayId()); } }; @@ -84,7 +84,7 @@ public: void OnDisplayChange(const sptr displayInfo, DisplayChangeEvent event) override { - if (displayInfo == nullptr || displayInfo->id_ == DISPLAY_ID_INVALD) { + if (displayInfo == nullptr || displayInfo->GetDisplayId() == DISPLAY_ID_INVALD) { WLOGFE("OnDisplayChange, displayInfo is invalid."); return; } @@ -92,9 +92,9 @@ public: WLOGFE("OnDisplayChange, impl is nullptr."); return; } - WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->id_, event); + WLOGD("OnDisplayChange. display %{public}" PRIu64", event %{public}u", displayInfo->GetDisplayId(), event); for (auto listener : pImpl_->displayListeners_) { - listener->OnChange(displayInfo->id_, event); + listener->OnChange(displayInfo->GetDisplayId(), event); } }; private: @@ -380,7 +380,7 @@ void DisplayManager::NotifyDisplayChangedEvent(const sptr info, Dis WLOGI("NotifyDisplayChangedEvent event:%{public}u, size:%{public}zu", event, pImpl_->displayListeners_.size()); std::lock_guard lock(pImpl_->mutex_); for (auto& listener : pImpl_->displayListeners_) { - listener->OnChange(info->id_, event); + listener->OnChange(info->GetDisplayId(), event); } } diff --git a/dm/src/display_manager_adapter.cpp b/dm/src/display_manager_adapter.cpp index 80ad19ba..2e58f1d6 100644 --- a/dm/src/display_manager_adapter.cpp +++ b/dm/src/display_manager_adapter.cpp @@ -26,6 +26,7 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "DisplayManagerAdapter"}; } WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManagerAdapter) +WM_IMPLEMENT_SINGLE_INSTANCE(ScreenManagerAdapter) DisplayId DisplayManagerAdapter::GetDefaultDisplayId() { @@ -56,35 +57,34 @@ sptr DisplayManagerAdapter::GetDisplayById(DisplayId displayId) if (iter != displayMap_.end()) { // Update display in map // should be updated automatically - DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); - if (displayInfo.id_ == DISPLAY_ID_INVALD) { + auto displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + if (displayInfo == nullptr) { + WLOGFE("GetDisplayById: displayInfo is nullptr!"); + displayMap_.erase(iter); + return nullptr; + } + if (displayInfo->GetDisplayId() == DISPLAY_ID_INVALD) { WLOGFE("GetDisplayById: Get invalid displayInfo!"); + displayMap_.erase(iter); return nullptr; } sptr display = iter->second; - if (displayInfo.width_ != display->GetWidth()) { - display->SetWidth(displayInfo.width_); - WLOGFI("GetDisplayById: set new width %{public}d", display->GetWidth()); - } - if (displayInfo.height_ != display->GetHeight()) { - display->SetHeight(displayInfo.height_); - WLOGFI("GetDisplayById: set new height %{public}d", display->GetHeight()); - } - if (displayInfo.freshRate_ != display->GetFreshRate()) { - display->SetFreshRate(displayInfo.freshRate_); - WLOGFI("GetDisplayById: set new freshRate %{public}ud", display->GetFreshRate()); - } + display->UpdateDisplayInfo(displayInfo); return iter->second; } - DisplayInfo displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); - sptr display = new Display("", &displayInfo); + auto displayInfo = displayManagerServiceProxy_->GetDisplayInfoById(displayId); + if (displayInfo == nullptr) { + WLOGFE("GetDisplayById: displayInfo is nullptr!"); + return nullptr; + } + sptr display = new Display("", displayInfo); if (display->GetId() != DISPLAY_ID_INVALD) { displayMap_[display->GetId()] = display; } return display; } -bool DisplayManagerAdapter::RequestRotation(ScreenId screenId, Rotation rotation) +bool ScreenManagerAdapter::RequestRotation(ScreenId screenId, Rotation rotation) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { @@ -109,7 +109,7 @@ std::shared_ptr DisplayManagerAdapter::GetDisplaySnapshot(Displ return dispalySnapshot; } -DMError DisplayManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId, +DMError ScreenManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId, std::vector& colorGamuts) { std::lock_guard lock(mutex_); @@ -123,7 +123,7 @@ DMError DisplayManagerAdapter::GetScreenSupportedColorGamuts(ScreenId screenId, return ret; } -DMError DisplayManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) +DMError ScreenManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut) { std::lock_guard lock(mutex_); @@ -136,7 +136,7 @@ DMError DisplayManagerAdapter::GetScreenColorGamut(ScreenId screenId, ScreenColo return ret; } -DMError DisplayManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx) +DMError ScreenManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx) { std::lock_guard lock(mutex_); @@ -149,7 +149,7 @@ DMError DisplayManagerAdapter::SetScreenColorGamut(ScreenId screenId, int32_t co return ret; } -DMError DisplayManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap) +DMError ScreenManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap) { std::lock_guard lock(mutex_); @@ -162,7 +162,7 @@ DMError DisplayManagerAdapter::GetScreenGamutMap(ScreenId screenId, ScreenGamutM return ret; } -DMError DisplayManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap) +DMError ScreenManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap) { std::lock_guard lock(mutex_); @@ -175,7 +175,7 @@ DMError DisplayManagerAdapter::SetScreenGamutMap(ScreenId screenId, ScreenGamutM return ret; } -DMError DisplayManagerAdapter::SetScreenColorTransform(ScreenId screenId) +DMError ScreenManagerAdapter::SetScreenColorTransform(ScreenId screenId) { std::lock_guard lock(mutex_); @@ -188,7 +188,7 @@ DMError DisplayManagerAdapter::SetScreenColorTransform(ScreenId screenId) return ret; } -ScreenId DisplayManagerAdapter::CreateVirtualScreen(VirtualScreenOption option) +ScreenId ScreenManagerAdapter::CreateVirtualScreen(VirtualScreenOption option) { if (!InitDMSProxyLocked()) { return SCREEN_ID_INVALID; @@ -197,7 +197,7 @@ ScreenId DisplayManagerAdapter::CreateVirtualScreen(VirtualScreenOption option) return displayManagerServiceProxy_->CreateVirtualScreen(option); } -DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) +DMError ScreenManagerAdapter::DestroyVirtualScreen(ScreenId screenId) { if (!InitDMSProxyLocked()) { return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; @@ -206,7 +206,7 @@ DMError DisplayManagerAdapter::DestroyVirtualScreen(ScreenId screenId) return displayManagerServiceProxy_->DestroyVirtualScreen(screenId); } -DMError DisplayManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr surface) +DMError ScreenManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptr surface) { if (!InitDMSProxyLocked()) { return DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED; @@ -215,7 +215,7 @@ DMError DisplayManagerAdapter::SetVirtualScreenSurface(ScreenId screenId, sptrSetVirtualScreenSurface(screenId, surface); } -bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool BaseAdapter::RegisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); @@ -225,7 +225,7 @@ bool DisplayManagerAdapter::RegisterDisplayManagerAgent(const sptrRegisterDisplayManagerAgent(displayManagerAgent, type); } -bool DisplayManagerAdapter::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, +bool BaseAdapter::UnregisterDisplayManagerAgent(const sptr& displayManagerAgent, DisplayManagerAgentType type) { std::lock_guard lock(mutex_); @@ -308,7 +308,7 @@ void DisplayManagerAdapter::NotifyDisplayEvent(DisplayEvent event) displayManagerServiceProxy_->NotifyDisplayEvent(event); } -bool DisplayManagerAdapter::InitDMSProxyLocked() +bool BaseAdapter::InitDMSProxyLocked() { if (!displayManagerServiceProxy_) { sptr systemAbilityManager = @@ -331,7 +331,7 @@ bool DisplayManagerAdapter::InitDMSProxyLocked() return false; } - dmsDeath_ = new DMSDeathRecipient(); + dmsDeath_ = new DMSDeathRecipient(*this); if (!dmsDeath_) { WLOGFE("Failed to create death Recipient ptr DMSDeathRecipient"); return false; @@ -344,6 +344,10 @@ bool DisplayManagerAdapter::InitDMSProxyLocked() return true; } +DMSDeathRecipient::DMSDeathRecipient(BaseAdapter& adapter) : adapter_(adapter) +{ +} + void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) { if (wptrDeath == nullptr) { @@ -356,11 +360,11 @@ void DMSDeathRecipient::OnRemoteDied(const wptr& wptrDeath) WLOGFE("object is null"); return; } - SingletonContainer::Get().Clear(); + adapter_.Clear(); return; } -void DisplayManagerAdapter::Clear() +void BaseAdapter::Clear() { std::lock_guard lock(mutex_); if ((displayManagerServiceProxy_ != nullptr) && (displayManagerServiceProxy_->AsObject() != nullptr)) { @@ -369,7 +373,7 @@ void DisplayManagerAdapter::Clear() displayManagerServiceProxy_ = nullptr; } -DMError DisplayManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) +DMError ScreenManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vector mirrorScreenId) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { @@ -378,7 +382,7 @@ DMError DisplayManagerAdapter::MakeMirror(ScreenId mainScreenId, std::vectorMakeMirror(mainScreenId, mirrorScreenId); } -sptr DisplayManagerAdapter::GetScreenInfo(ScreenId screenId) +sptr ScreenManagerAdapter::GetScreenInfo(ScreenId screenId) { if (screenId == SCREEN_ID_INVALID) { WLOGFE("screen id is invalid"); @@ -396,80 +400,76 @@ sptr DisplayManagerAdapter::GetScreenInfo(ScreenId screenId) return screenInfo; } -DisplayInfo DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId) +sptr DisplayManagerAdapter::GetDisplayInfo(DisplayId displayId) { if (displayId == DISPLAY_ID_INVALD) { WLOGFE("screen id is invalid"); - return DisplayInfo(); + return nullptr; } std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { WLOGFE("InitDMSProxyLocked failed!"); - return DisplayInfo(); + return nullptr; } return displayManagerServiceProxy_->GetDisplayInfoById(displayId); } -sptr DisplayManagerAdapter::GetScreenById(ScreenId screenId) +sptr ScreenManagerAdapter::GetScreenById(ScreenId screenId) { std::lock_guard lock(mutex_); - if (screenId == SCREEN_ID_INVALID) { - WLOGFE("screen id is invalid"); + sptr screenInfo = GetScreenInfo(screenId); + if (screenInfo == nullptr) { + WLOGFE("screenInfo is null"); + screenMap_.erase(screenId); return nullptr; } auto iter = screenMap_.find(screenId); if (iter != screenMap_.end()) { WLOGFI("get screen in screen map"); + iter->second->UpdateScreenInfo(screenInfo); return iter->second; } - - if (!InitDMSProxyLocked()) { - WLOGFE("InitDMSProxyLocked failed!"); - return nullptr; - } - sptr screenInfo = displayManagerServiceProxy_->GetScreenInfoById(screenId); - if (screenInfo == nullptr) { - WLOGFE("screenInfo is null"); - return nullptr; - } - sptr screen = new Screen(screenInfo.GetRefPtr()); + sptr screen = new Screen(screenInfo); screenMap_.insert(std::make_pair(screenId, screen)); return screen; } -sptr DisplayManagerAdapter::GetScreenGroupById(ScreenId screenId) +sptr ScreenManagerAdapter::GetScreenGroupById(ScreenId screenId) { std::lock_guard lock(mutex_); if (screenId == SCREEN_ID_INVALID) { WLOGFE("screenGroup id is invalid"); return nullptr; } - auto iter = screenGroupMap_.find(screenId); - if (iter != screenGroupMap_.end()) { - WLOGFI("get screenGroup in screenGroup map"); - return iter->second; - } - if (!InitDMSProxyLocked()) { WLOGFE("InitDMSProxyLocked failed!"); + screenGroupMap_.clear(); return nullptr; } sptr screenGroupInfo = displayManagerServiceProxy_->GetScreenGroupInfoById(screenId); if (screenGroupInfo == nullptr) { WLOGFE("screenGroupInfo is null"); + screenGroupMap_.erase(screenId); return nullptr; } - sptr screenGroup = new ScreenGroup(screenGroupInfo.GetRefPtr()); + auto iter = screenGroupMap_.find(screenId); + if (iter != screenGroupMap_.end()) { + WLOGFI("get screenGroup in screenGroup map"); + iter->second->UpdateScreenGroupInfo(screenGroupInfo); + return iter->second; + } + sptr screenGroup = new ScreenGroup(screenGroupInfo); screenGroupMap_.insert(std::make_pair(screenId, screenGroup)); return screenGroup; } -std::vector> DisplayManagerAdapter::GetAllScreens() +std::vector> ScreenManagerAdapter::GetAllScreens() { std::lock_guard lock(mutex_); std::vector> screens; if (!InitDMSProxyLocked()) { WLOGFE("InitDMSProxyLocked failed!"); + screenMap_.clear(); return screens; } std::vector> screenInfos = displayManagerServiceProxy_->GetAllScreenInfos(); @@ -478,12 +478,24 @@ std::vector> DisplayManagerAdapter::GetAllScreens() WLOGFE("screenInfo is null"); continue; } - screens.emplace_back(new Screen(info.GetRefPtr())); + auto iter = screenMap_.find(info->GetScreenId()); + if (iter != screenMap_.end()) { + WLOGFI("get screen in screen map"); + iter->second->UpdateScreenInfo(info); + screens.emplace_back(iter->second); + } else { + sptr screen = new Screen(info); + screens.emplace_back(screen); + } + } + screenMap_.clear(); + for (auto screen: screens) { + screenMap_.insert(std::make_pair(screen->GetId(), screen)); } return screens; } -DMError DisplayManagerAdapter::MakeExpand(std::vector screenId, std::vector startPoint) +DMError ScreenManagerAdapter::MakeExpand(std::vector screenId, std::vector startPoint) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { @@ -492,7 +504,7 @@ DMError DisplayManagerAdapter::MakeExpand(std::vector screenId, std::v return displayManagerServiceProxy_->MakeExpand(screenId, startPoint); } -bool DisplayManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) +bool ScreenManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t modeId) { std::lock_guard lock(mutex_); if (!InitDMSProxyLocked()) { @@ -500,4 +512,30 @@ bool DisplayManagerAdapter::SetScreenActiveMode(ScreenId screenId, uint32_t mode } return displayManagerServiceProxy_->SetScreenActiveMode(screenId, modeId); } + +void ScreenManagerAdapter::UpdateScreenInfo(ScreenId screenId) +{ + auto screenInfo = GetScreenInfo(screenId); + if (screenInfo == nullptr) { + WLOGFE("screenInfo is invalid"); + return; + } + auto iter = screenMap_.find(screenId); + if (iter != screenMap_.end()) { + iter->second->UpdateScreenInfo(screenInfo); + } +} + +void DisplayManagerAdapter::UpdateDisplayInfo(DisplayId displayId) +{ + auto displayInfo = GetDisplayInfo(displayId); + if (displayInfo == nullptr) { + WLOGFE("displayInfo is invalid"); + return; + } + auto iter = displayMap_.find(displayId); + if (iter != displayMap_.end()) { + iter->second->UpdateDisplayInfo(displayInfo); + } +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/screen.cpp b/dm/src/screen.cpp index d4a227b3..ba7fd260 100644 --- a/dm/src/screen.cpp +++ b/dm/src/screen.cpp @@ -16,7 +16,6 @@ #include "screen.h" #include "display_manager_adapter.h" -#include "screen_group.h" #include "screen_info.h" #include "window_manager_hilog.h" @@ -25,55 +24,21 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "Screen"}; } class Screen::Impl : public RefBase { -friend class Screen; public: - Impl() = default; + Impl(sptr info) + { + if (info == nullptr) { + WLOGFE("ScreenInfo is nullptr."); + } + screenInfo_ = info; + } ~Impl() = default; - void UpdateScreen(sptr info); - - ScreenId id_ { SCREEN_ID_INVALID }; - uint32_t virtualWidth_ { 0 }; - uint32_t virtualHeight_ { 0 }; - float virtualPixelRatio_ { 0.0 }; - ScreenId parent_ { SCREEN_ID_INVALID }; - bool canHasChild_ { false }; - uint32_t modeId_ { 0 }; - std::vector> modes_ {}; - Rotation rotation_ { Rotation::ROTATION_0 }; + DEFINE_VAR_FUNC_GET_SET(sptr, ScreenInfo, screenInfo); }; -void Screen::Impl::UpdateScreen(sptr info) +Screen::Screen(sptr info) + : pImpl_(new Impl(info)) { - if (info == nullptr) { - WLOGFE("info is nullptr."); - return; - } - virtualWidth_ = info->virtualWidth_; - virtualHeight_ = info->virtualHeight_; - virtualPixelRatio_ = info->virtualPixelRatio_; - parent_ = info->parent_; - canHasChild_ = info->canHasChild_; - modeId_ = info->modeId_; - modes_ = info->modes_; - rotation_ = info->rotation_; -} - -Screen::Screen(const ScreenInfo* info) - : pImpl_(new Impl()) -{ - if (info == nullptr) { - WLOGFE("info is nullptr."); - return; - } - pImpl_->id_ = info->id_; - pImpl_->virtualWidth_ = info->virtualWidth_; - pImpl_->virtualHeight_ = info->virtualHeight_; - pImpl_->virtualPixelRatio_ = info->virtualPixelRatio_; - pImpl_->parent_ = info->parent_; - pImpl_->canHasChild_ = info->canHasChild_; - pImpl_->modeId_ = info->modeId_; - pImpl_->modes_ = info->modes_; - pImpl_->rotation_ = info->rotation_; } Screen::~Screen() @@ -82,22 +47,20 @@ Screen::~Screen() bool Screen::IsGroup() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - return pImpl_->canHasChild_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + return pImpl_->GetScreenInfo()->GetCanHasChild(); } ScreenId Screen::GetId() const { - return pImpl_->id_; + return pImpl_->GetScreenInfo()->GetScreenId(); } uint32_t Screen::GetWidth() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - auto modeId = pImpl_->modeId_; - auto modes = pImpl_->modes_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + auto modeId = GetModeId(); + auto modes = GetSupportedModes(); if (modeId < 0 || modeId >= modes.size()) { return 0; } @@ -106,10 +69,9 @@ uint32_t Screen::GetWidth() const uint32_t Screen::GetHeight() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - auto modeId = pImpl_->modeId_; - auto modes = pImpl_->modes_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + auto modeId = GetModeId(); + auto modes = GetSupportedModes(); if (modeId < 0 || modeId >= modes.size()) { return 0; } @@ -118,93 +80,98 @@ uint32_t Screen::GetHeight() const uint32_t Screen::GetVirtualWidth() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - return pImpl_->virtualWidth_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + return pImpl_->GetScreenInfo()->GetVirtualWidth(); } uint32_t Screen::GetVirtualHeight() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - return pImpl_->virtualHeight_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + return pImpl_->GetScreenInfo()->GetVirtualHeight(); } float Screen::GetVirtualPixelRatio() const { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - return pImpl_->virtualPixelRatio_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + return pImpl_->GetScreenInfo()->GetVirtualPixelRatio(); } Rotation Screen::GetRotation() { - sptr info = SingletonContainer::Get().GetScreenInfo(pImpl_->id_); - pImpl_->UpdateScreen(info); - return pImpl_->rotation_; + SingletonContainer::Get().UpdateScreenInfo(GetId()); + return pImpl_->GetScreenInfo()->GetRotation(); } bool Screen::RequestRotation(Rotation rotation) { WLOGFD("rotation the screen"); - return SingletonContainer::Get().RequestRotation(pImpl_->id_, rotation); + return SingletonContainer::Get().RequestRotation(GetId(), rotation); } DMError Screen::GetScreenSupportedColorGamuts(std::vector& colorGamuts) const { - return SingletonContainer::Get().GetScreenSupportedColorGamuts(pImpl_->id_, colorGamuts); + return SingletonContainer::Get().GetScreenSupportedColorGamuts(GetId(), colorGamuts); } DMError Screen::GetScreenColorGamut(ScreenColorGamut& colorGamut) const { - return SingletonContainer::Get().GetScreenColorGamut(pImpl_->id_, colorGamut); + return SingletonContainer::Get().GetScreenColorGamut(GetId(), colorGamut); } DMError Screen::SetScreenColorGamut(int32_t colorGamutIdx) { - return SingletonContainer::Get().SetScreenColorGamut(pImpl_->id_, colorGamutIdx); + return SingletonContainer::Get().SetScreenColorGamut(GetId(), colorGamutIdx); } DMError Screen::GetScreenGamutMap(ScreenGamutMap& gamutMap) const { - return SingletonContainer::Get().GetScreenGamutMap(pImpl_->id_, gamutMap); + return SingletonContainer::Get().GetScreenGamutMap(GetId(), gamutMap); } DMError Screen::SetScreenGamutMap(ScreenGamutMap gamutMap) { - return SingletonContainer::Get().SetScreenGamutMap(pImpl_->id_, gamutMap); + return SingletonContainer::Get().SetScreenGamutMap(GetId(), gamutMap); } DMError Screen::SetScreenColorTransform() { - return SingletonContainer::Get().SetScreenColorTransform(pImpl_->id_); + return SingletonContainer::Get().SetScreenColorTransform(GetId()); } ScreenId Screen::GetParentId() const { - return pImpl_->parent_; + return pImpl_->GetScreenInfo()->GetParentId(); } uint32_t Screen::GetModeId() const { - return pImpl_->modeId_; + return pImpl_->GetScreenInfo()->GetModeId(); } std::vector> Screen::GetSupportedModes() const { - return pImpl_->modes_; + return pImpl_->GetScreenInfo()->GetModes(); } bool Screen::SetScreenActiveMode(uint32_t modeId) { - ScreenId screenId = pImpl_->id_; - if (modeId < 0 || modeId >= pImpl_->modes_.size()) { + ScreenId screenId = GetId(); + if (modeId < 0 || modeId >= GetSupportedModes().size()) { return false; } - if (SingletonContainer::Get().SetScreenActiveMode(screenId, modeId)) { - pImpl_->modeId_ = modeId; + if (SingletonContainer::Get().SetScreenActiveMode(screenId, modeId)) { + pImpl_->GetScreenInfo()->SetModeId(modeId); return true; } return false; } + +void Screen::UpdateScreenInfo(sptr screenInfo) +{ + if (screenInfo == nullptr) { + WLOGFE("ScreenInfo is invalid"); + return; + } + pImpl_->SetScreenInfo(screenInfo); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/screen_group.cpp b/dm/src/screen_group.cpp index 91e17a8d..9ac64d7b 100644 --- a/dm/src/screen_group.cpp +++ b/dm/src/screen_group.cpp @@ -23,26 +23,30 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "ScreenGroup"}; } class ScreenGroup::Impl : public RefBase { -friend class ScreenGroup; -private: - Impl() = default; +public: + Impl(sptr info) + { + if (info == nullptr) { + WLOGFE("ScreenGroupInfo is nullptr."); + } + screenGroupInfo_ = info; + } ~Impl() = default; - std::vector children_; - std::vector position_; - ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; + DEFINE_VAR_FUNC_GET_SET(sptr, ScreenGroupInfo, screenGroupInfo); }; -ScreenGroup::ScreenGroup(const ScreenGroupInfo* info) - : Screen(info), pImpl_(new Impl()) +ScreenGroup::ScreenGroup(sptr info) + : Screen(info), pImpl_(new Impl(info)) +{ +} + +void ScreenGroup::UpdateScreenGroupInfo(sptr info) { if (info == nullptr) { - WLOGFE("info is nullptr."); - return; + WLOGFE("ScreenGroupInfo is nullptr."); } - pImpl_->children_ = info->children_; - pImpl_->position_ = info->position_; - pImpl_->combination_ = info->combination_; + pImpl_->SetScreenGroupInfo(info); } ScreenGroup::~ScreenGroup() @@ -51,16 +55,16 @@ ScreenGroup::~ScreenGroup() ScreenCombination ScreenGroup::GetCombination() const { - return pImpl_->combination_; + return pImpl_->GetScreenGroupInfo()->GetCombination(); } -std::vector ScreenGroup::GetChild() const +std::vector ScreenGroup::GetChildIds() const { - return pImpl_->children_; + return pImpl_->GetScreenGroupInfo()->GetChildren(); } -std::vector ScreenGroup::GetChildPosition() const +std::vector ScreenGroup::GetChildPositions() const { - return pImpl_->position_; + return pImpl_->GetScreenGroupInfo()->GetPosition(); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/src/screen_manager.cpp b/dm/src/screen_manager.cpp index abbbee9d..b81e640e 100644 --- a/dm/src/screen_manager.cpp +++ b/dm/src/screen_manager.cpp @@ -43,7 +43,7 @@ public: void OnScreenConnect(sptr screenInfo) { - if (screenInfo == nullptr || screenInfo->id_ == SCREEN_ID_INVALID) { + if (screenInfo == nullptr || screenInfo->GetScreenId() == SCREEN_ID_INVALID) { WLOGFE("OnScreenConnect, screenInfo is invalid."); return; } @@ -52,7 +52,7 @@ public: return; } for (auto listener : pImpl_->screenListeners_) { - listener->OnConnect(screenInfo->id_); + listener->OnConnect(screenInfo->GetScreenId()); } }; @@ -84,8 +84,8 @@ public: WLOGFD("OnScreenChange. event %{public}u", event); std::vector screenIds; for (auto screenInfo : screenInfos) { - if (screenInfo->id_ != SCREEN_ID_INVALID) { - screenIds.push_back(screenInfo->id_); + if (screenInfo->GetScreenId() != SCREEN_ID_INVALID) { + screenIds.push_back(screenInfo->GetScreenId()); } } for (auto listener: pImpl_->screenListeners_) { @@ -108,17 +108,17 @@ ScreenManager::~ScreenManager() sptr ScreenManager::GetScreenById(ScreenId screenId) { - return SingletonContainer::Get().GetScreenById(screenId); + return SingletonContainer::Get().GetScreenById(screenId); } sptr ScreenManager::GetScreenGroupById(ScreenId screenId) { - return SingletonContainer::Get().GetScreenGroupById(screenId); + return SingletonContainer::Get().GetScreenGroupById(screenId); } std::vector> ScreenManager::GetAllScreens() { - return SingletonContainer::Get().GetAllScreens(); + return SingletonContainer::Get().GetAllScreens(); } bool ScreenManager::RegisterScreenListener(sptr listener) @@ -131,7 +131,7 @@ bool ScreenManager::RegisterScreenListener(sptr listener) pImpl_->screenListeners_.push_back(listener); if (screenManagerListener_ == nullptr) { screenManagerListener_ = new ScreenManagerListener(pImpl_); - SingletonContainer::Get().RegisterDisplayManagerAgent( + SingletonContainer::Get().RegisterDisplayManagerAgent( screenManagerListener_, DisplayManagerAgentType::SCREEN_EVENT_LISTENER); } @@ -152,7 +152,7 @@ bool ScreenManager::UnregisterScreenListener(sptr listener) } pImpl_->screenListeners_.erase(iter); if (pImpl_->screenListeners_.empty() && screenManagerListener_ != nullptr) { - SingletonContainer::Get().UnregisterDisplayManagerAgent( + SingletonContainer::Get().UnregisterDisplayManagerAgent( screenManagerListener_, DisplayManagerAgentType::SCREEN_EVENT_LISTENER); screenManagerListener_ = nullptr; @@ -172,7 +172,7 @@ ScreenId ScreenManager::MakeExpand(const std::vector& options) screenIds.emplace_back(option.screenId_); startPoints.emplace_back(Point(option.startX_, option.startY_)); } - DMError result = SingletonContainer::Get().MakeExpand(screenIds, startPoints); + DMError result = SingletonContainer::Get().MakeExpand(screenIds, startPoints); if (result != DMError::DM_OK) { return SCREEN_ID_INVALID; } @@ -184,7 +184,7 @@ ScreenId ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector { WLOGFI("create mirror for screen: %{public}" PRIu64"", mainScreenId); // TODO: "record screen" should use another function, "MakeMirror" should return group id. - DMError result = SingletonContainer::Get().MakeMirror(mainScreenId, mirrorScreenId); + DMError result = SingletonContainer::Get().MakeMirror(mainScreenId, mirrorScreenId); if (result == DMError::DM_OK) { WLOGFI("create mirror success"); } @@ -193,16 +193,16 @@ ScreenId ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option) { - return SingletonContainer::Get().CreateVirtualScreen(option); + return SingletonContainer::Get().CreateVirtualScreen(option); } DMError ScreenManager::DestroyVirtualScreen(ScreenId screenId) { - return SingletonContainer::Get().DestroyVirtualScreen(screenId); + return SingletonContainer::Get().DestroyVirtualScreen(screenId); } DMError ScreenManager::SetVirtualScreenSurface(ScreenId screenId, sptr surface) { - return SingletonContainer::Get().SetVirtualScreenSurface(screenId, surface); + return SingletonContainer::Get().SetVirtualScreenSurface(screenId, surface); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/test/unittest/mock_display_manager_adapter.h b/dm/test/unittest/mock_display_manager_adapter.h index 97dbef49..46ee9bc5 100644 --- a/dm/test/unittest/mock_display_manager_adapter.h +++ b/dm/test/unittest/mock_display_manager_adapter.h @@ -23,25 +23,45 @@ namespace OHOS { namespace Rosen { class MockDisplayManagerAdapter : public DisplayManagerAdapter { public: - MOCK_METHOD0(GetDefaultDisplayId, DisplayId()); - MOCK_METHOD1(GetDisplayById, sptr(DisplayId displayId)); - MOCK_METHOD1(CreateVirtualScreen, ScreenId(VirtualScreenOption option)); - MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId)); - MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr(DisplayId displayId)); MOCK_METHOD0(Clear, void()); MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, DisplayManagerAgentType type)); MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, DisplayManagerAgentType type)); + MOCK_METHOD0(GetDefaultDisplayId, DisplayId()); + MOCK_METHOD1(GetDisplayById, sptr(DisplayId displayId)); + MOCK_METHOD1(GetDisplaySnapshot, std::shared_ptr(DisplayId displayId)); + MOCK_METHOD1(WakeUpBegin, bool(PowerStateChangeReason reason)); MOCK_METHOD0(WakeUpEnd, bool()); MOCK_METHOD1(SuspendBegin, bool(PowerStateChangeReason reason)); MOCK_METHOD0(SuspendEnd, bool()); MOCK_METHOD2(SetScreenPowerForAll, bool(DisplayPowerState state, PowerStateChangeReason reason)); MOCK_METHOD1(SetDisplayState, bool(DisplayState state)); - MOCK_METHOD1(GetDisplayState, DisplayState(uint64_t displayId)); - MOCK_METHOD2(SetScreenActiveMode, bool(ScreenId screenId, uint32_t modeId)); + MOCK_METHOD1(GetDisplayState, DisplayState(DisplayId displayId)); + MOCK_METHOD1(NotifyDisplayEvent, void(DisplayEvent event)); + MOCK_METHOD1(UpdateDisplayInfo, void(DisplayId displayId)); +}; + +class MockScreenManagerAdapter : public ScreenManagerAdapter { +public: + MOCK_METHOD0(Clear, void()); + MOCK_METHOD2(RegisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, + DisplayManagerAgentType type)); + MOCK_METHOD2(UnregisterDisplayManagerAgent, bool(const sptr& displayManagerAgent, + DisplayManagerAgentType type)); + MOCK_METHOD2(RequestRotation, bool(ScreenId screenId, Rotation rotation)); + MOCK_METHOD1(CreateVirtualScreen, ScreenId(VirtualScreenOption option)); + MOCK_METHOD1(DestroyVirtualScreen, DMError(ScreenId screenId)); + MOCK_METHOD2(SetVirtualScreenSurface, DMError(ScreenId screenId, sptr surface)); + MOCK_METHOD1(GetScreenById, sptr(ScreenId screenId)); + MOCK_METHOD1(GetScreenGroupById, sptr(ScreenId screenId)); + MOCK_METHOD0(GetAllScreens, std::vector>()); + MOCK_METHOD2(MakeMirror, DMError(ScreenId mainScreenId, std::vector mirrorScreenId)); MOCK_METHOD2(MakeExpand, DMError(std::vector screenId, std::vector startPoint)); + MOCK_METHOD2(SetScreenActiveMode, bool(ScreenId screenId, uint32_t modeId)); + MOCK_METHOD1(UpdateScreenInfo, void(ScreenId screenId)); + MOCK_METHOD2(GetScreenSupportedColorGamuts, DMError(ScreenId screenId, std::vector& colorGamuts)); MOCK_METHOD2(GetScreenColorGamut, DMError(ScreenId screenId, ScreenColorGamut& colorGamut)); MOCK_METHOD2(SetScreenColorGamut, DMError(ScreenId screenId, int32_t colorGamutIdx)); diff --git a/dm/test/unittest/screen_manager_test.cpp b/dm/test/unittest/screen_manager_test.cpp index d6da30be..eeafc8b3 100644 --- a/dm/test/unittest/screen_manager_test.cpp +++ b/dm/test/unittest/screen_manager_test.cpp @@ -22,7 +22,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using Mocker = SingletonMocker; +using Mocker = SingletonMocker; sptr ScreenManagerTest::defaultDisplay_ = nullptr; DisplayId ScreenManagerTest::defaultDisplayId_ = DISPLAY_ID_INVALD; diff --git a/dm/test/unittest/screen_test.cpp b/dm/test/unittest/screen_test.cpp index 23086993..e6aebea0 100644 --- a/dm/test/unittest/screen_test.cpp +++ b/dm/test/unittest/screen_test.cpp @@ -22,7 +22,7 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { -using Mocker = SingletonMocker; +using Mocker = SingletonMocker; sptr ScreenTest::defaultDisplay_ = nullptr; ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID; diff --git a/dmserver/include/abstract_display.h b/dmserver/include/abstract_display.h index 3b505006..79ba8b9c 100644 --- a/dmserver/include/abstract_display.h +++ b/dmserver/include/abstract_display.h @@ -28,7 +28,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(const DisplayInfo& info); + AbstractDisplay(const DisplayInfo* info); AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate); ~AbstractDisplay() = default; static inline bool IsVertical(Rotation rotation) @@ -43,7 +43,7 @@ public: ScreenId GetAbstractScreenId() const; bool BindAbstractScreen(ScreenId dmsScreenId); bool BindAbstractScreen(sptr abstractDisplay); - const sptr ConvertToDisplayInfo() const; + sptr ConvertToDisplayInfo() const; void SetId(DisplayId displayId); void SetWidth(int32_t width); diff --git a/dmserver/include/abstract_screen.h b/dmserver/include/abstract_screen.h index c89d392d..cbf32a2a 100644 --- a/dmserver/include/abstract_screen.h +++ b/dmserver/include/abstract_screen.h @@ -46,7 +46,7 @@ public: sptr GetActiveScreenMode() const; std::vector> GetAbstractScreenModes() const; sptr GetGroup() const; - const sptr ConvertToScreenInfo() const; + sptr ConvertToScreenInfo() const; void RequestRotation(Rotation rotation); Rotation GetRotation() const; @@ -90,7 +90,7 @@ public: std::vector> GetChildren() const; std::vector GetChildrenPosition() const; size_t GetChildCount() const; - const sptr ConvertToScreenGroupInfo() const; + sptr ConvertToScreenGroupInfo() const; bool SetRSDisplayNodeConfig(sptr& dmsScreen, struct RSDisplayNodeConfig& config); ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; diff --git a/dmserver/include/display_manager_interface.h b/dmserver/include/display_manager_interface.h index c4cb521b..9e9c40f6 100644 --- a/dmserver/include/display_manager_interface.h +++ b/dmserver/include/display_manager_interface.h @@ -68,7 +68,7 @@ public: }; virtual DisplayId GetDefaultDisplayId() = 0; - virtual DisplayInfo GetDisplayInfoById(DisplayId displayId) = 0; + virtual sptr GetDisplayInfoById(DisplayId displayId) = 0; virtual ScreenId CreateVirtualScreen(VirtualScreenOption option) = 0; virtual DMError DestroyVirtualScreen(ScreenId screenId) = 0; diff --git a/dmserver/include/display_manager_proxy.h b/dmserver/include/display_manager_proxy.h index 0d30ce4c..28d98a68 100644 --- a/dmserver/include/display_manager_proxy.h +++ b/dmserver/include/display_manager_proxy.h @@ -32,7 +32,7 @@ public: ~DisplayManagerProxy() {}; DisplayId GetDefaultDisplayId() override; - DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + sptr GetDisplayInfoById(DisplayId displayId) override; ScreenId CreateVirtualScreen(VirtualScreenOption option) override; DMError DestroyVirtualScreen(ScreenId screenId) override; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index ee3dc6d9..356521ba 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -51,7 +51,7 @@ public: DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; DisplayId GetDefaultDisplayId() override; - DisplayInfo GetDisplayInfoById(DisplayId displayId) override; + sptr GetDisplayInfoById(DisplayId displayId) override; bool RequestRotation(ScreenId screenId, Rotation rotation) override; std::shared_ptr GetDispalySnapshot(DisplayId displayId) override; ScreenId GetRSScreenId(DisplayId displayId) const; diff --git a/dmserver/src/abstract_display.cpp b/dmserver/src/abstract_display.cpp index e9ad85f9..c425a631 100644 --- a/dmserver/src/abstract_display.cpp +++ b/dmserver/src/abstract_display.cpp @@ -24,12 +24,16 @@ namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "AbstractDisplay"}; } -AbstractDisplay::AbstractDisplay(const DisplayInfo& info) - : id_(info.id_), - width_(info.width_), - height_(info.height_), - freshRate_(info.freshRate_) +AbstractDisplay::AbstractDisplay(const DisplayInfo* info) { + if (info == nullptr) { + WLOGFE("DisplayInfo is nullptr"); + return; + } + id_ = info->GetDisplayId(); + width_ = info->GetWidth(); + height_ = info->GetHeight(); + freshRate_ = info->GetHeight(); } AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t freshRate) @@ -146,7 +150,7 @@ ScreenId AbstractDisplay::GetAbstractScreenId() const return screenId_; } -const sptr AbstractDisplay::ConvertToDisplayInfo() const +sptr AbstractDisplay::ConvertToDisplayInfo() const { sptr displayInfo = new DisplayInfo(); displayInfo->width_ = width_; diff --git a/dmserver/src/abstract_screen.cpp b/dmserver/src/abstract_screen.cpp index fb124012..bddd68c8 100644 --- a/dmserver/src/abstract_screen.cpp +++ b/dmserver/src/abstract_screen.cpp @@ -53,7 +53,7 @@ sptr AbstractScreen::GetGroup() const return DisplayManagerService::GetInstance().GetAbstractScreenController()->GetAbstractScreenGroup(groupDmsId_); } -const sptr AbstractScreen::ConvertToScreenInfo() const +sptr AbstractScreen::ConvertToScreenInfo() const { sptr info = new ScreenInfo(); FillScreenInfo(info); @@ -215,7 +215,7 @@ AbstractScreenGroup::~AbstractScreenGroup() abstractScreenMap_.clear(); } -const sptr AbstractScreenGroup::ConvertToScreenGroupInfo() const +sptr AbstractScreenGroup::ConvertToScreenGroupInfo() const { sptr screenGroupInfo = new ScreenGroupInfo(); FillScreenInfo(screenGroupInfo); diff --git a/dmserver/src/display_manager_proxy.cpp b/dmserver/src/display_manager_proxy.cpp index 180dc4a4..3dfc287a 100644 --- a/dmserver/src/display_manager_proxy.cpp +++ b/dmserver/src/display_manager_proxy.cpp @@ -52,12 +52,12 @@ DisplayId DisplayManagerProxy::GetDefaultDisplayId() return displayId; } -DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) +sptr DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) { sptr remote = Remote(); if (remote == nullptr) { WLOGFW("GetDisplayInfoById: remote is nullptr"); - return DisplayInfo(); + return nullptr; } MessageParcel data; @@ -65,23 +65,23 @@ DisplayInfo DisplayManagerProxy::GetDisplayInfoById(DisplayId displayId) MessageOption option; if (!data.WriteInterfaceToken(GetDescriptor())) { WLOGFE("GetDisplayInfoById: WriteInterfaceToken failed"); - return DisplayInfo(); + return nullptr; } if (!data.WriteUint64(displayId)) { WLOGFW("GetDisplayInfoById: WriteUint64 displayId failed"); - return DisplayInfo(); + return nullptr; } if (remote->SendRequest(TRANS_ID_GET_DISPLAY_BY_ID, data, reply, option) != ERR_NONE) { WLOGFW("GetDisplayInfoById: SendRequest failed"); - return DisplayInfo(); + return nullptr; } sptr info = reply.ReadParcelable(); if (info == nullptr) { WLOGFW("DisplayManagerProxy::GetDisplayInfoById SendRequest nullptr."); - return DisplayInfo(); + return nullptr; } - return *info; + return info; } ScreenId DisplayManagerProxy::CreateVirtualScreen(VirtualScreenOption virtualOption) @@ -682,9 +682,10 @@ sptr DisplayManagerProxy::GetScreenInfoById(ScreenId screenId) WLOGFW("GetScreenInfoById SendRequest nullptr."); return nullptr; } - for (int i = 0; i < info->modes_.size(); i++) { + auto modes = info->GetModes(); + for (int i = 0; i < modes.size(); i++) { WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u", - info->modes_[i]->width_, info->modes_[i]->height_, info->modes_[i]->freshRate_); + modes[i]->width_, modes[i]->height_, modes[i]->freshRate_); } return info; } diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 0e3c34e0..047dbfee 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -89,21 +89,14 @@ DisplayId DisplayManagerService::GetDefaultDisplayId() return GetDisplayIdFromScreenId(screenId); } -DisplayInfo DisplayManagerService::GetDisplayInfoById(DisplayId displayId) +sptr DisplayManagerService::GetDisplayInfoById(DisplayId displayId) { - DisplayInfo displayInfo; sptr display = GetDisplayByDisplayId(displayId); if (display == nullptr) { WLOGFE("GetDisplayById: Get invalid display!"); - return displayInfo; + return nullptr; } - displayInfo.id_ = displayId; - displayInfo.width_ = display->GetWidth(); - displayInfo.height_ = display->GetHeight(); - displayInfo.freshRate_ = display->GetFreshRate(); - displayInfo.screenId_ = display->GetAbstractScreenId(); - displayInfo.rotation_ = display->GetRotation(); - return displayInfo; + return display->ConvertToDisplayInfo(); } sptr DisplayManagerService::GetAbstractDisplay(DisplayId displayId) diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index edaaa5cd..8c84b84a 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -41,7 +41,7 @@ const sptr DisplayManagerServiceInner::GetDisplayById(DisplayId { sptr display = DisplayManagerService::GetInstance().GetAbstractDisplay(displayId); if (display == nullptr) { - DisplayInfo displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId); + auto displayInfo = DisplayManagerService::GetInstance().GetDisplayInfoById(displayId); display = new AbstractDisplay(displayInfo); WLOGFE("GetDisplayById create new!\n"); } diff --git a/dmserver/src/display_manager_stub.cpp b/dmserver/src/display_manager_stub.cpp index 2504aef4..824fddaf 100644 --- a/dmserver/src/display_manager_stub.cpp +++ b/dmserver/src/display_manager_stub.cpp @@ -45,7 +45,7 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case TRANS_ID_GET_DISPLAY_BY_ID: { DisplayId displayId = data.ReadUint64(); auto info = GetDisplayInfoById(displayId); - reply.WriteParcelable(&info); + reply.WriteParcelable(info); break; } case TRANS_ID_CREATE_VIRTUAL_SCREEN: { @@ -166,9 +166,10 @@ int32_t DisplayManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, case TRANS_ID_GET_SCREEN_INFO_BY_ID: { ScreenId screenId = static_cast(data.ReadUint64()); auto screenInfo = GetScreenInfoById(screenId); - for (int i = 0; i < screenInfo->modes_.size(); i++) { + auto modes = screenInfo->GetModes(); + for (int i = 0; i < modes.size(); i++) { WLOGFI("info modes is width: %{public}u, height: %{public}u, freshRate: %{public}u", - screenInfo->modes_[i]->width_, screenInfo->modes_[i]->height_, screenInfo->modes_[i]->freshRate_); + modes[i]->width_, modes[i]->height_, modes[i]->freshRate_); } reply.WriteStrongParcelable(screenInfo); break; diff --git a/interfaces/innerkits/dm/display.h b/interfaces/innerkits/dm/display.h index a71df544..5846b76c 100644 --- a/interfaces/innerkits/dm/display.h +++ b/interfaces/innerkits/dm/display.h @@ -27,23 +27,22 @@ typedef enum DisplayType { } DisplayType; class Display : public RefBase { +friend class DisplayManagerAdapter; public: - Display(const std::string& name, DisplayInfo* info); ~Display() = default; - + Display(const Display&) = delete; + Display(Display&&) = delete; + Display& operator=(const Display&) = delete; + Display& operator=(Display&&) = delete; DisplayId GetId() const; int32_t GetWidth() const; int32_t GetHeight() const; uint32_t GetFreshRate() const; ScreenId GetScreenId() const; float GetVirtualPixelRatio() const; - - void SetId(DisplayId displayId); - void SetWidth(int32_t width); - void SetHeight(int32_t height); - void SetFreshRate(uint32_t freshRate); - private: + Display(const std::string& name, sptr info); + void UpdateDisplayInfo(sptr); class Impl; sptr pImpl_; }; diff --git a/interfaces/innerkits/dm/screen.h b/interfaces/innerkits/dm/screen.h index 8c71c4f9..baf1d56d 100644 --- a/interfaces/innerkits/dm/screen.h +++ b/interfaces/innerkits/dm/screen.h @@ -57,9 +57,13 @@ struct ExpandOption { }; class Screen : public RefBase { +friend class ScreenManagerAdapter; public: - Screen(const ScreenInfo* info); ~Screen(); + Screen(const Screen&) = delete; + Screen(Screen&&) = delete; + Screen& operator=(const Screen&) = delete; + Screen& operator=(Screen&&) = delete; bool IsGroup() const; ScreenId GetId() const; uint32_t GetWidth() const; @@ -81,7 +85,9 @@ public: DMError GetScreenGamutMap(ScreenGamutMap& gamutMap) const; DMError SetScreenGamutMap(ScreenGamutMap gamutMap); DMError SetScreenColorTransform(); - +protected: + Screen(sptr info); + void UpdateScreenInfo(sptr screenInfo); private: class Impl; sptr pImpl_; diff --git a/interfaces/innerkits/dm/screen_group.h b/interfaces/innerkits/dm/screen_group.h index 78377f88..bb879536 100644 --- a/interfaces/innerkits/dm/screen_group.h +++ b/interfaces/innerkits/dm/screen_group.h @@ -29,14 +29,20 @@ enum class ScreenCombination : uint32_t { }; class ScreenGroup : public Screen { +friend class ScreenManagerAdapter; public: - ScreenGroup(const ScreenGroupInfo* info); ~ScreenGroup(); + ScreenGroup(const ScreenGroup&) = delete; + ScreenGroup(ScreenGroup&&) = delete; + ScreenGroup& operator=(const ScreenGroup&) = delete; + ScreenGroup& operator=(ScreenGroup&&) = delete; ScreenCombination GetCombination() const; - std::vector GetChild() const; - std::vector GetChildPosition() const; + std::vector GetChildIds() const; + std::vector GetChildPositions() const; private: + ScreenGroup(sptr info); + void UpdateScreenGroupInfo(sptr info); class Impl; sptr pImpl_; }; diff --git a/interfaces/innerkits/wm/wm_common.h b/interfaces/innerkits/wm/wm_common.h index ef7065f0..4d9cafaf 100644 --- a/interfaces/innerkits/wm/wm_common.h +++ b/interfaces/innerkits/wm/wm_common.h @@ -138,14 +138,7 @@ struct PointInfo { namespace { constexpr uint32_t SYSTEM_COLOR_WHITE = 0xE5FFFFFF; constexpr uint32_t SYSTEM_COLOR_BLACK = 0x66000000; - constexpr float DEFAULT_SPLIT_RATIO = 0.5; - constexpr uint32_t DIVIDER_WIDTH = 8; constexpr uint32_t INVALID_WINDOW_ID = 0; - constexpr uint32_t HOTZONE = 40; - constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240; - constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426; - constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426; - constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426; } struct SystemBarProperty { diff --git a/tools/wmdebug/src/window_manager_debug_command.cpp b/tools/wmdebug/src/window_manager_debug_command.cpp index 88b7ab29..0a4f4737 100644 --- a/tools/wmdebug/src/window_manager_debug_command.cpp +++ b/tools/wmdebug/src/window_manager_debug_command.cpp @@ -150,21 +150,21 @@ void WindowManagerDebugCommand::DumpResults(WindowDumpType dumpType) } } switch (dumpType) { - case WindowDumpType::ALL: { - result_ += (ret == WMError::WM_OK) ? DUMP_ALL_OK_MSG : DUMP_ALL_FAIL_MSG; - break; - } - case WindowDumpType::TREE: { - result_ += (ret == WMError::WM_OK) ? DUMP_TREE_OK_MSG : DUMP_TREE_FAIL_MSG; - break; - } - case WindowDumpType::CLEAR: { - result_ += (ret == WMError::WM_OK) ? CLEAR_DUMP_INFO_OK_MSG : CLEAR_DUMP_INFO_FAIL_MSG; - break; - } - default: { - result_ = " "; - } + case WindowDumpType::ALL: { + result_ += (ret == WMError::WM_OK) ? DUMP_ALL_OK_MSG : DUMP_ALL_FAIL_MSG; + break; + } + case WindowDumpType::TREE: { + result_ += (ret == WMError::WM_OK) ? DUMP_TREE_OK_MSG : DUMP_TREE_FAIL_MSG; + break; + } + case WindowDumpType::CLEAR: { + result_ += (ret == WMError::WM_OK) ? CLEAR_DUMP_INFO_OK_MSG : CLEAR_DUMP_INFO_FAIL_MSG; + break; + } + default: { + result_ = " "; + } } } diff --git a/utils/include/class_var_defination.h b/utils/include/class_var_defination.h new file mode 100644 index 00000000..27bce64e --- /dev/null +++ b/utils/include/class_var_defination.h @@ -0,0 +1,59 @@ +/* + * 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 p ermissions and + * limitations under the License. + */ + +#ifndef OHOS_ROSEN_CLASS_VAR_DEFINATION_H +#define OHOS_ROSEN_CLASS_VAR_DEFINATION_H +namespace OHOS::Rosen { +#define DEFINE_VAR(type, memberName) \ +private: \ + type memberName##_; + +#define DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \ +private: \ + type memberName##_ {defaultValue}; + +#define DEFINE_FUNC_GET(type, funcName, memberName) \ +public: \ + type Get##funcName() const \ + { \ + return memberName##_; \ + } + +#define DEFINE_FUNC_SET(type, funcName, memberName) \ +public: \ + void Set##funcName(type value) \ + { \ + memberName##_ = value; \ + } + +#define DEFINE_VAR_FUNC_GET(type, funcName, memberName) \ + DEFINE_VAR(type, memberName) \ + DEFINE_FUNC_GET(type, funcName, memberName) + +#define DEFINE_VAR_DEFAULT_FUNC_GET(type, funcName, memberName, defaultValue) \ + DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \ + DEFINE_FUNC_GET(type, funcName, memberName) + +#define DEFINE_VAR_FUNC_GET_SET(type, funcName, memberName) \ + DEFINE_VAR(type, memberName) \ + DEFINE_FUNC_GET(type, funcName, memberName) \ + DEFINE_FUNC_SET(type, funcName, memberName) + +#define DEFINE_VAR_DEFAULT_FUNC_GET_SET(type, funcName, memberName, defaultValue) \ + DEFINE_VAR_DEFAULT(type, memberName, defaultValue) \ + DEFINE_FUNC_GET(type, funcName, memberName) \ + DEFINE_FUNC_SET(type, funcName, memberName) +} // namespace OHOS::Rosen +#endif // OHOS_ROSEN_CLASS_VAR_DEFINATION_H diff --git a/utils/include/display_info.h b/utils/include/display_info.h index 0aab1010..e7ec23c9 100644 --- a/utils/include/display_info.h +++ b/utils/include/display_info.h @@ -18,29 +18,34 @@ #include +#include "class_var_defination.h" #include "display.h" #include "dm_common.h" namespace OHOS::Rosen { class DisplayInfo : public Parcelable { +friend class AbstractDisplay; public: - DisplayInfo() = default; ~DisplayInfo() = default; - - void Update(DisplayInfo* info); + DisplayInfo(const DisplayInfo&) = delete; + DisplayInfo(DisplayInfo&&) = delete; + DisplayInfo& operator=(const DisplayInfo&) = delete; + DisplayInfo& operator=(DisplayInfo&&) = delete; virtual bool Marshalling(Parcel& parcel) const override; static DisplayInfo *Unmarshalling(Parcel& parcel); - DisplayId id_ { DISPLAY_ID_INVALD }; - DisplayType type_ {DisplayType::DEFAULT }; - int32_t width_ { 0 }; - int32_t height_ { 0 }; - uint32_t freshRate_ { 0 }; - ScreenId screenId_ { SCREEN_ID_INVALID }; - float xDpi_ { 0.0 }; - float yDpi_ { 0.0 }; - Rotation rotation_ { Rotation::ROTATION_0 }; + DEFINE_VAR_DEFAULT_FUNC_GET(DisplayId, DisplayId, id, DISPLAY_ID_INVALD); + DEFINE_VAR_DEFAULT_FUNC_GET(DisplayType, DisplayType, type, DisplayType::DEFAULT); + DEFINE_VAR_DEFAULT_FUNC_GET(int32_t, Width, width, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(int32_t, Height, height, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, FreshRate, freshRate, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ScreenId, screenId, SCREEN_ID_INVALID); + DEFINE_VAR_DEFAULT_FUNC_GET(float, XDpi, xDpi, 0.0f); + DEFINE_VAR_DEFAULT_FUNC_GET(float, YDpi, yDpi, 0.0f); + DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0); +private: + DisplayInfo() = default; }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H \ No newline at end of file diff --git a/utils/include/screen_group_info.h b/utils/include/screen_group_info.h index 6a9addbf..c1980182 100644 --- a/utils/include/screen_group_info.h +++ b/utils/include/screen_group_info.h @@ -23,20 +23,23 @@ namespace OHOS::Rosen { class ScreenGroupInfo : public ScreenInfo { +friend class AbstractScreenGroup; public: - ScreenGroupInfo() = default; ~ScreenGroupInfo() = default; - - void Update(sptr info); + ScreenGroupInfo(const ScreenGroupInfo&) = delete; + ScreenGroupInfo(ScreenGroupInfo&&) = delete; + ScreenGroupInfo& operator=(const ScreenGroupInfo&) = delete; + ScreenGroupInfo& operator=(ScreenGroupInfo&&) = delete; virtual bool Marshalling(Parcel& parcel) const override; static ScreenGroupInfo* Unmarshalling(Parcel& parcel); - std::vector children_; - std::vector position_; - ScreenCombination combination_ { ScreenCombination::SCREEN_ALONE }; -protected: - ScreenGroupInfo* InnerUnmarshalling(Parcel& parcel); + DEFINE_VAR_FUNC_GET(std::vector, Children, children); + DEFINE_VAR_FUNC_GET(std::vector, Position, position); + DEFINE_VAR_DEFAULT_FUNC_GET(ScreenCombination, Combination, combination, ScreenCombination::SCREEN_ALONE); +private: + ScreenGroupInfo() = default; + bool InnerUnmarshalling(Parcel& parcel); }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_SCREEN_GROUP_INFO_H \ No newline at end of file diff --git a/utils/include/screen_info.h b/utils/include/screen_info.h index c39fad9d..618a67ce 100644 --- a/utils/include/screen_info.h +++ b/utils/include/screen_info.h @@ -18,30 +18,34 @@ #include +#include "class_var_defination.h" #include "screen.h" namespace OHOS::Rosen { class ScreenInfo : public Parcelable { +friend class AbstractScreen; public: - ScreenInfo() = default; ~ScreenInfo() = default; - - void Update(sptr info); + ScreenInfo(const ScreenInfo&) = delete; + ScreenInfo(ScreenInfo&&) = delete; + ScreenInfo& operator=(const ScreenInfo&) = delete; + ScreenInfo& operator= (ScreenInfo&&) = delete; virtual bool Marshalling(Parcel& parcel) const override; static ScreenInfo* Unmarshalling(Parcel& parcel); - ScreenId id_ { SCREEN_ID_INVALID }; - uint32_t virtualWidth_ { 0 }; - uint32_t virtualHeight_ { 0 }; - float virtualPixelRatio_ { 0.0 }; - ScreenId parent_ { 0 }; - bool canHasChild_ { false }; - Rotation rotation_ { Rotation::ROTATION_0 }; - uint32_t modeId_ { 0 }; - std::vector> modes_ {}; + DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ScreenId, id, SCREEN_ID_INVALID); + DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualWidth, virtualWidth, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualHeight, virtualHeight, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(float, VirtualPixelRatio, virtualPixelRatio, 0.0f); + DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ParentId, parent, 0); + DEFINE_VAR_DEFAULT_FUNC_GET(bool, CanHasChild, canHasChild, false); + DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0); + DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ModeId, modeId, 0); + DEFINE_VAR_FUNC_GET(std::vector>, Modes, modes); protected: - ScreenInfo* InnerUnmarshalling(Parcel& parcel); + ScreenInfo() = default; + bool InnerUnmarshalling(Parcel& parcel); }; } // namespace OHOS::Rosen #endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H diff --git a/utils/include/window_helper.h b/utils/include/window_helper.h index f521d3be..9e822ae0 100644 --- a/utils/include/window_helper.h +++ b/utils/include/window_helper.h @@ -17,6 +17,7 @@ #define OHOS_WM_INCLUDE_WM_HELPER_H #include +#include namespace OHOS { namespace Rosen { @@ -79,15 +80,18 @@ public: return (r.posX_ == 0 && r.posY_ == 0 && r.width_ == 0 && r.height_ == 0); } - static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical) + static Rect GetFixedWindowRectByMinRect(const Rect& oriDstRect, const Rect& lastRect, bool isVertical, + float virtualPixelRatio) { + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); Rect dstRect = oriDstRect; if (isVertical) { - dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.width_); - dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.height_); + dstRect.width_ = std::max(minVerticalFloatingW, oriDstRect.width_); + dstRect.height_ = std::max(minVerticalFloatingH, oriDstRect.height_); } else { - dstRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, oriDstRect.width_); - dstRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, oriDstRect.height_); + dstRect.width_ = std::max(minVerticalFloatingH, oriDstRect.width_); + dstRect.height_ = std::max(minVerticalFloatingW, oriDstRect.height_); } // limit position by fixed width or height diff --git a/utils/include/wm_common_inner.h b/utils/include/wm_common_inner.h index fda04fe8..369fd40d 100644 --- a/utils/include/wm_common_inner.h +++ b/utils/include/wm_common_inner.h @@ -44,6 +44,18 @@ enum class WindowUpdateReason : uint32_t { UPDATE_TYPE, UPDATE_OTHER_PROPS, }; +namespace { + constexpr float DEFAULT_SPLIT_RATIO = 0.5; + constexpr uint32_t DIVIDER_WIDTH = 8; + constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48; + constexpr uint32_t WINDOW_FRAME_WIDTH = 4; + constexpr uint32_t HOTZONE = 40; + constexpr uint32_t DIV_HOTZONE = 20; + constexpr uint32_t MIN_VERTICAL_FLOATING_WIDTH = 240; + constexpr uint32_t MIN_VERTICAL_FLOATING_HEIGHT = 426; + constexpr uint32_t MIN_VERTICAL_SPLIT_HEIGHT = 426; + constexpr uint32_t MIN_HORIZONTAL_SPLIT_WIDTH = 426; +} } } #endif // OHOS_ROSEN_WM_COMMON_INNER_H \ No newline at end of file diff --git a/utils/src/display_info.cpp b/utils/src/display_info.cpp index 0ff79f31..ca033643 100644 --- a/utils/src/display_info.cpp +++ b/utils/src/display_info.cpp @@ -16,19 +16,6 @@ #include "display_info.h" namespace OHOS::Rosen { -void DisplayInfo::Update(DisplayInfo* info) -{ - id_ = info->id_; - type_ = info->type_; - width_ = info->width_; - height_ = info->height_; - freshRate_ = info->freshRate_; - screenId_ = info->screenId_; - xDpi_ = info->xDpi_; - yDpi_ = info->yDpi_; - rotation_ = info->rotation_; -} - bool DisplayInfo::Marshalling(Parcel &parcel) const { return parcel.WriteUint64(id_) && parcel.WriteUint32(type_) && @@ -41,9 +28,6 @@ bool DisplayInfo::Marshalling(Parcel &parcel) const DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) { DisplayInfo *displayInfo = new DisplayInfo(); - if (displayInfo == nullptr) { - return nullptr; - } uint32_t type = (uint32_t)DisplayType::DEFAULT; uint32_t rotation; bool res = parcel.ReadUint64(displayInfo->id_) && parcel.ReadUint32(type) && @@ -52,11 +36,11 @@ DisplayInfo *DisplayInfo::Unmarshalling(Parcel &parcel) parcel.ReadFloat(displayInfo->xDpi_) && parcel.ReadFloat(displayInfo->yDpi_) && parcel.ReadUint32(rotation); if (!res) { - displayInfo = nullptr; - } else { - displayInfo->type_ = (DisplayType)type; - displayInfo->rotation_ = static_cast(rotation); + delete displayInfo; + return nullptr; } + displayInfo->type_ = (DisplayType)type; + displayInfo->rotation_ = static_cast(rotation); return displayInfo; } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/utils/src/screen_group_info.cpp b/utils/src/screen_group_info.cpp index 56268c74..ed4e4122 100644 --- a/utils/src/screen_group_info.cpp +++ b/utils/src/screen_group_info.cpp @@ -16,16 +16,6 @@ #include "screen_group_info.h" namespace OHOS::Rosen { -void ScreenGroupInfo::Update(sptr info) -{ - ScreenInfo::Update(info); - children_.clear(); - children_.insert(children_.begin(), info->children_.begin(), info->children_.end()); - position_.clear(); - position_.insert(position_.begin(), info->position_.begin(), info->position_.end()); - combination_ = info->combination_; -} - bool ScreenGroupInfo::Marshalling(Parcel &parcel) const { bool res = ScreenInfo::Marshalling(parcel) && parcel.WriteUint32((uint32_t)combination_) && @@ -48,29 +38,34 @@ bool ScreenGroupInfo::Marshalling(Parcel &parcel) const ScreenGroupInfo* ScreenGroupInfo::Unmarshalling(Parcel &parcel) { ScreenGroupInfo* screenGroupInfo = new ScreenGroupInfo(); - return screenGroupInfo->InnerUnmarshalling(parcel); + bool res = screenGroupInfo->InnerUnmarshalling(parcel); + if (res) { + return screenGroupInfo; + } + delete screenGroupInfo; + return nullptr; } -ScreenGroupInfo* ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel) +bool ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel) { uint32_t combination; if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) || !parcel.ReadUInt64Vector(&children_)) { - return nullptr; + return false; } combination_ = (ScreenCombination) combination; uint32_t size; if (!parcel.ReadUint32(size)) { - return nullptr; + return false; } for (size_t i = 0; i < size; i++) { Point point; if (parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_)) { position_.push_back(point); } else { - return nullptr; + return false; } } - return this; + return true; } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/utils/src/screen_info.cpp b/utils/src/screen_info.cpp index a3df26fe..4e16e2a7 100644 --- a/utils/src/screen_info.cpp +++ b/utils/src/screen_info.cpp @@ -16,19 +16,6 @@ #include "screen_info.h" namespace OHOS::Rosen { -void ScreenInfo::Update(sptr info) -{ - id_ = info->id_; - virtualWidth_ = info->virtualWidth_; - virtualHeight_ = info->virtualHeight_; - virtualPixelRatio_ = info->virtualPixelRatio_; - parent_ = info->parent_; - canHasChild_ = info->canHasChild_; - rotation_ = info->rotation_; - modeId_ = info->modeId_; - modes_ = info->modes_; -} - bool ScreenInfo::Marshalling(Parcel &parcel) const { bool res = parcel.WriteUint64(id_) && @@ -53,10 +40,15 @@ bool ScreenInfo::Marshalling(Parcel &parcel) const ScreenInfo* ScreenInfo::Unmarshalling(Parcel &parcel) { ScreenInfo* info = new ScreenInfo(); - return info->InnerUnmarshalling(parcel); + bool res = info->InnerUnmarshalling(parcel); + if (res) { + return info; + } + delete info; + return nullptr; } -ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel) +bool ScreenInfo::InnerUnmarshalling(Parcel& parcel) { uint32_t size = 0; uint32_t rotation; @@ -66,7 +58,7 @@ ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel) parcel.ReadBool(canHasChild_) && parcel.ReadUint32(rotation) && parcel.ReadUint32(modeId_) && parcel.ReadUint32(size); if (!res1) { - return nullptr; + return false; } modes_.clear(); for (uint32_t modeIndex = 0; modeIndex < size; modeIndex++) { @@ -76,10 +68,10 @@ ScreenInfo* ScreenInfo::InnerUnmarshalling(Parcel& parcel) parcel.ReadUint32(mode->freshRate_)) { modes_.push_back(mode); } else { - return nullptr; + return false; } } rotation_ = static_cast(rotation); - return this; + return true; } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/wm/src/window_impl.cpp b/wm/src/window_impl.cpp index a92b3194..bd797a1a 100644 --- a/wm/src/window_impl.cpp +++ b/wm/src/window_impl.cpp @@ -1125,26 +1125,22 @@ void WindowImpl::UpdateWindowState(WindowState state) switch (state) { case WindowState::STATE_FROZEN: { state_ = WindowState::STATE_HIDDEN; - if (uiContent_ != nullptr) { - uiContent_->Background(); - } if (abilityContext_ != nullptr) { WLOGFD("DoAbilityBackground KEYGUARD, id: %{public}d", GetWindowId()); AAFwk::AbilityManagerClient::GetInstance()->DoAbilityBackground(abilityContext_->GetToken(), static_cast(WindowStateChangeReason::KEYGUARD)); } + NotifyAfterBackground(); break; } case WindowState::STATE_UNFROZEN: { state_ = WindowState::STATE_SHOWN; - if (uiContent_ != nullptr) { - uiContent_->Foreground(); - } if (abilityContext_ != nullptr) { WLOGFD("DoAbilityForeground KEYGUARD, id: %{public}d", GetWindowId()); AAFwk::AbilityManagerClient::GetInstance()->DoAbilityForeground(abilityContext_->GetToken(), static_cast(WindowStateChangeReason::KEYGUARD)); } + NotifyAfterForeground(); break; } default: { diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp index 9b5b381e..6bb5c15a 100644 --- a/wm/test/systemtest/window_layout_test.cpp +++ b/wm/test/systemtest/window_layout_test.cpp @@ -32,6 +32,7 @@ public: DisplayId displayId_ = 0; std::vector> activeWindows_; static vector fullScreenExpecteds_; + static inline float virtualPixelRatio_ = 0.0; }; vector WindowLayoutTest::fullScreenExpecteds_; @@ -47,6 +48,9 @@ void WindowLayoutTest::SetUpTestCase() } Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; utils::InitByDisplayRect(displayRect); + + virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); + // calc expected rects Rect expected = { // 0. only statusBar 0, @@ -110,7 +114,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) activeWindows_.push_back(window); ASSERT_EQ(WMError::WM_OK, window->Show()); - ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(window, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_EQ(WMError::WM_OK, window->Hide()); } @@ -140,12 +144,12 @@ HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) activeWindows_.push_back(statBar); ASSERT_EQ(WMError::WM_OK, appWin->Show()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_EQ(WMError::WM_OK, statBar->Show()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); ASSERT_EQ(WMError::WM_OK, statBar->Hide()); - ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_))); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::GetFloatingLimitedRect(utils::customAppRect_, virtualPixelRatio_))); } /** @@ -277,7 +281,7 @@ HWTEST_F(WindowLayoutTest, LayoutWindow09, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window->Resize(2u, 2u)); // 2: custom min size Rect finalExcept = { expect.posX_, expect.posY_, 2u, 2u}; // 2: custom min size - finalExcept = utils::GetFloatingLimitedRect(finalExcept); + finalExcept = utils::GetFloatingLimitedRect(finalExcept, virtualPixelRatio_); ASSERT_TRUE(utils::RectEqualTo(window, finalExcept)); ASSERT_EQ(WMError::WM_OK, window->Hide()); } diff --git a/wm/test/systemtest/window_move_drag_test.cpp b/wm/test/systemtest/window_move_drag_test.cpp index 38783803..fc033776 100644 --- a/wm/test/systemtest/window_move_drag_test.cpp +++ b/wm/test/systemtest/window_move_drag_test.cpp @@ -18,6 +18,7 @@ #include "pointer_event.h" #include "window_helper.h" #include "window_test_utils.h" +#include "wm_common_inner.h" using namespace testing; using namespace testing::ext; @@ -54,6 +55,8 @@ private: static inline Rect startPointRect_ = {0, 0, 0, 0}; static inline Rect expectRect_ = {0, 0, 0, 0}; static inline sptr window_ = nullptr; + static inline float virtualPixelRatio_ = 0.0; + static inline uint32_t hotZone_ = 0; }; void WindowMoveDragTest::SetUpTestCase() @@ -83,6 +86,9 @@ void WindowMoveDragTest::SetUp() Rect displayRect = {0, 0, display->GetWidth(), display->GetHeight()}; utils::InitByDisplayRect(displayRect); + virtualPixelRatio_ = WindowTestUtils::GetVirtualPixelRatio(0); + hotZone_ = static_cast(HOTZONE * virtualPixelRatio_); + winInfo_ = { .name = "Floating", .rect = {0, 0, 0, 0}, @@ -174,7 +180,7 @@ void WindowMoveDragTest::CalExpectRects() } } bool isVertical = (utils::displayRect_.width_ < utils::displayRect_.height_) ? true : false; - expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical); + expectRect_ = WindowHelper::GetFixedWindowRectByMinRect(oriRect, startPointRect_, isVertical, virtualPixelRatio_); } namespace { @@ -188,10 +194,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow01, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -206,11 +212,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow02, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -225,11 +231,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow03, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ - HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ - hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -244,10 +250,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow04, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; startPointY_ = startPointRect_.posY_ + startPointRect_.height_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; pointY_ = startPointRect_.posY_ + startPointRect_.height_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); @@ -263,11 +269,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow05, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -282,11 +288,11 @@ HWTEST_F(WindowMoveDragTest, DragWindow06, Function | MediumTest | Level3) { ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); - startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; - pointX_ = startPointRect_.posX_ + startPointRect_.width_ + HOTZONE * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointX_ = startPointRect_.posX_ + startPointRect_.width_ + hotZone_ * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -302,10 +308,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow07, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ - HOTZONE * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ - hotZone_ * POINT_HOTZONE_RATIO; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ - HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ - hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -321,10 +327,10 @@ HWTEST_F(WindowMoveDragTest, DragWindow08, Function | MediumTest | Level3) ASSERT_EQ(WMError::WM_OK, window_->Show()); startPointRect_ = window_->GetRect(); startPointX_ = startPointRect_.posX_ + startPointRect_.width_ * POINT_HOTZONE_RATIO; - startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * POINT_HOTZONE_RATIO; + startPointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * POINT_HOTZONE_RATIO; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -343,7 +349,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow09, Function | MediumTest | Level3) startPointY_ = startPointRect_.posY_ + 1; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + startPointRect_.height_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + startPointRect_.height_ + hotZone_ * DRAG_HOTZONE_RATIO; DoMoveOrDrag(); ASSERT_EQ(WMError::WM_OK, window_->Hide()); } @@ -362,7 +368,7 @@ HWTEST_F(WindowMoveDragTest, DragWindow10, Function | MediumTest | Level3) startPointY_ = startPointRect_.posY_ + 1; pointX_ = startPointRect_.posX_ + startPointRect_.width_ * DRAG_HOTZONE_RATIO; - pointY_ = startPointRect_.posY_ + HOTZONE * DRAG_HOTZONE_RATIO; + pointY_ = startPointRect_.posY_ + hotZone_ * DRAG_HOTZONE_RATIO; window_->StartMove(); hasStartMove_ = true; DoMoveOrDrag(); diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp index 23fa2b83..3f7b91dd 100644 --- a/wm/test/systemtest/window_test_utils.cpp +++ b/wm/test/systemtest/window_test_utils.cpp @@ -15,6 +15,7 @@ #include "window_test_utils.h" #include +#include "wm_common_inner.h" namespace OHOS { namespace Rosen { namespace { @@ -123,13 +124,18 @@ Rect WindowTestUtils::GetDefaultFoatingRect(const sptr& window) return resRect; } -Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect) +Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio) { - constexpr uint32_t winFrameH = 52u; - constexpr uint32_t winFrameW = 8u; + constexpr uint32_t windowTitleBarHeight = 48; + constexpr uint32_t windowFrameWidth = 4; + uint32_t winFrameH = static_cast((windowTitleBarHeight + windowFrameWidth) * virtualPixelRatio); + uint32_t winFrameW = static_cast((windowFrameWidth + windowFrameWidth) * virtualPixelRatio); + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); + bool vertical = displayRect_.width_ < displayRect_.height_; - uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT; - uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH; + uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH; + uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW; Rect resRect = { rect.posX_, rect.posY_, @@ -139,11 +145,14 @@ Rect WindowTestUtils::GetLimitedDecoRect(const Rect& rect) return resRect; } -Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect) +Rect WindowTestUtils::GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio) { + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); bool vertical = displayRect_.width_ < displayRect_.height_; - uint32_t minFloatingW = vertical ? MIN_VERTICAL_FLOATING_WIDTH : MIN_VERTICAL_FLOATING_HEIGHT; - uint32_t minFloatingH = vertical ? MIN_VERTICAL_FLOATING_HEIGHT : MIN_VERTICAL_FLOATING_WIDTH; + + uint32_t minFloatingW = vertical ? minVerticalFloatingW : minVerticalFloatingH; + uint32_t minFloatingH = vertical ? minVerticalFloatingH : minVerticalFloatingW; Rect resRect = { rect.posX_, rect.posY_, @@ -257,18 +266,21 @@ void WindowTestUtils::InitSplitRects() displayRect_ = displayRect; limitDisplayRect_ = displayRect; + float virtualPixelRatio = WindowTestUtils::GetVirtualPixelRatio(0); + uint32_t dividerWidth = static_cast(DIVIDER_WIDTH * virtualPixelRatio); + if (displayRect_.width_ < displayRect_.height_) { isVerticalDisplay_ = true; } if (isVerticalDisplay_) { splitRects_.dividerRect = { 0, - static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), + static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), displayRect_.width_, - DIVIDER_WIDTH, }; + dividerWidth, }; } else { - splitRects_.dividerRect = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), + splitRects_.dividerRect = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, - DIVIDER_WIDTH, + dividerWidth, displayRect_.height_ }; } } @@ -374,5 +386,17 @@ void WindowTestUtils::UpdateLimitSplitRect(Rect& limitSplitRect) curLimitRect.posY_ + curLimitRect.height_) - limitSplitRect.posY_; } + +float WindowTestUtils::GetVirtualPixelRatio(DisplayId displayId) +{ + auto display = DisplayManager::GetInstance().GetDisplayById(displayId); + if (display == nullptr) { + WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, 0.0); + return 0.0; + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", displayId, virtualPixelRatio); + return virtualPixelRatio; +} } // namespace ROSEN } // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h index 2742aa30..5234262b 100644 --- a/wm/test/systemtest/window_test_utils.h +++ b/wm/test/systemtest/window_test_utils.h @@ -66,9 +66,10 @@ public: static void UpdateSplitRects(const sptr& window); static bool RectEqualToRect(const Rect& l, const Rect& r); static Rect GetDefaultFoatingRect(const sptr& window); - static Rect GetLimitedDecoRect(const Rect& rect); - static Rect GetFloatingLimitedRect(const Rect& rect); + static Rect GetLimitedDecoRect(const Rect& rect, float virtualPixelRatio); + static Rect GetFloatingLimitedRect(const Rect& rect, float virtualPixelRatio); static void InitTileWindowRects(const sptr& window); + static float GetVirtualPixelRatio(DisplayId displayId); private: void UpdateLimitDisplayRect(Rect& avoidRect); diff --git a/wmserver/BUILD.gn b/wmserver/BUILD.gn index 906480e1..5bfc6106 100644 --- a/wmserver/BUILD.gn +++ b/wmserver/BUILD.gn @@ -76,6 +76,7 @@ ohos_shared_library("libwms") { ":window_divider_image", "//foundation/ace/ace_engine/build/external_config/flutter/skia:ace_skia_ohos", "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//foundation/windowmanager/dm:libdm", "//foundation/windowmanager/dmserver:libdms", "//foundation/windowmanager/utils:libwmutil", "//foundation/windowmanager/wm:libwm", diff --git a/wmserver/include/window_layout_policy.h b/wmserver/include/window_layout_policy.h index d2b0fc7a..20738683 100644 --- a/wmserver/include/window_layout_policy.h +++ b/wmserver/include/window_layout_policy.h @@ -50,6 +50,7 @@ public: virtual void UpdateWindowNode(sptr& node); virtual void UpdateLayoutRect(sptr& node) = 0; void UpdateDefaultFoatingRect(); + float GetVirtualPixelRatio() const; protected: const Rect& displayRect_; @@ -66,6 +67,7 @@ protected: void UpdateLimitRect(const sptr& node, Rect& limitRect); virtual void LayoutWindowNode(sptr& node); AvoidPosType GetAvoidPosType(const Rect& rect); + void CalcAndSetNodeHotZone(Rect layoutOutRect, sptr& node); void LimitWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect); void SetRectForFloating(const sptr& node); Rect ComputeDecoratedWindowRect(const Rect& winRect); diff --git a/wmserver/include/window_node.h b/wmserver/include/window_node.h index 94eb7b26..6ba52af3 100644 --- a/wmserver/include/window_node.h +++ b/wmserver/include/window_node.h @@ -42,6 +42,7 @@ public: void SetDisplayId(DisplayId displayId); void SetLayoutRect(const Rect& rect); + void SetHotZoneRect(const Rect& rect); void SetWindowRect(const Rect& rect); void SetWindowProperty(const sptr& property); void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); @@ -95,6 +96,7 @@ private: sptr property_; sptr windowToken_; Rect layoutRect_ { 0, 0, 0, 0 }; + Rect hotZoneRect_ { 0, 0, 0, 0 }; int32_t callingPid_; int32_t callingUid_; WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED}; diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 3c5146d5..8e34fc2a 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -68,6 +68,7 @@ public: sptr GetAppWindowNode() const; sptr GetAboveAppWindowNode() const; void DumpWindowTree(std::vector &windowTreeInfos, WindowDumpType type); + float GetVirtualPixelRatio() const; private: void AssignZOrder(sptr& node); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index b53549a2..c1453a38 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -63,6 +63,7 @@ public: void NotifySystemBarTints(); WMError RaiseZOrderForAppWindow(sptr& node); WMError DumpWindowTree(std::vector &windowTreeInfos, WindowDumpType type); + float GetVirtualPixelRatio(DisplayId displayId) const; private: void OnRemoteDied(const sptr& remoteObject); diff --git a/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index f8ad19ac..393659c4 100644 --- a/wmserver/src/input_window_monitor.cpp +++ b/wmserver/src/input_window_monitor.cpp @@ -163,7 +163,7 @@ void InputWindowMonitor::TraverseWindowNodes(const std::vector> void InputWindowMonitor::UpdateDisplayDirection(MMI::PhysicalDisplayInfo& physicalDisplayInfo, DisplayId displayId) { - Rotation rotation = DisplayManagerServiceInner::GetInstance().GetScreenInfoByDisplayId(displayId)->rotation_; + Rotation rotation = DisplayManagerServiceInner::GetInstance().GetScreenInfoByDisplayId(displayId)->GetRotation(); switch (rotation) { case Rotation::ROTATION_0: physicalDisplayInfo.direction = MMI::Direction0; diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index d119a600..6df89217 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -141,8 +141,9 @@ WMError WindowController::ResizeRect(uint32_t windowId, const Rect& rect, Window } else if (reason == WindowSizeChangeReason::DRAG) { if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { // fix rect in case of moving window when dragging - newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, - property->GetWindowRect(), windowRoot_->isVerticalDisplay(node)); + float virtualPixelRatio = windowRoot_->GetVirtualPixelRatio(node->GetDisplayId()); + newRect = WindowHelper::GetFixedWindowRectByMinRect(rect, property->GetWindowRect(), + windowRoot_->isVerticalDisplay(node), virtualPixelRatio); } else { newRect = rect; } diff --git a/wmserver/src/window_layout_policy.cpp b/wmserver/src/window_layout_policy.cpp index 3ec0e274..a3ccfb89 100644 --- a/wmserver/src/window_layout_policy.cpp +++ b/wmserver/src/window_layout_policy.cpp @@ -14,16 +14,16 @@ */ #include "window_layout_policy.h" +#include "display_manager.h" #include "window_helper.h" #include "window_manager_hilog.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { namespace Rosen { namespace { constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowLayoutPolicy"}; - constexpr uint32_t WINDOW_TITLE_BAR_HEIGHT = 48; - constexpr uint32_t WINDOW_FRAME_WIDTH = 4; } WindowLayoutPolicy::WindowLayoutPolicy(const Rect& displayRect, const uint64_t& screenId, sptr& belowAppNode, sptr& appNode, sptr& aboveAppNode) @@ -115,11 +115,14 @@ void WindowLayoutPolicy::UpdateDefaultFoatingRect() void WindowLayoutPolicy::SetRectForFloating(const sptr& node) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t winFrameW = static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + uint32_t winTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); // deduct decor size Rect rect = defaultFloatingRect_; if (node->GetWindowProperty()->GetDecorEnable()) { - rect.width_ -= (WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH); - rect.height_ -= (WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH); + rect.width_ -= (winFrameW + winFrameW); + rect.height_ -= (winTitleBarH + winFrameW); } node->SetWindowRect(rect); @@ -174,11 +177,15 @@ void WindowLayoutPolicy::UpdateFloatingLayoutRect(Rect& limitRect, Rect& winRect Rect WindowLayoutPolicy::ComputeDecoratedWindowRect(const Rect& winRect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t winFrameW = static_cast(WINDOW_FRAME_WIDTH * virtualPixelRatio); + uint32_t winTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); + Rect rect; rect.posX_ = winRect.posX_; rect.posY_ = winRect.posY_; - rect.width_ = winRect.width_ + WINDOW_FRAME_WIDTH + WINDOW_FRAME_WIDTH; - rect.height_ = winRect.height_ + WINDOW_TITLE_BAR_HEIGHT + WINDOW_FRAME_WIDTH; + rect.width_ = winRect.width_ + winFrameW + winFrameW; + rect.height_ = winRect.height_ + winTitleBarH + winFrameW; return rect; } @@ -221,14 +228,44 @@ void WindowLayoutPolicy::UpdateLayoutRect(sptr& node) LimitWindowSize(node, displayRect, winRect); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); } } +void WindowLayoutPolicy::CalcAndSetNodeHotZone(Rect layoutOutRect, sptr& node) +{ + Rect rect = layoutOutRect; + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t hotZone = static_cast(HOTZONE * virtualPixelRatio); + uint32_t divHotZone = static_cast(DIV_HOTZONE * virtualPixelRatio); + + if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { + if (rect.width_ < rect.height_) { + rect.posX_ -= divHotZone; + rect.width_ += (divHotZone + divHotZone); + } else { + rect.posY_ -= divHotZone; + rect.height_ += (divHotZone + divHotZone); + } + } else if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), node->GetWindowMode())) { + rect.posX_ -= hotZone; + rect.posY_ -= hotZone; + rect.width_ += (hotZone + hotZone); + rect.height_ += (hotZone + hotZone); + } + node->SetHotZoneRect(rect); +} + void WindowLayoutPolicy::LimitWindowSize(const sptr& node, const Rect& displayRect, Rect& winRect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t minVerticalFloatingW = static_cast(MIN_VERTICAL_FLOATING_WIDTH * virtualPixelRatio); + uint32_t minVerticalFloatingH = static_cast(MIN_VERTICAL_FLOATING_HEIGHT * virtualPixelRatio); + uint32_t windowTitleBarH = static_cast(WINDOW_TITLE_BAR_HEIGHT * virtualPixelRatio); + WindowType windowType = node->GetWindowType(); WindowMode windowMode = node->GetWindowMode(); bool isVertical = (displayRect.height_ > displayRect.width_) ? true : false; @@ -238,16 +275,16 @@ void WindowLayoutPolicy::LimitWindowSize(const sptr& node, const Rec } if ((windowMode == WindowMode::WINDOW_MODE_FLOATING) && !WindowHelper::IsSystemWindow(windowType)) { if (isVertical) { - winRect.width_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.width_); - winRect.height_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.height_); + winRect.width_ = std::max(minVerticalFloatingW, winRect.width_); + winRect.height_ = std::max(minVerticalFloatingH, winRect.height_); } else { - winRect.width_ = std::max(MIN_VERTICAL_FLOATING_HEIGHT, winRect.width_); - winRect.height_ = std::max(MIN_VERTICAL_FLOATING_WIDTH, winRect.height_); + winRect.width_ = std::max(minVerticalFloatingH, winRect.width_); + winRect.height_ = std::max(minVerticalFloatingW, winRect.height_); } } if (WindowHelper::IsMainFloatingWindow(windowType, windowMode)) { winRect.posY_ = std::max(limitRect_.posY_, winRect.posY_); - winRect.posY_ = std::min(limitRect_.posY_ + static_cast(limitRect_.height_ - WINDOW_TITLE_BAR_HEIGHT), + winRect.posY_ = std::min(limitRect_.posY_ + static_cast(limitRect_.height_ - windowTitleBarH), winRect.posY_); } } @@ -314,5 +351,17 @@ void WindowLayoutPolicy::UpdateLimitRect(const sptr& node, Rect& lim void WindowLayoutPolicy::Reset() { } + +float WindowLayoutPolicy::GetVirtualPixelRatio() const +{ + auto display = DisplayManager::GetInstance().GetDisplayById(screenId_); + if (display == nullptr) { + WLOGFE("GetVirtualPixel fail. Get display fail. displayId:%{public}" PRIu64", use Default vpr:1.0", screenId_); + return 1.0; // Use DefaultVPR 1.0 + } + float virtualPixelRatio = display->GetVirtualPixelRatio(); + WLOGFI("GetVirtualPixel success. displayId:%{public}" PRIu64", vpr:%{public}f", screenId_, virtualPixelRatio); + return virtualPixelRatio; +} } } diff --git a/wmserver/src/window_layout_policy_cascade.cpp b/wmserver/src/window_layout_policy_cascade.cpp index 490449df..3854543b 100644 --- a/wmserver/src/window_layout_policy_cascade.cpp +++ b/wmserver/src/window_layout_policy_cascade.cpp @@ -17,6 +17,7 @@ #include "window_helper.h" #include "window_inner_manager.h" #include "window_manager_hilog.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { @@ -130,19 +131,23 @@ static bool IsLayoutChanged(const Rect& l, const Rect& r) void WindowLayoutPolicyCascade::LimitMoveBounds(Rect& rect) { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t minHorizontalSplitW = static_cast(MIN_HORIZONTAL_SPLIT_WIDTH * virtualPixelRatio); + uint32_t minVerticalSplitH = static_cast(MIN_VERTICAL_SPLIT_HEIGHT * virtualPixelRatio); + if (rect.width_ < rect.height_) { - if (rect.posX_ < (limitRect_.posX_ + static_cast(MIN_HORIZONTAL_SPLIT_WIDTH))) { - rect.posX_ = limitRect_.posX_ + static_cast(MIN_HORIZONTAL_SPLIT_WIDTH); + if (rect.posX_ < (limitRect_.posX_ + static_cast(minHorizontalSplitW))) { + rect.posX_ = limitRect_.posX_ + static_cast(minHorizontalSplitW); } else if (rect.posX_ > - (limitRect_.posX_ + limitRect_.width_ - static_cast(MIN_HORIZONTAL_SPLIT_WIDTH))) { - rect.posX_ = limitRect_.posX_ + static_cast(limitRect_.width_ - MIN_HORIZONTAL_SPLIT_WIDTH); + (limitRect_.posX_ + limitRect_.width_ - static_cast(minHorizontalSplitW))) { + rect.posX_ = limitRect_.posX_ + static_cast(limitRect_.width_ - minHorizontalSplitW); } } else { - if (rect.posY_ < (limitRect_.posY_ + static_cast(MIN_VERTICAL_SPLIT_HEIGHT))) { - rect.posY_ = limitRect_.posY_ + static_cast(MIN_VERTICAL_SPLIT_HEIGHT); + if (rect.posY_ < (limitRect_.posY_ + static_cast(minVerticalSplitH))) { + rect.posY_ = limitRect_.posY_ + static_cast(minVerticalSplitH); } else if (rect.posY_ > - (limitRect_.posY_ + static_cast(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT))) { - rect.posY_ = limitRect_.posY_ + static_cast(limitRect_.height_ - MIN_VERTICAL_SPLIT_HEIGHT); + (limitRect_.posY_ + static_cast(limitRect_.height_ - minVerticalSplitH))) { + rect.posY_ = limitRect_.posY_ + static_cast(limitRect_.height_ - minVerticalSplitH); } } } @@ -215,6 +220,7 @@ void WindowLayoutPolicyCascade::UpdateLayoutRect(sptr& node) } node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (IsLayoutChanged(lastRect, winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); @@ -265,12 +271,15 @@ void WindowLayoutPolicyCascade::UpdateSplitLimitRect(const Rect& limitRect, Rect void WindowLayoutPolicyCascade::InitSplitRects() { + float virtualPixelRatio = GetVirtualPixelRatio(); + uint32_t dividerWidth = static_cast(DIVIDER_WIDTH * virtualPixelRatio); + if (!IsVertical()) { - dividerRect_ = { static_cast((displayRect_.width_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), 0, - DIVIDER_WIDTH, displayRect_.height_ }; + dividerRect_ = { static_cast((displayRect_.width_ - dividerWidth) * DEFAULT_SPLIT_RATIO), 0, + dividerWidth, displayRect_.height_ }; } else { - dividerRect_ = { 0, static_cast((displayRect_.height_ - DIVIDER_WIDTH) * DEFAULT_SPLIT_RATIO), - displayRect_.width_, DIVIDER_WIDTH }; + dividerRect_ = { 0, static_cast((displayRect_.height_ - dividerWidth) * DEFAULT_SPLIT_RATIO), + displayRect_.width_, dividerWidth }; } WLOGFI("init dividerRect :[%{public}d, %{public}d, %{public}u, %{public}u]", dividerRect_.posX_, dividerRect_.posY_, dividerRect_.width_, dividerRect_.height_); diff --git a/wmserver/src/window_layout_policy_tile.cpp b/wmserver/src/window_layout_policy_tile.cpp index 073ada6a..9c24ada2 100644 --- a/wmserver/src/window_layout_policy_tile.cpp +++ b/wmserver/src/window_layout_policy_tile.cpp @@ -99,6 +99,7 @@ void WindowLayoutPolicyTile::LayoutForegroundNodeQueue() Rect lastRect = node->GetLayoutRect(); Rect winRect = node->GetWindowProperty()->GetWindowRect(); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); @@ -204,6 +205,7 @@ void WindowLayoutPolicyTile::UpdateLayoutRect(sptr& node) } LimitWindowSize(node, displayRect, winRect); node->SetLayoutRect(winRect); + CalcAndSetNodeHotZone(winRect, node); if (!(lastRect == winRect)) { node->GetWindowToken()->UpdateWindowRect(winRect, node->GetWindowSizeChangeReason()); node->surfaceNode_->SetBounds(winRect.posX_, winRect.posY_, winRect.width_, winRect.height_); diff --git a/wmserver/src/window_manager_recorder.cpp b/wmserver/src/window_manager_recorder.cpp index 96062e18..04fd2fc5 100644 --- a/wmserver/src/window_manager_recorder.cpp +++ b/wmserver/src/window_manager_recorder.cpp @@ -42,7 +42,7 @@ void WindowManagerRecorder::AddNodeRecord(WindowManagerRecordInfo record) { std::string historyRecord; int32_t number = records_.size(); - historyRecord += "\nNo." + std::to_string(number) + "\t[WINDOW-ACTIVITY]\n"; + historyRecord += "\nNo." + std::to_string(number) + "\t[WINDOW-RECORD]\n"; char systime[TIME_LENGTH]; if (strftime(systime, sizeof(char) * TIME_LENGTH, "%Y/%m/%d %H:%M:%S %p", &record.recordTime) != 0) { std::string recordTime = "Time: " + std::string(systime) + "\n"; diff --git a/wmserver/src/window_node.cpp b/wmserver/src/window_node.cpp index e17a389e..9d2ee306 100644 --- a/wmserver/src/window_node.cpp +++ b/wmserver/src/window_node.cpp @@ -38,6 +38,11 @@ void WindowNode::SetLayoutRect(const Rect& rect) layoutRect_ = rect; } +void WindowNode::SetHotZoneRect(const Rect& rect) +{ + hotZoneRect_ = rect; +} + void WindowNode::SetWindowRect(const Rect& rect) { property_->SetWindowRect(rect); @@ -134,23 +139,7 @@ const Rect& WindowNode::GetLayoutRect() const Rect WindowNode::GetHotZoneRect() const { - Rect rect = layoutRect_; - if (GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) { - const int32_t divHotZone = 20; - if (rect.width_ < rect.height_) { - rect.posX_ -= divHotZone; - rect.width_ += (divHotZone + divHotZone); - } else { - rect.posY_ -= divHotZone; - rect.height_ += (divHotZone + divHotZone); - } - } else if (WindowHelper::IsMainFloatingWindow(GetWindowType(), GetWindowMode())) { - rect.posX_ -= HOTZONE; - rect.posY_ -= HOTZONE; - rect.width_ += (HOTZONE + HOTZONE); - rect.height_ += (HOTZONE + HOTZONE); - } - return rect; + return hotZoneRect_; } WindowType WindowNode::GetWindowType() const diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 439a568c..1519544a 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -30,6 +30,7 @@ #include "window_manager_agent_controller.h" #include "window_manager_hilog.h" #include "wm_common.h" +#include "wm_common_inner.h" #include "wm_trace.h" namespace OHOS { @@ -1070,6 +1071,11 @@ sptr WindowNodeContainer::GetAboveAppWindowNode() const return aboveAppWindowNode_; } +float WindowNodeContainer::GetVirtualPixelRatio() const +{ + return layoutPolicy_->GetVirtualPixelRatio(); +} + bool WindowNodeContainer::ReadIsWindowAnimationEnabledProperty() { if (access(DISABLE_WINDOW_ANIMATION_PATH, F_OK) == 0) { diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index ef834053..ed0d8aad 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -488,5 +488,11 @@ WMError WindowRoot::DumpWindowTree(std::vector &windowTreeInfos, Wi } return WMError::WM_OK; } + +float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const +{ + auto container = const_cast(this)->GetOrCreateWindowNodeContainer(displayId); + return container->GetVirtualPixelRatio(); +} } }