• 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 #include "sensor_agent.h"
23 
24 #include "dm_common.h"
25 #include "window_manager_hilog.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 enum class SensorRotation: int32_t {
30     INVALID = -1,
31     ROTATION_0 = 0,
32     ROTATION_90,
33     ROTATION_180,
34     ROTATION_270,
35 };
36 
37 enum class DeviceRotation: int32_t {
38     INVALID = -1,
39     ROTATION_PORTRAIT = 0,
40     ROTATION_LANDSCAPE,
41     ROTATION_PORTRAIT_INVERTED,
42     ROTATION_LANDSCAPE_INVERTED,
43 };
44 
45 class ScreenRotationProperty : public RefBase {
46 public:
47     ScreenRotationProperty() = delete;
48     ~ScreenRotationProperty() = default;
49     static void Init();
50     static void HandleSensorEventInput(DeviceRotation deviceRotation);
51     static bool IsScreenRotationLocked();
52     static DMError SetScreenRotationLocked(bool isLocked);
53     static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset);
54     static void ProcessOrientationSwitch(Orientation orientation);
55 
56     static bool IsDefaultDisplayRotationPortrait();
57     static bool IsDisplayRotationVertical(Rotation rotation);
58     static bool IsDisplayRotationHorizontal(Rotation rotation);
59     static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation);
60     static DisplayOrientation ConvertRotationToDisplayOrientation(Rotation rotation);
61 private:
62     static void HandleGravitySensorEventCallback(SensorEvent *event);
63     static Rotation GetCurrentDisplayRotation();
64     static Orientation GetPreferredOrientation();
65     static void SetScreenRotation(Rotation targetRotation);
66     static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation,
67         DeviceRotation sensorRotationConverted);
68     static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation);
69     static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted);
70 
71     static bool IsDeviceRotationVertical(DeviceRotation deviceRotation);
72     static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation);
73     static bool IsCurrentDisplayVertical();
74     static bool IsCurrentDisplayHorizontal();
75     static bool IsSensorRelatedOrientation(Orientation orientation);
76 
77     static void ProcessRotationMapping();
78     static void ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation);
79     static void ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation);
80     static void ProcessSwitchToAutoRotation(DeviceRotation rotation);
81     static void ProcessSwitchToAutoRotationPortraitRestricted();
82     static void ProcessSwitchToAutoRotationLandscapeRestricted();
83     static void ProcessSwitchToSensorRelatedOrientation(Orientation orientation, DeviceRotation deviceRotation);
84     static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation);
85     static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted);
86     static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted);
87 
88     static DisplayId GetDefaultDisplayId();
89 
90     static DisplayId defaultDisplayId_;
91     static uint32_t defaultDeviceRotationOffset_;
92     static uint32_t defaultDeviceRotation_;
93     static std::map<SensorRotation, DeviceRotation> sensorToDeviceRotationMap_;
94     static std::map<DeviceRotation, Rotation> deviceToDisplayRotationMap_;
95     static std::map<Rotation, DisplayOrientation> displayToDisplayOrientationMap_;
96     static Orientation lastOrientationType_;
97     static Rotation currentDisplayRotation_;
98     static Rotation lastSensorDecidedRotation_;
99     static Rotation rotationLockedRotation_;
100     static bool isScreenRotationLocked_;
101     static DeviceRotation lastSensorRotationConverted_;
102 };
103 } // Rosen
104 } // OHOS
105 #endif // OHOS_ROSEN_SCREEN_ROTATION_CONTROLLER_H