From dade459fe33c501cb2e53c3ec739691da100a4c5 Mon Sep 17 00:00:00 2001 From: MirMort Date: Tue, 26 Aug 2025 14:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9SetOrientation=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MirMort --- .../src/screen_session_manager.cpp | 5 +- .../session/screen/include/screen_session.h | 1 + .../session/screen/src/screen_session.cpp | 29 +++-- .../screen_session_manager_test2.cpp | 16 ++- .../test/dms_unittest/screen_session_test.cpp | 106 +++++------------- 5 files changed, 66 insertions(+), 91 deletions(-) diff --git a/window_scene/screen_session_manager/src/screen_session_manager.cpp b/window_scene/screen_session_manager/src/screen_session_manager.cpp index 4e1c16aee8..f915ab66e9 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -11505,7 +11505,7 @@ Rotation ScreenSessionManager::RemoveRotationCorrection(Rotation rotation) Rotation ScreenSessionManager::GetConfigCorrectionByDisplayMode(FoldDisplayMode displayMode) { if (!CORRECTION_ENABLE) { - return Rotation::ROTATION_0; + return Rotation::ROTATION_0; } InitRotationCorrectionMap(DISPLAYMODE_CORRECTION); std::shared_lock lock(rotationCorrectionMutex_); @@ -11519,6 +11519,9 @@ Rotation ScreenSessionManager::GetConfigCorrectionByDisplayMode(FoldDisplayMode void ScreenSessionManager::InitRotationCorrectionMap(std::string displayModeCorrectionConfig) { + if (!CORRECTION_ENABLE) { + return; + } if (!rotationCorrectionMap_.empty()) { return; } diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index dbb4b80795..de8bf49dba 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -388,6 +388,7 @@ public: void UpdateMirrorHeight(uint32_t mirrorHeight); private: + bool IsVertical(Rotation rotation) const; ScreenProperty property_; mutable std::mutex propertyMutex_; // above guarded by clientProxyMutex_ std::shared_ptr displayNode_; diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 4f04d8d8da..8dd4b21834 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -1317,16 +1317,16 @@ void ScreenSession::SetScreenType(ScreenType type) Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode foldDisplayMode) const { - sptr info = GetActiveScreenMode(); - if (info == nullptr) { - return Rotation::ROTATION_0; - } - // vertical: phone(Plugin screen); horizontal: pad & external screen - bool isVerticalScreen = info->width_ < info->height_; - if (foldDisplayMode != FoldDisplayMode::UNKNOWN && - (g_screenRotationOffSet == ROTATION_90 || g_screenRotationOffSet == ROTATION_270)) { - isVerticalScreen = info->width_ > info->height_; - } + // Calculate the width and height based on the 0-degree rotation direction, and set the orientation + Rotation deviceRotation = property_.GetDeviceRotation(); + auto bounds = property_.GetBounds(); + uint32_t width = bounds.rect_.GetWidth(); + uint32_t height = bounds.rect_.GetHeight(); + if (!IsVertical(deviceRotation)) { + width = bounds.rect_.GetHeight(); + height = bounds.rect_.GetWidth(); + } + bool isVerticalScreen = width < height; switch (orientation) { case Orientation::UNSPECIFIED: { return Rotation::ROTATION_0; @@ -1335,13 +1335,13 @@ Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode fo return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90; } case Orientation::HORIZONTAL: { - return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0; + return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_180; } case Orientation::REVERSE_VERTICAL: { return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270; } case Orientation::REVERSE_HORIZONTAL: { - return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180; + return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_0; } default: { TLOGE(WmsLogTag::DMS, "unknown orientation %{public}u", orientation); @@ -1350,6 +1350,11 @@ Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode fo } } +bool ScreenSession::IsVertical(Rotation rotation) const +{ + return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); +} + DisplayOrientation ScreenSession::CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) { diff --git a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp index d92a8d0d65..73e3ba2af7 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_test2.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_test2.cpp @@ -1703,8 +1703,7 @@ HWTEST_F(ScreenSessionManagerTest, RemoveRotationCorrection, TestSize.Level1) HWTEST_F(ScreenSessionManagerTest, GetConfigCorrectionByDisplayMode, TestSize.Level1) { ssm_->rotationCorrectionMap_.clear(); - bool correctionEnable = system::GetIntParameter("const.system.sensor_correction_enable", 0) == 1; - if (correctionEnable) { + if (CORRECTION_ENABLE) { auto rotation = ssm_->GetConfigCorrectionByDisplayMode(FoldDisplayMode::MAIN); EXPECT_EQ(rotation, Rotation::ROTATION_0); std::unordered_map rotationCorrectionMap; @@ -1727,13 +1726,18 @@ HWTEST_F(ScreenSessionManagerTest, GetConfigCorrectionByDisplayMode, TestSize.Le HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap01, TestSize.Level1) { ssm_->rotationCorrectionMap_.clear(); + std::string config = "1,0;2,0;5,3;"; + if (!CORRECTION_ENABLE) { + ssm_->InitRotationCorrectionMap(config); + EXPECT_EQ(ssm_->rotationCorrectionMap_.size(), 0); + GTEST_SKIP(); + } std::unordered_map rotationCorrectionMap; rotationCorrectionMap.insert({FoldDisplayMode::MAIN, 3}); ssm_->rotationCorrectionMap_ = rotationCorrectionMap; ssm_->InitRotationCorrectionMap(""); EXPECT_TRUE(ssm_->rotationCorrectionMap_.find(FoldDisplayMode::MAIN) != ssm_->rotationCorrectionMap_.end()); ssm_->rotationCorrectionMap_.clear(); - std::string config = "1,0;2,0;5,3;"; ssm_->InitRotationCorrectionMap(config); EXPECT_EQ(ssm_->rotationCorrectionMap_[FoldDisplayMode::GLOBAL_FULL], 3); } @@ -1745,6 +1749,9 @@ HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap01, TestSize.Level1) */ HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap02, TestSize.Level1) { + if (!CORRECTION_ENABLE) { + GTEST_SKIP(); + } ssm_->rotationCorrectionMap_.clear(); ssm_->InitRotationCorrectionMap(""); EXPECT_TRUE(ssm_->rotationCorrectionMap_.empty()); @@ -1761,6 +1768,9 @@ HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap02, TestSize.Level1) */ HWTEST_F(ScreenSessionManagerTest, InitRotationCorrectionMap03, TestSize.Level1) { + if (!CORRECTION_ENABLE) { + GTEST_SKIP(); + } ssm_->rotationCorrectionMap_.clear(); std::string config = "1,0,1;1,0;2,0;5,3;3,a;a,a"; ssm_->InitRotationCorrectionMap(config); diff --git a/window_scene/test/dms_unittest/screen_session_test.cpp b/window_scene/test/dms_unittest/screen_session_test.cpp index 545d230bc2..bd958ec087 100644 --- a/window_scene/test/dms_unittest/screen_session_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_test.cpp @@ -2228,115 +2228,71 @@ HWTEST_F(ScreenSessionTest, GetRSScreenId, TestSize.Level1) } /** - * @tc.name: CalcRotation01 + * @tc.name: CalcRotation * @tc.desc: normal function * @tc.type: FUNC */ -HWTEST_F(ScreenSessionTest, CalcRotation01, TestSize.Level1) +HWTEST_F(ScreenSessionTest, CalcRotation, TestSize.Level1) { - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start"; - Orientation orientation { Orientation::BEGIN }; - FoldDisplayMode foldDisplayMode { FoldDisplayMode::COORDINATION }; sptr session = sptr::MakeSptr(); - session->activeIdx_ = -1; + ScreenProperty property; + RRect bounds; + bounds.rect_.width_ = 1344; + bounds.rect_.height_ = 2772; + property.SetBounds(bounds); + property.UpdateDeviceRotation(Rotation::ROTATION_0); + session->SetScreenProperty(property); + Orientation orientation = Orientation::BEGIN; + FoldDisplayMode foldDisplayMode = FoldDisplayMode::UNKNOWN; auto res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - - sptr supportedScreenModes = new SupportedScreenModes; - supportedScreenModes->width_ = 40; - supportedScreenModes->height_ = 20; - session->modes_ = { supportedScreenModes }; - session->activeIdx_ = 0; - orientation = Orientation::UNSPECIFIED; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - orientation = Orientation::VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_0, res); - } else { - EXPECT_EQ(Rotation::ROTATION_90, res); - } - + EXPECT_EQ(Rotation::ROTATION_0, res); orientation = Orientation::HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_90, res); - } else { - EXPECT_EQ(Rotation::ROTATION_0, res); - } - + EXPECT_EQ(Rotation::ROTATION_90, res); orientation = Orientation::REVERSE_VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_180, res); - } else { - EXPECT_EQ(Rotation::ROTATION_270, res); - } - + EXPECT_EQ(Rotation::ROTATION_180, res); orientation = Orientation::REVERSE_HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_270, res); - } else { - EXPECT_EQ(Rotation::ROTATION_180, res); - } - + EXPECT_EQ(Rotation::ROTATION_270, res); orientation = Orientation::LOCKED; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end"; -} - -/** - * @tc.name: CalcRotation02 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(ScreenSessionTest, CalcRotation02, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start"; - Orientation orientation { Orientation::BEGIN }; - FoldDisplayMode foldDisplayMode { FoldDisplayMode::UNKNOWN }; - sptr session = sptr::MakeSptr(); - session->activeIdx_ = -1; - auto res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - - sptr supportedScreenModes = new SupportedScreenModes; - supportedScreenModes->width_ = 40; - supportedScreenModes->height_ = 20; - session->modes_ = { supportedScreenModes }; - session->activeIdx_ = 0; - - orientation = Orientation::UNSPECIFIED; - res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - + property.UpdateDeviceRotation(Rotation::ROTATION_90); + session->SetScreenProperty(property); orientation = Orientation::VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_90, res); - orientation = Orientation::HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - + EXPECT_EQ(Rotation::ROTATION_180, res); orientation = Orientation::REVERSE_VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_270, res); - orientation = Orientation::REVERSE_HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_180, res); - - orientation = Orientation::LOCKED; - res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); +} - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end"; +/** + * @tc.name: IsVertical + * @tc.desc: IsVertical + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, IsVertical, TestSize.Level1) +{ + sptr session = sptr::MakeSptr(); + EXPECT_TRUE(session->IsVertical(Rotation::ROTATION_0)); + EXPECT_FALSE(session->IsVertical(Rotation::ROTATION_90)); + EXPECT_TRUE(session->IsVertical(Rotation::ROTATION_180)); + EXPECT_FALSE(session->IsVertical(Rotation::ROTATION_270)); } /** -- Gitee