• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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(sptr<DisplayInfo> displayInfo);
44     sptr<WindowNode> GetWindowNode(uint32_t windowId) const;
45     void GetBackgroundNodesByScreenId(ScreenId screenGroupId, std::vector<sptr<WindowNode>>& windowNodes) const;
46 
47     WMError SaveWindow(const sptr<WindowNode>& node);
48     void AddDeathRecipient(sptr<WindowNode> node);
49     sptr<WindowNode> FindWindowNodeWithToken(const sptr<IRemoteObject>& token) const;
50     WMError AddWindowNode(uint32_t parentId, sptr<WindowNode>& node, bool fromStartingWin = false);
51     WMError RemoveWindowNode(uint32_t windowId, bool fromAnimation = false);
52     WMError DestroyWindow(uint32_t windowId, bool onlySelf);
53     WMError UpdateWindowNode(uint32_t windowId, WindowUpdateReason reason);
54     bool IsVerticalDisplay(sptr<WindowNode>& node) const;
55     bool IsForbidDockSliceMove(DisplayId displayId) const;
56     bool IsDockSliceInExitSplitModeArea(DisplayId displayId) const;
57     void ExitSplitMode(DisplayId displayId);
58     void NotifyWindowVisibilityChange(std::shared_ptr<RSOcclusionData> occlusionData);
59     void AddSurfaceNodeIdWindowNodePair(uint64_t surfaceNodeId, sptr<WindowNode> node);
60 
61     WMError RequestFocus(uint32_t windowId);
62     WMError RequestActiveWindow(uint32_t windowId);
63     WMError MinimizeStructuredAppWindowsExceptSelf(sptr<WindowNode>& node);
64     AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType);
65     WMError SetWindowMode(sptr<WindowNode>& node, WindowMode dstMode);
66     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
67     void MinimizeAllAppWindows(DisplayId displayId);
68     WMError ToggleShownStateForAllAppWindows();
69     WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
70 
71     void ProcessWindowStateChange(WindowState state, WindowStateChangeReason reason);
72     void ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
73         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type);
74     void ProcessDisplayDestroy(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
75         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap);
76     void ProcessDisplayCreate(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
77         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap);
78 
79     void NotifySystemBarTints();
80     WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node);
81     void FocusFaultDetection() const;
82     float GetVirtualPixelRatio(DisplayId displayId) const;
83     Rect GetDisplayGroupRect(DisplayId displayId) const;
84     WMError UpdateSizeChangeReason(uint32_t windowId, WindowSizeChangeReason reason);
85     void SetBrightness(uint32_t windowId, float brightness);
86     void HandleKeepScreenOn(uint32_t windowId, bool requireLock);
87     void UpdateFocusableProperty(uint32_t windowId);
88     void SetMaxAppWindowNumber(uint32_t windowNum);
89     void SetMaxUniRenderAppWindowNumber(uint32_t uniAppWindowNum);
90     uint32_t GetMaxUniRenderAppWindowNumber() const;
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> FindDialogCallerNode(WindowType type, sptr<IRemoteObject> token);
105     bool CheckMultiDialogWindows(WindowType type, sptr<IRemoteObject> token);
106     bool HasPrivateWindow(DisplayId displayId);
107     Rect GetDisplayRectWithoutSystemBarAreas(DisplayId displayId);
108     void SwitchRenderModeIfNeeded();
109     void OnRenderModeChanged(bool isUniRender);
110     sptr<WindowNode> GetWindowNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken);
111     bool TakeWindowPairSnapshot(DisplayId displayId);
112     void ClearWindowPairSnapshot(DisplayId displayId);
IsUniRender()113     bool IsUniRender()
114     {
115         return renderMode_ == RenderMode::UNIFIED;
116     }
117     void LayoutWhenAddWindowNode(sptr<WindowNode>& node, bool afterAnimation = false);
118     void GetAllAnimationPlayingNodes(std::vector<wptr<WindowNode>>& windowNodes);
119     void GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const;
120 private:
121     enum class RenderMode : uint8_t {
122         SEPARATED,
123         UNIFIED,
124         SEPARATING,
125         UNIFYING,
126     };
127 
128     void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
129     WMError DestroyWindowInner(sptr<WindowNode>& node);
130     WMError DestroyWindowSelf(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container);
131     WMError DestroyWindowWithChild(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container);
132     void UpdateFocusWindowWithWindowRemoved(const sptr<WindowNode>& node,
133         const sptr<WindowNodeContainer>& container) const;
134     void UpdateActiveWindowWithWindowRemoved(const sptr<WindowNode>& node,
135         const sptr<WindowNodeContainer>& container) const;
136     void UpdateBrightnessWithWindowRemoved(uint32_t windowId, const sptr<WindowNodeContainer>& container) const;
137     std::string GenAllWindowsLogInfo() const;
138     bool CheckDisplayInfo(const sptr<DisplayInfo>& display);
139     ScreenId GetScreenGroupId(DisplayId displayId, bool& isRecordedDisplay);
140     void ProcessExpandDisplayCreate(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo,
141         std::map<DisplayId, Rect>& displayRectMap);
142     std::map<DisplayId, sptr<DisplayInfo>> GetAllDisplayInfos(const std::vector<DisplayId>& displayIdVec);
143     std::map<DisplayId, Rect> GetAllDisplayRectsByDMS(sptr<DisplayInfo> displayInfo);
144     std::map<DisplayId, Rect> GetAllDisplayRectsByDisplayInfo(
145         const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap);
146     void MoveNotShowingWindowToDefaultDisplay(DisplayId defaultDisplayId, DisplayId displayId);
147     WMError PostProcessAddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode,
148         sptr<WindowNodeContainer>& container);
149     std::vector<std::pair<uint64_t, bool>> GetWindowVisibilityChangeInfo(
150         std::shared_ptr<RSOcclusionData> occlusionData);
151     bool NeedToStopAddingNode(sptr<WindowNode>& node, const sptr<WindowNodeContainer>& container);
152     void ChangeRSRenderModeIfNeeded(bool isToUnified);
153     bool IsAppWindowExceed() const;
154 
155     std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
156     std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
157     std::map<uint64_t, sptr<WindowNode>> surfaceIdWindowNodeMap_;
158     std::shared_ptr<RSOcclusionData> lastOcclusionData_ = std::make_shared<RSOcclusionData>();
159     std::map<ScreenId, sptr<WindowNodeContainer>> windowNodeContainerMap_;
160     std::map<ScreenId, std::vector<DisplayId>> displayIdMap_;
161 
162     bool needCheckFocusWindow = false;
163 
164     std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_;
165 
166     sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient(std::bind(&WindowRoot::OnRemoteDied,
167         this, std::placeholders::_1));
168     Callback callback_;
169     uint32_t maxAppWindowNumber_ = 100;
170     uint32_t maxUniRenderAppWindowNumber_ { maxAppWindowNumber_ };
171     SplitRatioConfig splitRatioConfig_ = {0.1, 0.9, {}};
172     RenderMode renderMode_ { RenderMode::UNIFIED };
173 };
174 }
175 }
176 #endif // OHOS_ROSEN_WINDOW_ROOT_H
177