From 3917edf204ec2ed11805744ccf8e619de40c63ce Mon Sep 17 00:00:00 2001 From: xiaojianfeng Date: Tue, 22 Feb 2022 10:32:26 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"modify=20screenInfo?= =?UTF-8?q?=EF=BC=8C=20screengroupinfo=EF=BC=8C=20displayInfo=EF=BC=8C=20s?= =?UTF-8?q?creen=EF=BC=8C=20screengroup=EF=BC=8C=20display""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaojianfeng Change-Id: I6fe2ae942f41c4f58888b1fe6d60abedc770557b --- dm/include/display_manager_adapter.h | 76 ++++---- dm/src/display.cpp | 90 ++++------ dm/src/display_manager.cpp | 12 +- dm/src/display_manager_adapter.cpp | 164 +++++++++++------- dm/src/screen.cpp | 133 ++++++-------- dm/src/screen_group.cpp | 40 +++-- dm/src/screen_manager.cpp | 28 +-- .../unittest/mock_display_manager_adapter.h | 34 +++- dm/test/unittest/screen_manager_test.cpp | 2 +- dm/test/unittest/screen_test.cpp | 2 +- dmserver/include/abstract_display.h | 4 +- dmserver/include/abstract_screen.h | 4 +- dmserver/include/display_manager_interface.h | 2 +- dmserver/include/display_manager_proxy.h | 2 +- dmserver/include/display_manager_service.h | 2 +- dmserver/src/abstract_display.cpp | 16 +- dmserver/src/abstract_screen.cpp | 4 +- dmserver/src/display_manager_proxy.cpp | 19 +- dmserver/src/display_manager_service.cpp | 15 +- .../src/display_manager_service_inner.cpp | 2 +- dmserver/src/display_manager_stub.cpp | 7 +- interfaces/innerkits/dm/display.h | 17 +- interfaces/innerkits/dm/screen.h | 10 +- interfaces/innerkits/dm/screen_group.h | 12 +- utils/include/class_var_defination.h | 59 +++++++ utils/include/display_info.h | 29 ++-- utils/include/screen_group_info.h | 19 +- utils/include/screen_info.h | 30 ++-- utils/src/display_info.cpp | 24 +-- utils/src/screen_group_info.cpp | 27 ++- utils/src/screen_info.cpp | 28 ++- wmserver/src/input_window_monitor.cpp | 2 +- 32 files changed, 496 insertions(+), 419 deletions(-) create mode 100644 utils/include/class_var_defination.h diff --git a/dm/include/display_manager_adapter.h b/dm/include/display_manager_adapter.h index aa129871b2..19fe9849a2 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 BaseAdapter { +public: + 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 { +class DisplayManagerAdapter : public BaseAdapter { 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 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 void UpdateDisplayInfo(DisplayId); +private: + sptr GetDisplayInfo(DisplayId displayId); + + static inline SingletonDelegator delegator; + + 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: - bool InitDMSProxyLocked(); + sptr GetScreenInfo(ScreenId screenId); - static inline SingletonDelegator delegator; + static inline SingletonDelegator delegator; - std::recursive_mutex mutex_; - sptr displayManagerServiceProxy_ = nullptr; - sptr dmsDeath_ = nullptr; - std::map> displayMap_; 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 faa6ebf744..2ec22f2249 100644 --- a/dm/src/display.cpp +++ b/dm/src/display.cpp @@ -16,89 +16,72 @@ #include "display.h" #include "display_info.h" #include "display_manager_adapter.h" +#include "window_manager_hilog.h" namespace OHOS::Rosen { +namespace { + constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "Display"}; +} class Display::Impl : public RefBase { -friend class Display; -private: - void UpdateDisplay(DisplayInfo& 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(DisplayInfo& info) +Display::Display(const std::string& name, sptr info) + : pImpl_(new Impl(name, info)) { - 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()) +Display::~Display() { - 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_; -} - -void Display::SetWidth(int32_t width) -{ - pImpl_->width_ = width; + SingletonContainer::Get().UpdateDisplayInfo(GetId()); + return pImpl_->GetDisplayInfo()->GetScreenId(); } -void Display::SetHeight(int32_t height) +void Display::UpdateDisplayInfo(sptr displayInfo) { - 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 @@ -110,9 +93,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 370f56c32d..bc113aa90e 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 80ad19ba5e..2e58f1d61c 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 d4a227b3df..ba7fd2606e 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 91e17a8d7d..9ac64d7b0b 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 abbbee9db0..b81e640e56 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 97dbef4911..46ee9bc5ce 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 d6da30be96..eeafc8b36b 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 2308699325..e6aebea09c 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 3b505006f3..79ba8b9c32 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 c89d392de7..cbf32a2a62 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 c4cb521bcd..9e9c40f696 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 0d30ce4c77..28d98a68d8 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 ee3dc6d9c8..356521ba46 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 e9ad85f94a..c425a631b5 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 fb124012b1..bddd68c8c2 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 180dc4a427..3dfc287a91 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 0e3c34e080..047dbfeece 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; - } - 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 nullptr; + } + 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 edaaa5cd4e..8c84b84ac3 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 2504aef448..824fddaf14 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 a71df54436..3d9ed5f9b0 100644 --- a/interfaces/innerkits/dm/display.h +++ b/interfaces/innerkits/dm/display.h @@ -27,10 +27,13 @@ typedef enum DisplayType { } DisplayType; class Display : public RefBase { +friend class DisplayManagerAdapter; public: - Display(const std::string& name, DisplayInfo* info); - ~Display() = default; - + ~Display(); + 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; @@ -38,12 +41,10 @@ public: 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); - +protected: + Display(const std::string& name, sptr info); private: + void UpdateDisplayInfo(sptr); class Impl; sptr pImpl_; }; diff --git a/interfaces/innerkits/dm/screen.h b/interfaces/innerkits/dm/screen.h index 8c71c4f98c..baf1d56d21 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 78377f88a8..bb879536e0 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/utils/include/class_var_defination.h b/utils/include/class_var_defination.h new file mode 100644 index 0000000000..27bce64eba --- /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 0aab10100d..d22d49e85f 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); +protected: + 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 6a9addbf8a..c1980182d2 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 c39fad9d23..618a67ce04 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/src/display_info.cpp b/utils/src/display_info.cpp index 0ff79f3179..ca03364380 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 56268c744b..ed4e41229d 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 a3df26fece..4e16e2a7ce 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/wmserver/src/input_window_monitor.cpp b/wmserver/src/input_window_monitor.cpp index f8ad19acad..393659c490 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; -- Gitee