• 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 
21 #include "agent_death_recipient.h"
22 #include "display_manager_service_inner.h"
23 #include "window_node_container.h"
24 #include "zidl/window_manager_agent_interface.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 enum class Event : uint32_t {
29     REMOTE_DIED,
30 };
31 
32 class WindowRoot : public RefBase {
33 using Callback = std::function<void (Event event, uint32_t windowId)>;
34 
35 public:
WindowRoot(std::recursive_mutex & mutex,Callback callback)36     WindowRoot(std::recursive_mutex& mutex, Callback callback) : mutex_(mutex), callback_(callback) {}
37     ~WindowRoot() = default;
38 
39     sptr<WindowNodeContainer> GetOrCreateWindowNodeContainer(DisplayId displayId);
40     void NotifyDisplayRemoved(DisplayId displayId);
41     sptr<WindowNode> GetWindowNode(uint32_t windowId) const;
42 
43     WMError SaveWindow(const sptr<WindowNode>& node);
44     WMError AddWindowNode(uint32_t parentId, sptr<WindowNode>& node);
45     WMError RemoveWindowNode(uint32_t windowId);
46     WMError DestroyWindow(uint32_t windowId, bool onlySelf);
47     WMError UpdateWindowNode(uint32_t windowId, WindowUpdateReason reason);
48     bool isVerticalDisplay(sptr<WindowNode>& node) const;
49 
50     WMError RequestFocus(uint32_t windowId);
51     WMError RequestActiveWindow(uint32_t windowId);
52     WMError MinimizeStructuredAppWindowsExceptSelf(sptr<WindowNode>& node);
53     std::vector<Rect> GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType);
54     WMError EnterSplitWindowMode(sptr<WindowNode>& node);
55     WMError ExitSplitWindowMode(sptr<WindowNode>& node);
56     std::shared_ptr<RSSurfaceNode> GetSurfaceNodeByAbilityToken(const sptr<IRemoteObject>& abilityToken) const;
57     WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId);
58     void MinimizeAllAppWindows(DisplayId displayId);
59     WMError MaxmizeWindow(uint32_t windowId);
60     WMError SetWindowLayoutMode(DisplayId displayId, WindowLayoutMode mode);
61 
62     void NotifyWindowStateChange(WindowState state, WindowStateChangeReason reason);
63     void NotifyDisplayChange(sptr<DisplayInfo> abstractDisplay);
64     void NotifyDisplayDestroy(DisplayId displayId);
65     void NotifySystemBarTints();
66     WMError RaiseZOrderForAppWindow(sptr<WindowNode>& node);
67     void FocusFaultDetection() const;
68     float GetVirtualPixelRatio(DisplayId displayId) const;
69     Rect GetDisplayLimitRect(DisplayId displayId) const;
70     WMError UpdateSizeChangeReason(uint32_t windowId, WindowSizeChangeReason reason);
71     void SetBrightness(uint32_t windowId, float brightness);
72     void HandleKeepScreenOn(uint32_t windowId, bool requireLock);
73     void UpdateFocusableProperty(uint32_t windowId);
74 
75 private:
76     void OnRemoteDied(const sptr<IRemoteObject>& remoteObject);
77     WMError DestroyWindowInner(sptr<WindowNode>& node);
78     void UpdateFocusWindowWithWindowRemoved(const sptr<WindowNode>& node,
79         const sptr<WindowNodeContainer>& container) const;
80     void UpdateActiveWindowWithWindowRemoved(const sptr<WindowNode>& node,
81         const sptr<WindowNodeContainer>& container) const;
82     void UpdateBrightnessWithWindowRemoved(uint32_t windowId, const sptr<WindowNodeContainer>& container) const;
83     std::string GenAllWindowsLogInfo() const;
84     bool CheckDisplayInfo(const sptr<DisplayInfo>& display);
85     void NotifyKeyboardSizeChangeInfo(const sptr<WindowNode>& node,
86         const sptr<WindowNodeContainer>& container, Rect rect);
87 
88     std::recursive_mutex& mutex_;
89     std::map<int32_t, sptr<WindowNodeContainer>> windowNodeContainerMap_;
90     std::map<uint32_t, sptr<WindowNode>> windowNodeMap_;
91     std::map<sptr<IRemoteObject>, uint32_t> windowIdMap_;
92     bool needCheckFocusWindow = false;
93 
94     std::map<WindowManagerAgentType, std::vector<sptr<IWindowManagerAgent>>> windowManagerAgents_;
95 
96     sptr<AgentDeathRecipient> windowDeath_ = new AgentDeathRecipient(std::bind(&WindowRoot::OnRemoteDied,
97         this, std::placeholders::_1));
98     Callback callback_;
99 };
100 }
101 }
102 #endif // OHOS_ROSEN_WINDOW_ROOT_H
103