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_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H 17 #define FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H 18 19 #include <map> 20 #include <vector> 21 22 #include <event_handler.h> 23 #include <refbase.h> 24 #include <surface.h> 25 #include <transaction/rs_interfaces.h> 26 27 #include "abstract_screen.h" 28 #include "dm_common.h" 29 #include "screen.h" 30 31 namespace OHOS::Rosen { 32 class AbstractScreenController : public RefBase { 33 using OnAbstractScreenConnectCb = std::function<void(sptr<AbstractScreen>)>; 34 using OnAbstractScreenChangeCb = std::function<void(sptr<AbstractScreen>, DisplayChangeEvent event)>; 35 public: 36 struct AbstractScreenCallback : public RefBase { 37 OnAbstractScreenConnectCb onConnect_; 38 OnAbstractScreenConnectCb onDisconnect_; 39 OnAbstractScreenChangeCb onChange_; 40 }; 41 42 AbstractScreenController(std::recursive_mutex& mutex); 43 ~AbstractScreenController(); 44 WM_DISALLOW_COPY_AND_MOVE(AbstractScreenController); 45 46 void Init(); 47 void ScreenConnectionInDisplayInit(sptr<AbstractScreenCallback> abstractScreenCallback); 48 std::vector<ScreenId> GetAllScreenIds() const; 49 sptr<AbstractScreen> GetAbstractScreen(ScreenId dmsScreenId) const; 50 std::vector<ScreenId> GetShotScreenIds(std::vector<ScreenId>) const; 51 std::vector<ScreenId> GetAllExpandOrMirrorScreenIds(std::vector<ScreenId>) const; 52 sptr<AbstractScreenGroup> GetAbstractScreenGroup(ScreenId dmsScreenId); 53 ScreenId GetDefaultAbstractScreenId(); 54 ScreenId ConvertToRsScreenId(ScreenId dmsScreenId) const; 55 ScreenId ConvertToDmsScreenId(ScreenId rsScreenId) const; 56 void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb); 57 ScreenId CreateVirtualScreen(VirtualScreenOption option); 58 DMError DestroyVirtualScreen(ScreenId screenId); 59 DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 60 bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow); 61 62 bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 63 std::shared_ptr<RSDisplayNode> GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; 64 void UpdateRSTree(ScreenId dmsScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, bool isAdd); 65 bool MakeMirror(ScreenId, std::vector<ScreenId> screens); 66 bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints); 67 void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 68 void DumpScreenInfo() const; 69 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) const; 70 ScreenPowerState GetScreenPower(ScreenId dmsScreenId) const; 71 72 // colorspace, gamut 73 DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 74 DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 75 DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 76 DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 77 DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 78 DMError SetScreenColorTransform(ScreenId screenId); 79 80 private: 81 void RegisterRsScreenConnectionChangeListener(); 82 void OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent); 83 void ProcessScreenConnected(ScreenId rsScreenId); 84 sptr<AbstractScreen> InitAndGetScreen(ScreenId rsScreenId); 85 void ProcessScreenDisconnected(ScreenId rsScreenId); 86 bool FillAbstractScreen(sptr<AbstractScreen>& absScreen, ScreenId rsScreenId); 87 sptr<AbstractScreenGroup> AddToGroupLocked(sptr<AbstractScreen> newScreen); 88 sptr<AbstractScreenGroup> RemoveFromGroupLocked(sptr<AbstractScreen> newScreen); 89 bool RemoveChildFromGroup(sptr<AbstractScreen>, sptr<AbstractScreenGroup>); 90 bool CheckScreenInScreenGroup(sptr<AbstractScreen> newScreen) const; 91 sptr<AbstractScreenGroup> AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen); 92 sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen); 93 void ProcessScreenModeChanged(ScreenId dmsScreenId); 94 void ChangeScreenGroup(sptr<AbstractScreenGroup> group, const std::vector<ScreenId>& screens, 95 const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination); 96 void AddScreenToGroup(sptr<AbstractScreenGroup>, const std::vector<ScreenId>&, 97 const std::vector<Point>&, std::map<ScreenId, bool>&); 98 void NotifyScreenConnected(sptr<ScreenInfo>) const; 99 void NotifyScreenDisconnected(ScreenId screenId) const; 100 void NotifyScreenChanged(sptr<ScreenInfo> screenInfo, ScreenChangeEvent event) const; 101 void NotifyScreenGroupChanged(const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent event) const; 102 void NotifyScreenGroupChanged(const std::vector<sptr<ScreenInfo>>& screenInfo, ScreenGroupChangeEvent event) const; 103 void DumpScreenGroupInfo() const; 104 105 class ScreenIdManager { 106 public: 107 ScreenIdManager() = default; 108 ~ScreenIdManager() = default; 109 WM_DISALLOW_COPY_AND_MOVE(ScreenIdManager); 110 ScreenId CreateAndGetNewScreenId(ScreenId rsScreenId); 111 bool DeleteScreenId(ScreenId dmsScreenId); 112 bool HasDmsScreenId(ScreenId dmsScreenId) const; 113 bool HasRsScreenId(ScreenId dmsScreenId) const; 114 bool ConvertToRsScreenId(ScreenId, ScreenId&) const; 115 ScreenId ConvertToRsScreenId(ScreenId) const; 116 bool ConvertToDmsScreenId(ScreenId, ScreenId&) const; 117 ScreenId ConvertToDmsScreenId(ScreenId) const; 118 void DumpScreenIdInfo() const; 119 private: 120 std::atomic<ScreenId> dmsScreenCount_ {0}; 121 std::map<ScreenId, ScreenId> rs2DmsScreenIdMap_; 122 std::map<ScreenId, ScreenId> dms2RsScreenIdMap_; 123 }; 124 125 const std::string CONTROLLER_THREAD_ID = "abstract_screen_controller_thread"; 126 127 std::recursive_mutex& mutex_; 128 OHOS::Rosen::RSInterfaces& rsInterface_; 129 ScreenIdManager screenIdManager_; 130 std::map<ScreenId, sptr<AbstractScreen>> dmsScreenMap_; 131 std::map<ScreenId, sptr<AbstractScreenGroup>> dmsScreenGroupMap_; 132 sptr<AbstractScreenCallback> abstractScreenCallback_; 133 std::shared_ptr<AppExecFwk::EventHandler> controllerHandler_; 134 }; 135 } // namespace OHOS::Rosen 136 #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H