1 /* 2 * Copyright (c) 2024 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_MULTI_SCREEN_MANAGER_H 17 #define OHOS_ROSEN_MULTI_SCREEN_MANAGER_H 18 19 #include <hitrace_meter.h> 20 #include <transaction/rs_interfaces.h> 21 22 #include "dm_common.h" 23 #include "screen_session_manager.h" 24 #include "wm_single_instance.h" 25 26 namespace OHOS::Rosen { 27 28 class MultiScreenManager { 29 WM_DECLARE_SINGLE_INSTANCE_BASE(MultiScreenManager); 30 public: 31 DMError VirtualScreenUniqueSwitch(sptr<ScreenSession> screenSession, const std::vector<ScreenId>& screenIds); 32 33 DMError UniqueSwitch(const std::vector<ScreenId>& screenIds, std::vector<DisplayId>& displayIds); 34 35 DMError MirrorSwitch(const ScreenId mainScreenId, const std::vector<ScreenId>& screenIds, DMRect mainScreenRegion, 36 ScreenId& screenGroupId); 37 38 void MultiScreenModeChange(sptr<ScreenSession> mainSession, sptr<ScreenSession> secondarySession, 39 const std::string& operateType); 40 41 void MultiScreenModeChange(ScreenId mainScreenId, ScreenId secondaryScreenId, const std::string& operateType); 42 43 void SetLastScreenMode(ScreenId mainScreenId, MultiScreenMode secondaryScreenMode); 44 45 void InternalScreenOnChange(sptr<ScreenSession> internalSession, sptr<ScreenSession> externalSession); 46 47 void InternalScreenOffChange(sptr<ScreenSession> internalSession, sptr<ScreenSession> externalSession); 48 49 void ExternalScreenDisconnectChange(sptr<ScreenSession> internalSession, sptr<ScreenSession> externalSession); 50 51 bool AreScreensTouching(sptr<ScreenSession> mainScreenSession, sptr<ScreenSession> secondScreenSession, 52 MultiScreenPositionOptions mainScreenOptions, MultiScreenPositionOptions secondScreenOption); 53 54 void MultiScreenReportDataToRss(std::string multiScreenType, std::string status); 55 void NotifyScreenConnectCompletion(ScreenId screenId); 56 private: 57 MultiScreenManager(); 58 ~MultiScreenManager(); 59 60 void FilterPhysicalAndVirtualScreen(const std::vector<ScreenId>& allScreenIds, 61 std::vector<ScreenId>& physicalScreenIds, std::vector<ScreenId>& virtualScreenIds); 62 63 DMError VirtualScreenMirrorSwitch(const ScreenId mainScreenId, const std::vector<ScreenId>& screenIds, 64 DMRect mainScreenRegion, ScreenId& screenGroupId); 65 66 DMError PhysicalScreenMirrorSwitch(const std::vector<ScreenId>& screenIds, DMRect mainScreenRegion); 67 68 DMError PhysicalScreenUniqueSwitch(const std::vector<ScreenId>& screenIds); 69 70 /* pc multi screen switch */ 71 void DoFirstExtendChange(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession, 72 const std::string& operateType); 73 74 void DoFirstMainChangeExtend(sptr<IScreenSessionManagerClient> scbClient, sptr<ScreenSession> firstSession, 75 sptr<ScreenSession> secondarySession); 76 77 void DoFirstMainChangeMirror(sptr<IScreenSessionManagerClient> scbClient, sptr<ScreenSession> firstSession, 78 sptr<ScreenSession> secondarySession); 79 80 void DoFirstMirrorChange(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession, 81 const std::string& operateType); 82 void DoFirstMirrorChangeExtend(sptr<IScreenSessionManagerClient> scbClient, sptr<ScreenSession> firstSession, 83 sptr<ScreenSession> secondarySession); 84 void DoFirstMirrorChangeMirror(sptr<IScreenSessionManagerClient> scbClient, sptr<ScreenSession> firstSession, 85 sptr<ScreenSession> secondarySession); 86 87 void DoFirstMainChange(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession, 88 const std::string& operateType); 89 void DoFirstExtendChangeExtend(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession); 90 void DoFirstExtendChangeMirror(sptr<ScreenSession> firstSession, sptr<ScreenSession> secondarySession); 91 92 std::pair<ScreenId, MultiScreenMode> lastScreenMode_; // main screen id & secondary screen mode 93 94 void BlockScreenConnect(sptr<ScreenSession>& screenSession, ScreenId screenId); 95 std::mutex uniqueScreenMutex_; 96 std::condition_variable uniqueScreenCV_; 97 std::map<ScreenId, bool> uniqueScreenTimeoutMap_; 98 }; 99 } // namespace OHOS::Rosen 100 #endif // OHOS_ROSEN_MULTI_SCREEN_MANAGER_H 101