1e0dac50fSopenharmony_ci/* 2e0dac50fSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License. 5e0dac50fSopenharmony_ci * You may obtain a copy of the License at 6e0dac50fSopenharmony_ci * 7e0dac50fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0dac50fSopenharmony_ci * 9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and 13e0dac50fSopenharmony_ci * limitations under the License. 14e0dac50fSopenharmony_ci */ 15e0dac50fSopenharmony_ci 16e0dac50fSopenharmony_ci#ifndef OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H 17e0dac50fSopenharmony_ci#define OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H 18e0dac50fSopenharmony_ci 19e0dac50fSopenharmony_ci#include <map> 20e0dac50fSopenharmony_ci#include <refbase.h> 21e0dac50fSopenharmony_ci 22e0dac50fSopenharmony_ci#include "dm_common.h" 23e0dac50fSopenharmony_ci#include "window_manager_hilog.h" 24e0dac50fSopenharmony_ci 25e0dac50fSopenharmony_cinamespace OHOS { 26e0dac50fSopenharmony_cinamespace Rosen { 27e0dac50fSopenharmony_cienum class SensorRotation: int32_t { 28e0dac50fSopenharmony_ci INVALID = -1, 29e0dac50fSopenharmony_ci ROTATION_0 = 0, 30e0dac50fSopenharmony_ci ROTATION_90, 31e0dac50fSopenharmony_ci ROTATION_180, 32e0dac50fSopenharmony_ci ROTATION_270, 33e0dac50fSopenharmony_ci}; 34e0dac50fSopenharmony_ci 35e0dac50fSopenharmony_cienum class DeviceRotation: int32_t { 36e0dac50fSopenharmony_ci INVALID = -1, 37e0dac50fSopenharmony_ci ROTATION_PORTRAIT = 0, 38e0dac50fSopenharmony_ci ROTATION_LANDSCAPE, 39e0dac50fSopenharmony_ci ROTATION_PORTRAIT_INVERTED, 40e0dac50fSopenharmony_ci ROTATION_LANDSCAPE_INVERTED, 41e0dac50fSopenharmony_ci}; 42e0dac50fSopenharmony_ci 43e0dac50fSopenharmony_ciclass ScreenRotationController : public RefBase { 44e0dac50fSopenharmony_cipublic: 45e0dac50fSopenharmony_ci ScreenRotationController() = delete; 46e0dac50fSopenharmony_ci ~ScreenRotationController() = default; 47e0dac50fSopenharmony_ci static void Init(); 48e0dac50fSopenharmony_ci static void HandleSensorEventInput(DeviceRotation deviceRotation); 49e0dac50fSopenharmony_ci static bool IsScreenRotationLocked(); 50e0dac50fSopenharmony_ci static DMError SetScreenRotationLocked(bool isLocked); 51e0dac50fSopenharmony_ci static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); 52e0dac50fSopenharmony_ci static void ProcessOrientationSwitch(Orientation orientation, bool withAnimation); 53e0dac50fSopenharmony_ci 54e0dac50fSopenharmony_ci static bool IsDefaultDisplayRotationPortrait(); 55e0dac50fSopenharmony_ci static bool IsDisplayRotationVertical(Rotation rotation); 56e0dac50fSopenharmony_ci static bool IsDisplayRotationHorizontal(Rotation rotation); 57e0dac50fSopenharmony_ci static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation); 58e0dac50fSopenharmony_ci static DisplayOrientation ConvertRotationToDisplayOrientation(Rotation rotation); 59e0dac50fSopenharmony_ciprivate: 60e0dac50fSopenharmony_ci static Rotation GetCurrentDisplayRotation(); 61e0dac50fSopenharmony_ci static Orientation GetPreferredOrientation(); 62e0dac50fSopenharmony_ci static void SetScreenRotation(Rotation targetRotation, bool withAnimation = true); 63e0dac50fSopenharmony_ci static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, 64e0dac50fSopenharmony_ci DeviceRotation sensorRotationConverted); 65e0dac50fSopenharmony_ci static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation); 66e0dac50fSopenharmony_ci static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted); 67e0dac50fSopenharmony_ci 68e0dac50fSopenharmony_ci static bool IsDeviceRotationVertical(DeviceRotation deviceRotation); 69e0dac50fSopenharmony_ci static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation); 70e0dac50fSopenharmony_ci static bool IsCurrentDisplayVertical(); 71e0dac50fSopenharmony_ci static bool IsCurrentDisplayHorizontal(); 72e0dac50fSopenharmony_ci static bool IsSensorRelatedOrientation(Orientation orientation); 73e0dac50fSopenharmony_ci 74e0dac50fSopenharmony_ci static void ProcessRotationMapping(); 75e0dac50fSopenharmony_ci static void ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation); 76e0dac50fSopenharmony_ci static void ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation); 77e0dac50fSopenharmony_ci static void ProcessSwitchToAutoRotation(DeviceRotation rotation); 78e0dac50fSopenharmony_ci static void ProcessSwitchToAutoRotationPortraitRestricted(); 79e0dac50fSopenharmony_ci static void ProcessSwitchToAutoRotationLandscapeRestricted(); 80e0dac50fSopenharmony_ci static void ProcessSwitchToSensorRelatedOrientation(Orientation orientation, DeviceRotation deviceRotation); 81e0dac50fSopenharmony_ci static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation, bool withAnimation); 82e0dac50fSopenharmony_ci static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); 83e0dac50fSopenharmony_ci static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); 84e0dac50fSopenharmony_ci 85e0dac50fSopenharmony_ci static DisplayId defaultDisplayId_; 86e0dac50fSopenharmony_ci static uint32_t defaultDeviceRotationOffset_; 87e0dac50fSopenharmony_ci static uint32_t defaultDeviceRotation_; 88e0dac50fSopenharmony_ci static std::map<SensorRotation, DeviceRotation> sensorToDeviceRotationMap_; 89e0dac50fSopenharmony_ci static std::map<DeviceRotation, Rotation> deviceToDisplayRotationMap_; 90e0dac50fSopenharmony_ci static std::map<Rotation, DisplayOrientation> displayToDisplayOrientationMap_; 91e0dac50fSopenharmony_ci static Orientation lastOrientationType_; 92e0dac50fSopenharmony_ci static Rotation currentDisplayRotation_; 93e0dac50fSopenharmony_ci static Rotation lastSensorDecidedRotation_; 94e0dac50fSopenharmony_ci static Rotation rotationLockedRotation_; 95e0dac50fSopenharmony_ci static bool isScreenRotationLocked_; 96e0dac50fSopenharmony_ci static DeviceRotation lastSensorRotationConverted_; 97e0dac50fSopenharmony_ci}; 98e0dac50fSopenharmony_ci} // Rosen 99e0dac50fSopenharmony_ci} // OHOS 100e0dac50fSopenharmony_ci#endif // OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H 101