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 "agent_death_recipient.h" 29 #include "display_manager_agent_controller.h" 30 #include "dm_common.h" 31 #include "rsscreen_change_listener.h" 32 #include "screen.h" 33 #include "zidl/display_manager_agent_interface.h" 34 35 namespace OHOS::Rosen { 36 class AbstractScreenController : public RefBase { 37 using OnAbstractScreenConnectCb = std::function<void(sptr<AbstractScreen>)>; 38 using OnAbstractScreenChangeCb = std::function<void(sptr<AbstractScreen>, DisplayChangeEvent event)>; 39 public: 40 struct AbstractScreenCallback : public RefBase { 41 OnAbstractScreenConnectCb onConnect_; 42 OnAbstractScreenConnectCb onDisconnect_; 43 OnAbstractScreenChangeCb onChange_; 44 }; 45 46 explicit AbstractScreenController(std::recursive_mutex& mutex); 47 ~AbstractScreenController(); 48 WM_DISALLOW_COPY_AND_MOVE(AbstractScreenController); 49 50 void Init(); 51 std::vector<ScreenId> GetAllScreenIds() const; 52 uint32_t GetRSScreenNum() const; 53 sptr<AbstractScreen> GetAbstractScreen(ScreenId dmsScreenId) const; 54 std::vector<ScreenId> GetAllValidScreenIds(const std::vector<ScreenId>& screenIds) const; 55 sptr<AbstractScreenGroup> GetAbstractScreenGroup(ScreenId dmsScreenId); 56 ScreenId GetDefaultAbstractScreenId(); 57 ScreenId ConvertToRsScreenId(ScreenId dmsScreenId) const; 58 ScreenId ConvertToDmsScreenId(ScreenId rsScreenId) const; 59 void RegisterAbstractScreenCallback(sptr<AbstractScreenCallback> cb); 60 void RegisterRSScreenChangeListener(const sptr<IRSScreenChangeListener>& listener); 61 ScreenId CreateVirtualScreen(VirtualScreenOption option, const sptr<IRemoteObject>& displayManagerAgent); 62 DMError DestroyVirtualScreen(ScreenId screenId); 63 DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface); 64 void SetBuildInDefaultOrientation(Orientation orientation); 65 bool SetOrientation(ScreenId screenId, Orientation orientation, bool isFromWindow); 66 bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow); 67 68 bool SetScreenActiveMode(ScreenId screenId, uint32_t modeId); 69 const std::shared_ptr<RSDisplayNode>& GetRSDisplayNodeByScreenId(ScreenId dmsScreenId) const; 70 void UpdateRSTree(ScreenId dmsScreenId, ScreenId parentScreenId, std::shared_ptr<RSSurfaceNode>& surfaceNode, 71 bool isAdd, bool isMultiDisplay); 72 bool MakeMirror(ScreenId, std::vector<ScreenId> screens); 73 bool MakeExpand(std::vector<ScreenId> screenIds, std::vector<Point> startPoints); 74 void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens); 75 bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason) const; 76 ScreenPowerState GetScreenPower(ScreenId dmsScreenId) const; 77 bool SetVirtualPixelRatio(ScreenId screenId, float virtualPixelRatio); 78 79 // colorspace, gamut 80 DMError GetScreenSupportedColorGamuts(ScreenId screenId, std::vector<ScreenColorGamut>& colorGamuts); 81 DMError GetScreenColorGamut(ScreenId screenId, ScreenColorGamut& colorGamut); 82 DMError SetScreenColorGamut(ScreenId screenId, int32_t colorGamutIdx); 83 DMError GetScreenGamutMap(ScreenId screenId, ScreenGamutMap& gamutMap); 84 DMError SetScreenGamutMap(ScreenId screenId, ScreenGamutMap gamutMap); 85 DMError SetScreenColorTransform(ScreenId screenId); 86 87 private: IsVertical(Rotation rotation)88 static inline bool IsVertical(Rotation rotation) 89 { 90 return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); 91 } 92 void SetScreenRotateAnimation(sptr<AbstractScreen>& screen, ScreenId screenId, Rotation rotationAfter); 93 void RegisterRsScreenConnectionChangeListener(); 94 void OnRsScreenConnectionChange(ScreenId rsScreenId, ScreenEvent screenEvent); 95 bool OnRemoteDied(const sptr<IRemoteObject>& agent); 96 void ProcessScreenConnected(ScreenId rsScreenId); 97 sptr<AbstractScreen> InitAndGetScreen(ScreenId rsScreenId); 98 void ProcessScreenDisconnected(ScreenId rsScreenId); 99 bool InitAbstractScreenModesInfo(sptr<AbstractScreen>& absScreen); 100 sptr<AbstractScreen> InitVirtualScreen(ScreenId dmsScreenId, ScreenId rsId, VirtualScreenOption option); 101 sptr<AbstractScreenGroup> AddToGroupLocked(sptr<AbstractScreen> newScreen); 102 sptr<AbstractScreenGroup> RemoveFromGroupLocked(sptr<AbstractScreen> newScreen); 103 bool RemoveChildFromGroup(sptr<AbstractScreen>, sptr<AbstractScreenGroup>); 104 bool CheckScreenInScreenGroup(sptr<AbstractScreen> newScreen) const; 105 sptr<AbstractScreenGroup> AddAsFirstScreenLocked(sptr<AbstractScreen> newScreen); 106 sptr<AbstractScreenGroup> AddAsSuccedentScreenLocked(sptr<AbstractScreen> newScreen); 107 void ProcessScreenModeChanged(ScreenId dmsScreenId); 108 void ChangeScreenGroup(sptr<AbstractScreenGroup> group, const std::vector<ScreenId>& screens, 109 const std::vector<Point>& startPoints, bool filterScreen, ScreenCombination combination); 110 void AddScreenToGroup(sptr<AbstractScreenGroup>, const std::vector<ScreenId>&, 111 const std::vector<Point>&, std::map<ScreenId, bool>&); 112 void NotifyScreenConnected(sptr<ScreenInfo>) const; 113 void NotifyScreenDisconnected(ScreenId screenId) const; 114 void NotifyScreenChanged(sptr<ScreenInfo> screenInfo, ScreenChangeEvent event) const; 115 void NotifyScreenGroupChanged(const sptr<ScreenInfo>& screenInfo, ScreenGroupChangeEvent event) const; 116 void NotifyScreenGroupChanged(const std::vector<sptr<ScreenInfo>>& screenInfo, ScreenGroupChangeEvent event) const; 117 118 class ScreenIdManager { 119 public: 120 ScreenIdManager() = default; 121 ~ScreenIdManager() = default; 122 WM_DISALLOW_COPY_AND_MOVE(ScreenIdManager); 123 ScreenId CreateAndGetNewScreenId(ScreenId rsScreenId); 124 bool DeleteScreenId(ScreenId dmsScreenId); 125 bool HasDmsScreenId(ScreenId dmsScreenId) const; 126 bool HasRsScreenId(ScreenId dmsScreenId) const; 127 bool ConvertToRsScreenId(ScreenId, ScreenId&) const; 128 ScreenId ConvertToRsScreenId(ScreenId) const; 129 bool ConvertToDmsScreenId(ScreenId, ScreenId&) const; 130 ScreenId ConvertToDmsScreenId(ScreenId) const; 131 uint32_t GetRSScreenNum() const; 132 private: 133 std::atomic<ScreenId> dmsScreenCount_ {0}; 134 std::map<ScreenId, ScreenId> rs2DmsScreenIdMap_; 135 std::map<ScreenId, ScreenId> dms2RsScreenIdMap_; 136 }; 137 138 std::recursive_mutex& mutex_; 139 OHOS::Rosen::RSInterfaces& rsInterface_; 140 ScreenIdManager screenIdManager_; 141 std::map<ScreenId, sptr<AbstractScreen>> dmsScreenMap_; 142 std::map<ScreenId, sptr<AbstractScreenGroup>> dmsScreenGroupMap_; 143 std::map<sptr<IRemoteObject>, std::vector<ScreenId>> screenAgentMap_; 144 sptr<AgentDeathRecipient> deathRecipient_ { nullptr }; 145 sptr<AbstractScreenCallback> abstractScreenCallback_; 146 sptr<IRSScreenChangeListener> rSScreenChangeListener_; 147 std::shared_ptr<AppExecFwk::EventHandler> controllerHandler_; 148 std::atomic<ScreenId> defaultRsScreenId_ {SCREEN_ID_INVALID }; 149 Orientation buildInDefaultOrientation_ { Orientation::UNSPECIFIED }; 150 bool isExpandCombination_ = false; 151 }; 152 } // namespace OHOS::Rosen 153 #endif // FOUNDATION_DMSERVER_ABSTRACT_SCREEN_CONTROLLER_H