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