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