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