From 1e0bca3020494ebd29a7ca5460cc481b09cf172e Mon Sep 17 00:00:00 2001 From: MirMort Date: Wed, 10 Sep 2025 14:42:24 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9orientation=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MirMort --- .../src/screen_aod_plugin.cpp | 5 + .../src/screen_sensor_plugin.cpp | 5 + .../src/screen_session_manager.cpp | 2 +- .../session/screen/include/screen_session.h | 2 + .../session/screen/src/screen_session.cpp | 58 ++++++-- .../test/dms_unittest/screen_session_test.cpp | 128 ++++++++---------- 6 files changed, 111 insertions(+), 89 deletions(-) diff --git a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp index 26c1e83461..57346a3f21 100644 --- a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp @@ -31,9 +31,14 @@ bool LoadAodLib(void) } int32_t cnt = 0; int32_t retryTimes = 3; + const cahr* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_AOD_SO_PATH.c_str(), RTLD_LAZY); + dlopenError = dlerror(); + if (dlopenError) { + TlogE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_AOD_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); } while (!g_handle && cnt < retryTimes); diff --git a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp index 2a5d33b0c9..28631ab7ec 100644 --- a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp @@ -31,9 +31,14 @@ bool LoadMotionSensor(void) } int32_t cnt = 0; int32_t retryTimes = 3; + const cahr* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_SO_PATH.c_str(), RTLD_LAZY); + dlopenError = dlerror(); + if (dlopenError) { + TlogE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); } while (!g_handle && cnt < retryTimes); 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 693884c894..7bdfa57ee8 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -11843,7 +11843,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_); diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index dbb4b80795..eeb58bc24c 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -388,6 +388,8 @@ public: void UpdateMirrorHeight(uint32_t mirrorHeight); private: + bool isVertical(Rotation rotation) const; + Orientation CalcDisplayOrientationToOrientation(DisplayOrientation displayOrientation) 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 6873db100d..8acee96ce2 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) { @@ -1581,7 +1586,7 @@ void ScreenSession::FillScreenInfo(sptr info) const info->SetVirtualHeight(height / virtualPixelRatio); info->SetVirtualWidth(width / virtualPixelRatio); info->SetRotation(property_.GetScreenRotation()); - info->SetOrientation(static_cast(property_.GetDisplayOrientation())); + info->SetOrientation(CalcDisplayOrientationToOrientation(property_.GetDisplayOrientation())); info->SetSourceMode(sourceMode); info->SetType(property_.GetScreenType()); info->SetModeId(activeIdx_); @@ -1595,6 +1600,33 @@ void ScreenSession::FillScreenInfo(sptr info) const info->modes_ = modes_; } +Orientation ScreenSession::CalcDisplayOrientationToOrientation(DisplayOrientation displayOrientation) const +{ + Orientation orientation = Orientation::UNSPECIFIED; + switch (displayOrientation) { + case DisplayOrientation::PORTRAIT: { + orientation = Orientation::VERTICAL; + break; + } + case DisplayOrientation::LANDSCAPE: { + orientation = Orientation::HORIZONTAL; + break; + } + case DisplayOrientation::PORTRAIT_INVERTED: { + orientation = Orientation::REVERSE_VERTICAL; + break; + } + case DisplayOrientation::LANDSCAPE_INVERTED: { + orientation = Orientation::REVERSE_HORIZONTAL; + break; + } + default: { + TLOGE(WmsLogTag::DMS, "unknown displayOrientation %{public}d", displayOrientation); + } + } + return orientation; +} + sptr ScreenSession::ConvertToScreenInfo() const { sptr info = new(std::nothrow) ScreenInfo(); diff --git a/window_scene/test/dms_unittest/screen_session_test.cpp b/window_scene/test/dms_unittest/screen_session_test.cpp index 545d230bc2..7ff4d543d4 100644 --- a/window_scene/test/dms_unittest/screen_session_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_test.cpp @@ -2228,115 +2228,93 @@ 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)); +} + +/** + * @tc.name: CalcDisplayOrientationToOrientation + * @tc.desc: CalcDisplayOrientationToOrientation Test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, CalcDisplayOrientationToOrientation, TestSize.Level2) +{ + ScreenId screenId = 0; + ScreenProperty screenProperty; + sptr screenSession = sptr::MakeSptr(screenId, screenProperty, screenId); + Orientation orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::UNKNOWN); + EXPECT_EQ(orientation, Orientation::UNSPECIFIED); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::PORTRAIT); + EXPECT_EQ(orientation, Orientation::VERTICAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::LANDSCAPE); + EXPECT_EQ(orientation, Orientation::HORIZONTAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::PORTRAIT_INVERTED); + EXPECT_EQ(orientation, Orientation::REVERSE_VERTICAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::LANDSCAPE_INVERTED); + EXPECT_EQ(orientation, Orientation::REVERSE_HORIZONTAL); } /** -- Gitee From 601603ab8746582f18551c7661951d03ab43350a Mon Sep 17 00:00:00 2001 From: MirMort Date: Wed, 10 Sep 2025 15:15:23 +0800 Subject: [PATCH 2/4] add Signed-off-by: MirMort --- window_scene/screen_session_manager/src/screen_aod_plugin.cpp | 2 +- .../screen_session_manager/src/screen_sensor_plugin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp index 57346a3f21..e336ab2d28 100644 --- a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp @@ -31,7 +31,7 @@ bool LoadAodLib(void) } int32_t cnt = 0; int32_t retryTimes = 3; - const cahr* dlopenError; + const char* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_AOD_SO_PATH.c_str(), RTLD_LAZY); diff --git a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp index 28631ab7ec..f250c5f2ec 100644 --- a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp @@ -31,7 +31,7 @@ bool LoadMotionSensor(void) } int32_t cnt = 0; int32_t retryTimes = 3; - const cahr* dlopenError; + const char* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_SO_PATH.c_str(), RTLD_LAZY); -- Gitee From 66ea7898d83ef4be3f42d85c695eb7567d41db58 Mon Sep 17 00:00:00 2001 From: MirMort Date: Wed, 10 Sep 2025 15:17:09 +0800 Subject: [PATCH 3/4] add Signed-off-by: MirMort --- window_scene/session/screen/include/screen_session.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index eeb58bc24c..5ab1768dd6 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -388,7 +388,7 @@ public: void UpdateMirrorHeight(uint32_t mirrorHeight); private: - bool isVertical(Rotation rotation) const; + bool IsVertical(Rotation rotation) const; Orientation CalcDisplayOrientationToOrientation(DisplayOrientation displayOrientation) const; ScreenProperty property_; mutable std::mutex propertyMutex_; // above guarded by clientProxyMutex_ -- Gitee From e8f6aee70d9e5fe4864c1934fd81599755cfcd4f Mon Sep 17 00:00:00 2001 From: MirMort Date: Wed, 10 Sep 2025 15:40:46 +0800 Subject: [PATCH 4/4] add Signed-off-by: MirMort --- window_scene/screen_session_manager/src/screen_aod_plugin.cpp | 2 +- .../screen_session_manager/src/screen_sensor_plugin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp index e336ab2d28..d9a46b7a2c 100644 --- a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp @@ -37,7 +37,7 @@ bool LoadAodLib(void) g_handle = dlopen(PLUGIN_AOD_SO_PATH.c_str(), RTLD_LAZY); dlopenError = dlerror(); if (dlopenError) { - TlogE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + TLOGE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_AOD_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); diff --git a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp index f250c5f2ec..489fcb89be 100644 --- a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp @@ -37,7 +37,7 @@ bool LoadMotionSensor(void) g_handle = dlopen(PLUGIN_SO_PATH.c_str(), RTLD_LAZY); dlopenError = dlerror(); if (dlopenError) { - TlogE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + TLOGE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); -- Gitee