From b287cbf734082a72e456e16fd55d609cda1870f2 Mon Sep 17 00:00:00 2001 From: pengxin Date: Thu, 28 Apr 2022 09:34:57 +0800 Subject: [PATCH] Resolve review comments' problems Signed-off-by: pengxin Change-Id: Ide86a0245cacfa727343400024ab4b734dc94a20 --- dm/src/screen.cpp | 3 ++- dm/test/systemtest/display_change_test.cpp | 3 --- .../include/abstract_display_controller.h | 2 +- dmserver/src/abstract_display_controller.cpp | 8 +++++-- wmserver/include/window_node_container.h | 4 ---- wmserver/src/window_node_container.cpp | 23 ++----------------- 6 files changed, 11 insertions(+), 32 deletions(-) diff --git a/dm/src/screen.cpp b/dm/src/screen.cpp index 8c5d1897d5..f3ca785ea0 100644 --- a/dm/src/screen.cpp +++ b/dm/src/screen.cpp @@ -198,7 +198,8 @@ bool Screen::SetDensityDpi(uint32_t dpi) const DOT_PER_INCH_MINIMIM_VALUE, DOT_PER_INCH_MAXIMUM_VALUE); return false; } - float density = float(dpi) / 160.0; // calculate display density + // Calculate display density, Density = Dpi / 160. + float density = static_cast(dpi) / 160; // 160 is the coefficient between density and dpi. return SingletonContainer::Get().SetVirtualPixelRatio(GetId(), density); } } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dm/test/systemtest/display_change_test.cpp b/dm/test/systemtest/display_change_test.cpp index 73dbfd8022..4f5379fb86 100644 --- a/dm/test/systemtest/display_change_test.cpp +++ b/dm/test/systemtest/display_change_test.cpp @@ -327,7 +327,6 @@ HWTEST_F(DisplayChangeTest, CheckDisplaySizeChange02, Function | MediumTest | Le */ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange01, Function | SmallTest | Level2) { - auto modes = defaultScreen_->GetSupportedModes(); uint32_t densityDpi = 320; ASSERT_EQ(true, defaultScreen_->SetDensityDpi(densityDpi)); sleep(SPLIT_TEST_SLEEP_S); @@ -340,7 +339,6 @@ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange01, Function | SmallTest | L */ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange02, Function | SmallTest | Level2) { - auto modes = defaultScreen_->GetSupportedModes(); uint32_t densityDpi = 80; ASSERT_EQ(true, defaultScreen_->SetDensityDpi(densityDpi)); sleep(SPLIT_TEST_SLEEP_S); @@ -353,7 +351,6 @@ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange02, Function | SmallTest | L */ HWTEST_F(DisplayChangeTest, CheckScreenDensityChange03, Function | SmallTest | Level2) { - auto modes = defaultScreen_->GetSupportedModes(); uint32_t densityDpi = 160; ASSERT_EQ(true, defaultScreen_->SetDensityDpi(densityDpi)); sleep(SPLIT_TEST_SLEEP_S); diff --git a/dmserver/include/abstract_display_controller.h b/dmserver/include/abstract_display_controller.h index 0ffaecea26..128169c931 100644 --- a/dmserver/include/abstract_display_controller.h +++ b/dmserver/include/abstract_display_controller.h @@ -53,7 +53,7 @@ private: void OnAbstractScreenChange(sptr absScreen, DisplayChangeEvent event); void ProcessDisplayUpdateOrientation(sptr absScreen); void ProcessDisplaySizeChange(sptr absScreen); - void ProcessDisplayDensityChange(sptr absScreen); + void ProcessVirtualPixelRatioChange(sptr absScreen); void BindAloneScreenLocked(sptr absScreen); void AddScreenToMirrorLocked(sptr absScreen); void AddScreenToExpandLocked(sptr absScreen); diff --git a/dmserver/src/abstract_display_controller.cpp b/dmserver/src/abstract_display_controller.cpp index edb3b3ae2e..a7c0d4af5c 100644 --- a/dmserver/src/abstract_display_controller.cpp +++ b/dmserver/src/abstract_display_controller.cpp @@ -248,7 +248,7 @@ void AbstractDisplayController::OnAbstractScreenChange(sptr absS } else if (event == DisplayChangeEvent::DISPLAY_SIZE_CHANGED) { ProcessDisplaySizeChange(absScreen); } else if (event == DisplayChangeEvent::DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED) { - ProcessDisplayDensityChange(absScreen); + ProcessVirtualPixelRatioChange(absScreen); } else { WLOGE("unknown screen change event. id:%{public}" PRIu64" event %{public}u", absScreen->dmsId_, event); } @@ -350,7 +350,7 @@ bool AbstractDisplayController::UpdateDisplaySize(sptr absDispl return true; } -void AbstractDisplayController::ProcessDisplayDensityChange(sptr absScreen) +void AbstractDisplayController::ProcessVirtualPixelRatioChange(sptr absScreen) { sptr abstractDisplay = nullptr; { @@ -365,6 +365,10 @@ void AbstractDisplayController::ProcessDisplayDensityChange(sptr } } } + if (abstractDisplay == nullptr) { + WLOGE("Failed to find abstract display of the screen."); + return; + } abstractDisplay->SetVirtualPixelRatio(absScreen->virtualPixelRatio_); // Notify virtual pixel ratio change event to WMS displayStateChangeListener_(abstractDisplay->GetId(), DisplayStateChangeType::VIRTUAL_PIXEL_RATIO_CHANGE); diff --git a/wmserver/include/window_node_container.h b/wmserver/include/window_node_container.h index 4cef712ddf..555bdbe739 100644 --- a/wmserver/include/window_node_container.h +++ b/wmserver/include/window_node_container.h @@ -89,8 +89,6 @@ public: void SetMinimizedByOther(bool isMinimizedByOther); void GetModeChangeHotZones(DisplayId displayId, ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); - void SetLastVirutalPixelRatio(DisplayId displayId, float virtualPixelRatio); - float GetLastVirtualPixelRatio(DisplayId displayId); void UpdateVirtualPixelRatio(DisplayId displayId, float virtualPixelRatio); private: @@ -143,8 +141,6 @@ private: uint32_t focusedWindow_ { INVALID_WINDOW_ID }; uint32_t activeWindow_ = INVALID_WINDOW_ID; - std::map lastVirtualPixelRatioMap_; - sptr avoidController_; sptr zorderPolicy_ = new WindowZorderPolicy(); std::unordered_map> layoutPolicys_; diff --git a/wmserver/src/window_node_container.cpp b/wmserver/src/window_node_container.cpp index 4a6b893b73..8e50f29a61 100644 --- a/wmserver/src/window_node_container.cpp +++ b/wmserver/src/window_node_container.cpp @@ -1593,30 +1593,11 @@ void WindowNodeContainer::GetModeChangeHotZones(DisplayId displayId, ModeChangeH hotZones.secondary_.height_ = displayRect.height_; } -void WindowNodeContainer::SetLastVirutalPixelRatio(DisplayId displayId, float virtualPixelRatio) -{ - lastVirtualPixelRatioMap_[displayId] = virtualPixelRatio; -} - -float WindowNodeContainer::GetLastVirtualPixelRatio(DisplayId displayId) -{ - if (lastVirtualPixelRatioMap_.find(displayId) == lastVirtualPixelRatioMap_.end()) { - WLOGE("cannot find last virtual pixel ratio for display: %{public}" PRIu64"", displayId); - return -1; - } - return lastVirtualPixelRatioMap_[displayId]; -} - void WindowNodeContainer::UpdateVirtualPixelRatio(DisplayId displayId, float virtualPixelRatio) { - if (fabs(GetLastVirtualPixelRatio(displayId) - virtualPixelRatio) > 1e-6) { - layoutPolicy_->SetVirtualPixelRatioChangedFlag(true); - SetLastVirutalPixelRatio(displayId, virtualPixelRatio); - } + layoutPolicy_->SetVirtualPixelRatioChangedFlag(true); layoutPolicy_->LayoutWindowTree(displayId); - if (layoutPolicy_->GetVirtualPixelRatioChangedFlag()) { - layoutPolicy_->SetVirtualPixelRatioChangedFlag(false); - } + layoutPolicy_->SetVirtualPixelRatioChangedFlag(false); } } // namespace Rosen } // namespace OHOS