From 587529be8e57422bb370630b346091c80740f0e1 Mon Sep 17 00:00:00 2001 From: Laiganlu Date: Mon, 18 Aug 2025 20:31:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=88=AA=E5=9B=BE=E5=BD=A2=E6=80=81=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Laiganlu --- window_scene/session/host/include/session.h | 2 +- .../session/host/include/ws_snapshot_helper.h | 22 ++++++++++- window_scene/session/host/src/session.cpp | 23 ++---------- .../session/host/src/ws_snapshot_helper.cpp | 37 +++++++++++++++++++ .../src/scene_session_manager.cpp | 3 ++ .../window_pattern_snapshot_test.cpp | 11 +----- 6 files changed, 67 insertions(+), 31 deletions(-) diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index e5d8b434d1..1b85e0e8f8 100644 --- a/window_scene/session/host/include/session.h +++ b/window_scene/session/host/include/session.h @@ -736,7 +736,7 @@ public: void InitSnapshotCapacity(); SnapshotStatus GetWindowStatus() const; SnapshotStatus GetSessionSnapshotStatus(BackgroundReason reason = BackgroundReason::DEFAULT) const; - DisplayOrientation GetWindowOrientation() const; + uint32_t GetWindowOrientation() const; uint32_t GetLastOrientation() const; bool HasSnapshotFreeMultiWindow(); bool HasSnapshot(SnapshotStatus key); diff --git a/window_scene/session/host/include/ws_snapshot_helper.h b/window_scene/session/host/include/ws_snapshot_helper.h index f3b9a23165..8110b041bd 100644 --- a/window_scene/session/host/include/ws_snapshot_helper.h +++ b/window_scene/session/host/include/ws_snapshot_helper.h @@ -44,11 +44,16 @@ constexpr SnapshotStatus maxCapacity = { SCREEN_COUNT, ORIENTATION_COUNT }; class WSSnapshotHelper { public: - WSSnapshotHelper() = default; - ~WSSnapshotHelper() = default; + static WSSnapshotHelper* GetInstance(); static uint32_t GetScreenStatus(); static uint32_t GetScreenStatus(FoldStatus foldStatus); static DisplayOrientation GetDisplayOrientation(int32_t rotation); + static void SetWindowScreenStatus(uint32_t screenStatus); + static void SetWindowScreenStatus(FoldStatus foldStatus); + static void SetWindowOrientationStatus(uint32_t orientationStatus); + static void SetWindowOrientationStatus(Rotation rotation); + static SnapshotStatus GetWindowStatus(); + static uint32_t GetRotation(); static inline uint32_t GetOrientation(int32_t rotation) { if (rotation == LANDSCAPE_ANGLE || rotation == LANDSCAPE_INVERTED_ANGLE) { @@ -65,6 +70,19 @@ public: } return SNAPSHOT_PORTRAIT; } + + static inline uint32_t GetOrientation(Rotation rotation) + { + if (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180) { + return SNAPSHOT_PORTRAIT; + } + return SNAPSHOT_LANDSCAPE; + } +private: + WSSnapshotHelper() = default; + ~WSSnapshotHelper() = default; + SnapshotStatus windowStatus_; + Rotation windowRotation_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index 6ffc701025..f8b4088cbe 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -2889,10 +2889,7 @@ SnapshotStatus Session::GetWindowStatus() const if (!SupportSnapshotAllSessionStatus()) { return defaultStatus; } - uint32_t snapshotScreen = WSSnapshotHelper::GetScreenStatus(); - auto windowOrientation = GetWindowOrientation(); - uint32_t orientation = WSSnapshotHelper::GetOrientation(windowOrientation); - return std::make_pair(snapshotScreen, orientation); + return WSSnapshotHelper::GetWindowStatus(); } SnapshotStatus Session::GetSessionSnapshotStatus(BackgroundReason reason) const @@ -2913,25 +2910,13 @@ SnapshotStatus Session::GetSessionSnapshotStatus(BackgroundReason reason) const return std::make_pair(snapshotScreen, orientation); } -DisplayOrientation Session::GetWindowOrientation() const +uint32_t Session::GetWindowOrientation() const { if (!SupportSnapshotAllSessionStatus()) { - return DisplayOrientation::PORTRAIT; + return 0; } DisplayId displayId = GetScreenId(); - auto screenSession = ScreenSessionManagerClient::GetInstance().GetScreenSession(displayId); - if (!screenSession) { - TLOGE(WmsLogTag::WMS_PATTERN, "screenSession is nullptr, id:%{public}d", persistentId_); - return DisplayOrientation::PORTRAIT; - } - auto screenProperty = screenSession->GetScreenProperty(); - DisplayOrientation displayOrientation = screenProperty.GetDisplayOrientation(); - auto windowOrientation = static_cast(displayOrientation); - auto snapshotScreen = WSSnapshotHelper::GetScreenStatus(); - if (snapshotScreen == SCREEN_UNKNOWN) { - windowOrientation = (windowOrientation + SECONDARY_EXPAND_OFFSET) % ROTATION_COUNT; - } - return static_cast(windowOrientation); + return WSSnapshotHelper::GetRotation(); } uint32_t Session::GetLastOrientation() const diff --git a/window_scene/session/host/src/ws_snapshot_helper.cpp b/window_scene/session/host/src/ws_snapshot_helper.cpp index dd8c3eb10d..c6fbb1768d 100644 --- a/window_scene/session/host/src/ws_snapshot_helper.cpp +++ b/window_scene/session/host/src/ws_snapshot_helper.cpp @@ -26,6 +26,12 @@ const std::unordered_map ROTATION_TO_DISPLAYORIENTA }; } +WSSnapshotHelper* WSSnapshotHelper::GetInstance() +{ + static WSSnapshotHelper instance; + return &instance; +} + uint32_t WSSnapshotHelper::GetScreenStatus() { FoldStatus foldStatus = ScreenSessionManagerClient::GetInstance().GetFoldStatus(); @@ -53,5 +59,36 @@ DisplayOrientation WSSnapshotHelper::GetDisplayOrientation(int32_t rotation) } return DisplayOrientation::PORTRAIT; } + +static void SetWindowScreenStatus(uint32_t screenStatus) +{ + GetInstance()->windowStatus_.first = screenStatus; +} + +static void SetWindowScreenStatus(FoldStatus foldStatus) +{ + SetWindowScreenStatus(GetScreenStatus(foldStatus)); +} + +static void SetWindowOrientationStatus(uint32_t orientationStatus) +{ + GetInstance()->windowStatus_.second = orientationStatus; +} + +static void SetWindowOrientationStatus(Rotation rotation) +{ + GetInstance()->windowRotation_ = rotation; + SetWindowOrientationStatus(GetOrientation(rotation)); +} + +static SnapshotStatus GetWindowStatus() +{ + return GetInstance()->windowStatus_; +} + +static uint32_t GetRotation() +{ + return static_cast(GetInstance()->windowRotation_); +} // LCOV_EXCL_STOP } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index 1a104d886f..d8722bee8d 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -71,6 +71,7 @@ #include "session/host/include/session_change_recorder.h" #include "session/host/include/session_utils.h" #include "session/host/include/sub_session.h" +#include "session/host/include/ws_snapshot_helper.h" #include "session_helper.h" #include "session_manager_agent_controller.h" #include "singleton_container.h" @@ -12210,6 +12211,7 @@ void SceneSessionManager::ProcessUpdateRotationChange(DisplayId defaultDisplayId sceneSession->SetRotation(displayInfo->GetRotation()); sceneSession->UpdateOrientation(); } + WSSnapshotHelper::SetWindowOrientationStatus(displayInfo->GetRotation()); UpdateDisplayRegion(displayInfo); return WSError::WS_OK; }, "ProcessUpdateRotationChange" + std::to_string(defaultDisplayId)); @@ -15336,6 +15338,7 @@ WMError SceneSessionManager::MakeScreenFoldData(const std::vector& screenFoldData.currentScreenFoldStatusDuration_ = std::stoi(screenFoldInfo[2]); // 2: current duration screenFoldData.postureAngle_ = std::atof(screenFoldInfo[3].c_str()); // 3: posture angle (type: float) screenFoldData.screenRotation_ = std::stoi(screenFoldInfo[4]); // 4: screen rotation + WSSnapshotHelper::SetWindowScreenStatus(static_cast(screenFoldData.nextScreenFoldStatus_)); if (!screenFoldData.GetTypeCThermalWithUtil()) { TLOGI(WmsLogTag::DMS, "Error: fail to get typeC thermal."); return WMError::WM_DO_NOTHING; diff --git a/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp b/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp index c94e1bd2cc..d1dd2693b4 100644 --- a/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp +++ b/window_scene/test/unittest/window_pattern/window_pattern_snapshot_test.cpp @@ -752,21 +752,14 @@ HWTEST_F(WindowPatternSnapshotTest, GetWindowOrientation, TestSize.Level1) info.screenId_ = 0; sptr sceneSession = sptr::MakeSptr(info, nullptr); auto ret = sceneSession->GetWindowOrientation(); - EXPECT_EQ(ret, DisplayOrientation::PORTRAIT); + EXPECT_EQ(ret, 0); sceneSession->capacity_ = maxCapacity; - ScreenId screenId = 0; - sptr screenSession = nullptr; - screenSession = new ScreenSession(0, ScreenProperty(), 0); - ASSERT_NE(screenSession, nullptr); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.emplace(screenId, screenSession); - sceneSession->GetWindowOrientation(); - ScreenSessionManagerClient::GetInstance().screenSessionMap_.clear(); session_->capacity_ = maxCapacity; ret = session_->GetWindowOrientation(); - EXPECT_EQ(ret, DisplayOrientation::PORTRAIT); + EXPECT_EQ(ret, WSSnapshotHelper::GetRotation()); } /** -- Gitee