• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 namespace OHOS {
24 namespace Rosen {
25 using DisplayId = uint64_t;
26 using ScreenId = uint64_t;
27 
28 namespace {
29 constexpr DisplayId DISPLAY_ID_INVALID = -1ULL;
30 constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
31 constexpr ScreenId SCREEN_ID_FAKE = 999;
32 constexpr DisplayId DISPLAY_ID_FAKE = 999;
33 constexpr ScreenId ERROR_ID_NOT_SYSTEM_APP = -202ULL;
34 constexpr int DOT_PER_INCH = 160;
35 const static std::string DEFAULT_SCREEN_NAME = "buildIn";
36 constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 1000;
37 constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
38 constexpr uint32_t BASELINE_DENSITY = 160;
39 constexpr uint32_t HALF_SCREEN_PARAM = 2;
40 }
41 
42 /**
43  * @struct HookInfo.
44  *
45  * @brief hook diaplayinfo deepending on the window size.
46  */
47 struct DMHookInfo {
48     uint32_t width_;
49     uint32_t height_;
50     float_t density_;
51     uint32_t rotation_;
52     bool enableHookRotation_;
53 };
54 
55 /**
56  * @brief Power state change reason.
57  */
58 enum class PowerStateChangeReason : uint32_t {
59     POWER_BUTTON = 0,
60     STATE_CHANGE_REASON_INIT = 0,
61     STATE_CHANGE_REASON_TIMEOUT = 1,
62     STATE_CHANGE_REASON_RUNNING_LOCK = 2,
63     STATE_CHANGE_REASON_BATTERY = 3,
64     STATE_CHANGE_REASON_THERMAL = 4,
65     STATE_CHANGE_REASON_WORK = 5,
66     STATE_CHANGE_REASON_SYSTEM = 6,
67     STATE_CHANGE_REASON_APPLICATION = 10,
68     STATE_CHANGE_REASON_SETTINGS = 11,
69     STATE_CHANGE_REASON_HARD_KEY = 12,
70     STATE_CHANGE_REASON_TOUCH = 13,
71     STATE_CHANGE_REASON_CABLE = 14,
72     STATE_CHANGE_REASON_SENSOR = 15,
73     STATE_CHANGE_REASON_LID = 16,
74     STATE_CHANGE_REASON_CAMERA = 17,
75     STATE_CHANGE_REASON_ACCESS = 18,
76     STATE_CHANGE_REASON_RESET = 19,
77     STATE_CHANGE_REASON_POWER_KEY = 20,
78     STATE_CHANGE_REASON_KEYBOARD = 21,
79     STATE_CHANGE_REASON_MOUSE = 22,
80     STATE_CHANGE_REASON_DOUBLE_CLICK = 23,
81     STATE_CHANGE_REASON_COLLABORATION = 24,
82     STATE_CHANGE_REASON_SWITCH = 25,
83     STATE_CHANGE_REASON_PRE_BRIGHT = 26,
84     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_SUCCESS = 27,
85     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_ON = 28,
86     STATE_CHANGE_REASON_PRE_BRIGHT_AUTH_FAIL_SCREEN_OFF = 29,
87     STATE_CHANGE_REASON_DISPLAY_SWITCH = 30,
88     STATE_CHANGE_REASON_PROXIMITY = 32,
89     STATE_CHANGE_REASON_AOD_SLIDING = 40,
90     STATE_CHANGE_REASON_PEN = 41,
91     STATE_CHANGE_REASON_SHUT_DOWN = 42,
92     STATE_CHANGE_REASON_SCREEN_CONNECT = 43,
93     STATE_CHANGE_REASON_HIBERNATE = 45,
94     STATE_CHANGE_REASON_EX_SCREEN_INIT = 46,
95     STATE_CHANGE_REASON_ABNORMAL_SCREEN_CONNECT = 47,
96     STATE_CHANGE_REASON_ROLLBACK_HIBERNATE = 48,
97     STATE_CHANGE_REASON_START_DREAM = 49,
98     STATE_CHANGE_REASON_END_DREAM = 50,
99     STATE_CHANGE_REASON_REMOTE = 100,
100     STATE_CHANGE_REASON_UNKNOWN = 1000,
101 };
102 
103 /**
104  * @brief Enumerates the state of the screen power.
105  */
106 enum class ScreenPowerState : uint32_t {
107     POWER_ON,
108     POWER_STAND_BY,
109     POWER_SUSPEND,
110     POWER_OFF,
111     POWER_BUTT,
112     INVALID_STATE,
113     POWER_DOZE,
114     POWER_DOZE_SUSPEND,
115 };
116 
117 enum class ScreenPropertyChangeType : uint32_t {
118     UNSPECIFIED = 0,
119     /* Screen connection. */
120     ROTATION_BEGIN,
121     /* Screen disconnection. */
122     ROTATION_END,
123     /* Only update screen rotation property info to DMS. */
124     ROTATION_UPDATE_PROPERTY_ONLY,
125     /* Only update screen rotation property info not notify. */
126     ROTATION_UPDATE_PROPERTY_ONLY_NOT_NOTIFY,
127     /* Switch single hand mode. */
128     SINGLE_HAND_SWITCH,
129     /* Undefined. */
130     UNDEFINED,
131 };
132 
133 /**
134  * @brief Enumerates screen shape.
135  */
136 enum class ScreenShape : uint32_t {
137     RECTANGLE = 0,
138     ROUND = 1,
139 };
140 
141 /**
142  * @brief displayed soure mode
143  */
144 enum class DisplaySourceMode : uint32_t {
145     NONE = 0,
146     MAIN = 1,
147     MIRROR = 2,
148     EXTEND = 3,
149     ALONE = 4,
150 };
151 
152 /**
153  * @brief Enumerates the state of the display.
154  */
155 enum class DisplayState : uint32_t {
156     UNKNOWN,
157     OFF,
158     ON,
159     DOZE,
160     DOZE_SUSPEND,
161     VR,
162     ON_SUSPEND,
163 };
164 
165 /**
166  * @brief Enumerates display events.
167  */
168 enum class DisplayEvent : uint32_t {
169     UNLOCK,
170     KEYGUARD_DRAWN,
171     SCREEN_LOCK_SUSPEND,
172     SCREEN_LOCK_OFF,
173     SCREEN_LOCK_FINGERPRINT,
174     SCREEN_LOCK_DOZE_FINISH,
175     SCREEN_LOCK_START_DREAM,
176     SCREEN_LOCK_END_DREAM,
177 };
178 
179 /**
180  * @brief Enumerates DMError.
181  */
182 enum class DMError : int32_t {
183     DM_OK = 0,
184     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
185     DM_ERROR_IPC_FAILED = 101,
186     DM_ERROR_REMOTE_CREATE_FAILED = 110,
187     DM_ERROR_NULLPTR = 120,
188     DM_ERROR_INVALID_PARAM = 130,
189     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
190     DM_ERROR_DEATH_RECIPIENT = 150,
191     DM_ERROR_INVALID_MODE_ID = 160,
192     DM_ERROR_WRITE_DATA_FAILED = 170,
193     DM_ERROR_RENDER_SERVICE_FAILED = 180,
194     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
195     DM_ERROR_INVALID_CALLING = 200,
196     DM_ERROR_INVALID_PERMISSION = 201,
197     DM_ERROR_NOT_SYSTEM_APP = 202,
198     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
199     DM_ERROR_UNKNOWN = -1,
200 };
201 
202 /**
203  * @brief Enumerates DM error codes.
204  */
205 enum class DmErrorCode : int32_t {
206     DM_OK = 0,
207     DM_ERROR_NO_PERMISSION = 201,
208     DM_ERROR_NOT_SYSTEM_APP = 202,
209     DM_ERROR_INVALID_PARAM = 401,
210     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
211     DM_ERROR_INVALID_SCREEN = 1400001,
212     DM_ERROR_INVALID_CALLING = 1400002,
213     DM_ERROR_SYSTEM_INNORMAL = 1400003,
214 };
215 
216 /**
217  * @brief Constructs the mapping of the DM errors to the DM error codes.
218  */
219 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
220     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
221     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
222     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
223     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
224     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
225     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
226     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
227     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
228     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
229     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
230     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
231     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
232     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
233     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
234     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DmErrorCode::DM_ERROR_NOT_SYSTEM_APP        },
235     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
236     {DMError::DM_ERROR_DEVICE_NOT_SUPPORT,              DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT    },
237 };
238 
239 using DisplayStateCallback = std::function<void(DisplayState)>;
240 
241 /**
242  * @brief Enumerates display power events.
243  */
244 enum class DisplayPowerEvent : uint32_t {
245     WAKE_UP,
246     SLEEP,
247     DISPLAY_ON,
248     DISPLAY_OFF,
249     DESKTOP_READY,
250     DISPLAY_DOZE,
251     DISPLAY_DOZE_SUSPEND,
252     DISPLAY_OFF_CANCELED,
253     DISPLAY_START_DREAM,
254     DISPLAY_END_DREAM,
255 };
256 
257 /**
258  * @brief Enumerates event status.
259  */
260 enum class EventStatus : uint32_t {
261     BEGIN,
262     END,
263 };
264 
265 enum class VirtualScreenFlag : uint32_t {
266     DEFAULT = 0,
267     CAST = 1,
268     MAX = 2,
269 };
270 
271 class IDisplayPowerEventListener : public RefBase {
272 public:
273     /**
274      * @brief Notify when display power event status changed.
275      */
276     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
277 };
278 
279 /**
280  * @brief Enumerates screen change events.
281  */
282 enum class ScreenChangeEvent : uint32_t {
283     UPDATE_ORIENTATION,
284     UPDATE_ROTATION,
285     CHANGE_MODE,
286     VIRTUAL_PIXEL_RATIO_CHANGED,
287     SCREEN_SOURCE_MODE_CHANGE,
288     SCREEN_SWITCH_CHANGE,
289     UNKNOWN,
290 };
291 
292 /**
293  * @brief Enumerates screen group change events.
294  */
295 enum class ScreenGroupChangeEvent : uint32_t {
296     ADD_TO_GROUP,
297     REMOVE_FROM_GROUP,
298     CHANGE_GROUP,
299 };
300 
301 /**
302  * @brief Enumerates rotations.
303  */
304 enum class Rotation : uint32_t {
305     ROTATION_0,
306     ROTATION_90,
307     ROTATION_180,
308     ROTATION_270,
309 };
310 
311 /**
312  * @brief Enumerates orientations.
313  */
314 enum class Orientation : uint32_t {
315     BEGIN = 0,
316     UNSPECIFIED = BEGIN,
317     VERTICAL = 1,
318     HORIZONTAL = 2,
319     REVERSE_VERTICAL = 3,
320     REVERSE_HORIZONTAL = 4,
321     SENSOR = 5,
322     SENSOR_VERTICAL = 6,
323     SENSOR_HORIZONTAL = 7,
324     AUTO_ROTATION_RESTRICTED = 8,
325     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
326     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
327     LOCKED = 11,
328     FOLLOW_RECENT = 12,
329     AUTO_ROTATION_UNSPECIFIED = 13,
330     USER_ROTATION_PORTRAIT = 14,
331     USER_ROTATION_LANDSCAPE = 15,
332     USER_ROTATION_PORTRAIT_INVERTED = 16,
333     USER_ROTATION_LANDSCAPE_INVERTED = 17,
334     FOLLOW_DESKTOP = 18,
335     END = FOLLOW_DESKTOP,
336 };
337 
338 /**
339  * @brief Enumerates display orientations.
340  */
341 enum class DisplayOrientation : uint32_t {
342     PORTRAIT = 0,
343     LANDSCAPE,
344     PORTRAIT_INVERTED,
345     LANDSCAPE_INVERTED,
346     UNKNOWN,
347 };
348 
349 /**
350  * @brief Enumerates display change events.
351  */
352 enum class DisplayChangeEvent : uint32_t {
353     UPDATE_ORIENTATION,
354     UPDATE_ROTATION,
355     DISPLAY_SIZE_CHANGED,
356     DISPLAY_FREEZED,
357     DISPLAY_UNFREEZED,
358     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
359     UPDATE_ORIENTATION_FROM_WINDOW,
360     UPDATE_ROTATION_FROM_WINDOW,
361     UPDATE_REFRESHRATE,
362     SUPER_FOLD_RESOLUTION_CHANGED,
363     UNKNOWN,
364 };
365 
366 /**
367  * @brief Enumerates display state change type.
368  */
369 enum class DisplayStateChangeType : uint32_t {
370     BEFORE_SUSPEND,
371     BEFORE_UNLOCK,
372     UPDATE_ROTATION,
373     UPDATE_ROTATION_FROM_WINDOW,
374     SIZE_CHANGE,
375     CREATE,
376     DESTROY,
377     FREEZE,
378     UNFREEZE,
379     VIRTUAL_PIXEL_RATIO_CHANGE,
380     DISPLAY_COMPRESS,
381     UPDATE_SCALE,
382     UNKNOWN,
383     RESOLUTION_CHANGE,
384 };
385 
386 /**
387  * @brief Enumerates screen source mode.
388  */
389 enum class ScreenSourceMode: uint32_t {
390     SCREEN_MAIN = 0,
391     SCREEN_MIRROR = 1,
392     SCREEN_EXTEND = 2,
393     SCREEN_ALONE = 3,
394     SCREEN_UNIQUE = 4,
395 };
396 
397 /**
398  * @brief Enumerates the fold status.
399  */
400 enum class FoldStatus: uint32_t {
401     UNKNOWN = 0,
402     EXPAND = 1,
403     FOLDED = 2,
404     HALF_FOLD = 3,
405     FOLD_STATE_EXPAND_WITH_SECOND_EXPAND = 11,
406     FOLD_STATE_EXPAND_WITH_SECOND_HALF_FOLDED = 21,
407     FOLD_STATE_FOLDED_WITH_SECOND_EXPAND = 12,
408     FOLD_STATE_FOLDED_WITH_SECOND_HALF_FOLDED = 22,
409     FOLD_STATE_HALF_FOLDED_WITH_SECOND_EXPAND = 13,
410     FOLD_STATE_HALF_FOLDED_WITH_SECOND_HALF_FOLDED = 23,
411 };
412 
413 /**
414  * @brief Enumerates the super fold state change events.
415  */
416 enum class SuperFoldStatusChangeEvents : uint32_t {
417     UNDEFINED = 0,
418     ANGLE_CHANGE_EXPANDED,
419     ANGLE_CHANGE_HALF_FOLDED,
420     ANGLE_CHANGE_FOLDED,
421     KEYBOARD_ON,
422     KEYBOARD_OFF,
423     SYSTEM_KEYBOARD_ON,
424     SYSTEM_KEYBOARD_OFF,
425     INVALID,
426 };
427 
428 /**
429  * @brief Enumerates the super fold state.
430  */
431 enum class SuperFoldStatus : uint32_t {
432     UNKNOWN,
433     FOLDED,
434     HALF_FOLDED,
435     EXPANDED,
436     KEYBOARD,
437 };
438 
439 /**
440  * @brief Enumerates the extend screen connect status.
441  */
442 enum class ExtendScreenConnectStatus: uint32_t {
443     UNKNOWN = 0,
444     CONNECT,
445     DISCONNECT,
446 };
447 
448 /**
449  * @brief Enumerates the fold display mode.
450  */
451 enum class FoldDisplayMode: uint32_t {
452     UNKNOWN = 0,
453     FULL = 1,
454     MAIN = 2,
455     SUB = 3,
456     COORDINATION = 4,
457     GLOBAL_FULL = 5,
458 };
459 
460 enum class DisplayType : uint32_t {
461     DEFAULT = 0,
462 };
463 
464 enum class ScreenCombination : uint32_t {
465     SCREEN_ALONE,
466     SCREEN_EXPAND,
467     SCREEN_MIRROR,
468     SCREEN_UNIQUE,
469     SCREEN_EXTEND,
470     SCREEN_MAIN,
471 };
472 
473 enum class MultiScreenMode : uint32_t {
474     SCREEN_MIRROR = 0,
475     SCREEN_EXTEND = 1,
476 };
477 
478 /**
479  * @brief Enumerates the low temp mode.
480  */
481 enum class LowTempMode: int32_t {
482     UNKNOWN = -1,
483     LOW_TEMP_OFF = 0,
484     LOW_TEMP_ON = 1,
485 };
486 
487 /**
488  * @brief Enumerates the virtual screen type.
489  */
490 enum class VirtualScreenType: uint32_t {
491     UNKNOWN = 0,
492     SCREEN_CASTING,
493     SCREEN_RECORDING,
494     SUPER_DESKTOP,
495     HICAR,
496 };
497 
498 struct Point {
499     int32_t posX_;
500     int32_t posY_;
PointPoint501     Point() : posX_(0), posY_(0) {};
PointPoint502     Point(int32_t posX, int32_t posY) : posX_(posX), posY_(posY) {};
503 };
504 
505 struct SupportedScreenModes : public RefBase {
506     uint32_t id_;
507     uint32_t width_;
508     uint32_t height_;
509     uint32_t refreshRate_;
510 };
511 
512 struct CaptureOption {
513     DisplayId displayId_ = DISPLAY_ID_INVALID;
514     bool isNeedNotify_ = true;
515     bool isNeedPointer_ = true;
516 };
517 
518 struct ExpandOption {
519     ScreenId screenId_;
520     uint32_t startX_;
521     uint32_t startY_;
522 };
523 
524 struct MultiScreenRecoverOption {
525     ScreenId screenId_;
526     uint32_t first_;
527     uint32_t second_;
528 };
529 
530 struct MultiScreenPositionOptions {
531     ScreenId screenId_;
532     uint32_t startX_;
533     uint32_t startY_;
534 };
535 
536 /**
537  * @brief fold display physical resolution
538  */
539 struct DisplayPhysicalResolution {
540     FoldDisplayMode foldDisplayMode_;
541     uint32_t physicalWidth_;
542     uint32_t physicalHeight_;
543 };
544 
545 /**
546  * @brief scrollable param
547  */
548 struct ScrollableParam {
549     std::string velocityScale_;
550     std::string friction_;
551 };
552 
553 /**
554  * @brief screen direction info
555  */
556 struct ScreenDirectionInfo {
557     int32_t notifyRotation_;
558     int32_t screenRotation_;
559     int32_t rotation_;
560     int32_t phyRotation_;
561 };
562 
563 /**
564  * @brief displayRect
565  */
566 struct DMRect {
567     int32_t posX_;
568     int32_t posY_;
569     uint32_t width_;
570     uint32_t height_;
571 
572     bool operator==(const DMRect& a) const
573     {
574         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
575     }
576 
577     bool operator!=(const DMRect& a) const
578     {
579         return !this->operator==(a);
580     }
581 
IsUninitializedRectDMRect582     bool IsUninitializedRect() const
583     {
584         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
585     }
586 
IsInsideOfDMRect587     bool IsInsideOf(const DMRect& a) const
588     {
589         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
590             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
591     }
NONEDMRect592     static DMRect NONE()
593     {
594         return {0, 0, 0, 0};
595     }
596 };
597 
598 /**
599  * @brief Session option when connect
600  */
601 struct SessionOption {
602     ScreenId rsId_;
603     std::string name_;
604     bool isExtend_;
605     std::string innerName_;
606     ScreenId screenId_;
607 };
608 }
609 }
610 #endif // OHOS_ROSEN_DM_COMMON_H
611