From 6a0c9dcb7c874b9dfd675580f402dd5a514158b8 Mon Sep 17 00:00:00 2001 From: xpeng Date: Wed, 8 Mar 2023 09:50:16 +0800 Subject: [PATCH] pack function to calculate target display rotation Signed-off-by: xpeng Change-Id: I15df7fb8f9ef813a73d72e980730491632770223 --- dmserver/include/display_manager_service.h | 1 + .../include/display_manager_service_inner.h | 1 + dmserver/include/screen_rotation_controller.h | 1 + dmserver/src/display_manager_service.cpp | 5 ++++ .../src/display_manager_service_inner.cpp | 5 ++++ dmserver/src/screen_rotation_controller.cpp | 27 +++++++++++++++++++ 6 files changed, 40 insertions(+) diff --git a/dmserver/include/display_manager_service.h b/dmserver/include/display_manager_service.h index e50f3c44bb..9a3fc82070 100644 --- a/dmserver/include/display_manager_service.h +++ b/dmserver/include/display_manager_service.h @@ -53,6 +53,7 @@ public: DMError SetVirtualScreenSurface(ScreenId screenId, sptr surface) override; DMError IsScreenRotationLocked(bool& isLocked) override; DMError SetScreenRotationLocked(bool isLocked) override; + Rotation GetTargetDisplayRotation(Orientation orientation); sptr GetDefaultDisplayInfo() override; sptr GetDisplayInfoById(DisplayId displayId) override; diff --git a/dmserver/include/display_manager_service_inner.h b/dmserver/include/display_manager_service_inner.h index a40f65b883..c361424bd8 100644 --- a/dmserver/include/display_manager_service_inner.h +++ b/dmserver/include/display_manager_service_inner.h @@ -54,6 +54,7 @@ public: void RegisterRSScreenChangeListener(const sptr& listener); sptr GetCutoutInfo(DisplayId displayId) const; void NotifyPrivateWindowStateChanged(bool hasPrivate); + Rotation GetTargetDisplayRotation(Orientation orientation); }; } // namespace OHOS::Rosen diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index 1f4a9c59d0..1575a6d330 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -52,6 +52,7 @@ public: static DMError SetScreenRotationLocked(bool isLocked); static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); static void ProcessOrientationSwitch(Orientation orientation, bool withAnimation); + static Rotation GetTargetDisplayRotation(Orientation orientation); static bool IsDefaultDisplayRotationPortrait(); static bool IsDisplayRotationVertical(Rotation rotation); diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index e9b8f914a8..81526decd2 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -719,6 +719,11 @@ DMError DisplayManagerService::SetScreenRotationLocked(bool isLocked) return ScreenRotationController::SetScreenRotationLocked(isLocked); } +Rotation DisplayManagerService::GetTargetDisplayRotation(Orientation orientation) +{ + return ScreenRotationController::GetTargetDisplayRotation(orientation); +} + void DisplayManagerService::SetGravitySensorSubscriptionEnabled() { if (!isAutoRotationOpen_) { diff --git a/dmserver/src/display_manager_service_inner.cpp b/dmserver/src/display_manager_service_inner.cpp index 605aec9a27..b6dc689b39 100644 --- a/dmserver/src/display_manager_service_inner.cpp +++ b/dmserver/src/display_manager_service_inner.cpp @@ -173,4 +173,9 @@ void DisplayManagerServiceInner::NotifyPrivateWindowStateChanged(bool hasPrivate { return DisplayManagerService::GetInstance().NotifyPrivateWindowStateChanged(hasPrivate); } + +Rotation DisplayManagerServiceInner::GetTargetDisplayRotation(Orientation orientation) +{ + return DisplayManagerService::GetInstance().GetTargetDisplayRotation(orientation); +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 3eb08270e2..92c5871300 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -98,6 +98,33 @@ void ScreenRotationController::HandleSensorEventInput(DeviceRotation deviceRotat SetScreenRotation(targetDisplayRotation); } +Rotation ScreenRotationController::GetTargetDisplayRotation(Orientation orientation) +{ + if (!IsSensorRelatedOrientation(orientation)) { + switch (orientation) { + case Orientation::UNSPECIFIED: + return Rotation::ROTATION_0; + case Orientation::VERTICAL: + return ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT); + case Orientation::HORIZONTAL: + return ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE); + case Orientation::REVERSE_VERTICAL: + return ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED); + case Orientation::REVERSE_HORIZONTAL: + return ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED); + case Orientation::LOCKED: + return currentDisplayRotation_; + default: + return Rotation::ROTATION_0; + } + } + + if (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(lastSensorRotationConverted_)) { + return currentDisplayRotation_; + } + return CalcTargetDisplayRotation(orientation, lastSensorRotationConverted_); +} + Rotation ScreenRotationController::GetCurrentDisplayRotation() { sptr defaultDisplayInfo = DisplayManagerServiceInner::GetInstance().GetDefaultDisplay(); -- Gitee