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