From 8f40eaabfa83ebbe426ebe749ed8b7f701092a87 Mon Sep 17 00:00:00 2001 From: wangjiaqi Date: Sat, 13 Sep 2025 11:28:26 +0800 Subject: [PATCH 1/2] pageRotation xts fixed Signed-off-by: wangjiaqi --- .../session/host/include/scene_session.h | 1 + .../session/host/src/scene_session.cpp | 26 ++++++++++- .../test/unittest/scene_session_test5.cpp | 45 +++++++++++++++++++ wm/src/window_scene_session_impl.cpp | 5 +-- 4 files changed, 72 insertions(+), 5 deletions(-) diff --git a/window_scene/session/host/include/scene_session.h b/window_scene/session/host/include/scene_session.h index 9d327a9443..b7a08c1330 100644 --- a/window_scene/session/host/include/scene_session.h +++ b/window_scene/session/host/include/scene_session.h @@ -573,6 +573,7 @@ public: */ void RegisterRequestedOrientationChangeCallback(NotifyReqOrientationChangeFunc&& callback); WSError NotifyRotationProperty(uint32_t rotation, uint32_t width, uint32_t height); + WSError ConvertRotationToOrientation(uint32_t rotation, uint32_t& orientation); void RegisterUpdateRotationChangeListener(NotifyRotationChangeFunc&& callback); WSError UpdateRotationChangeRegistered(int32_t persistentId, bool isRegister) override; RotationChangeResult NotifyRotationChange(const RotationChangeInfo& rotationChangeInfo, diff --git a/window_scene/session/host/src/scene_session.cpp b/window_scene/session/host/src/scene_session.cpp index 932968ca90..390d98570b 100644 --- a/window_scene/session/host/src/scene_session.cpp +++ b/window_scene/session/host/src/scene_session.cpp @@ -8599,19 +8599,41 @@ WSError SceneSession::NotifyRotationProperty(uint32_t rotation, uint32_t width, WSRect wsrect = { 0, 0, width, height }; auto properties = session->GetSystemBarPropertyForRotation(); std::map avoidAreas; + uint32_t orientation = 0; + WSError ret = session->ConvertRotationToOrientation(rotation, orientation); + if (ret != WSError::WS_OK) { + TLOGNE(WmsLogTag::WMS_ROTATION, "failed to convert Rotation to Orientation"); + return ret; + } + // Orientation type is required here session->GetAvoidAreasByRotation( - static_cast(rotation / ROTATION_DEGREE), wsrect, properties, avoidAreas); + static_cast(orientation), wsrect, properties, avoidAreas); if (!session->sessionStage_) { return WSError::WS_ERROR_NULLPTR; } Rect rect = { wsrect.posX_, wsrect.posY_, wsrect.width_, wsrect.height_ }; - OrientationInfo info = { rotation, rect, avoidAreas }; + OrientationInfo info = { orientation, rect, avoidAreas }; session->sessionStage_->NotifyTargetRotationInfo(info); return WSError::WS_OK; }, __func__); return WSError::WS_OK; } +WSError SceneSession::ConvertRotationToOrientation(uint32_t rotation, uint32_t& orientation) +{ + sptr screenSession = + ScreenSessionManagerClient::GetInstance().GetScreenSessionById(GetSessionProperty()->GetDisplayId()); + if (screenSession == nullptr) { + TLOGW(WmsLogTag::WMS_ROTATION, "Screen session is null"); + return WSError::WS_ERROR_INVALID_DISPLAY; + } + FoldDisplayMode foldDisplayMode = ScreenSessionManagerClient::GetInstance().GetFoldDisplayMode(); + Rotation targetRotation = static_cast(rotation / ROTATION_DEGREE); + DisplayOrientation displayOrientation = screenSession->CalcDisplayOrientation(targetRotation, foldDisplayMode); + orientation = static_cast(displayOrientation); + return WSError::WS_OK; +} + void SceneSession::SetSystemBarPropertyForRotation( const std::map& properties) { diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 36b9cc8d43..9376a538fb 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -2803,12 +2803,19 @@ HWTEST_F(SceneSessionTest5, GetTargetOrientationConfigInfo, Function | SmallTest */ HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level2) { + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); SessionInfo info; info.abilityName_ = "NotifyRotationProperty"; info.bundleName_ = "NotifyRotationProperty"; sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); + sceneSession->GetSessionProperty()->SetDisplayId(1001); + ScreenSessionConfig config; + sptr screenSession = sptr::MakeSptr(config, + ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1001, screenSession); WSError result = sceneSession->NotifyRotationProperty(0, 0, 0); EXPECT_EQ(result, WSError::WS_OK); @@ -2818,6 +2825,44 @@ HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level EXPECT_EQ(result2, WSError::WS_OK); WSError result3 = sceneSession->NotifyRotationProperty(90, 1, 1); EXPECT_EQ(result3, WSError::WS_OK); + sceneSession->GetSessionProperty()->SetDisplayId(1024); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1024, nullptr); + sceneSession->NotifyRotationProperty(90, 1, 1); + usleep(100000); + EXPECT_TRUE(g_errLog.find("failed to convert Rotation to Orientation") != std::string::npos); +} + +/** + * @tc.name: ConvertRotationToOrientation + * @tc.desc: ConvertRotationToOrientation + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionTest5, ConvertRotationToOrientation, Function | SmallTest | Level2) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + SessionInfo info; + info.abilityName_ = "ConvertRotationToOrientation"; + info.bundleName_ = "ConvertRotationToOrientation"; + + sptr sceneSession = sptr::MakeSptr(info, nullptr); + EXPECT_NE(sceneSession, nullptr); + sceneSession->GetSessionProperty()->SetDisplayId(1001); + ScreenSessionConfig config; + sptr screenSession = sptr::MakeSptr(config, + ScreenSessionReason::CREATE_SESSION_FOR_CLIENT); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1001, screenSession); + + uint32_t orientation = 0; + WSError result = sceneSession->ConvertRotationToOrientation(90, orientation); + EXPECT_EQ(result, WSError::WS_OK); + + sceneSession->GetSessionProperty()->SetDisplayId(1024); + ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(1024, nullptr); + uint32_t orientation1 = 0; + WSError result1 = sceneSession->ConvertRotationToOrientation(90, orientation1); + EXPECT_EQ(result1, WSError::WS_ERROR_INVALID_DISPLAY); + EXPECT_TRUE(g_errLog.find("Screen session is null") != std::string::npos); } /** diff --git a/wm/src/window_scene_session_impl.cpp b/wm/src/window_scene_session_impl.cpp index ae00ed918b..a5062c20ba 100644 --- a/wm/src/window_scene_session_impl.cpp +++ b/wm/src/window_scene_session_impl.cpp @@ -2573,14 +2573,13 @@ Ace::ViewportConfig WindowSceneSessionImpl::FillTargetOrientationConfig( return config; } auto deviceRotation = static_cast(displayInfo->GetDefaultDeviceRotationOffset()); - uint32_t transformHint = (targetRotation + deviceRotation) % FULL_CIRCLE_DEGREE; + uint32_t transformHint = (targetRotation * ONE_FOURTH_FULL_CIRCLE_DEGREE + deviceRotation) % FULL_CIRCLE_DEGREE; float density = GetVirtualPixelRatio(displayInfo); - int32_t orientation = static_cast(targetRotation) / ONE_FOURTH_FULL_CIRCLE_DEGREE; virtualPixelRatio_ = density; config.SetSize(targetRect.width_, targetRect.height_); config.SetPosition(targetRect.posX_, targetRect.posY_); config.SetDensity(density); - config.SetOrientation(orientation); + config.SetOrientation(targetRotation); config.SetTransformHint(transformHint); config.SetDisplayId(displayId); return config; -- Gitee From 8ac3e0f7c950acc2f252eabe58364570a290fe55 Mon Sep 17 00:00:00 2001 From: wangjiaqi Date: Sat, 13 Sep 2025 14:13:53 +0800 Subject: [PATCH 2/2] pageRotation xts fixed Signed-off-by: wangjiaqi --- window_scene/test/unittest/scene_session_test5.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 9376a538fb..c403483567 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -2839,7 +2839,7 @@ HWTEST_F(SceneSessionTest5, NotifyRotationProperty, Function | SmallTest | Level */ HWTEST_F(SceneSessionTest5, ConvertRotationToOrientation, Function | SmallTest | Level2) { - g_errLog.clear(); + g_errLog.clear(); LOG_SetCallback(MyLogCallback); SessionInfo info; info.abilityName_ = "ConvertRotationToOrientation"; -- Gitee