From 98e297a1ac0f47156868592cbe8930bce44f4060 Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Sat, 22 Jan 2022 21:32:26 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"!132=20=E9=9A=90=E8=97=8FDisplay?= =?UTF-8?q?=E5=AF=B9=E5=A4=96=E6=8E=A5=E5=8F=A3=E7=B1=BB=E7=9A=84=E5=86=85?= =?UTF-8?q?=E9=83=A8=E5=AE=9E=E7=8E=B0"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 215e0de38cc0965fb5348b6cb66011449f761912, reversing changes made to 9cf85ebd355489de56b644efe966ec2a130321df. Signed-off-by: jiangdayuan Change-Id: I89bd9517570bf7c8afd33a51e854cf5af2c3135d --- dm/src/display.cpp | 37 ++--- dm/src/display_manager.cpp | 164 ++++++++++------------ interfaces/innerkits/dm/display.h | 7 +- interfaces/innerkits/dm/display_manager.h | 19 ++- 4 files changed, 104 insertions(+), 123 deletions(-) diff --git a/dm/src/display.cpp b/dm/src/display.cpp index 20ecf8b6d0..9f9866ec6d 100644 --- a/dm/src/display.cpp +++ b/dm/src/display.cpp @@ -17,59 +17,48 @@ #include "display_info.h" namespace OHOS::Rosen { -class Display::Impl : public RefBase { -friend class Display; -private: - std::string name_; - DisplayId id_ { DISPLAY_ID_INVALD }; - int32_t width_ { 0 }; - int32_t height_ { 0 }; - uint32_t freshRate_ { 0 }; -}; - Display::Display(const std::string& name, DisplayInfo* info) - : pImpl_(new Impl()) + : name_(name), + id_(info->id_), + width_(info->width_), + height_(info->height_), + freshRate_(info->freshRate_) { - pImpl_->name_ = name; - pImpl_->id_ = info->id_; - pImpl_->width_ = info->width_; - pImpl_->height_ = info->height_; - pImpl_->freshRate_ = info->freshRate_; } DisplayId Display::GetId() const { - return pImpl_->id_; + return id_; } int32_t Display::GetWidth() const { - return pImpl_->width_; + return width_; } int32_t Display::GetHeight() const { - return pImpl_->height_; + return height_; } uint32_t Display::GetFreshRate() const { - return pImpl_->freshRate_; + return freshRate_; } void Display::SetWidth(int32_t width) { - pImpl_->width_ = width; + width_ = width; } void Display::SetHeight(int32_t height) { - pImpl_->height_ = height; + height_ = height; } void Display::SetFreshRate(uint32_t freshRate) { - pImpl_->freshRate_ = freshRate; + freshRate_ = freshRate; } float Display::GetVirtualPixelRatio() const @@ -84,6 +73,6 @@ float Display::GetVirtualPixelRatio() const void Display::SetId(DisplayId id) { - pImpl_->id_ = id; + 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 3a8551fb35..2a7f9fa9fa 100644 --- a/dm/src/display_manager.cpp +++ b/dm/src/display_manager.cpp @@ -30,65 +30,7 @@ namespace { } WM_IMPLEMENT_SINGLE_INSTANCE(DisplayManager) -class DisplayManager::Impl : public RefBase { -friend class DisplayManager; -private: - constexpr static int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K - std::recursive_mutex mutex_; - std::vector> powerEventListeners_; - sptr powerEventListenerAgent_; - sptr displayStateAgent_; - DisplayStateCallback displayStateCallback_; - - bool CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const; - bool CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const; - void ClearDisplayStateCallback(); -}; - -bool DisplayManager::Impl::CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const -{ - if (!((rect.left >= 0) and (rect.left < oriWidth) and (rect.top >= 0) and (rect.top < oriHeight))) { - WLOGFE("rect left or top invalid!"); - return false; - } - - if (!((rect.width > 0) and (rect.width <= (oriWidth - rect.left)) and - (rect.height > 0) and (rect.height <= (oriHeight - rect.top)))) { - if (!((rect.width == 0) and (rect.height == 0))) { - WLOGFE("rect height or width invalid!"); - return false; - } - } - return true; -} - -bool DisplayManager::Impl::CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const -{ - if (!((size.width > 0) and (size.height > 0))) { - if (!((size.width == 0) and (size.height == 0))) { - WLOGFE("width or height invalid!"); - return false; - } - } - - if ((size.width > MAX_RESOLUTION_SIZE_SCREENSHOT) or (size.height > MAX_RESOLUTION_SIZE_SCREENSHOT)) { - WLOGFE("width or height too big!"); - return false; - } - return true; -} - -void DisplayManager::Impl::ClearDisplayStateCallback() -{ - displayStateCallback_ = nullptr; - if (displayStateAgent_ != nullptr) { - SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, - DisplayManagerAgentType::DISPLAY_STATE_LISTENER); - displayStateAgent_ = nullptr; - } -} - -DisplayManager::DisplayManager() : pImpl_(new Impl()) +DisplayManager::DisplayManager() { } @@ -127,6 +69,39 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display return screenShot; } +bool DisplayManager::CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const +{ + if (!((rect.left >= 0) and (rect.left < oriWidth) and (rect.top >= 0) and (rect.top < oriHeight))) { + WLOGFE("CheckRectValid rect left top invalid!"); + return false; + } + + if (!((rect.width > 0) and (rect.width <= (oriWidth - rect.left)) and + (rect.height > 0) and (rect.height <= (oriHeight - rect.top)))) { + if (!((rect.width == 0) and (rect.height == 0))) { + WLOGFE("CheckRectValid rect height width invalid!"); + return false; + } + } + return true; +} + +bool DisplayManager::CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const +{ + if (!((size.width > 0) and (size.height > 0))) { + if (!((size.width == 0) and (size.height == 0))) { + WLOGFE("CheckSizeValid width height invalid!"); + return false; + } + } + + if ((size.width > MAX_RESOLUTION_SIZE_SCREENSHOT) or (size.height > MAX_RESOLUTION_SIZE_SCREENSHOT)) { + WLOGFE("CheckSizeValid width and height too big!"); + return false; + } + return true; +} + std::shared_ptr DisplayManager::GetScreenshot(DisplayId displayId, const Media::Rect &rect, const Media::Size &size, int rotation) { @@ -145,12 +120,12 @@ std::shared_ptr DisplayManager::GetScreenshot(DisplayId display // check parameters int32_t oriHeight = screenShot->GetHeight(); int32_t oriWidth = screenShot->GetWidth(); - if (!pImpl_->CheckRectValid(rect, oriHeight, oriWidth)) { + if (!CheckRectValid(rect, oriHeight, oriWidth)) { WLOGFE("rect invalid! left %{public}d, top %{public}d, w %{public}d, h %{public}d", rect.left, rect.top, rect.width, rect.height); return nullptr; } - if (!pImpl_->CheckSizeValid(size, oriHeight, oriWidth)) { + if (!CheckSizeValid(size, oriHeight, oriWidth)) { WLOGFE("size invalid! w %{public}d, h %{public}d", rect.width, rect.height); return nullptr; } @@ -205,17 +180,16 @@ bool DisplayManager::RegisterDisplayPowerEventListener(sptr lock(pImpl_->mutex_); - pImpl_->powerEventListeners_.push_back(listener); + std::lock_guard lock(mutex_); + powerEventListeners_.push_back(listener); bool ret = true; - if (pImpl_->powerEventListenerAgent_ == nullptr) { - pImpl_->powerEventListenerAgent_ = new DisplayManagerAgent(); - ret = SingletonContainer::Get().RegisterDisplayManagerAgent( - pImpl_->powerEventListenerAgent_, + if (powerEventListenerAgent_ == nullptr) { + powerEventListenerAgent_ = new DisplayManagerAgent(); + ret = SingletonContainer::Get().RegisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); if (!ret) { WLOGFW("RegisterDisplayManagerAgent failed ! remove listener!"); - pImpl_->powerEventListeners_.pop_back(); + powerEventListeners_.pop_back(); } } WLOGFI("RegisterDisplayPowerEventListener end"); @@ -229,19 +203,18 @@ bool DisplayManager::UnregisterDisplayPowerEventListener(sptr lock(pImpl_->mutex_); - auto iter = std::find(pImpl_->powerEventListeners_.begin(), pImpl_->powerEventListeners_.end(), listener); - if (iter == pImpl_->powerEventListeners_.end()) { + std::lock_guard lock(mutex_); + auto iter = std::find(powerEventListeners_.begin(), powerEventListeners_.end(), listener); + if (iter == powerEventListeners_.end()) { WLOGFE("could not find this listener"); return false; } - pImpl_->powerEventListeners_.erase(iter); + powerEventListeners_.erase(iter); bool ret = true; - if (pImpl_->powerEventListeners_.empty() && pImpl_->powerEventListenerAgent_ != nullptr) { - ret = SingletonContainer::Get().UnregisterDisplayManagerAgent( - pImpl_->powerEventListenerAgent_, + if (powerEventListeners_.empty() && powerEventListenerAgent_ != nullptr) { + ret = SingletonContainer::Get().UnregisterDisplayManagerAgent(powerEventListenerAgent_, DisplayManagerAgentType::DISPLAY_POWER_EVENT_LISTENER); - pImpl_->powerEventListenerAgent_ = nullptr; + powerEventListenerAgent_ = nullptr; } WLOGFI("UnregisterDisplayPowerEventListener end"); return ret; @@ -250,9 +223,9 @@ bool DisplayManager::UnregisterDisplayPowerEventListener(sptrpowerEventListeners_.size()); - std::lock_guard lock(pImpl_->mutex_); - for (auto& listener : pImpl_->powerEventListeners_) { + powerEventListeners_.size()); + std::lock_guard lock(mutex_); + for (auto& listener : powerEventListeners_) { listener->OnDisplayPowerEvent(event, status); } } @@ -260,16 +233,26 @@ void DisplayManager::NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatu void DisplayManager::NotifyDisplayStateChanged(DisplayState state) { WLOGFI("state:%{public}u", state); - std::lock_guard lock(pImpl_->mutex_); - if (pImpl_->displayStateCallback_) { - pImpl_->displayStateCallback_(state); + std::lock_guard lock(mutex_); + if (displayStateCallback_) { + displayStateCallback_(state); WLOGFW("displayStateCallback_ end"); - pImpl_->ClearDisplayStateCallback(); + ClearDisplayStateCallback(); return; } WLOGFW("callback_ target is not set!"); } +void DisplayManager::ClearDisplayStateCallback() +{ + displayStateCallback_ = nullptr; + if (displayStateAgent_ != nullptr) { + SingletonContainer::Get().UnregisterDisplayManagerAgent(displayStateAgent_, + DisplayManagerAgentType::DISPLAY_STATE_LISTENER); + displayStateAgent_ = nullptr; + } +} + bool DisplayManager::WakeUpBegin(PowerStateChangeReason reason) { return SingletonContainer::Get().WakeUpBegin(reason); @@ -330,23 +313,22 @@ DisplayPowerState DisplayManager::GetScreenPower(uint64_t screenId) bool DisplayManager::SetDisplayState(DisplayState state, DisplayStateCallback callback) { WLOGFI("state:%{public}u", state); - std::lock_guard lock(pImpl_->mutex_); - if (pImpl_->displayStateCallback_ != nullptr || callback == nullptr) { + std::lock_guard lock(mutex_); + if (displayStateCallback_ != nullptr || callback == nullptr) { WLOGFI("previous callback not called or callback invalid"); return false; } - pImpl_->displayStateCallback_ = callback; + displayStateCallback_ = callback; bool ret = true; - if (pImpl_->displayStateAgent_ == nullptr) { - pImpl_->displayStateAgent_ = new DisplayManagerAgent(); - ret = SingletonContainer::Get().RegisterDisplayManagerAgent( - pImpl_->displayStateAgent_, + if (displayStateAgent_ == nullptr) { + displayStateAgent_ = new DisplayManagerAgent(); + ret = SingletonContainer::Get().RegisterDisplayManagerAgent(displayStateAgent_, DisplayManagerAgentType::DISPLAY_STATE_LISTENER); } ret &= SingletonContainer::Get().SetDisplayState(state); if (!ret) { - pImpl_->ClearDisplayStateCallback(); + ClearDisplayStateCallback(); } return ret; } diff --git a/interfaces/innerkits/dm/display.h b/interfaces/innerkits/dm/display.h index c4e09fd78a..f45d1e3fee 100644 --- a/interfaces/innerkits/dm/display.h +++ b/interfaces/innerkits/dm/display.h @@ -46,8 +46,11 @@ public: void SetFreshRate(uint32_t freshRate); private: - class Impl; - sptr pImpl_; + std::string name_; + DisplayId id_ {DISPLAY_ID_INVALD}; + int32_t width_ {0}; + int32_t height_ {0}; + uint32_t freshRate_ {0}; }; } // namespace OHOS::Rosen diff --git a/interfaces/innerkits/dm/display_manager.h b/interfaces/innerkits/dm/display_manager.h index 45aaaf1cea..e974b9c649 100644 --- a/interfaces/innerkits/dm/display_manager.h +++ b/interfaces/innerkits/dm/display_manager.h @@ -19,11 +19,11 @@ #include #include #include -#include #include "display.h" #include "dm_common.h" -#include "wm_single_instance.h" +#include "singleton_delegator.h" +// #include "wm_common.h" namespace OHOS::Rosen { class DisplayManagerAdapter; @@ -62,12 +62,19 @@ public: private: DisplayManager(); ~DisplayManager(); - - class Impl; - sptr pImpl_; - + bool CheckRectValid(const Media::Rect &rect, int32_t oriHeight, int32_t oriWidth) const; + bool CheckSizeValid(const Media::Size &size, int32_t oriHeight, int32_t oriWidth) const; void NotifyDisplayPowerEvent(DisplayPowerEvent event, EventStatus status); void NotifyDisplayStateChanged(DisplayState state); + void ClearDisplayStateCallback(); + + static inline SingletonDelegator delegator; + const int32_t MAX_RESOLUTION_SIZE_SCREENSHOT = 15360; // max resolution, 16K + std::recursive_mutex mutex_; + std::vector> powerEventListeners_; + sptr powerEventListenerAgent_; + sptr displayStateAgent_; + DisplayStateCallback displayStateCallback_; }; } // namespace OHOS::Rosen -- Gitee