From 43048d65c01cf210f2865aa1c845547a08fa55f8 Mon Sep 17 00:00:00 2001 From: Laiganlu Date: Fri, 12 Sep 2025 14:32:22 +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 | 28 +++++++++-- window_scene/session/host/src/session.cpp | 47 +++++++++--------- .../session/host/src/ws_snapshot_helper.cpp | 49 +++++++++++++++++-- .../src/scene_session_manager.cpp | 4 ++ .../window_pattern_snapshot_test.cpp | 11 +---- 6 files changed, 101 insertions(+), 40 deletions(-) diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index fc32a0a89c..19a1df9eff 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 GetSessionStatus(ScreenLockReason reason = ScreenLockReason::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..b470286f60 100644 --- a/window_scene/session/host/include/ws_snapshot_helper.h +++ b/window_scene/session/host/include/ws_snapshot_helper.h @@ -16,6 +16,7 @@ #ifndef OHOS_ROSEN_WINDOW_SCENE_SNAPSHOT_HELPER_H #define OHOS_ROSEN_WINDOW_SCENE_SNAPSHOT_HELPER_H +#include #include #include @@ -44,11 +45,16 @@ constexpr SnapshotStatus maxCapacity = { SCREEN_COUNT, ORIENTATION_COUNT }; class WSSnapshotHelper { public: - WSSnapshotHelper() = default; - ~WSSnapshotHelper() = default; - static uint32_t GetScreenStatus(); + static WSSnapshotHelper* GetInstance(); + uint32_t GetScreenStatus(); static uint32_t GetScreenStatus(FoldStatus foldStatus); static DisplayOrientation GetDisplayOrientation(int32_t rotation); + void SetWindowScreenStatus(uint32_t screenStatus); + void SetWindowScreenStatus(FoldStatus foldStatus); + void SetWindowOrientationStatus(uint32_t orientationStatus); + void SetWindowOrientationStatus(Rotation rotation); + SnapshotStatus GetWindowStatus() const; + uint32_t GetWindowRotation() const; static inline uint32_t GetOrientation(int32_t rotation) { if (rotation == LANDSCAPE_ANGLE || rotation == LANDSCAPE_INVERTED_ANGLE) { @@ -65,6 +71,22 @@ 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_; + mutable std::mutex statusMutex_; + mutable std::mutex rotationMutex_; }; } // namespace OHOS::Rosen diff --git a/window_scene/session/host/src/session.cpp b/window_scene/session/host/src/session.cpp index d6db683e8e..4807652d08 100644 --- a/window_scene/session/host/src/session.cpp +++ b/window_scene/session/host/src/session.cpp @@ -29,6 +29,7 @@ #include "proxy/include/window_info.h" #include "common/include/session_permission.h" +#include "fold_screen_state_internel.h" #include "rs_adapter.h" #include "session_coordinate_helper.h" #include "session_helper.h" @@ -77,6 +78,7 @@ const std::map DETACH_MAP = { { SessionState::STATE_INACTIVE, true }, { SessionState::STATE_BACKGROUND, true }, }; +const uint32_t ROTATION_LANDSCAPE_INVERTED = 3; } // namespace std::shared_ptr Session::mainHandler_; @@ -1504,7 +1506,7 @@ WSError Session::Background(bool isFromClient, const std::string& identityToken) return WSError::WS_ERROR_INVALID_SESSION; } UpdateSessionState(SessionState::STATE_BACKGROUND); - lastSnapshotScreen_ = WSSnapshotHelper::GetScreenStatus(); + lastSnapshotScreen_ = WSSnapshotHelper::GetInstance()->GetScreenStatus(); SetIsPendingToBackgroundState(false); NotifyBackground(); PostSpecificSessionLifeCycleTimeoutTask(DETACH_EVENT_NAME); @@ -1547,7 +1549,7 @@ WSError Session::Disconnect(bool isFromClient, const std::string& identityToken) } UpdateSessionState(SessionState::STATE_BACKGROUND); UpdateSessionState(SessionState::STATE_DISCONNECT); - lastSnapshotScreen_ = WSSnapshotHelper::GetScreenStatus(); + lastSnapshotScreen_ = WSSnapshotHelper::GetInstance()->GetScreenStatus(); NotifyDisconnect(); if (visibilityChangedDetectFunc_) { visibilityChangedDetectFunc_(GetCallingPid(), isVisible_, false); @@ -2713,7 +2715,12 @@ void Session::SaveSnapshot(bool useFfrt, bool needPersist, std::shared_ptrGetScreenStatus() == SCREEN_FOLDED) { + rotation = ROTATION_LANDSCAPE_INVERTED; + } + auto rotate = WSSnapshotHelper::GetDisplayOrientation(rotation); if (persistentPixelMap) { key = defaultStatus; rotate = DisplayOrientation::PORTRAIT; @@ -2889,10 +2896,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::GetInstance()->GetWindowStatus(); } SnapshotStatus Session::GetSessionStatus(ScreenLockReason reason) const @@ -2904,34 +2908,25 @@ SnapshotStatus Session::GetSessionStatus(ScreenLockReason reason) const if (state_ == SessionState::STATE_BACKGROUND || state_ == SessionState::STATE_DISCONNECT) { snapshotScreen = lastSnapshotScreen_; } else { - snapshotScreen = WSSnapshotHelper::GetScreenStatus(); + snapshotScreen = WSSnapshotHelper::GetInstance()->GetScreenStatus(); } if (reason == ScreenLockReason::EXPAND_TO_FOLD_SINGLE_POCKET) { snapshotScreen = SCREEN_EXPAND; } uint32_t orientation = WSSnapshotHelper::GetOrientation(currentRotation_); + if (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() && + WSSnapshotHelper::GetInstance()->GetScreenStatus() == SCREEN_FOLDED) { + orientation = 1; + } 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::GetInstance()->GetWindowRotation(); } uint32_t Session::GetLastOrientation() const @@ -2939,6 +2934,10 @@ uint32_t Session::GetLastOrientation() const if (!SupportSnapshotAllSessionStatus()) { return SNAPSHOT_PORTRAIT; } + if (FoldScreenStateInternel::IsSingleDisplayPocketFoldDevice() && + WSSnapshotHelper::GetInstance()->GetScreenStatus() == SCREEN_FOLDED) { + return ROTATION_LANDSCAPE_INVERTED; + } return static_cast(WSSnapshotHelper::GetDisplayOrientation(currentRotation_)); } diff --git a/window_scene/session/host/src/ws_snapshot_helper.cpp b/window_scene/session/host/src/ws_snapshot_helper.cpp index dd8c3eb10d..9f3fa82106 100644 --- a/window_scene/session/host/src/ws_snapshot_helper.cpp +++ b/window_scene/session/host/src/ws_snapshot_helper.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "screen_session_manager_client/include/screen_session_manager_client.h" #include "session/host/include/ws_snapshot_helper.h" namespace OHOS::Rosen { @@ -26,10 +25,16 @@ const std::unordered_map ROTATION_TO_DISPLAYORIENTA }; } +WSSnapshotHelper* WSSnapshotHelper::GetInstance() +{ + static WSSnapshotHelper instance; + return &instance; +} + uint32_t WSSnapshotHelper::GetScreenStatus() { - FoldStatus foldStatus = ScreenSessionManagerClient::GetInstance().GetFoldStatus(); - return GetScreenStatus(foldStatus); + std::lock_guard lock(statusMutex_); + return GetInstance()->windowStatus_.first; } // LCOV_EXCL_START @@ -53,5 +58,43 @@ DisplayOrientation WSSnapshotHelper::GetDisplayOrientation(int32_t rotation) } return DisplayOrientation::PORTRAIT; } + +void WSSnapshotHelper::SetWindowScreenStatus(uint32_t screenStatus) +{ + std::lock_guard lock(statusMutex_); + GetInstance()->windowStatus_.first = screenStatus; +} + +void WSSnapshotHelper::SetWindowScreenStatus(FoldStatus foldStatus) +{ + SetWindowScreenStatus(GetScreenStatus(foldStatus)); +} + +void WSSnapshotHelper::SetWindowOrientationStatus(uint32_t orientationStatus) +{ + std::lock_guard lock(statusMutex_); + GetInstance()->windowStatus_.second = orientationStatus; +} + +void WSSnapshotHelper::SetWindowOrientationStatus(Rotation rotation) +{ + { + std::lock_guard lock (rotationMutex_); + GetInstance()->windowRotation_ = rotation; + } + SetWindowOrientationStatus(GetOrientation(rotation)); +} + +SnapshotStatus WSSnapshotHelper::GetWindowStatus() const +{ + std::lock_guard lock(statusMutex_); + return GetInstance()->windowStatus_; +} + +uint32_t WSSnapshotHelper::GetWindowRotation() const +{ + std::lock_guard lock(rotationMutex_); + 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 c48cdaca15..8d9d3c9230 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" @@ -12204,6 +12205,7 @@ void SceneSessionManager::ProcessUpdateRotationChange(DisplayId defaultDisplayId sceneSession->SetRotation(displayInfo->GetRotation()); sceneSession->UpdateOrientation(); } + WSSnapshotHelper::GetInstance()->SetWindowOrientationStatus(displayInfo->GetRotation()); UpdateDisplayRegion(displayInfo); return WSError::WS_OK; }, "ProcessUpdateRotationChange" + std::to_string(defaultDisplayId)); @@ -15330,6 +15332,8 @@ 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::GetInstance()->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 538698fecd..576579b04c 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::GetInstance()->GetWindowRotation()); } /** -- Gitee