• 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 namespace {
28     constexpr DisplayId DISPLAY_ID_INVALID = -1ULL;
29     constexpr ScreenId SCREEN_ID_INVALID = -1ULL;
30     constexpr int DOT_PER_INCH = 160;
31     const static std::string DEFAULT_SCREEN_NAME = "buildIn";
32     constexpr int DOT_PER_INCH_MAXIMUM_VALUE = 640;
33     constexpr int DOT_PER_INCH_MINIMUM_VALUE = 80;
34     constexpr uint32_t BASELINE_DENSITY = 160;
35 }
36 
37 /**
38  * @brief Power state change reason.
39  */
40 enum class PowerStateChangeReason : uint32_t {
41     POWER_BUTTON = 0,
42     STATE_CHANGE_REASON_INIT = 0,
43     STATE_CHANGE_REASON_TIMEOUT = 1,
44     STATE_CHANGE_REASON_RUNNING_LOCK = 2,
45     STATE_CHANGE_REASON_BATTERY = 3,
46     STATE_CHANGE_REASON_THERMAL = 4,
47     STATE_CHANGE_REASON_WORK = 5,
48     STATE_CHANGE_REASON_SYSTEM = 6,
49     STATE_CHANGE_REASON_APPLICATION = 10,
50     STATE_CHANGE_REASON_SETTINGS = 11,
51     STATE_CHANGE_REASON_HARD_KEY = 12,
52     STATE_CHANGE_REASON_TOUCH = 13,
53     STATE_CHANGE_REASON_CABLE = 14,
54     STATE_CHANGE_REASON_SENSOR = 15,
55     STATE_CHANGE_REASON_LID = 16,
56     STATE_CHANGE_REASON_CAMERA = 17,
57     STATE_CHANGE_REASON_ACCESS = 18,
58     STATE_CHANGE_REASON_RESET = 19,
59     STATE_CHANGE_REASON_POWER_KEY = 20,
60     STATE_CHANGE_REASON_KEYBOARD = 21,
61     STATE_CHANGE_REASON_MOUSE = 22,
62     STATE_CHANGE_REASON_DOUBLE_CLICK = 23,
63     STATE_CHANGE_REASON_COLLABORATION = 24,
64     STATE_CHANGE_REASON_REMOTE = 100,
65     STATE_CHANGE_REASON_UNKNOWN = 1000,
66 };
67 
68 /**
69  * @brief Enumerates the state of the screen power.
70  */
71 enum class ScreenPowerState : uint32_t {
72     POWER_ON,
73     POWER_STAND_BY,
74     POWER_SUSPEND,
75     POWER_OFF,
76     POWER_BUTT,
77     INVALID_STATE,
78 };
79 
80 /**
81  * @brief Enumerates the state of the display.
82  */
83 enum class DisplayState : uint32_t {
84     UNKNOWN,
85     OFF,
86     ON,
87     DOZE,
88     DOZE_SUSPEND,
89     VR,
90     ON_SUSPEND,
91 };
92 
93 /**
94  * @brief Enumerates display events.
95  */
96 enum class DisplayEvent : uint32_t {
97     UNLOCK,
98     KEYGUARD_DRAWN,
99     SCREEN_LOCK_SUSPEND,
100     SCREEN_LOCK_OFF,
101 };
102 
103 /**
104  * @brief Enumerates DMError.
105  */
106 enum class DMError : int32_t {
107     DM_OK = 0,
108     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
109     DM_ERROR_IPC_FAILED = 101,
110     DM_ERROR_REMOTE_CREATE_FAILED = 110,
111     DM_ERROR_NULLPTR = 120,
112     DM_ERROR_INVALID_PARAM = 130,
113     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
114     DM_ERROR_DEATH_RECIPIENT = 150,
115     DM_ERROR_INVALID_MODE_ID = 160,
116     DM_ERROR_WRITE_DATA_FAILED = 170,
117     DM_ERROR_RENDER_SERVICE_FAILED = 180,
118     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
119     DM_ERROR_INVALID_CALLING = 200,
120     DM_ERROR_INVALID_PERMISSION = 201,
121     DM_ERROR_NOT_SYSTEM_APP = 202,
122     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
123     DM_ERROR_UNKNOWN = -1,
124 };
125 
126 /**
127  * @brief Enumerates DM error codes.
128  */
129 enum class DmErrorCode : int32_t {
130     DM_OK = 0,
131     DM_ERROR_NO_PERMISSION = 201,
132     DM_ERROR_NOT_SYSTEM_APP = 202,
133     DM_ERROR_INVALID_PARAM = 401,
134     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
135     DM_ERROR_INVALID_SCREEN = 1400001,
136     DM_ERROR_INVALID_CALLING = 1400002,
137     DM_ERROR_SYSTEM_INNORMAL = 1400003,
138 };
139 
140 /**
141  * @brief Constructs the mapping of the DM errors to the DM error codes.
142  */
143 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
144     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
145     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
146     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
147     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
148     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
149     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
150     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
151     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
152     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
153     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
154     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
155     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
156     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
157     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
158     {DMError::DM_ERROR_NOT_SYSTEM_APP,                  DmErrorCode::DM_ERROR_NOT_SYSTEM_APP        },
159     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
160     {DMError::DM_ERROR_DEVICE_NOT_SUPPORT,              DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT    },
161 };
162 
163 using DisplayStateCallback = std::function<void(DisplayState)>;
164 
165 /**
166  * @brief Enumerates display power events.
167  */
168 enum class DisplayPowerEvent : uint32_t {
169     WAKE_UP,
170     SLEEP,
171     DISPLAY_ON,
172     DISPLAY_OFF,
173     DESKTOP_READY,
174 };
175 
176 /**
177  * @brief Enumerates event status.
178  */
179 enum class EventStatus : uint32_t {
180     BEGIN,
181     END,
182 };
183 
184 class IDisplayPowerEventListener : public RefBase {
185 public:
186     /**
187      * @brief Notify when display power event status changed.
188      */
189     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
190 };
191 
192 /**
193  * @brief Enumerates screen change events.
194  */
195 enum class ScreenChangeEvent : uint32_t {
196     UPDATE_ORIENTATION,
197     UPDATE_ROTATION,
198     CHANGE_MODE,
199     VIRTUAL_PIXEL_RATIO_CHANGED,
200 };
201 
202 /**
203  * @brief Enumerates screen group change events.
204  */
205 enum class ScreenGroupChangeEvent : uint32_t {
206     ADD_TO_GROUP,
207     REMOVE_FROM_GROUP,
208     CHANGE_GROUP,
209 };
210 
211 /**
212  * @brief Enumerates refreshrate modes.
213  */
214 enum class RefreshRateMode : int32_t {
215     SMART = -1,
216     NORMAL = 1,
217     MIDDLE = 2,
218     HIGH = 3,
219 };
220 
221 /**
222  * @brief Enumerates refreshrates.
223  */
224 enum class RefreshRate : uint32_t {
225     NORMAL = 60,
226     MIDDLE = 90,
227     HIGH = 120,
228 };
229 
230 /**
231  * @brief Enumerates rotations.
232  */
233 enum class Rotation : uint32_t {
234     ROTATION_0,
235     ROTATION_90,
236     ROTATION_180,
237     ROTATION_270,
238 };
239 
240 /**
241  * @brief Enumerates orientations.
242  */
243 enum class Orientation : uint32_t {
244     BEGIN = 0,
245     UNSPECIFIED = BEGIN,
246     VERTICAL = 1,
247     HORIZONTAL = 2,
248     REVERSE_VERTICAL = 3,
249     REVERSE_HORIZONTAL = 4,
250     SENSOR = 5,
251     SENSOR_VERTICAL = 6,
252     SENSOR_HORIZONTAL = 7,
253     AUTO_ROTATION_RESTRICTED = 8,
254     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
255     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
256     LOCKED = 11,
257     END = LOCKED,
258 };
259 
260 /**
261  * @brief Enumerates display orientations.
262  */
263 enum class DisplayOrientation : uint32_t {
264     PORTRAIT = 0,
265     LANDSCAPE,
266     PORTRAIT_INVERTED,
267     LANDSCAPE_INVERTED,
268     UNKNOWN,
269 };
270 
271 /**
272  * @brief Enumerates display change events.
273  */
274 enum class DisplayChangeEvent : uint32_t {
275     UPDATE_ORIENTATION,
276     UPDATE_ROTATION,
277     DISPLAY_SIZE_CHANGED,
278     DISPLAY_FREEZED,
279     DISPLAY_UNFREEZED,
280     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
281     UPDATE_ORIENTATION_FROM_WINDOW,
282     UPDATE_ROTATION_FROM_WINDOW,
283     UNKNOWN,
284 };
285 
286 /**
287  * @brief Enumerates display state change type.
288  */
289 enum class DisplayStateChangeType : uint32_t {
290     BEFORE_SUSPEND,
291     BEFORE_UNLOCK,
292     UPDATE_ROTATION,
293     UPDATE_ROTATION_FROM_WINDOW,
294     SIZE_CHANGE,
295     CREATE,
296     DESTROY,
297     FREEZE,
298     UNFREEZE,
299     VIRTUAL_PIXEL_RATIO_CHANGE,
300     DISPLAY_COMPRESS,
301     UNKNOWN,
302 };
303 
304 /**
305  * @brief Enumerates screen source mode.
306  */
307 enum class ScreenSourceMode: uint32_t {
308     SCREEN_MAIN = 0,
309     SCREEN_MIRROR = 1,
310     SCREEN_EXTEND = 2,
311     SCREEN_ALONE = 3,
312 };
313 
314 /**
315  * @brief Enumerates the fold status.
316  */
317 enum class FoldStatus: uint32_t {
318     UNKNOWN = 0,
319     EXPAND = 1,
320     FOLDED = 2,
321     HALF_FOLD = 3,
322 };
323 
324 /**
325  * @brief Enumerates the fold display mode.
326  */
327 enum class FoldDisplayMode: uint32_t {
328     UNKNOWN = 0,
329     FULL = 1,
330     MAIN = 2,
331     SUB = 3,
332     COORDINATION = 4,
333 };
334 
335 enum class DisplayType : uint32_t {
336     DEFAULT = 0,
337 };
338 
339 enum class ScreenCombination : uint32_t {
340     SCREEN_ALONE,
341     SCREEN_EXPAND,
342     SCREEN_MIRROR,
343     SCREEN_UNIQUE,
344 };
345 
346 struct Point {
347     int32_t posX_;
348     int32_t posY_;
PointPoint349     Point() : posX_(0), posY_(0) {};
PointPoint350     Point(int32_t posX, int32_t posY) : posX_(posX), posY_(posY) {};
351 };
352 
353 struct SupportedScreenModes : public RefBase {
354     uint32_t id_;
355     uint32_t width_;
356     uint32_t height_;
357     uint32_t refreshRate_;
358 };
359 
360 struct ExpandOption {
361     ScreenId screenId_;
362     uint32_t startX_;
363     uint32_t startY_;
364 };
365 
366 /**
367  * @brief displayRect
368  */
369 struct DMRect {
370     int32_t posX_;
371     int32_t posY_;
372     uint32_t width_;
373     uint32_t height_;
374 
375     bool operator==(const DMRect& a) const
376     {
377         return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_);
378     }
379 
380     bool operator!=(const DMRect& a) const
381     {
382         return !this->operator==(a);
383     }
384 
IsUninitializedRectDMRect385     bool IsUninitializedRect() const
386     {
387         return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0);
388     }
389 
IsInsideOfDMRect390     bool IsInsideOf(const DMRect& a) const
391     {
392         return (posX_ >= a.posX_ && posY_ >= a.posY_ &&
393             posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_);
394     }
NONEDMRect395     static DMRect NONE()
396     {
397         return {0, 0, 0, 0};
398     }
399 };
400 }
401 }
402 #endif // OHOS_ROSEN_DM_COMMON_H
403