1 /* 2 * Copyright (c) 2021-2023 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_WINDOW_ROOT_H 17 #define OHOS_ROSEN_WINDOW_ROOT_H 18 19 #include <refbase.h> 20 #include <iremote_object.h> 21 #include <transaction/rs_interfaces.h> 22 23 #include "agent_death_recipient.h" 24 #include "display_manager_service_inner.h" 25 #include "parameters.h" 26 #include "window_node_container.h" 27 #include "zidl/window_manager_agent_interface.h" 28 29 namespace OHOS { 30 namespace Rosen { 31 enum class Event : uint32_t { 32 REMOTE_DIED, 33 }; 34 35 class WindowRoot : public RefBase { 36 using Callback = std::function<void (Event event, const sptr<IRemoteObject>& remoteObject)>; 37 38 public: WindowRoot(Callback callback)39 explicit WindowRoot(Callback callback) : callback_(callback) {} 40 ~WindowRoot() = default; 41 42 sptr<WindowNodeContainer> GetOrCreateWindowNodeContainer(DisplayId displayId); 43 sptr<WindowNodeContainer> GetWindowNodeContainer(DisplayId displayId); 44 sptr<WindowNodeContainer> CreateWindowNodeContainer(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo); 45 sptr<WindowNode> GetWindowNode(uint32_t windowId) const; 46 sptr<WindowNode> GetWindowNodeByMissionId(uint32_t missionId) const; 47 void GetBackgroundNodesByScreenId(ScreenId screenGroupId, std::vector<sptr<WindowNode>>& windowNodes); 48 void GetForegroundNodes(std::vector<sptr<WindowNode>>& windowNodes); 49 50 sptr<WindowNode> FindWallpaperWindow(); 51 WMError SaveWindow(const sptr<WindowNode>& node); 52 void AddDeathRecipient(sptr<WindowNode> node); 53 sptr<WindowNode> FindWindowNodeWithToken(const sptr<IRemoteObject>& token) const; 54 WMError AddWindowNode(uint32_t parentId, sptr<WindowNode>& node, bool fromStartingWin = false); 55 WMError RemoveWindowNode(uint32_t windowId, bool fromAnimation = false); 56 WMError DestroyWindow(uint32_t windowId, bool onlySelf); 57 WMError UpdateWindowNode(uint32_t windowId, WindowUpdateReason reason); 58 bool IsVerticalDisplay(sptr<WindowNode>& node) const; 59 bool IsForbidDockSliceMove(DisplayId displayId) const; 60 bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const; 61 void ExitSplitMode(DisplayId displayId); 62 void NotifyWindowVisibilityChange(std::shared_ptr<RSOcclusionData> occlusionData); 63 void AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr<WindowNode> node); 64 65 WMError RequestFocus(uint32_t windowId); 66 WMError RequestActiveWindow(uint32_t windowId); 67 WMError MinimizeStructuredAppWindowsExceptSelf(sptr<WindowNode>& node); 68 AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType); 69 WMError SetWindowMode(sptr<WindowNode>& node, WindowMode dstMode); 70 WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); 71 void MinimizeAllAppWindows(DisplayId displayId); 72 WMError ToggleShownStateForAllAppWindows(); 73 WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode); 74 75 void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason); 76 void ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 77 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 78 void ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 79 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap); 80 void ProcessDisplayCreate(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 81 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap); 82 83 void NotifySystemBarTints(); 84 WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node); 85 void DispatchKeyEvent(sptr<WindowNode> node, std::shared_ptr<MMI::KeyEvent> event); 86 void FocusFaultDetection() const; 87 Rect GetDisplayGroupRect(DisplayId displayId) const; 88 WMError UpdateSizeChangeReason(uint32_t windowId, WindowSizeChangeReason reason); 89 void SetBrightness(uint32_t windowId, float brightness); 90 void HandleKeepScreenOn(uint32_t windowId, bool requireLock); 91 void UpdateFocusableProperty(uint32_t windowId); 92 void SetMaxAppWindowNumber(uint32_t windowNum); 93 WMError GetModeChangeHotZones(DisplayId displayId, 94 ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); 95 std::vector<DisplayId> GetAllDisplayIds() const; 96 uint32_t GetTotalWindowNum() const; 97 uint32_t GetWindowIdByObject(const sptr<IRemoteObject>& remoteObject); 98 sptr<WindowNode> GetWindowForDumpAceHelpInfo() const; 99 void NotifyMMIServiceOnline(); 100 void DestroyLeakStartingWindow(); 101 void SetSplitRatios(const std::vector<float>& splitRatioNumbers); 102 std::vector<sptr<WindowNode>> GetSplitScreenWindowNodes(DisplayId displayId); 103 void SetExitSplitRatios(const std::vector<float>& exitSplitRatios); 104 void MinimizeTargetWindows(std::vector<uint32_t>& windowIds); 105 WMError UpdateRsTree(uint32_t windowId, bool isAdd); 106 void RemoveSingleUserWindowNodes(int accountId); 107 sptr<WindowNode> FindMainWindowWithToken(sptr<IRemoteObject> token); 108 bool CheckMultiDialogWindows(WindowType type, sptr<IRemoteObject> token); 109 bool HasPrivateWindow(DisplayId displayId); 110 Rect GetDisplayRectWithoutSystemBarAreas(const sptr<WindowNode> destNode); 111 sptr<WindowNode> GetWindowNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken); 112 bool TakeWindowPairSnapshot(DisplayId displayId); 113 void ClearWindowPairSnapshot(DisplayId displayId); 114 void LayoutWhenAddWindowNode(sptr<WindowNode>& node, bool afterAnimation = false); 115 void GetAllAnimationPlayingNodes(std::vector<wptr<WindowNode>>& windowNodes); 116 void GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const; 117 void GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) const; 118 WMError NotifyDesktopUnfrozen(); 119 void UpdateDisplayOrientationWhenHideWindow(sptr<WindowNode>& node); 120 bool HasMainFullScreenWindowShown(DisplayId displayId); 121 WMError SetGestureNavigationEnabled(bool enable); 122 123 private: 124 void OnRemoteDied(const sptr<IRemoteObject>& remoteObject); 125 WMError DestroyWindowInner(sptr<WindowNode>& node); 126 WMError DestroyWindowSelf(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container); 127 WMError DestroyWindowWithChild(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container); 128 void UpdateFocusWindowWithWindowRemoved(const sptr<WindowNode>& node, 129 const sptr<WindowNodeContainer>& container) const; 130 void UpdateActiveWindowWithWindowRemoved(const sptr<WindowNode>& node, 131 const sptr<WindowNodeContainer>& container) const; 132 void UpdateBrightnessWithWindowRemoved(uint32_t windowId, const sptr<WindowNodeContainer>& container) const; 133 std::string GenAllWindowsLogInfo() const; 134 bool CheckDisplayInfo(const sptr<DisplayInfo>& display); 135 ScreenId GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay); 136 void ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 137 std::map<DisplayId, Rect>& displayRectMap); 138 std::map<DisplayId, Rect> GetAllDisplayRectsByDMS(sptr<DisplayInfo> displayInfo); 139 std::map<DisplayId, Rect> GetAllDisplayRectsByDisplayInfo( 140 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap); 141 void MoveNotShowingWindowToDefaultDisplay(DisplayId defaultDisplayId, DisplayId displayId); 142 WMError PostProcessAddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode, 143 sptr<WindowNodeContainer>& container); 144 std::vector<std::pair<uint64_t, WindowVisibilityState>> GetWindowVisibilityChangeInfo( 145 std::shared_ptr<RSOcclusionData> occlusionData); 146 bool CheckAddingModeAndSize(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container); 147 WMError BindDialogToParent(sptr<WindowNode>& node, sptr<WindowNode>& parentNode); 148 void CheckAndNotifyWaterMarkChangedResult(); 149 150 std::map<uint32_t, sptr<WindowNode>> windowNodeMap_; 151 std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_; 152 std::map<uint64_t, sptr<WindowNode>> surfaceIdWindowNodeMap_; 153 std::vector<std::pair<uint64_t, WindowVisibilityState> > lastVisibleData_; 154 std::map<ScreenId, sptr<WindowNodeContainer>> windowNodeContainerMap_; 155 std::map<ScreenId, std::vector<DisplayId>> displayIdMap_; 156 bool lastWaterMarkShowStates_ { false }; 157 bool needCheckFocusWindow = false; 158 bool lastGestureNativeEnabled_ { true }; 159 160 std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_; 161 162 sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient( 163 [this](const sptr<IRemoteObject>& remoteObject) { this->OnRemoteDied(remoteObject); }); 164 Callback callback_; 165 uint32_t maxAppWindowNumber_ = 100; 166 SplitRatioConfig splitRatioConfig_ = {0.1, 0.9, {}}; 167 }; 168 } 169 } 170 #endif // OHOS_ROSEN_WINDOW_ROOT_H 171