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 */ 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 screens as unique-screen. 117 * 118 * @param screenIds Unique screen ids. 119 * @return DM_OK means make unique screen success, others means make unique failed. 120 */ 121 DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds); 122 123 /** 124 * @brief Stop expand screens. 125 * 126 * @param expandScreenIds Expand screen ids. 127 * @return DM_OK means stop expand success, others means stop expand failed. 128 */ 129 DMError StopExpand(const std::vector<ScreenId>& expandScreenIds); 130 131 /** 132 * @brief Stop mirror screens. 133 * 134 * @param mirrorScreenIds Mirror screen ids. 135 * @return DM_OK means stop mirror success, others means stop mirror failed. 136 */ 137 DMError StopMirror(const std::vector<ScreenId>& mirrorScreenIds); 138 139 /** 140 * @brief Disable/enable global mirror screen. 141 * 142 * @param disableOrNot disable mirror screen or not. 143 * @return DM_OK means disable or enable mirror success, others means failed. 144 */ 145 DMError DisableMirror(bool disableOrNot); 146 147 /** 148 * @brief Remove virtual screen from group. 149 * 150 * @param screens Screen ids. 151 * @return DM_OK means remove success, others means remove failed. 152 */ 153 DMError RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 154 155 /** 156 * @brief Create virtual screen. 157 * 158 * @param option Indicates the options of the virtual screen. 159 * @return Screen id. 160 */ 161 ScreenId CreateVirtualScreen(VirtualScreenOption option); 162 163 /** 164 * @brief Destroy virtual screen. 165 * 166 * @param screenId Indicates the screen id of the virtual screen. 167 * @return DM_OK means destroy success, others means destroy failed. 168 */ 169 DMError DestroyVirtualScreen(ScreenId screenId); 170 171 /** 172 * @brief Set surface for the virtual screen. 173 * 174 * @param screenId Screen id. 175 * @param surface Surface object. 176 * @return DM_OK means set success, others means set failed. 177 */ 178 DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 179 180 /** 181 * @brief Set canvas auto rotate 182 * 183 * @param screenId Screen id. 184 * @param canvasRotation auto rotate 185 * @return DM_OK means set success, others means set failed. 186 */ 187 DMError SetVirtualMirrorScreenCanvasRotation(ScreenId screenId, bool canvasRotation); 188 189 /** 190 * @brief Resize virtual screen 191 * 192 * @param screenId the id of virtual screen to be resized. 193 * @param width the new width. 194 * @param height the new height. 195 * @return DM_OK means set success, others means set failed. 196 */ 197 DMError ResizeVirtualScreen(ScreenId screenId, uint32_t width, uint32_t height); 198 199 /** 200 * @brief Set virtual screen scale mode 201 * 202 * @param screenId Screen id. 203 * @param scaleMode scale mode 204 * @return DM_OK means set success, others means set failed. 205 */ 206 DMError SetVirtualMirrorScreenScaleMode(ScreenId screenId, ScreenScaleMode scaleMode); 207 208 /** 209 * @brief Set the screen power state on the specified screen. 210 * 211 * @param screenId Screen id. 212 * @param state Screen power state. 213 * @param reason Reason for power state change. 214 * @return True means set success, false means set failed. 215 */ 216 bool SetSpecifiedScreenPower(ScreenId screenId, ScreenPowerState state, PowerStateChangeReason reason); 217 218 /** 219 * @brief Set the screen power states for all screens. 220 * 221 * @param state Screen power state. 222 * @param reason Reason for power state change. 223 * @return True means set success, false means set failed. 224 */ 225 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason); 226 227 /** 228 * @brief Get screen power state. 229 * 230 * @param screenId Screen id. 231 * @return Power state of screen. 232 */ 233 ScreenPowerState GetScreenPower(ScreenId screenId); 234 235 /** 236 * @brief Set screen rotation lock status. 237 * 238 * @param isLocked True means forbid to rotate screen, false means the opposite. 239 * @return DM_OK means set success, others means set failed. 240 */ 241 DMError SetScreenRotationLocked(bool isLocked); 242 243 /** 244 * @brief Set screen rotation lock status from js. 245 * 246 * @param isLocked True means forbid to rotate screen, false means the opposite. 247 * @return DM_OK means set success, others means set failed. 248 */ 249 DMError SetScreenRotationLockedFromJs(bool isLocked); 250 251 /** 252 * @brief Get screen rotation lock status. 253 * 254 * @param isLocked Query the rotation lock status. 255 * @return DM_OK means query success, others means query failed. 256 */ 257 DMError IsScreenRotationLocked(bool& isLocked); 258 259 /** 260 * @brief Register screen listener. 261 * 262 * @param listener IScreenListener. 263 * @return DM_OK means register success, others means register failed. 264 */ 265 DMError RegisterScreenListener(sptr<IScreenListener> listener); 266 267 /** 268 * @brief Unregister screen listener. 269 * 270 * @param listener IScreenListener. 271 * @return DM_OK means unregister success, others means unregister failed. 272 */ 273 DMError UnregisterScreenListener(sptr<IScreenListener> listener); 274 275 /** 276 * @brief Register screen group listener. 277 * 278 * @param listener IScreenGroupListener. 279 * @return DM_OK means register success, others means register failed. 280 */ 281 DMError RegisterScreenGroupListener(sptr<IScreenGroupListener> listener); 282 283 /** 284 * @brief Unregister screen group listener. 285 * 286 * @param listener IScreenGroupListener. 287 * @return DM_OK means unregister success, others means unregister failed. 288 */ 289 DMError UnregisterScreenGroupListener(sptr<IScreenGroupListener> listener); 290 291 /** 292 * @brief Register virtual screen group listener. 293 * 294 * @param listener IVirtualScreenGroupListener. 295 * @return DM_OK means register success, others means register failed. 296 */ 297 DMError RegisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener); 298 299 /** 300 * @brief Unregister virtual screen group listener. 301 * 302 * @param listener IVirtualScreenGroupListener. 303 * @return DM_OK means unregister success, others means unregister failed. 304 */ 305 DMError UnregisterVirtualScreenGroupListener(sptr<IVirtualScreenGroupListener> listener); 306 307 /** 308 * @brief Get virtual screen flag. 309 * 310 * @param screenId virtual screen id. 311 * @return virtual screen flag 312 */ 313 VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId); 314 315 /** 316 * @brief Set virtual screen flag. 317 * 318 * @param screenId virtual screen id. 319 * @param screenFlag virtual screen flag. 320 * @return DM_OK means set success, others means failed. 321 */ 322 DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag); 323 324 /** 325 * @brief Set virtual screen refresh rate with a refresh interval relative to the main screen. 326 * 327 * @param screenId virtual screen id. 328 * @param refreshInterval refresh interval: range [1, main screen max refresh rate]. 2 indicates that 329 * the virtual screen refreshes 1 frame when the main screen refreshes 2 frames, 5 indicates that 330 * the virtual screen refreshes 1 frame when the main screen refreshes 5 frames, and so on. 331 * @return DM_OK means set success, others means failed. 332 */ 333 DMError SetVirtualScreenRefreshRate(ScreenId screenId, uint32_t refreshInterval); 334 335 /** 336 * @brief Set virtual screen max refresh rate . 337 * 338 * @param screenId virtual screen id. 339 * @param refreshRate max refresh rate to be set. 340 * @param actualRefreshRate the actual refresh rate that is finally set. 341 * @return DM_OK means set success, others means failed. 342 */ 343 DMError SetVirtualScreenMaxRefreshRate(ScreenId id, uint32_t refreshRate, 344 uint32_t& actualRefreshRate); 345 private: 346 ScreenManager(); 347 ~ScreenManager(); 348 void OnRemoteDied(); 349 350 class Impl; 351 sptr<Impl> pImpl_; 352 }; 353 } // namespace OHOS::Rosen 354 355 #endif // FOUNDATION_DM_SCREEN_MANAGER_H