diff --git a/window_scene/session/host/include/session.h b/window_scene/session/host/include/session.h index fc32a0a89cb49eaa898168184d66269a4f7eff93..19a1df9eff532824525d26fb84a2538c7a6fa2a6 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 f3b9a23165d81827e6127164e05229c030a9e060..b470286f601f9c4740271c0f9d0c26200402054e 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 d6db683e8e4d0d9ecbecad428a4cf568888fc8b5..4807652d0869a32e9c7751a4a02f34b57fdf5074 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 dd8c3eb10dc993a95233321dbbe0bcfa8bb9fac5..9f3fa8210665868289dbb46f7bc7f9695a7221a3 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 c48cdaca156217c5a71665a2f612af80e2a60e32..8d9d3c9230ad9851cc2a2cc9d93a9e077a049f31 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 538698fecdba780f94303d97b1ff76d77066430f..576579b04ca6e1f964e9cbcb2c32adb78dc48d62 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()); } /**