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_HIBERNATE = 45, 90 STATE_CHANGE_REASON_REMOTE = 100, 91 STATE_CHANGE_REASON_UNKNOWN = 1000, 92 }; 93 94 /** 95 * @brief Enumerates the state of the screen power. 96 */ 97 enum class ScreenPowerState : uint32_t { 98 POWER_ON, 99 POWER_STAND_BY, 100 POWER_SUSPEND, 101 POWER_OFF, 102 POWER_BUTT, 103 INVALID_STATE, 104 }; 105 106 enum class ScreenPropertyChangeType : uint32_t { 107 UNSPECIFIED = 0, 108 /* Screen connection. */ 109 ROTATION_BEGIN, 110 /* Screen disconnection. */ 111 ROTATION_END, 112 /* Only update screen rotation property info to DMS. */ 113 ROTATION_UPDATE_PROPERTY_ONLY, 114 /* Only update screen rotation property info not notify. */ 115 ROTATION_UPDATE_PROPERTY_ONLY_NOT_NOTIFY, 116 /* Switch single hand mode. */ 117 SINGLE_HAND_SWITCH, 118 /* Undefined. */ 119 UNDEFINED, 120 }; 121 122 /** 123 * @brief Enumerates the state of the display. 124 */ 125 enum class DisplayState : uint32_t { 126 UNKNOWN, 127 OFF, 128 ON, 129 DOZE, 130 DOZE_SUSPEND, 131 VR, 132 ON_SUSPEND, 133 }; 134 135 /** 136 * @brief Enumerates display events. 137 */ 138 enum class DisplayEvent : uint32_t { 139 UNLOCK, 140 KEYGUARD_DRAWN, 141 SCREEN_LOCK_SUSPEND, 142 SCREEN_LOCK_OFF, 143 SCREEN_LOCK_FINGERPRINT, 144 }; 145 146 /** 147 * @brief Enumerates DMError. 148 */ 149 enum class DMError : int32_t { 150 DM_OK = 0, 151 DM_ERROR_INIT_DMS_PROXY_LOCKED = 100, 152 DM_ERROR_IPC_FAILED = 101, 153 DM_ERROR_REMOTE_CREATE_FAILED = 110, 154 DM_ERROR_NULLPTR = 120, 155 DM_ERROR_INVALID_PARAM = 130, 156 DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED = 140, 157 DM_ERROR_DEATH_RECIPIENT = 150, 158 DM_ERROR_INVALID_MODE_ID = 160, 159 DM_ERROR_WRITE_DATA_FAILED = 170, 160 DM_ERROR_RENDER_SERVICE_FAILED = 180, 161 DM_ERROR_UNREGISTER_AGENT_FAILED = 190, 162 DM_ERROR_INVALID_CALLING = 200, 163 DM_ERROR_INVALID_PERMISSION = 201, 164 DM_ERROR_NOT_SYSTEM_APP = 202, 165 DM_ERROR_DEVICE_NOT_SUPPORT = 801, 166 DM_ERROR_UNKNOWN = -1, 167 }; 168 169 /** 170 * @brief Enumerates DM error codes. 171 */ 172 enum class DmErrorCode : int32_t { 173 DM_OK = 0, 174 DM_ERROR_NO_PERMISSION = 201, 175 DM_ERROR_NOT_SYSTEM_APP = 202, 176 DM_ERROR_INVALID_PARAM = 401, 177 DM_ERROR_DEVICE_NOT_SUPPORT = 801, 178 DM_ERROR_INVALID_SCREEN = 1400001, 179 DM_ERROR_INVALID_CALLING = 1400002, 180 DM_ERROR_SYSTEM_INNORMAL = 1400003, 181 }; 182 183 /** 184 * @brief Constructs the mapping of the DM errors to the DM error codes. 185 */ 186 const std::map<DMError, DmErrorCode> DM_JS_TO_ERROR_CODE_MAP { 187 {DMError::DM_OK, DmErrorCode::DM_OK }, 188 {DMError::DM_ERROR_INVALID_PERMISSION, DmErrorCode::DM_ERROR_NO_PERMISSION }, 189 {DMError::DM_ERROR_INIT_DMS_PROXY_LOCKED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 190 {DMError::DM_ERROR_IPC_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 191 {DMError::DM_ERROR_REMOTE_CREATE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 192 {DMError::DM_ERROR_NULLPTR, DmErrorCode::DM_ERROR_INVALID_SCREEN }, 193 {DMError::DM_ERROR_INVALID_PARAM, DmErrorCode::DM_ERROR_INVALID_PARAM }, 194 {DMError::DM_ERROR_WRITE_INTERFACE_TOKEN_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 195 {DMError::DM_ERROR_DEATH_RECIPIENT, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 196 {DMError::DM_ERROR_INVALID_MODE_ID, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 197 {DMError::DM_ERROR_WRITE_DATA_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 198 {DMError::DM_ERROR_RENDER_SERVICE_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 199 {DMError::DM_ERROR_UNREGISTER_AGENT_FAILED, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 200 {DMError::DM_ERROR_INVALID_CALLING, DmErrorCode::DM_ERROR_INVALID_CALLING }, 201 {DMError::DM_ERROR_NOT_SYSTEM_APP, DmErrorCode::DM_ERROR_NOT_SYSTEM_APP }, 202 {DMError::DM_ERROR_UNKNOWN, DmErrorCode::DM_ERROR_SYSTEM_INNORMAL }, 203 {DMError::DM_ERROR_DEVICE_NOT_SUPPORT, DmErrorCode::DM_ERROR_DEVICE_NOT_SUPPORT }, 204 }; 205 206 using DisplayStateCallback = std::function<void(DisplayState)>; 207 208 /** 209 * @brief Enumerates display power events. 210 */ 211 enum class DisplayPowerEvent : uint32_t { 212 WAKE_UP, 213 SLEEP, 214 DISPLAY_ON, 215 DISPLAY_OFF, 216 DESKTOP_READY, 217 DOZE, 218 DOZE_SUSPEND, 219 DISPLAY_OFF_CANCELED, 220 }; 221 222 /** 223 * @brief Enumerates event status. 224 */ 225 enum class EventStatus : uint32_t { 226 BEGIN, 227 END, 228 }; 229 230 enum class VirtualScreenFlag : uint32_t { 231 DEFAULT = 0, 232 CAST = 1, 233 MAX = 2, 234 }; 235 236 class IDisplayPowerEventListener : public RefBase { 237 public: 238 /** 239 * @brief Notify when display power event status changed. 240 */ 241 virtual void OnDisplayPowerEvent(DisplayPowerEvent event, EventStatus status) = 0; 242 }; 243 244 /** 245 * @brief Enumerates screen change events. 246 */ 247 enum class ScreenChangeEvent : uint32_t { 248 UPDATE_ORIENTATION, 249 UPDATE_ROTATION, 250 CHANGE_MODE, 251 VIRTUAL_PIXEL_RATIO_CHANGED, 252 SCREEN_SWITCH_CHANGE, 253 UNKNOWN, 254 }; 255 256 /** 257 * @brief Enumerates screen group change events. 258 */ 259 enum class ScreenGroupChangeEvent : uint32_t { 260 ADD_TO_GROUP, 261 REMOVE_FROM_GROUP, 262 CHANGE_GROUP, 263 }; 264 265 /** 266 * @brief Enumerates rotations. 267 */ 268 enum class Rotation : uint32_t { 269 ROTATION_0, 270 ROTATION_90, 271 ROTATION_180, 272 ROTATION_270, 273 }; 274 275 /** 276 * @brief Enumerates orientations. 277 */ 278 enum class Orientation : uint32_t { 279 BEGIN = 0, 280 UNSPECIFIED = BEGIN, 281 VERTICAL = 1, 282 HORIZONTAL = 2, 283 REVERSE_VERTICAL = 3, 284 REVERSE_HORIZONTAL = 4, 285 SENSOR = 5, 286 SENSOR_VERTICAL = 6, 287 SENSOR_HORIZONTAL = 7, 288 AUTO_ROTATION_RESTRICTED = 8, 289 AUTO_ROTATION_PORTRAIT_RESTRICTED = 9, 290 AUTO_ROTATION_LANDSCAPE_RESTRICTED = 10, 291 LOCKED = 11, 292 FOLLOW_RECENT = 12, 293 AUTO_ROTATION_UNSPECIFIED = 13, 294 USER_ROTATION_PORTRAIT = 14, 295 USER_ROTATION_LANDSCAPE = 15, 296 USER_ROTATION_PORTRAIT_INVERTED = 16, 297 USER_ROTATION_LANDSCAPE_INVERTED = 17, 298 FOLLOW_DESKTOP = 18, 299 END = FOLLOW_DESKTOP, 300 }; 301 302 /** 303 * @brief Enumerates display orientations. 304 */ 305 enum class DisplayOrientation : uint32_t { 306 PORTRAIT = 0, 307 LANDSCAPE, 308 PORTRAIT_INVERTED, 309 LANDSCAPE_INVERTED, 310 UNKNOWN, 311 }; 312 313 /** 314 * @brief Enumerates display change events. 315 */ 316 enum class DisplayChangeEvent : uint32_t { 317 UPDATE_ORIENTATION, 318 UPDATE_ROTATION, 319 DISPLAY_SIZE_CHANGED, 320 DISPLAY_FREEZED, 321 DISPLAY_UNFREEZED, 322 DISPLAY_VIRTUAL_PIXEL_RATIO_CHANGED, 323 UPDATE_ORIENTATION_FROM_WINDOW, 324 UPDATE_ROTATION_FROM_WINDOW, 325 UPDATE_REFRESHRATE, 326 UNKNOWN, 327 }; 328 329 /** 330 * @brief Enumerates display state change type. 331 */ 332 enum class DisplayStateChangeType : uint32_t { 333 BEFORE_SUSPEND, 334 BEFORE_UNLOCK, 335 UPDATE_ROTATION, 336 UPDATE_ROTATION_FROM_WINDOW, 337 SIZE_CHANGE, 338 CREATE, 339 DESTROY, 340 FREEZE, 341 UNFREEZE, 342 VIRTUAL_PIXEL_RATIO_CHANGE, 343 DISPLAY_COMPRESS, 344 UPDATE_SCALE, 345 UNKNOWN, 346 RESOLUTION_CHANGE, 347 }; 348 349 /** 350 * @brief Enumerates screen source mode. 351 */ 352 enum class ScreenSourceMode: uint32_t { 353 SCREEN_MAIN = 0, 354 SCREEN_MIRROR = 1, 355 SCREEN_EXTEND = 2, 356 SCREEN_ALONE = 3, 357 SCREEN_UNIQUE = 4, 358 }; 359 360 /** 361 * @brief Enumerates the fold status. 362 */ 363 enum class FoldStatus: uint32_t { 364 UNKNOWN = 0, 365 EXPAND = 1, 366 FOLDED = 2, 367 HALF_FOLD = 3, 368 FOLD_STATE_EXPAND_WITH_SECOND_EXPAND = 11, 369 FOLD_STATE_EXPAND_WITH_SECOND_HALF_FOLDED = 21, 370 FOLD_STATE_FOLDED_WITH_SECOND_EXPAND = 12, 371 FOLD_STATE_FOLDED_WITH_SECOND_HALF_FOLDED = 22, 372 FOLD_STATE_HALF_FOLDED_WITH_SECOND_EXPAND = 13, 373 FOLD_STATE_HALF_FOLDED_WITH_SECOND_HALF_FOLDED = 23, 374 }; 375 376 /** 377 * @brief Enumerates the fold display mode. 378 */ 379 enum class FoldDisplayMode: uint32_t { 380 UNKNOWN = 0, 381 FULL = 1, 382 MAIN = 2, 383 SUB = 3, 384 COORDINATION = 4, 385 GLOBAL_FULL = 5, 386 }; 387 388 enum class DisplayType : uint32_t { 389 DEFAULT = 0, 390 }; 391 392 enum class ScreenCombination : uint32_t { 393 SCREEN_ALONE, 394 SCREEN_EXPAND, 395 SCREEN_MIRROR, 396 SCREEN_UNIQUE, 397 SCREEN_MAIN, 398 }; 399 400 /** 401 * @brief Enumerates the virtual screen type. 402 */ 403 enum class VirtualScreenType: uint32_t { 404 UNKNOWN = 0, 405 SCREEN_CASTING, 406 SCREEN_RECORDING, 407 SUPER_DESKTOP, 408 HICAR, 409 }; 410 411 struct Point { 412 int32_t posX_; 413 int32_t posY_; PointPoint414 Point() : posX_(0), posY_(0) {}; PointPoint415 Point(int32_t posX, int32_t posY) : posX_(posX), posY_(posY) {}; 416 }; 417 418 struct SupportedScreenModes : public RefBase { 419 uint32_t id_; 420 uint32_t width_; 421 uint32_t height_; 422 uint32_t refreshRate_; 423 }; 424 425 struct CaptureOption { 426 DisplayId displayId_ = DISPLAY_ID_INVALID; 427 bool isNeedNotify_ = true; 428 bool isNeedPointer_ = true; 429 }; 430 431 struct ExpandOption { 432 ScreenId screenId_; 433 uint32_t startX_; 434 uint32_t startY_; 435 }; 436 437 /** 438 * @brief fold display physical resolution 439 */ 440 struct DisplayPhysicalResolution { 441 FoldDisplayMode foldDisplayMode_; 442 uint32_t physicalWidth_; 443 uint32_t physicalHeight_; 444 }; 445 446 /** 447 * @brief screen direction info 448 */ 449 struct ScreenDirectionInfo { 450 int32_t notifyRotation_; 451 int32_t screenRotation_; 452 int32_t rotation_; 453 int32_t phyRotation_; 454 }; 455 456 /** 457 * @brief scrollable param 458 */ 459 struct ScrollableParam { 460 std::string velocityScale_; 461 std::string friction_; 462 }; 463 464 /** 465 * @brief displayRect 466 */ 467 struct DMRect { 468 int32_t posX_; 469 int32_t posY_; 470 uint32_t width_; 471 uint32_t height_; 472 473 bool operator==(const DMRect& a) const 474 { 475 return (posX_ == a.posX_ && posY_ == a.posY_ && width_ == a.width_ && height_ == a.height_); 476 } 477 478 bool operator!=(const DMRect& a) const 479 { 480 return !this->operator==(a); 481 } 482 IsUninitializedRectDMRect483 bool IsUninitializedRect() const 484 { 485 return (posX_ == 0 && posY_ == 0 && width_ == 0 && height_ == 0); 486 } 487 IsInsideOfDMRect488 bool IsInsideOf(const DMRect& a) const 489 { 490 return (posX_ >= a.posX_ && posY_ >= a.posY_ && 491 posX_ + width_ <= a.posX_ + a.width_ && posY_ + height_ <= a.posY_ + a.height_); 492 } NONEDMRect493 static DMRect NONE() 494 { 495 return {0, 0, 0, 0}; 496 } 497 }; 498 } 499 } 500 #endif // OHOS_ROSEN_DM_COMMON_H 501