• 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 = 1000;
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 = 0,
48     STATE_CHANGE_REASON_INIT = 0,
49     STATE_CHANGE_REASON_TIMEOUT = 1,
50     STATE_CHANGE_REASON_RUNNING_LOCK = 2,
51     STATE_CHANGE_REASON_BATTERY = 3,
52     STATE_CHANGE_REASON_THERMAL = 4,
53     STATE_CHANGE_REASON_WORK = 5,
54     STATE_CHANGE_REASON_SYSTEM = 6,
55     STATE_CHANGE_REASON_APPLICATION = 10,
56     STATE_CHANGE_REASON_SETTINGS = 11,
57     STATE_CHANGE_REASON_HARD_KEY = 12,
58     STATE_CHANGE_REASON_TOUCH = 13,
59     STATE_CHANGE_REASON_CABLE = 14,
60     STATE_CHANGE_REASON_SENSOR = 15,
61     STATE_CHANGE_REASON_LID = 16,
62     STATE_CHANGE_REASON_CAMERA = 17,
63     STATE_CHANGE_REASON_ACCESS = 18,
64     STATE_CHANGE_REASON_RESET = 19,
65     STATE_CHANGE_REASON_POWER_KEY = 20,
66     STATE_CHANGE_REASON_KEYBOARD = 21,
67     STATE_CHANGE_REASON_MOUSE = 22,
68     STATE_CHANGE_REASON_DOUBLE_CLICK = 23,
69     STATE_CHANGE_REASON_SWITCH = 25,
70     STATE_CHANGE_REASON_PRE_BRIGHT = 26,
71     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS = 27,
72     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_ON = 28,
73     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF = 29,
74     STATE_CHANGE_REASON_DISPLAY_SWITCH = 30,
75     STATE_CHANGE_REASON_PROXIMITY = 32,
76     STATE_CHANGE_REASON_AOD_SLIDING = 40,
77     STATE_CHANGE_REASON_PEN = 41,
78     STATE_CHANGE_REASON_SHUT_DOWN = 42,
79     STATE_CHANGE_REASON_HIBERNATE = 45,
80     STATE_CHANGE_REASON_REMOTE = 100,
81     STATE_CHANGE_REASON_UNKNOWN = 1000,
82 };
83 
84 /**
85  * @brief Enumerates the state of the screen power.
86  */
87 enum class ScreenPowerState : uint32_t {
88     POWER_ON,
89     POWER_STAND_BY,
90     POWER_SUSPEND,
91     POWER_OFF,
92     POWER_BUTT,
93     INVALID_STATE,
94 };
95 
96 /**
97  * @brief Enumerates the state of the display.
98  */
99 enum class DisplayState : uint32_t {
100     UNKNOWN,
101     OFF,
102     ON,
103     DOZE,
104     DOZE_SUSPEND,
105     VR,
106     ON_SUSPEND,
107 };
108 
109 /**
110  * @brief Enumerates display events.
111  */
112 enum class DisplayEvent : uint32_t {
113     UNLOCK,
114     KEYGUARD_DRAWN,
115 };
116 
117 /**
118  * @brief Enumerates DMError.
119  */
120 enum class DMError : int32_t {
121     DM_OK = 0,
122     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
123     DM_ERROR_IPC_FAILED = 101,
124     DM_ERROR_REMOTE_CREATE_FAILED = 110,
125     DM_ERROR_NULLPTR = 120,
126     DM_ERROR_INVALID_PARAM = 130,
127     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
128     DM_ERROR_DEATH_RECIPIENT = 150,
129     DM_ERROR_INVALID_MODE_ID = 160,
130     DM_ERROR_WRITE_DATA_FAILED = 170,
131     DM_ERROR_RENDER_SERVICE_FAILED = 180,
132     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
133     DM_ERROR_INVALID_CALLING = 200,
134     DM_ERROR_INVALID_PERMISSION = 201,
135     DM_ERROR_NOT_SYSTEM_APP = 202,
136     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
137     DM_ERROR_UNKNOWN = -1,
138 };
139 
140 /**
141  * @brief Enumerates DM error codes.
142  */
143 enum class DmErrorCode : int32_t {
144     DM_OK = 0,
145     DM_ERROR_NO_PERMISSION = 201,
146     DM_ERROR_NOT_SYSTEM_APP = 202,
147     DM_ERROR_INVALID_PARAM = 401,
148     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
149     DM_ERROR_INVALID_SCREEN = 1400001,
150     DM_ERROR_INVALID_CALLING = 1400002,
151     DM_ERROR_SYSTEM_INNORMAL = 1400003,
152 };
153 
154 /**
155  * @brief Constructs the mapping of the DM errors to the DM error codes.
156  */
157 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
158     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
159     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
160     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
161     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
162     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
163     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
164     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
165     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
166     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
167     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
168     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
169     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
170     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
171     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
172     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DmErrorCode::DM_ERROR_NOT_SYSTEM_APP        },
173     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
174 };
175 
176 using DisplayStateCallback = std::function<void(DisplayState)>;
177 
178 /**
179  * @brief Enumerates display power events.
180  */
181 enum class DisplayPowerEvent : uint32_t {
182     WAKE_UP,
183     SLEEP,
184     DISPLAY_ON,
185     DISPLAY_OFF,
186     DESKTOP_READY,
187     DOZE,
188     DOZE_SUSPEND,
189 };
190 
191 /**
192  * @brief Enumerates event status.
193  */
194 enum class EventStatus : uint32_t {
195     BEGIN,
196     END,
197 };
198 
199 class IDisplayPowerEventListener : public RefBase {
200 public:
201     /**
202      * @brief Notify when display power event status changed.
203      */
204     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
205 };
206 
207 /**
208  * @brief Enumerates screen change events.
209  */
210 enum class ScreenChangeEvent : uint32_t {
211     UPDATE_ORIENTATION,
212     UPDATE_ROTATION,
213     CHANGE_MODE,
214     VIRTUAL_PIXEL_RATIO_CHANGED,
215 };
216 
217 /**
218  * @brief Enumerates screen group change events.
219  */
220 enum class ScreenGroupChangeEvent : uint32_t {
221     ADD_TO_GROUP,
222     REMOVE_FROM_GROUP,
223     CHANGE_GROUP,
224 };
225 
226 /**
227  * @brief Enumerates rotations.
228  */
229 enum class Rotation : uint32_t {
230     ROTATION_0,
231     ROTATION_90,
232     ROTATION_180,
233     ROTATION_270,
234 };
235 
236 /**
237  * @brief Enumerates orientations.
238  */
239 enum class Orientation : uint32_t {
240     BEGIN = 0,
241     UNSPECIFIED = BEGIN,
242     VERTICAL = 1,
243     HORIZONTAL = 2,
244     REVERSE_VERTICAL = 3,
245     REVERSE_HORIZONTAL = 4,
246     SENSOR = 5,
247     SENSOR_VERTICAL = 6,
248     SENSOR_HORIZONTAL = 7,
249     AUTO_ROTATION_RESTRICTED = 8,
250     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
251     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
252     LOCKED = 11,
253     FOLLOW_RECENT = 12,
254     AUTO_ROTATION_UNSPECIFIED = 13,
255     USER_ROTATION_PORTRAIT = 14,
256     USER_ROTATION_LANDSCAPE = 15,
257     USER_ROTATION_PORTRAIT_INVERTED = 16,
258     USER_ROTATION_LANDSCAPE_INVERTED = 17,
259     FOLLOW_DESKTOP = 18,
260     END = FOLLOW_DESKTOP,
261 };
262 
263 /**
264  * @brief Enumerates display orientations.
265  */
266 enum class DisplayOrientation : uint32_t {
267     PORTRAIT = 0,
268     LANDSCAPE,
269     PORTRAIT_INVERTED,
270     LANDSCAPE_INVERTED,
271     UNKNOWN,
272 };
273 
274 /**
275  * @brief Enumerates display change events.
276  */
277 enum class DisplayChangeEvent : uint32_t {
278     UPDATE_ORIENTATION,
279     UPDATE_ROTATION,
280     DISPLAY_SIZE_CHANGED,
281     DISPLAY_FREEZED,
282     DISPLAY_UNFREEZED,
283     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
284     UPDATE_ORIENTATION_FROM_WINDOW,
285     UPDATE_ROTATION_FROM_WINDOW,
286     UPDATE_REFRESHRATE,
287     UNKNOWN,
288 };
289 
290 /**
291  * @brief Enumerates screen source mode.
292  */
293 enum class ScreenSourceMode: uint32_t {
294     SCREEN_MAIN = 0,
295     SCREEN_MIRROR = 1,
296     SCREEN_EXTEND = 2,
297     SCREEN_ALONE = 3,
298 };
299 
300 /**
301  * @brief Enumerates the fold status.
302  */
303 enum class FoldStatus: uint32_t {
304     UNKNOWN = 0,
305     EXPAND = 1,
306     FOLDED = 2,
307     HALF_FOLD = 3,
308 };
309 
310 /**
311  * @brief Enumerates the fold display mode.
312  */
313 enum class FoldDisplayMode: uint32_t {
314     UNKNOWN = 0,
315     FULL = 1,
316     MAIN = 2,
317     SUB = 3,
318     COORDINATION = 4,
319 };
320 
321 /**
322  * @brief displayRect
323  */
324 struct DMRect {
325     int32_t posX_;
326     int32_t posY_;
327     uint32_t width_;
328     uint32_t height_;
329 
330     bool operator==(const DMRect& a) const
331     {
332         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
333     }
334 
335     bool operator!=(const DMRect& a) const
336     {
337         return !this->operator==(a);
338     }
339 
IsUninitializedRectDMRect340     bool IsUninitializedRect() const
341     {
342         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
343     }
344 
IsInsideOfDMRect345     bool IsInsideOf(const DMRect& a) const
346     {
347         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
348             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
349     }
NONEDMRect350     static DMRect NONE()
351     {
352         return {0, 0, 0, 0};
353     }
354 };
355 }
356 }
357 #endif // OHOS_ROSEN_DM_COMMON_H
358