From de3c82b63a2265daf009d1301aefdd3cc8160c46 Mon Sep 17 00:00:00 2001 From: zhengjiangliang Date: Wed, 1 Jun 2022 20:19:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=87=BD=E6=95=B0=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E6=89=A9=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6cf74b5069d118a60811ec35c2346671ce6e60e4 Signed-off-by: zhengjiangliang --- dmserver/include/abstract_display.h | 4 +- .../include/abstract_display_controller.h | 11 +- dmserver/include/display_manager_service.h | 3 +- dmserver/include/display_power_controller.h | 3 +- dmserver/src/abstract_display.cpp | 16 ++- dmserver/src/abstract_display_controller.cpp | 73 +++++++--- dmserver/src/display_manager_service.cpp | 12 +- dmserver/src/display_power_controller.cpp | 10 +- utils/include/display_change_listener.h | 3 +- utils/include/display_info.h | 1 + wmserver/include/display_group_controller.h | 10 +- wmserver/include/window_controller.h | 6 +- wmserver/include/window_manager_service.h | 6 +- wmserver/include/window_root.h | 20 ++- wmserver/src/display_group_controller.cpp | 31 +++-- wmserver/src/window_controller.cpp | 18 +-- wmserver/src/window_manager_service.cpp | 15 +- wmserver/src/window_root.cpp | 129 +++++++++++------- 18 files changed, 240 insertions(+), 131 deletions(-) diff --git a/dmserver/include/abstract_display.h b/dmserver/include/abstract_display.h index 54c21b67a2..0461b3c015 100644 --- a/dmserver/include/abstract_display.h +++ b/dmserver/include/abstract_display.h @@ -33,7 +33,7 @@ public: constexpr static int32_t DEFAULT_HIGHT = 1280; constexpr static float DEFAULT_VIRTUAL_PIXEL_RATIO = 1.0; constexpr static uint32_t DEFAULT_FRESH_RATE = 60; - AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t refreshRate); + AbstractDisplay(DisplayId id, ScreenId screenId, ScreenId screenGroupId, sptr info); WM_DISALLOW_COPY_AND_MOVE(AbstractDisplay); ~AbstractDisplay() = default; static inline bool IsVertical(Rotation rotation) @@ -48,6 +48,7 @@ public: uint32_t GetRefreshRate() const; float GetVirtualPixelRatio() const; ScreenId GetAbstractScreenId() const; + ScreenId GetAbstractScreenGroupId() const; bool BindAbstractScreen(sptr abstractDisplay); sptr ConvertToDisplayInfo() const; Rotation GetRotation() const; @@ -69,6 +70,7 @@ public: private: DisplayId id_ { DISPLAY_ID_INVALID }; ScreenId screenId_ { SCREEN_ID_INVALID }; + ScreenId screenGroupId_ { SCREEN_ID_INVALID }; int32_t offsetX_ { 0 }; int32_t offsetY_ { 0 }; int32_t width_ { 0 }; diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 128169c931..077b22e42a 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -31,7 +31,8 @@ namespace OHOS::Rosen { class AbstractDisplayController : public RefBase { -using DisplayStateChangeListener = std::function; +using DisplayStateChangeListener = std::function, + const std::map>&, DisplayStateChangeType)>; public: AbstractDisplayController(std::recursive_mutex& mutex, DisplayStateChangeListener); ~AbstractDisplayController(); @@ -57,9 +58,13 @@ private: void BindAloneScreenLocked(sptr absScreen); void AddScreenToMirrorLocked(sptr absScreen); void AddScreenToExpandLocked(sptr absScreen); - DisplayId ProcessNormalScreenDisconnected(sptr absScreen, sptr screenGroup); - DisplayId ProcessExpandScreenDisconnected(sptr absScreen, sptr screenGroup); + std::map> GetAllDisplayInfoOfGroup(sptr info); + DisplayId ProcessNormalScreenDisconnected( + sptr absScreen, sptr screenGroup, sptr& absDisplay); + DisplayId ProcessExpandScreenDisconnected( + sptr absScreen, sptr screenGroup, sptr& absDisplay); bool UpdateDisplaySize(sptr absDisplay, sptr info); + void displayStateChangeListener(sptr abstractDisplay, DisplayStateChangeType type); std::recursive_mutex& mutex_; std::atomic displayCount_ { 0 }; diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index 2da6d4df0f..50f2b91978 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -101,7 +101,8 @@ private: DisplayManagerService(); ~DisplayManagerService() = default; bool Init(); - void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type); + void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type); ScreenId GetScreenIdByDisplayId(DisplayId displayId) const; std::shared_ptr GetRSDisplayNodeByDisplayId(DisplayId displayId) const; void ConfigureDisplayManagerService(); diff --git a/dmserver/include/display_power_controller.h b/dmserver/include/display_power_controller.h index d35163163c..7bba6a2bb2 100644 --- a/dmserver/include/display_power_controller.h +++ b/dmserver/include/display_power_controller.h @@ -26,7 +26,8 @@ namespace OHOS { namespace Rosen { class DisplayPowerController : public RefBase { -using DisplayStateChangeListener = std::function; +using DisplayStateChangeListener = std::function, + const std::map>&, DisplayStateChangeType)>; public: DisplayPowerController(std::recursive_mutex& mutex, DisplayStateChangeListener listener) : mutex_(mutex), displayStateChangeListener_(listener) diff --git a/dmserver/src/abstract_display.cpp b/dmserver/src/abstract_display.cpp index 1452e265be..35ee826621 100644 --- a/dmserver/src/abstract_display.cpp +++ b/dmserver/src/abstract_display.cpp @@ -26,12 +26,14 @@ namespace { constexpr int32_t PHONE_SCREEN_WIDTH = 2160; } -AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, int32_t width, int32_t height, uint32_t refreshRate) +AbstractDisplay::AbstractDisplay(DisplayId id, ScreenId screenId, + ScreenId screenGroupId, sptr info) : id_(id), screenId_(screenId), - width_(width), - height_(height), - refreshRate_(refreshRate) + screenGroupId_(screenGroupId), + width_(info->width_), + height_(info->height_), + refreshRate_(info->refreshRate_) { if (DisplayManagerService::GetCustomVirtualPixelRatio() && fabs(DisplayManagerService::GetCustomVirtualPixelRatio() + 1) > 1e-6) { @@ -194,6 +196,11 @@ ScreenId AbstractDisplay::GetAbstractScreenId() const return screenId_; } +ScreenId AbstractDisplay::GetAbstractScreenGroupId() const +{ + return screenGroupId_; +} + sptr AbstractDisplay::ConvertToDisplayInfo() const { sptr displayInfo = new(std::nothrow) DisplayInfo(); @@ -207,6 +214,7 @@ sptr AbstractDisplay::ConvertToDisplayInfo() const displayInfo->SetDisplayId(id_); displayInfo->SetRefreshRate(refreshRate_); displayInfo->SetScreenId(screenId_); + displayInfo->SetScreenGroupId(screenGroupId_); displayInfo->SetVirtualPixelRatio(virtualPixelRatio_); displayInfo->SetRotation(rotation_); displayInfo->SetOrientation(orientation_); diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index df9e823c37..5c47deca60 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -158,6 +158,7 @@ void AbstractDisplayController::OnAbstractScreenDisconnect(sptr WLOGI("disconnect screen. id:%{public}" PRIu64"", absScreen->dmsId_); sptr screenGroup; DisplayId absDisplayId = DISPLAY_ID_INVALID; + sptr abstractDisplay = nullptr; { std::lock_guard lock(mutex_); screenGroup = absScreen->GetGroup(); @@ -167,9 +168,9 @@ void AbstractDisplayController::OnAbstractScreenDisconnect(sptr } if (screenGroup->combination_ == ScreenCombination::SCREEN_ALONE || screenGroup->combination_ == ScreenCombination::SCREEN_MIRROR) { - absDisplayId = ProcessNormalScreenDisconnected(absScreen, screenGroup); + absDisplayId = ProcessNormalScreenDisconnected(absScreen, screenGroup, abstractDisplay); } else if (screenGroup->combination_ == ScreenCombination::SCREEN_EXPAND) { - absDisplayId = ProcessExpandScreenDisconnected(absScreen, screenGroup); + absDisplayId = ProcessExpandScreenDisconnected(absScreen, screenGroup, abstractDisplay); } else { WLOGE("support in future. combination:%{public}u", screenGroup->combination_); } @@ -185,7 +186,8 @@ void AbstractDisplayController::OnAbstractScreenDisconnect(sptr DisplayManagerAgentController::GetInstance().OnDisplayDestroy(absDisplayId); } } else if (screenGroup->combination_ == ScreenCombination::SCREEN_EXPAND) { - displayStateChangeListener_(absDisplayId, DisplayStateChangeType::DESTROY); + displayStateChangeListener(abstractDisplay, DisplayStateChangeType::DESTROY); + DisplayManagerAgentController::GetInstance().OnDisplayDestroy(absDisplayId); abstractDisplayMap_.erase(absDisplayId); } else { @@ -194,7 +196,7 @@ void AbstractDisplayController::OnAbstractScreenDisconnect(sptr } DisplayId AbstractDisplayController::ProcessNormalScreenDisconnected( - sptr absScreen, sptr screenGroup) + sptr absScreen, sptr screenGroup, sptr& absDisplay) { WLOGI("normal screen disconnect"); if (absScreen == nullptr || screenGroup == nullptr) { @@ -210,6 +212,7 @@ DisplayId AbstractDisplayController::ProcessNormalScreenDisconnected( WLOGI("normal screen disconnect, displayId: %{public}" PRIu64", screenId: %{public}" PRIu64"", displayId, abstractDisplay->GetAbstractScreenId()); abstractDisplay->BindAbstractScreen(defaultScreen); + absDisplay = abstractDisplay; return displayId; } } @@ -217,7 +220,7 @@ DisplayId AbstractDisplayController::ProcessNormalScreenDisconnected( } DisplayId AbstractDisplayController::ProcessExpandScreenDisconnected( - sptr absScreen, sptr screenGroup) + sptr absScreen, sptr screenGroup, sptr& absDisplay) { WLOGI("expand screen disconnect"); if (absScreen == nullptr || screenGroup == nullptr) { @@ -230,6 +233,7 @@ DisplayId AbstractDisplayController::ProcessExpandScreenDisconnected( if (abstractDisplay->GetAbstractScreenId() == absScreen->dmsId_) { WLOGI("expand screen disconnect, displayId: %{public}" PRIu64", screenId: %{public}" PRIu64"", displayId, abstractDisplay->GetAbstractScreenId()); + absDisplay = abstractDisplay; displayId = iter->first; } else { abstractDisplay->SetOffset(0, 0); @@ -296,11 +300,10 @@ void AbstractDisplayController::ProcessDisplayUpdateOrientation(sptrSetOrientation(absScreen->orientation_); if (abstractDisplay->RequestRotation(absScreen->rotation_)) { // Notify rotation event to WMS - displayStateChangeListener_(abstractDisplay->GetId(), DisplayStateChangeType::UPDATE_ROTATION); + displayStateChangeListener(abstractDisplay, DisplayStateChangeType::UPDATE_ROTATION); } // Notify orientation event to DisplayManager - sptr displayInfo = abstractDisplay->ConvertToDisplayInfo(); - DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo, + DisplayManagerAgentController::GetInstance().OnDisplayChange(abstractDisplay->ConvertToDisplayInfo(), DisplayChangeEvent::UPDATE_ORIENTATION); } @@ -330,9 +333,10 @@ void AbstractDisplayController::ProcessDisplaySizeChange(sptr ab WLOGFI("Size of matchedDisplays %{public}zu", matchedDisplays.size()); for (auto iter = matchedDisplays.begin(); iter != matchedDisplays.end(); ++iter) { WLOGFI("Notify display size change. Id %{public}" PRIu64"", iter->first); - displayStateChangeListener_(iter->first, DisplayStateChangeType::SIZE_CHANGE); + sptr abstractDisplay = iter->second; + displayStateChangeListener(abstractDisplay, DisplayStateChangeType::SIZE_CHANGE); DisplayManagerAgentController::GetInstance().OnDisplayChange( - iter->second->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_SIZE_CHANGED); + abstractDisplay->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_SIZE_CHANGED); } } @@ -375,10 +379,9 @@ void AbstractDisplayController::ProcessVirtualPixelRatioChange(sptrSetVirtualPixelRatio(absScreen->virtualPixelRatio_); // Notify virtual pixel ratio change event to WMS - displayStateChangeListener_(abstractDisplay->GetId(), DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE); + displayStateChangeListener(abstractDisplay, DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE); // Notify virtual pixel ratio change event to DisplayManager - sptr displayInfo = abstractDisplay->ConvertToDisplayInfo(); - DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo, + DisplayManagerAgentController::GetInstance().OnDisplayChange(abstractDisplay->ConvertToDisplayInfo(), DisplayChangeEvent::DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED); } @@ -401,7 +404,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr realA } if (dummyDisplay_ == nullptr) { sptr display = new(std::nothrow) AbstractDisplay(displayCount_.fetch_add(1), - realAbsScreen->dmsId_, info->width_, info->height_, info->refreshRate_); + realAbsScreen->dmsId_, realAbsScreen->groupDmsId_, info); if (display == nullptr) { WLOGFE("create display failed"); return; @@ -411,7 +414,7 @@ void AbstractDisplayController::BindAloneScreenLocked(sptr realA WLOGI("create display for new screen. screen:%{public}" PRIu64", display:%{public}" PRIu64"", realAbsScreen->dmsId_, display->GetId()); DisplayManagerAgentController::GetInstance().OnDisplayCreate(display->ConvertToDisplayInfo()); - displayStateChangeListener_(display->GetId(), DisplayStateChangeType::CREATE); + displayStateChangeListener(display, DisplayStateChangeType::CREATE); } else { WLOGI("bind display for new screen. screen:%{public}" PRIu64", display:%{public}" PRIu64"", realAbsScreen->dmsId_, dummyDisplay_->GetId()); @@ -448,10 +451,10 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr abs } WLOGI("bind display to expand. screen:%{public}" PRIu64"", absScreen->dmsId_); sptr info; + ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId(); + sptr defaultScreen = abstractScreenController_->GetAbstractScreen(defaultScreenId); if (absScreen->type_ == ScreenType::VIRTUAL) { WLOGI("screen type is virtual, use default screen info"); - ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId(); - sptr defaultScreen = abstractScreenController_->GetAbstractScreen(defaultScreenId); if (defaultScreen == nullptr) { WLOGE("bind display error, cannot get defaultScreen."); return; @@ -467,7 +470,7 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr abs } sptr display = new AbstractDisplay(displayCount_.fetch_add(1), - absScreen->dmsId_, info->width_, info->height_, info->refreshRate_); + absScreen->dmsId_, absScreen->groupDmsId_, info); Point point = abstractScreenController_->GetAbstractScreenGroup(absScreen->groupDmsId_)-> GetChildPosition(absScreen->dmsId_); display->SetOffset(point.posX_, point.posY_); @@ -475,7 +478,7 @@ void AbstractDisplayController::AddScreenToExpandLocked(sptr abs WLOGI("create display for new screen. screen:%{public}" PRIu64", display:%{public}" PRIu64"", absScreen->dmsId_, display->GetId()); DisplayManagerAgentController::GetInstance().OnDisplayCreate(display->ConvertToDisplayInfo()); - displayStateChangeListener_(display->GetId(), DisplayStateChangeType::CREATE); + displayStateChangeListener(display, DisplayStateChangeType::CREATE); } void AbstractDisplayController::SetFreeze(std::vector displayIds, bool toFreeze) @@ -508,10 +511,36 @@ void AbstractDisplayController::SetFreeze(std::vector displayIds, boo } // Notify freeze event to WMS - displayStateChangeListener_(displayId, type); + displayStateChangeListener(abstractDisplay, type); // Notify freeze event to DisplayManager - sptr displayInfo = abstractDisplay->ConvertToDisplayInfo(); - DisplayManagerAgentController::GetInstance().OnDisplayChange(displayInfo, event); + DisplayManagerAgentController::GetInstance().OnDisplayChange(abstractDisplay->ConvertToDisplayInfo(), event); + } +} + +std::map> AbstractDisplayController::GetAllDisplayInfoOfGroup(sptr info) +{ + ScreenId screenGroupId = info->GetScreenGroupId(); + std::map> displayInfoMap; + for (auto& iter : abstractDisplayMap_) { + sptr display = iter.second; + if (display->GetAbstractScreenGroupId() == screenGroupId) { + displayInfoMap.insert(std::make_pair(display->GetId(), display->ConvertToDisplayInfo())); + } + } + return displayInfoMap; +} + +void AbstractDisplayController::displayStateChangeListener( + sptr abstractDisplay, DisplayStateChangeType type) +{ + ScreenId defaultDisplayId = DISPLAY_ID_INVALID; + ScreenId defaultScreenId = abstractScreenController_->GetDefaultAbstractScreenId(); + sptr defaultDisplay = GetAbstractDisplayByScreen(defaultScreenId); + if (defaultDisplay != nullptr) { + defaultDisplayId = defaultDisplay->GetId(); } + std::map> displayInfoMap = GetAllDisplayInfoOfGroup( + abstractDisplay->ConvertToDisplayInfo()); + displayStateChangeListener_(defaultDisplayId, abstractDisplay->ConvertToDisplayInfo(), displayInfoMap, type); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index 7d9738aa1d..39b94f4c7f 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -44,10 +44,12 @@ float DisplayManagerService::customVirtualPixelRatio_ = -1.0f; DisplayManagerService::DisplayManagerService() : SystemAbility(DISPLAY_MANAGER_SERVICE_SA_ID, true), abstractDisplayController_(new AbstractDisplayController(mutex_, - std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, std::placeholders::_1, std::placeholders::_2))), + std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))), abstractScreenController_(new AbstractScreenController(mutex_)), displayPowerController_(new DisplayPowerController(mutex_, - std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, std::placeholders::_1, std::placeholders::_2))) + std::bind(&DisplayManagerService::NotifyDisplayStateChange, this, + std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4))) { } @@ -111,11 +113,13 @@ void DisplayManagerService::RegisterDisplayChangeListener(sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { + DisplayId id = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId(); WLOGFI("DisplayId %{public}" PRIu64"", id); if (displayChangeListener_ != nullptr) { - displayChangeListener_->OnDisplayStateChange(id, type); + displayChangeListener_->OnDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); } } diff --git a/dmserver/src/display_power_controller.cpp b/dmserver/src/display_power_controller.cpp index a98fb06d74..b2cca50d3b 100644 --- a/dmserver/src/display_power_controller.cpp +++ b/dmserver/src/display_power_controller.cpp @@ -27,7 +27,8 @@ namespace { bool DisplayPowerController::SuspendBegin(PowerStateChangeReason reason) { WLOGFI("reason:%{public}u", reason); - displayStateChangeListener_(DISPLAY_ID_INVALID, DisplayStateChangeType::BEFORE_SUSPEND); + std::map> emptyMap; + displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_SUSPEND); return true; } @@ -50,7 +51,9 @@ bool DisplayPowerController::SetDisplayState(DisplayState state) isKeyguardDrawn = isKeyguardDrawn_; } if (!isKeyguardDrawn) { - displayStateChangeListener_(DISPLAY_ID_INVALID, DisplayStateChangeType::BEFORE_UNLOCK); + std::map> emptyMap; + displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, + emptyMap, DisplayStateChangeType::BEFORE_UNLOCK); } DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DISPLAY_ON, EventStatus::BEGIN); @@ -83,7 +86,8 @@ void DisplayPowerController::NotifyDisplayEvent(DisplayEvent event) { WLOGFI("DisplayEvent:%{public}u", event); if (event == DisplayEvent::UNLOCK) { - displayStateChangeListener_(DISPLAY_ID_INVALID, DisplayStateChangeType::BEFORE_UNLOCK); + std::map> emptyMap; + displayStateChangeListener_(DISPLAY_ID_INVALID, nullptr, emptyMap, DisplayStateChangeType::BEFORE_UNLOCK); DisplayManagerAgentController::GetInstance().NotifyDisplayPowerEvent(DisplayPowerEvent::DESKTOP_READY, EventStatus::BEGIN); std::lock_guard lock(mutex_); diff --git a/utils/include/display_change_listener.h b/utils/include/display_change_listener.h index 48997a3ae8..8e622fe75f 100644 --- a/utils/include/display_change_listener.h +++ b/utils/include/display_change_listener.h @@ -33,7 +33,8 @@ enum class DisplayStateChangeType : uint32_t { }; class IDisplayChangeListener : public RefBase { public: - virtual void OnDisplayStateChange(DisplayId id, DisplayStateChangeType type) = 0; + virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr info, + const std::map>& displayInfoMap, DisplayStateChangeType type)= 0; }; } } diff --git a/utils/include/display_info.h b/utils/include/display_info.h index edc4bf0720..1aaa8d10ae 100644 --- a/utils/include/display_info.h +++ b/utils/include/display_info.h @@ -38,6 +38,7 @@ public: DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, Height, height, 0); DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, RefreshRate, refreshRate, 0); DEFINE_VAR_DEFAULT_FUNC_GET_SET(ScreenId, ScreenId, screenId, SCREEN_ID_INVALID); + DEFINE_VAR_DEFAULT_FUNC_GET_SET(ScreenId, ScreenGroupId, screenGroupId, SCREEN_ID_INVALID); DEFINE_VAR_DEFAULT_FUNC_GET_SET(float, VirtualPixelRatio, virtualPixelRatio, 1.0f); DEFINE_VAR_DEFAULT_FUNC_GET_SET(float, XDpi, xDpi, 0.0f); DEFINE_VAR_DEFAULT_FUNC_GET_SET(float, YDpi, yDpi, 0.0f); diff --git a/wmserver/include/display_group_controller.h b/wmserver/include/display_group_controller.h index 84dfd2bc18..2d726d6910 100644 --- a/wmserver/include/display_group_controller.h +++ b/wmserver/include/display_group_controller.h @@ -44,12 +44,12 @@ public: void InitNewDisplay(DisplayId displayId); void UpdateDisplayGroupWindowTree(); void PreProcessWindowNode(const sptr& node, WindowUpdateType type); - void ProcessDisplayCreate(DisplayId displayId, + void ProcessDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap); - void ProcessDisplayDestroy(DisplayId displayId, + void ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap, std::vector& windowIds); - void ProcessDisplayChange(DisplayId displayId, + void ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap, DisplayStateChangeType type); sptr GetWindowPairByDisplayId(DisplayId displayId); @@ -63,9 +63,9 @@ private: std::vector>* GetWindowNodesByDisplayIdAndRootType(DisplayId displayId, WindowRootNodeType type); void AddWindowNodeOnWindowTree(sptr& node, WindowRootNodeType rootType); void ProcessNotCrossNodesOnDestroiedDisplay(DisplayId displayId, std::vector& windowIds); - void ProcessDisplaySizeChangeOrRotation(DisplayId displayId, + void ProcessDisplaySizeChangeOrRotation(DisplayId defaultDisplayId, DisplayId displayId, const std::map& displayRectMap, DisplayStateChangeType type); - void ProcessCrossNodes(DisplayStateChangeType type); + void ProcessCrossNodes(DisplayId defaultDisplayId, DisplayStateChangeType type); void MoveCrossNodeToTargetDisplay(const sptr& node, DisplayId targetDisplayId); void MoveNotCrossNodeToDefaultDisplay(const sptr& node, DisplayId displayId); void UpdateWindowShowingDisplays(const sptr& node, const Rect& requestRect); diff --git a/wmserver/include/window_controller.h b/wmserver/include/window_controller.h index 39a788d83d..615c1db7f8 100644 --- a/wmserver/include/window_controller.h +++ b/wmserver/include/window_controller.h @@ -45,7 +45,8 @@ public: WMError SetAlpha(uint32_t windowId, float alpha); std::vector GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); - void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type); + void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type); WMError ProcessPointDown(uint32_t windowId, bool isStartDrag); WMError ProcessPointUp(uint32_t windowId); void MinimizeAllAppWindows(DisplayId displayId); @@ -67,7 +68,8 @@ private: void FlushWindowInfo(uint32_t windowId); void FlushWindowInfoWithDisplayId(DisplayId displayId); void UpdateWindowAnimation(const sptr& node); - void ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type); + void ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type); void StopBootAnimationIfNeed(WindowType type) const; WMError SetWindowType(uint32_t windowId, WindowType type); WMError SetWindowFlags(uint32_t windowId, uint32_t flags); diff --git a/wmserver/include/window_manager_service.h b/wmserver/include/window_manager_service.h index f6adb418df..181c7a25f3 100644 --- a/wmserver/include/window_manager_service.h +++ b/wmserver/include/window_manager_service.h @@ -39,7 +39,8 @@ namespace OHOS { namespace Rosen { class DisplayChangeListener : public IDisplayChangeListener { public: - virtual void OnDisplayStateChange(DisplayId id, DisplayStateChangeType type) override; + virtual void OnDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) override; }; class WindowManagerServiceHandler : public AAFwk::WindowManagerServiceHandlerStub { @@ -108,7 +109,8 @@ private: void RegisterSnapshotHandler(); void RegisterWindowManagerServiceHandler(); void OnWindowEvent(Event event, const sptr& remoteObject); - void NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type); + void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type); WMError GetFocusWindowInfo(sptr& abilityToken); void ConfigureWindowManagerService(); void ConfigFloatWindowLimits(); diff --git a/wmserver/include/window_root.h b/wmserver/include/window_root.h index 2614f11cdc..5c5bc12556 100644 --- a/wmserver/include/window_root.h +++ b/wmserver/include/window_root.h @@ -37,7 +37,7 @@ public: ~WindowRoot() = default; sptr GetOrCreateWindowNodeContainer(DisplayId displayId); - sptr CreateWindowNodeContainer(DisplayId displayId); + sptr CreateWindowNodeContainer(sptr displayInfo); sptr GetWindowNode(uint32_t windowId) const; WMError SaveWindow(const sptr& node); @@ -65,9 +65,12 @@ public: WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode); void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); - void ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type); - void ProcessDisplayDestroy(DisplayId displayId); - void ProcessDisplayCreate(DisplayId displayId); + void ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type); + void ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap); + void ProcessDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap); void NotifySystemBarTints(); WMError RaiseZOrderForAppWindow(sptr& node); @@ -102,10 +105,13 @@ private: std::string GenAllWindowsLogInfo() const; bool CheckDisplayInfo(const sptr& display); ScreenId GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay); - void ProcessExpandDisplayCreate(DisplayId displayId, ScreenId displayGroupId); + void ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, + std::map& displayRectMap); std::map> GetAllDisplayInfos(const std::vector& displayIdVec); - std::map GetAllDisplayRects(const std::vector& displayIdVec); - void MoveNotShowingWindowToDefaultDisplay(DisplayId displayId); + std::map GetAllDisplayRectsByDMS(sptr displayInfo); + std::map GetAllDisplayRectsByDisplayInfo( + const std::map>& displayInfoMap); + void MoveNotShowingWindowToDefaultDisplay(DisplayId defaultDisplayId, DisplayId displayId); WMError PostProcessAddWindowNode(sptr& node, sptr& parentNode, sptr& container); std::map> windowNodeMap_; diff --git a/wmserver/src/display_group_controller.cpp b/wmserver/src/display_group_controller.cpp index df29483bee..e54aa33d68 100644 --- a/wmserver/src/display_group_controller.cpp +++ b/wmserver/src/display_group_controller.cpp @@ -105,9 +105,9 @@ void DisplayGroupController::UpdateDisplayGroupWindowTree() } } -void DisplayGroupController::ProcessCrossNodes(DisplayStateChangeType type) +void DisplayGroupController::ProcessCrossNodes(DisplayId defaultDisplayId, DisplayStateChangeType type) { - defaultDisplayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); + defaultDisplayId_ = defaultDisplayId; for (auto& iter : displayGroupWindowTree_) { auto& nodeVec = *(iter.second[WindowRootNodeType::APP_WINDOW_NODE]); for (auto& node : nodeVec) { @@ -120,7 +120,7 @@ void DisplayGroupController::ProcessCrossNodes(DisplayStateChangeType type) if (type == DisplayStateChangeType::SIZE_CHANGE || type == DisplayStateChangeType::UPDATE_ROTATION) { newDisplayId = node->GetDisplayId(); } else { - newDisplayId = defaultDisplayId_; + newDisplayId = defaultDisplayId; } for (auto& displayId : showingDisplays) { @@ -351,47 +351,48 @@ void DisplayGroupController::ProcessNotCrossNodesOnDestroiedDisplay(DisplayId di } } -void DisplayGroupController::ProcessDisplayCreate(DisplayId displayId, +void DisplayGroupController::ProcessDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap) { - defaultDisplayId_ = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); - WLOGFI("defaultDisplay, displayId: %{public}" PRIu64"", defaultDisplayId_); + defaultDisplayId_ = defaultDisplayId; + WLOGFI("defaultDisplay, displayId: %{public}" PRIu64"", defaultDisplayId); + DisplayId displayId = displayInfo->GetDisplayId(); windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, true); InitNewDisplay(displayId); // add displayInfo in displayGroupInfo - auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); displayGroupInfo_->AddDisplayInfo(displayInfo); // modify RSTree and window tree of displayGroup for cross-display nodes - ProcessCrossNodes(DisplayStateChangeType::CREATE); + ProcessCrossNodes(defaultDisplayId, DisplayStateChangeType::CREATE); UpdateDisplayGroupWindowTree(); windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayCreate(displayId, displayRectMap); Rect initialDividerRect = windowNodeContainer_->GetLayoutPolicy()->GetInitalDividerRect(displayId); SetInitalDividerRect(displayId, initialDividerRect); } -void DisplayGroupController::ProcessDisplayDestroy(DisplayId displayId, +void DisplayGroupController::ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap, std::vector& windowIds) { + DisplayId displayId = displayInfo->GetDisplayId(); windowNodeContainer_->GetAvoidController()->UpdateAvoidNodesMap(displayId, false); // delete nodes and map element of deleted display ProcessNotCrossNodesOnDestroiedDisplay(displayId, windowIds); // modify RSTree and window tree of displayGroup for cross-display nodes - ProcessCrossNodes(DisplayStateChangeType::DESTROY); + ProcessCrossNodes(defaultDisplayId, DisplayStateChangeType::DESTROY); UpdateDisplayGroupWindowTree(); ClearMapOfDestroiedDisplay(displayId); windowNodeContainer_->GetLayoutPolicy()->ProcessDisplayDestroy(displayId, displayRectMap); } -void DisplayGroupController::ProcessDisplayChange(DisplayId displayId, +void DisplayGroupController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, const std::map& displayRectMap, DisplayStateChangeType type) { - const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + DisplayId displayId = displayInfo->GetDisplayId(); WLOGFI("display change, displayId: %{public}" PRIu64", type: %{public}d", displayId, type); switch (type) { case DisplayStateChangeType::UPDATE_ROTATION: { @@ -399,7 +400,7 @@ void DisplayGroupController::ProcessDisplayChange(DisplayId displayId, [[fallthrough]]; } case DisplayStateChangeType::SIZE_CHANGE: { - ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap, type); + ProcessDisplaySizeChangeOrRotation(defaultDisplayId, displayId, displayRectMap, type); break; } case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: { @@ -413,11 +414,11 @@ void DisplayGroupController::ProcessDisplayChange(DisplayId displayId, } } -void DisplayGroupController::ProcessDisplaySizeChangeOrRotation(DisplayId displayId, +void DisplayGroupController::ProcessDisplaySizeChangeOrRotation(DisplayId defaultDisplayId, DisplayId displayId, const std::map& displayRectMap, DisplayStateChangeType type) { // modify RSTree and window tree of displayGroup for cross-display nodes - ProcessCrossNodes(type); + ProcessCrossNodes(defaultDisplayId, type); UpdateDisplayGroupWindowTree(); windowNodeContainer_->GetLayoutPolicy()->ProcessDisplaySizeChangeOrRotation(displayId, displayRectMap); } diff --git a/wmserver/src/window_controller.cpp b/wmserver/src/window_controller.cpp index 6768629581..bb9621404b 100644 --- a/wmserver/src/window_controller.cpp +++ b/wmserver/src/window_controller.cpp @@ -402,7 +402,8 @@ WMError WindowController::SetAlpha(uint32_t windowId, float dstAlpha) return WMError::WM_OK; } -void WindowController::NotifyDisplayStateChange(DisplayId displayId, DisplayStateChangeType type) +void WindowController::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { WLOGFD("DisplayStateChangeType:%{public}u", type); switch (type) { @@ -417,17 +418,17 @@ void WindowController::NotifyDisplayStateChange(DisplayId displayId, DisplayStat break; } case DisplayStateChangeType::CREATE: { - windowRoot_->ProcessDisplayCreate(displayId); + windowRoot_->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayInfoMap); break; } case DisplayStateChangeType::DESTROY: { - windowRoot_->ProcessDisplayDestroy(displayId); + windowRoot_->ProcessDisplayDestroy(defaultDisplayId, displayInfo, displayInfoMap); break; } case DisplayStateChangeType::SIZE_CHANGE: case DisplayStateChangeType::UPDATE_ROTATION: case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: { - ProcessDisplayChange(displayId, type); + ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type); break; } default: { @@ -482,20 +483,21 @@ void WindowController::ProcessSystemBarChange(const sptr& displayIn } } -void WindowController::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type) +void WindowController::ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { - const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); if (displayInfo == nullptr) { - WLOGFE("get display failed displayId:%{public}" PRIu64 "", displayId); + WLOGFE("get display failed"); return; } + DisplayId displayId = displayInfo->GetDisplayId(); switch (type) { case DisplayStateChangeType::SIZE_CHANGE: case DisplayStateChangeType::UPDATE_ROTATION: ProcessSystemBarChange(displayInfo); [[fallthrough]]; case DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE: { - windowRoot_->ProcessDisplayChange(displayId, type); + windowRoot_->ProcessDisplayChange(defaultDisplayId, displayInfo, displayInfoMap, type); break; } default: { diff --git a/wmserver/src/window_manager_service.cpp b/wmserver/src/window_manager_service.cpp index 9326a2a363..fbc3c8425f 100644 --- a/wmserver/src/window_manager_service.cpp +++ b/wmserver/src/window_manager_service.cpp @@ -471,21 +471,24 @@ void WindowManagerService::OnWindowEvent(Event event, const sptr& } } -void WindowManagerService::NotifyDisplayStateChange(DisplayId id, DisplayStateChangeType type) +void WindowManagerService::NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { WM_SCOPED_TRACE("wms:NotifyDisplayStateChange(%u)", type); + DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId(); if (type == DisplayStateChangeType::FREEZE) { - freezeDisplayController_->FreezeDisplay(id); + freezeDisplayController_->FreezeDisplay(displayId); } else if (type == DisplayStateChangeType::UNFREEZE) { - freezeDisplayController_->UnfreezeDisplay(id); + freezeDisplayController_->UnfreezeDisplay(displayId); } else { - return windowController_->NotifyDisplayStateChange(id, type); + windowController_->NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); } } -void DisplayChangeListener::OnDisplayStateChange(DisplayId id, DisplayStateChangeType type) +void DisplayChangeListener::OnDisplayStateChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { - WindowManagerService::GetInstance().NotifyDisplayStateChange(id, type); + WindowManagerService::GetInstance().NotifyDisplayStateChange(defaultDisplayId, displayInfo, displayInfoMap, type); } void WindowManagerService::ProcessPointDown(uint32_t windowId, bool isStartDrag) diff --git a/wmserver/src/window_root.cpp b/wmserver/src/window_root.cpp index d3535a51f8..8c5bd5bd73 100644 --- a/wmserver/src/window_root.cpp +++ b/wmserver/src/window_root.cpp @@ -67,29 +67,34 @@ sptr WindowRoot::GetOrCreateWindowNodeContainer(DisplayId d { bool isRecordedDisplay; ScreenId displayGroupId = GetScreenGroupId(displayId, isRecordedDisplay); + sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter != windowNodeContainerMap_.end()) { // if container exist for screenGroup and display is not be recorded, process expand display if (!isRecordedDisplay) { - ProcessExpandDisplayCreate(displayId, displayGroupId); + // add displayId in displayId vector + displayIdMap_[displayGroupId].push_back(displayId); + auto displayRectMap = GetAllDisplayRectsByDMS(displayInfo); + DisplayId defaultDisplayId = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); + ProcessExpandDisplayCreate(defaultDisplayId, displayInfo, displayRectMap); } return iter->second; } // In case of have no container for default display, create container WLOGFE("Create container for current display, displayId: %{public}" PRIu64 "", displayId); - return CreateWindowNodeContainer(displayId); + return CreateWindowNodeContainer(displayInfo); } -sptr WindowRoot::CreateWindowNodeContainer(DisplayId displayId) +sptr WindowRoot::CreateWindowNodeContainer(sptr displayInfo) { - const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { - WLOGFE("get display failed or get invailed display info, displayId :%{public}" PRIu64 "", displayId); + WLOGFE("get display failed or get invailed display info"); return nullptr; } - ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + DisplayId displayId = displayInfo->GetDisplayId(); + ScreenId displayGroupId = displayInfo->GetScreenGroupId(); WLOGFI("create new container for display, width: %{public}d, height: %{public}d, " "displayGroupId:%{public}" PRIu64", displayId:%{public}" PRIu64"", displayInfo->GetWidth(), displayInfo->GetHeight(), displayGroupId, displayId); @@ -974,26 +979,23 @@ void WindowRoot::FocusFaultDetection() const } } -void WindowRoot::ProcessExpandDisplayCreate(DisplayId displayId, ScreenId displayGroupId) +void WindowRoot::ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, + std::map& displayRectMap) { - const sptr displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); - if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { - WLOGFE("get display failed or get invailed display info, displayId :%{public}" PRIu64 "", displayId); - return; - } - auto container = windowNodeContainerMap_[displayGroupId]; - if (container == nullptr) { - WLOGFE("window node container is nullptr, displayId :%{public}" PRIu64 "", displayId); - } - // add displayId in displayId vector - displayIdMap_[displayGroupId].push_back(displayId); - - WLOGFI("[Display Create] before add new display, displayId: %{public}" PRIu64"", displayId); - - auto displayRectMap = GetAllDisplayRects(displayIdMap_[displayGroupId]); - container->GetMutiDisplayController()->ProcessDisplayCreate(displayId, displayRectMap); + if (displayInfo == nullptr || !CheckDisplayInfo(displayInfo)) { + WLOGFE("get display failed or get invailed display info"); + return; + } + DisplayId displayId = displayInfo->GetDisplayId(); + ScreenId displayGroupId = displayInfo->GetScreenGroupId(); + auto container = windowNodeContainerMap_[displayGroupId]; + if (container == nullptr) { + WLOGFE("window node container is nullptr, displayId :%{public}" PRIu64 "", displayId); + } - WLOGFI("[Display Create] Container exist, add new display, displayId: %{public}" PRIu64"", displayId); + WLOGFI("[Display Create] before add new display, displayId: %{public}" PRIu64"", displayId); + container->GetMutiDisplayController()->ProcessDisplayCreate(defaultDisplayId, displayInfo, displayRectMap); + WLOGFI("[Display Create] Container exist, add new display, displayId: %{public}" PRIu64"", displayId); } std::map> WindowRoot::GetAllDisplayInfos(const std::vector& displayIdVec) @@ -1007,13 +1009,13 @@ std::map> WindowRoot::GetAllDisplayInfos(const std: return displayInfoMap; } -std::map WindowRoot::GetAllDisplayRects(const std::vector& displayIdVec) +std::map WindowRoot::GetAllDisplayRectsByDMS(sptr displayInfo) { std::map displayRectMap; - for (auto& displayId : displayIdVec) { - auto displayInfo = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); - Rect displayRect = { displayInfo->GetOffsetX(), displayInfo->GetOffsetY(), - displayInfo->GetWidth(), displayInfo->GetHeight() }; + + for (auto& displayId : displayIdMap_[displayInfo->GetScreenGroupId()]) { + auto info = DisplayManagerServiceInner::GetInstance().GetDisplayById(displayId); + Rect displayRect = { info->GetOffsetX(), info->GetOffsetY(), info->GetWidth(), info->GetHeight() }; displayRectMap.insert(std::make_pair(displayId, displayRect)); WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", @@ -1022,12 +1024,31 @@ std::map WindowRoot::GetAllDisplayRects(const std::vector WindowRoot::GetAllDisplayRectsByDisplayInfo( + const std::map>& displayInfoMap) { - ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + std::map displayRectMap; + + for (auto& iter : displayInfoMap) { + auto id = iter.first; + auto info = iter.second; + Rect displayRect = { info->GetOffsetX(), info->GetOffsetY(), info->GetWidth(), info->GetHeight() }; + displayRectMap.insert(std::make_pair(id, displayRect)); + + WLOGFI("displayId: %{public}" PRIu64", displayRect: [ %{public}d, %{public}d, %{public}d, %{public}d]", + id, displayRect.posX_, displayRect.posY_, displayRect.width_, displayRect.height_); + } + return displayRectMap; +} + +void WindowRoot::ProcessDisplayCreate(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap) +{ + DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId(); + ScreenId displayGroupId = (displayInfo == nullptr) ? SCREEN_ID_INVALID : displayInfo->GetScreenGroupId(); auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter == windowNodeContainerMap_.end()) { - CreateWindowNodeContainer(displayId); + CreateWindowNodeContainer(displayInfo); WLOGFI("[Display Create] Create new container for display, displayId: %{public}" PRIu64"", displayId); } else { auto& displayIdVec = displayIdMap_[displayGroupId]; @@ -1035,13 +1056,15 @@ void WindowRoot::ProcessDisplayCreate(DisplayId displayId) WLOGFI("[Display Create] Current display is already exist, displayId: %{public}" PRIu64"", displayId); return; } - ProcessExpandDisplayCreate(displayId, displayGroupId); + // add displayId in displayId vector + displayIdMap_[displayGroupId].push_back(displayId); + auto displayRectMap = GetAllDisplayRectsByDisplayInfo(displayInfoMap); + ProcessExpandDisplayCreate(defaultDisplayId, displayInfo, displayRectMap); } } -void WindowRoot::MoveNotShowingWindowToDefaultDisplay(DisplayId displayId) +void WindowRoot::MoveNotShowingWindowToDefaultDisplay(DisplayId defaultDisplayId, DisplayId displayId) { - DisplayId defaultDisplayId = DisplayManagerServiceInner::GetInstance().GetDefaultDisplayId(); for (auto& elem : windowNodeMap_) { auto& windowNode = elem.second; if (windowNode->GetDisplayId() == displayId && !windowNode->currentVisibility_) { @@ -1056,13 +1079,17 @@ void WindowRoot::MoveNotShowingWindowToDefaultDisplay(DisplayId displayId) } } -void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) +void WindowRoot::ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap) { - ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + DisplayId displayId = (displayInfo == nullptr) ? DISPLAY_ID_INVALID : displayInfo->GetDisplayId(); + ScreenId displayGroupId = (displayInfo == nullptr) ? SCREEN_ID_INVALID : displayInfo->GetScreenGroupId(); auto& displayIdVec = displayIdMap_[displayGroupId]; + auto iter = windowNodeContainerMap_.find(displayGroupId); - if (iter == windowNodeContainerMap_.end() || std::find(displayIdVec.begin(), - displayIdVec.end(), displayId) == displayIdVec.end()) { + if (iter == windowNodeContainerMap_.end() || + std::find(displayIdVec.begin(), displayIdVec.end(), displayId) == displayIdVec.end() || + displayInfoMap.find(displayId) == displayInfoMap.end()) { WLOGFE("[Display Destroy] could not find display, destroy failed, displayId: %{public}" PRIu64"", displayId); return; } @@ -1080,8 +1107,12 @@ void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) WLOGFI("[Display Destroy] displayId: %{public}" PRIu64"", displayId); std::vector needDestoryWindows; - auto displayRectMap = GetAllDisplayRects(displayIdVec); - container->GetMutiDisplayController()->ProcessDisplayDestroy(displayId, displayRectMap, needDestoryWindows); + auto displayRectMap = GetAllDisplayRectsByDisplayInfo(displayInfoMap); + // erase displayId in displayRectMap + auto displayRectIter = displayRectMap.find(displayId); + displayRectMap.erase(displayRectIter); + container->GetMutiDisplayController()->ProcessDisplayDestroy( + defaultDisplayId, displayInfo, displayRectMap, needDestoryWindows); for (auto id : needDestoryWindows) { auto node = GetWindowNode(id); if (node != nullptr) { @@ -1089,13 +1120,19 @@ void WindowRoot::ProcessDisplayDestroy(DisplayId displayId) } } // move window which is not showing on destroied display to default display - MoveNotShowingWindowToDefaultDisplay(displayId); + MoveNotShowingWindowToDefaultDisplay(defaultDisplayId, displayId); WLOGFI("[Display Destroy] displayId: %{public}" PRIu64" ", displayId); } -void WindowRoot::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeType type) +void WindowRoot::ProcessDisplayChange(DisplayId defaultDisplayId, sptr displayInfo, + const std::map>& displayInfoMap, DisplayStateChangeType type) { - ScreenId displayGroupId = DisplayManagerServiceInner::GetInstance().GetScreenGroupIdByDisplayId(displayId); + if (displayInfo == nullptr) { + WLOGFE("get display failed"); + return; + } + DisplayId displayId = displayInfo->GetDisplayId(); + ScreenId displayGroupId = displayInfo->GetScreenGroupId(); auto& displayIdVec = displayIdMap_[displayGroupId]; auto iter = windowNodeContainerMap_.find(displayGroupId); if (iter == windowNodeContainerMap_.end() || std::find(displayIdVec.begin(), @@ -1110,8 +1147,8 @@ void WindowRoot::ProcessDisplayChange(DisplayId displayId, DisplayStateChangeTyp return; } - auto displayRectMap = GetAllDisplayRects(displayIdVec); - container->GetMutiDisplayController()->ProcessDisplayChange(displayId, displayRectMap, type); + auto displayRectMap = GetAllDisplayRectsByDisplayInfo(displayInfoMap); + container->GetMutiDisplayController()->ProcessDisplayChange(defaultDisplayId, displayInfo, displayRectMap, type); } float WindowRoot::GetVirtualPixelRatio(DisplayId displayId) const -- Gitee