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