From 99a6eef1301c521a9e3e505cb2a081c729dfe880 Mon Sep 17 00:00:00 2001 From: cloud_nine Date: Sun, 25 Feb 2024 14:22:02 +0800 Subject: [PATCH] =?UTF-8?q?fixed=20df564de=20from=20https://gitee.com/clou?= =?UTF-8?q?d=5Fnine/window=5Fwindow=5Fmanager/pulls/5158=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8Dwindow=5Fscene=E4=B8=AD=E5=81=B6=E7=8E=B0=E6=97=8B?= =?UTF-8?q?=E8=BD=AC=E6=96=B9=E5=90=91=E5=81=8F=E5=B7=AE90=C2=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyunjiu --- dmserver/src/screen_rotation_controller.cpp | 15 +------------ .../include/screen_rotation_property.h | 1 + .../src/screen_cutout_controller.cpp | 2 ++ .../src/screen_rotation_property.cpp | 21 +++++++++++++++++-- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index 386e3f6cd6..41bcdaa619 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -19,7 +19,6 @@ #include #include "display_manager_service_inner.h" -#include "parameters.h" namespace OHOS { namespace Rosen { @@ -348,19 +347,7 @@ void ScreenRotationController::ProcessRotationMapping() DisplayManagerServiceInner::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); // 0 means PORTRAIT, 1 means LANDSCAPE. - if (modes == nullptr) { - defaultDeviceRotation_ = 0; - WLOGFE("Get screen modes is nullptr."); - } else { - defaultDeviceRotation_ = (modes->width_ < modes->height_) ? 0 : 1; - WLOGFI("Get screen modes width: %{public}d, height: %{public}d", modes->width_, modes->height_); - } - if (OHOS::system::GetParameter("const.product.devicetype", "unknown") == "phone") { - WLOGFI("Current device type is phone, set defaultDeviceRotation is portrait"); - defaultDeviceRotation_ = 0; - } - WLOGFI("defaultDeviceRotation: %{public}u, defaultDisplayId: %{public}u", - defaultDeviceRotation_, static_cast(defaultDisplayId_)); + defaultDeviceRotation_ = (modes == nullptr || modes->width_ < modes->height_) ? 0 : 1; if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { diff --git a/window_scene/session_manager/include/screen_rotation_property.h b/window_scene/session_manager/include/screen_rotation_property.h index 3aa6c53a05..98118fd25a 100644 --- a/window_scene/session_manager/include/screen_rotation_property.h +++ b/window_scene/session_manager/include/screen_rotation_property.h @@ -72,6 +72,7 @@ private: static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation); static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted); static float ConvertDeviceToFloat(DeviceRotation deviceRotation); + static void UpdateDefaultDeviceRotation(); static bool IsDeviceRotationVertical(DeviceRotation deviceRotation); static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation); diff --git a/window_scene/session_manager/src/screen_cutout_controller.cpp b/window_scene/session_manager/src/screen_cutout_controller.cpp index 05be13826e..50ac8377a3 100644 --- a/window_scene/session_manager/src/screen_cutout_controller.cpp +++ b/window_scene/session_manager/src/screen_cutout_controller.cpp @@ -304,6 +304,8 @@ void ScreenCutoutController::ProcessRotationMapping() // 0 means PORTRAIT, 1 means LANDSCAPE. defaultDeviceRotation_ = (!displayInfo || (displayInfo && (displayInfo->GetWidth() < displayInfo->GetHeight()))) ? 0 : 1; + WLOGFI("defaultDeviceRotation: %{public}u", defaultDeviceRotation_); + if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { { DeviceRotationValue::ROTATION_PORTRAIT, diff --git a/window_scene/session_manager/src/screen_rotation_property.cpp b/window_scene/session_manager/src/screen_rotation_property.cpp index 1eb9c923d5..0ce5e9c097 100644 --- a/window_scene/session_manager/src/screen_rotation_property.cpp +++ b/window_scene/session_manager/src/screen_rotation_property.cpp @@ -353,13 +353,30 @@ float ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation deviceRotation return deviceToFloatMap_.at(deviceRotation); } -void ScreenRotationProperty::ProcessRotationMapping() +void ScreenRotationProperty::UpdateDefaultDeviceRotation() { sptr modes = ScreenSessionManager::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); // 0 means PORTRAIT, 1 means LANDSCAPE. - defaultDeviceRotation_ = (modes == nullptr || modes->width_ < modes->height_) ? 0 : 1; + if (modes == nullptr) { + defaultDeviceRotation_ = 0; + WLOGFE("Get screen modes is nullptr."); + } else { + defaultDeviceRotation_ = (modes->width_ < modes->height_) ? 0 : 1; + WLOGFI("Get screen modes width: %{public}d, height: %{public}d", modes->width_, modes->height_); + } + if (OHOS::system::GetParameter("const.product.devicetype", "unknown") == "phone") { + WLOGFI("Current device type is phone, set defaultDeviceRotation is portrait"); + defaultDeviceRotation_ = 0; + } + WLOGFI("defaultDeviceRotation: %{public}u, defaultDisplayId: %{public}u", + defaultDeviceRotation_, static_cast(defaultDisplayId_)); +} + +void ScreenRotationProperty::ProcessRotationMapping() +{ + UpdateDefaultDeviceRotation(); if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { {DeviceRotation::ROTATION_PORTRAIT, -- Gitee