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 FOUNDATION_DM_SCREEN_MANAGER_H 17 #define FOUNDATION_DM_SCREEN_MANAGER_H 18 19 #include <refbase.h> 20 #include "screen.h" 21 #include "dm_common.h" 22 #include "screen_group.h" 23 #include "wm_single_instance.h" 24 #include "wm_single_instance.h" 25 #include <pixel_map.h> 26 27 namespace OHOS::Rosen { 28 class ScreenManager : public RefBase { 29 WM_DECLARE_SINGLE_INSTANCE_BASE(ScreenManager); 30 friend class DMSDeathRecipient; 31 public: 32 class IScreenListener : public virtual RefBase { 33 public: 34 /** 35 * @brief Notify when a new screen is connected. 36 */ 37 virtual void OnConnect(ScreenId) = 0; 38 39 /** 40 * @brief Notify when a screen is disconnected. 41 */ 42 virtual void OnDisconnect(ScreenId) = 0; 43 44 /** 45 * @brief Notify when state of the screen is changed. 46 */ 47 virtual void OnChange(ScreenId) = 0; 48 }; 49 50 class IScreenGroupListener : public virtual RefBase { 51 public: 52 /** 53 * @brief Notify when state of the screenGroup is changed. 54 */ 55 virtual void OnChange(const std::vector<ScreenId>&, ScreenGroupChangeEvent) = 0; 56 }; 57 58 class IVirtualScreenGroupListener : public virtual RefBase { 59 public: 60 struct ChangeInfo { 61 ScreenGroupChangeEvent event; 62 std::string trigger; 63 std::vector<ScreenId> ids; 64 }; 65 /** 66 * @brief Notify when an event related to screen mirror occurs. 67 * 68 * @param info Change info of screen mirror. 69 */ OnMirrorChange(const ChangeInfo & info)70 virtual void OnMirrorChange([[maybe_unused]]const ChangeInfo& info) {} 71 }; 72 73 /** 74 * @brief Get the screen object by screen id. 75 * 76 * @param screenId Screen id. 77 * @return Screen object. 78 */ 79 sptr<Screen> GetScreenById(ScreenId screenId); 80 81 /** 82 * @brief Get the screen group object by groupId. 83 * 84 * @param groupId Screen group id. 85 * @return ScreenGroup object. 86 */ 87 sptr<ScreenGroup> GetScreenGroup(ScreenId groupId); 88 89 /** 90 * @brief Get all screens object. 91 * 92 * @param screens All screen objects. 93 * @return DM_OK means get success, others means get failed. 94 */ 95 DMError GetAllScreens(std::vector<sptr<Screen>>& screens); 96 97 /** 98 * @brief Make screens as expand-screen. 99 * 100 * @param options Option of expand. 101 * @param screenGroupId Screen group id. 102 * @return DM_OK means make expand success, others means make expand failed. 103 */ 104 DMError MakeExpand(const std::vector<ExpandOption>& options, ScreenId& screenGroupId); 105 106 /** 107 * @brief Make screens as mirror-screen 108 * 109 * @param mainScreenId Main screen id. 110 * @param mirrorScreenId Mirror screen ids. 111 * @param screenGroupId Screen group id. 112 * @return DM_OK means make mirror success, others means make mirror failed. 113 */ 114 DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, ScreenId& screenGroupId); 115 116 /** 117 * @brief Make screens as mirror-screen 118 * 119 * @param mainScreenId Main screen id. 120 * @param mirrorScreenId Mirror screen ids. 121 * @param screenGroupId Screen group id. 122 * @return DM_OK means make mirror success, others means make mirror failed. 123 */ 124 DMError MakeMirrorForRecord(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, 125 ScreenId& screenGroupId); 126 127 /** 128 * @brief Make screen as mirror-screen for region of main screen. 129 * 130 * @param mainScreenId Main screen id. 131 * @param mirrorScreenId Mirror screen ids. 132 * @param mainScreenRegion Region of main screen. 133 * @param screenGroupId Screen group id. 134 * @return DM_OK means make mirror success, others means make mirror failed. 135 */ 136 DMError MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId, DMRect mainScreenRegion, 137 ScreenId& screenGroupId); 138 139 /** 140 * @brief Make screens as mirror-screen 141 * 142 * @param mainScreenId Main screen id. 143 * @param secondaryScreenId secondary screen id. 144 * @param screenMode Screen Combination Mode. 145 * @return DM_OK means make mirror success, others means make mirror failed. 146 */ 147 DMError SetMultiScreenMode(ScreenId mainScreenId, ScreenId secondaryScreenId, 148 MultiScreenMode screenMode); 149 150 /** 151 * @brief Set Screen Relative Position 152 * 153 * @param mainScreenOptions Main screen id and position. 154 * @param secondScreenOption secondary screen id and position. 155 * @return DM_OK means make mirror success, others means make mirror failed. 156 */ 157 DMError SetMultiScreenRelativePosition(MultiScreenPositionOptions mainScreenOptions, 158 MultiScreenPositionOptions secondScreenOption); 159 160 /** 161 * @brief Make screens as unique-screen. 162 * 163 * @param screenIds Unique screen ids. 164 * @return DM_OK means make unique screen success, others means make unique failed. 165 */ 166 DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds); 167 168 /** 169 * @brief Make screens as unique-screen. 170 * 171 * @param screenIds Unique screen ids. 172 * @param displayIds Unique display ids. 173 * @return DM_OK means make unique screen success, others means make unique failed. 174 */ 175 DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds, std::vector<DisplayId>& displayIds); 176 177 /** 178 * @brief Stop expand screens. 179 * 180 * @param expandScreenIds Expand screen ids. 181 * @return DM_OK means stop expand success, others means stop expand failed. 182 */ 183 DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 184 185 /** 186 * @brief Stop mirror screens. 187 * 188 * @param mirrorScreenIds Mirror screen ids. 189 * @return DM_OK means stop mirror success, others means stop mirror failed. 190 */ 191 DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 192 193 /** 194 * @brief Disable/enable global mirror screen. 195 * 196 * @param disableOrNot disable mirror screen or not. 197 * @return DM_OK means disable or enable mirror success, others means failed. 198 */ 199 DMError DisableMirror(bool disableOrNot); 200 201 /** 202 * @brief Remove virtual screen from group. 203 * 204 * @param screens Screen ids. 205 * @return DM_OK means remove success, others means remove failed. 206 */ 207 DMError RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 208 209 /** 210 * @brief Create virtual screen. 211 * 212 * @param option Indicates the options of the virtual screen. 213 * @return Screen id. 214 */ 215 ScreenId CreateVirtualScreen(VirtualScreenOption option); 216 217 /** 218 * @brief Destroy virtual screen. 219 * 220 * @param screenId Indicates the screen id of the virtual screen. 221 * @return DM_OK means destroy success, others means destroy failed. 222 */ 223 DMError DestroyVirtualScreen(ScreenId screenId); 224 225 /** 226 * @brief Set surface for the virtual screen. 227 * 228 * @param screenId Screen id. 229 * @param surface Surface object. 230 * @return DM_OK means set success, others means set failed. 231 */ 232 DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 233 234 /** 235 * @brief Add black window list in virtual screen 236 * 237 * @param persistentIds Black list window ids. 238 * @return DM_OK means set success, others means set failed. 239 */ 240 DMError AddVirtualScreenBlockList(const std::vector<int32_t>& peristentIds); 241 242 /** 243 * @brief Remove black window list in virtual screen 244 * 245 * @param persistentIds Black list window ids. 246 * @return DM_OK means set success, others means set failed. 247 */ 248 DMError RemoveVirtualScreenBlockList(const std::vector<int32_t>& peristentIds); 249 250 /** 251 * @brief Set privacy image. 252 * 253 * @param screenId Screen id. 254 * @param privacyMaskImg PixelMap object. 255 * @return DM_OK means set success, others means set failed. 256 */ 257 DMError SetScreenPrivacyMaskImage(ScreenId screenId, const std::shared_ptr<Media::PixelMap>& privacyMaskImg); 258 259 /** 260 * @brief Resize virtual screen 261 * 262 * @param screenId the id of virtual screen to be resized. 263 * @param width the new width. 264 * @param height the new height. 265 * @return DM_OK means set success, others means set failed. 266 */ 267 DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height); 268 269 /** 270 * @brief Set buffer auto rotate 271 * 272 * @param screenId Screen id. 273 * @param bufferRotation auto rotate 274 * @return DM_OK means set success, others means set failed. 275 */ 276 DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation); 277 278 /** 279 * @brief Set virtual screen scale mode 280 * 281 * @param screenId Screen id. 282 * @param scaleMode scale mode 283 * @return DM_OK means set success, others means set failed. 284 */ 285 DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode); 286 287 /** 288 * @brief Set the screen power state on the specified screen. 289 * 290 * @param screenId Screen id. 291 * @param state Screen power state. 292 * @param reason Reason for power state change. 293 * @return True means set success, false means set failed. 294 */ 295 bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 296 297 /** 298 * @brief Set the screen power states for all screens. 299 * 300 * @param state Screen power state. 301 * @param reason Reason for power state change. 302 * @return True means set success, false means set failed. 303 */ 304 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 305 306 /** 307 * @brief Get screen power state. 308 * 309 * @param screenId Screen id. 310 * @return Power state of screen. 311 */ 312 ScreenPowerState GetScreenPower(ScreenId screenId); 313 314 /** 315 * @brief Get screen power state. 316 * 317 * @return Power state of screen. 318 */ 319 ScreenPowerState GetScreenPower(); 320 321 /** 322 * @brief Set screen rotation lock status. 323 * 324 * @param isLocked True means forbid to rotate screen, false means the opposite. 325 * @return DM_OK means set success, others means set failed. 326 */ 327 DMError SetScreenRotationLocked(bool isLocked); 328 329 /** 330 * @brief Set screen rotation lock status from js. 331 * 332 * @param isLocked True means forbid to rotate screen, false means the opposite. 333 * @return DM_OK means set success, others means set failed. 334 */ 335 DMError SetScreenRotationLockedFromJs(bool isLocked); 336 337 /** 338 * @brief Get screen rotation lock status. 339 * 340 * @param isLocked Query the rotation lock status. 341 * @return DM_OK means query success, others means query failed. 342 */ 343 DMError IsScreenRotationLocked(bool& isLocked); 344 345 /** 346 * @brief Register screen listener. 347 * 348 * @param listener IScreenListener. 349 * @return DM_OK means register success, others means register failed. 350 */ 351 DMError RegisterScreenListener(sptr<IScreenListener> listener); 352 353 /** 354 * @brief Unregister screen listener. 355 * 356 * @param listener IScreenListener. 357 * @return DM_OK means unregister success, others means unregister failed. 358 */ 359 DMError UnregisterScreenListener(sptr<IScreenListener> listener); 360 361 /** 362 * @brief Register screen group listener. 363 * 364 * @param listener IScreenGroupListener. 365 * @return DM_OK means register success, others means register failed. 366 */ 367 DMError RegisterScreenGroupListener(sptr<IScreenGroupListener> listener); 368 369 /** 370 * @brief Unregister screen group listener. 371 * 372 * @param listener IScreenGroupListener. 373 * @return DM_OK means unregister success, others means unregister failed. 374 */ 375 DMError UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener); 376 377 /** 378 * @brief Register virtual screen group listener. 379 * 380 * @param listener IVirtualScreenGroupListener. 381 * @return DM_OK means register success, others means register failed. 382 */ 383 DMError RegisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener); 384 385 /** 386 * @brief Unregister virtual screen group listener. 387 * 388 * @param listener IVirtualScreenGroupListener. 389 * @return DM_OK means unregister success, others means unregister failed. 390 */ 391 DMError UnregisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener); 392 393 /** 394 * @brief Get virtual screen flag. 395 * 396 * @param screenId virtual screen id. 397 * @return virtual screen flag 398 */ 399 VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 400 401 /** 402 * @brief Set virtual screen flag. 403 * 404 * @param screenId virtual screen id. 405 * @param screenFlag virtual screen flag. 406 * @return DM_OK means set success, others means failed. 407 */ 408 DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag); 409 410 /** 411 * @brief Set virtual screen refresh rate with a refresh interval relative to the main screen. 412 * 413 * @param screenId virtual screen id. 414 * @param refreshInterval refresh interval: range [1, main screen max refresh rate]. 2 indicates that 415 * the virtual screen refreshes 1 frame when the main screen refreshes 2 frames, 5 indicates that 416 * the virtual screen refreshes 1 frame when the main screen refreshes 5 frames, and so on. 417 * @return DM_OK means set success, others means failed. 418 */ 419 DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval); 420 421 /** 422 * @brief Set virtual screen max refresh rate . 423 * 424 * @param screenId virtual screen id. 425 * @param refreshRate max refresh rate to be set. 426 * @param actualRefreshRate the actual refresh rate that is finally set. 427 * @return DM_OK means set success, others means failed. 428 */ 429 DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 430 uint32_t& actualRefreshRate); 431 432 /** 433 * @brief when casting the screen, Virtual screen playback and pause function. 434 * 435 * @param screenId screenId used in virtual screen. 436 * @param screenStatus VIRTUAL_SCREEN_PLAY or VIRTUAL_SCREEN_PAUSE. 437 * @return True means set success, false means set failed. 438 */ 439 bool SetVirtualScreenStatus(ScreenId screenId, VirtualScreenStatus screenStatus); 440 441 /** 442 * @brief Set screen sharing protect 443 * 444 * @param screenIds screen IDs for set the screen sharing protect. 445 * @param isEnable wether to enable the screen sharing protect. 446 * @return DM_OK means set success, others means failed. 447 */ 448 DMError SetScreenSkipProtectedWindow(const std::vector<ScreenId>& screenIds, bool isEnable); 449 450 private: 451 ScreenManager(); 452 ~ScreenManager(); 453 void OnRemoteDied(); 454 455 class Impl; 456 sptr<Impl> pImpl_; 457 }; 458 } // namespace OHOS::Rosen 459 460 #endif // FOUNDATION_DM_SCREEN_MANAGER_H 461