• 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_DM_COMMON_H
17 #define OHOS_ROSEN_DM_COMMON_H
18 
19 #include <refbase.h>
20 #include <string>
21 #include <map>
22 
23 #ifdef _WIN32
24 #define WINDOW_EXPORT __attribute__((dllexport))
25 #else
26 #define WINDOW_EXPORT __attribute__((visibility("default")))
27 #endif
28 
29 namespace OHOS {
30 namespace Rosen {
31 using DisplayId = uint64_t;
32 using ScreenId = uint64_t;
33 namespace {
34     constexpr DisplayId DISPLAY_ID_INVALID = -1ULL;
35     constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
36     constexpr int DOT_PER_INCH = 160;
37     const static std::string DEFAULT_SCREEN_NAME = "buildIn";
38     constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 640;
39     constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
40     constexpr uint32_t BASELINE_DENSITY = 160;
41 }
42 
43 /**
44  * @brief Power state change reason.
45  */
46 enum class PowerStateChangeReason : uint32_t {
47     POWER_BUTTON,
48 };
49 
50 /**
51  * @brief Enumerates the state of the screen power.
52  */
53 enum class ScreenPowerState : uint32_t {
54     POWER_ON,
55     POWER_STAND_BY,
56     POWER_SUSPEND,
57     POWER_OFF,
58     POWER_BUTT,
59     INVALID_STATE,
60 };
61 
62 /**
63  * @brief Enumerates the state of the display.
64  */
65 enum class DisplayState : uint32_t {
66     UNKNOWN,
67     OFF,
68     ON,
69     DOZE,
70     DOZE_SUSPEND,
71     VR,
72     ON_SUSPEND,
73 };
74 
75 /**
76  * @brief Enumerates display events.
77  */
78 enum class DisplayEvent : uint32_t {
79     UNLOCK,
80     KEYGUARD_DRAWN,
81 };
82 
83 /**
84  * @brief Enumerates DMError.
85  */
86 enum class DMError : int32_t {
87     DM_OK = 0,
88     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
89     DM_ERROR_IPC_FAILED = 101,
90     DM_ERROR_REMOTE_CREATE_FAILED = 110,
91     DM_ERROR_NULLPTR = 120,
92     DM_ERROR_INVALID_PARAM = 130,
93     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
94     DM_ERROR_DEATH_RECIPIENT = 150,
95     DM_ERROR_INVALID_MODE_ID = 160,
96     DM_ERROR_WRITE_DATA_FAILED = 170,
97     DM_ERROR_RENDER_SERVICE_FAILED = 180,
98     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
99     DM_ERROR_INVALID_CALLING = 200,
100     DM_ERROR_INVALID_PERMISSION = 201,
101     DM_ERROR_NOT_SYSTEM_APP = 202,
102     DM_ERROR_UNKNOWN = -1,
103 };
104 
105 /**
106  * @brief Enumerates DM error codes.
107  */
108 enum class DmErrorCode : int32_t {
109     DM_OK = 0,
110     DM_ERROR_NO_PERMISSION = 201,
111     DM_ERROR_NOT_SYSTEM_APP = 202,
112     DM_ERROR_INVALID_PARAM = 401,
113     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
114     DM_ERROR_INVALID_SCREEN = 1400001,
115     DM_ERROR_INVALID_CALLING = 1400002,
116     DM_ERROR_SYSTEM_INNORMAL = 1400003,
117 };
118 
119 /**
120  * @brief Constructs the mapping of the DM errors to the DM error codes.
121  */
122 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
123     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
124     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
125     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
126     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
127     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
128     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
129     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
130     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
131     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
132     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
133     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
134     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
135     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
136     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
137     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DmErrorCode::DM_ERROR_NOT_SYSTEM_APP        },
138     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
139 };
140 
141 using DisplayStateCallback = std::function<void(DisplayState)>;
142 
143 /**
144  * @brief Enumerates display power events.
145  */
146 enum class DisplayPowerEvent : uint32_t {
147     WAKE_UP,
148     SLEEP,
149     DISPLAY_ON,
150     DISPLAY_OFF,
151     DESKTOP_READY,
152 };
153 
154 /**
155  * @brief Enumerates event status.
156  */
157 enum class EventStatus : uint32_t {
158     BEGIN,
159     END,
160 };
161 
162 class IDisplayPowerEventListener : public RefBase {
163 public:
164     /**
165      * @brief Notify when display power event status changed.
166      */
167     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
168 };
169 
170 /**
171  * @brief Enumerates screen change events.
172  */
173 enum class ScreenChangeEvent : uint32_t {
174     UPDATE_ORIENTATION,
175     UPDATE_ROTATION,
176     CHANGE_MODE,
177     VIRTUAL_PIXEL_RATIO_CHANGED,
178 };
179 
180 /**
181  * @brief Enumerates screen group change events.
182  */
183 enum class ScreenGroupChangeEvent : uint32_t {
184     ADD_TO_GROUP,
185     REMOVE_FROM_GROUP,
186     CHANGE_GROUP,
187 };
188 
189 /**
190  * @brief Enumerates rotations.
191  */
192 enum class Rotation : uint32_t {
193     ROTATION_0,
194     ROTATION_90,
195     ROTATION_180,
196     ROTATION_270,
197 };
198 
199 /**
200  * @brief Enumerates orientations.
201  */
202 enum class Orientation : uint32_t {
203     BEGIN = 0,
204     UNSPECIFIED = BEGIN,
205     VERTICAL = 1,
206     HORIZONTAL = 2,
207     REVERSE_VERTICAL = 3,
208     REVERSE_HORIZONTAL = 4,
209     SENSOR = 5,
210     SENSOR_VERTICAL = 6,
211     SENSOR_HORIZONTAL = 7,
212     AUTO_ROTATION_RESTRICTED = 8,
213     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
214     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
215     LOCKED = 11,
216     END = LOCKED,
217 };
218 
219 /**
220  * @brief Enumerates display orientations.
221  */
222 enum class DisplayOrientation : uint32_t {
223     PORTRAIT = 0,
224     LANDSCAPE,
225     PORTRAIT_INVERTED,
226     LANDSCAPE_INVERTED,
227     UNKNOWN,
228 };
229 
230 /**
231  * @brief Enumerates display change events.
232  */
233 enum class DisplayChangeEvent : uint32_t {
234     UPDATE_ORIENTATION,
235     UPDATE_ROTATION,
236     DISPLAY_SIZE_CHANGED,
237     DISPLAY_FREEZED,
238     DISPLAY_UNFREEZED,
239     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
240     UPDATE_ORIENTATION_FROM_WINDOW,
241     UPDATE_ROTATION_FROM_WINDOW,
242     UNKNOWN,
243 };
244 
245 /**
246  * @brief Enumerates screen source mode.
247  */
248 enum class ScreenSourceMode: uint32_t {
249     SCREEN_MAIN = 0,
250     SCREEN_MIRROR = 1,
251     SCREEN_EXTEND = 2,
252     SCREEN_ALONE = 3,
253 };
254 }
255 }
256 #endif // OHOS_ROSEN_DM_COMMON_H