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