• 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 enum class PowerStateChangeReason : uint32_t {
38     POWER_BUTTON,
39 };
40 
41 enum class ScreenPowerState : uint32_t {
42     POWER_ON,
43     POWER_STAND_BY,
44     POWER_SUSPEND,
45     POWER_OFF,
46     POWER_BUTT,
47     INVALID_STATE,
48 };
49 
50 enum class DisplayState : uint32_t {
51     ON,
52     OFF,
53     UNKNOWN,
54 };
55 
56 enum class DisplayEvent : uint32_t {
57     UNLOCK,
58     KEYGUARD_DRAWN,
59 };
60 
61 enum class DMError : int32_t {
62     DM_OK = 0,
63     DM_ERROR_INIT_DMS_PROXY_LOCKED = 100,
64     DM_ERROR_IPC_FAILED = 101,
65     DM_ERROR_REMOTE_CREATE_FAILED = 110,
66     DM_ERROR_NULLPTR = 120,
67     DM_ERROR_INVALID_PARAM = 130,
68     DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140,
69     DM_ERROR_DEATH_RECIPIENT = 150,
70     DM_ERROR_INVALID_MODE_ID = 160,
71     DM_ERROR_WRITE_DATA_FAILED = 170,
72     DM_ERROR_RENDER_SERVICE_FAILED = 180,
73     DM_ERROR_UNREGISTER_AGENT_FAILED = 190,
74     DM_ERROR_INVALID_CALLING = 200,
75     DM_ERROR_INVALID_PERMISSION = 201,
76     DM_ERROR_UNKNOWN = -1,
77 };
78 
79 enum class DmErrorCode : int32_t {
80     DM_OK = 0,
81     DM_ERROR_NO_PERMISSION = 201,
82     DM_ERROR_INVALID_PARAM = 401,
83     DM_ERROR_DEVICE_NOT_SUPPORT = 801,
84     DM_ERROR_INVALID_SCREEN = 1400001,
85     DM_ERROR_INVALID_CALLING = 1400002,
86     DM_ERROR_SYSTEM_INNORMAL = 1400003,
87 };
88 
89 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP {
90     {DMError::DM_OK,                                    DmErrorCode::DM_OK                          },
91     {DMError::DM_ERROR_INVALID_PERMISSION,              DmErrorCode::DM_ERROR_NO_PERMISSION         },
92     {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
93     {DMError::DM_ERROR_IPC_FAILED,                      DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
94     {DMError::DM_ERROR_REMOTE_CREATE_FAILED,            DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
95     {DMError::DM_ERROR_NULLPTR,                         DmErrorCode::DM_ERROR_INVALID_SCREEN        },
96     {DMError::DM_ERROR_INVALID_PARAM,                   DmErrorCode::DM_ERROR_INVALID_PARAM         },
97     {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED,    DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
98     {DMError::DM_ERROR_DEATH_RECIPIENT,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
99     {DMError::DM_ERROR_INVALID_MODE_ID,                 DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
100     {DMError::DM_ERROR_WRITE_DATA_FAILED,               DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
101     {DMError::DM_ERROR_RENDER_SERVICE_FAILED,           DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
102     {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED,         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
103     {DMError::DM_ERROR_INVALID_CALLING,                 DmErrorCode::DM_ERROR_INVALID_CALLING       },
104     {DMError::DM_ERROR_UNKNOWN,                         DmErrorCode::DM_ERROR_SYSTEM_INNORMAL       },
105 };
106 
107 using DisplayStateCallback = std::function<void(DisplayState)>;
108 
109 enum class DisplayPowerEvent : uint32_t {
110     WAKE_UP,
111     SLEEP,
112     DISPLAY_ON,
113     DISPLAY_OFF,
114     DESKTOP_READY,
115 };
116 
117 enum class EventStatus : uint32_t {
118     BEGIN,
119     END,
120 };
121 
122 class IDisplayPowerEventListener : public RefBase {
123 public:
124     virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0;
125 };
126 
127 enum class ScreenChangeEvent : uint32_t {
128     UPDATE_ORIENTATION,
129     UPDATE_ROTATION,
130     CHANGE_MODE,
131     VIRTUAL_PIXEL_RATIO_CHANGED,
132 };
133 
134 enum class ScreenGroupChangeEvent : uint32_t {
135     ADD_TO_GROUP,
136     REMOVE_FROM_GROUP,
137     CHANGE_GROUP,
138 };
139 
140 enum class Rotation : uint32_t {
141     ROTATION_0,
142     ROTATION_90,
143     ROTATION_180,
144     ROTATION_270,
145 };
146 
147 enum class Orientation : uint32_t {
148     BEGIN = 0,
149     UNSPECIFIED = BEGIN,
150     VERTICAL = 1,
151     HORIZONTAL = 2,
152     REVERSE_VERTICAL = 3,
153     REVERSE_HORIZONTAL = 4,
154     SENSOR = 5,
155     SENSOR_VERTICAL = 6,
156     SENSOR_HORIZONTAL = 7,
157     AUTO_ROTATION_RESTRICTED = 8,
158     AUTO_ROTATION_PORTRAIT_RESTRICTED = 9,
159     AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10,
160     LOCKED = 11,
161     END = LOCKED,
162 };
163 
164 enum class DisplayChangeEvent : uint32_t {
165     UPDATE_ORIENTATION,
166     UPDATE_ROTATION,
167     DISPLAY_SIZE_CHANGED,
168     DISPLAY_FREEZED,
169     DISPLAY_UNFREEZED,
170     DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED,
171     UNKNOWN,
172 };
173 }
174 }
175 #endif // OHOS_ROSEN_DM_COMMON_H