• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_ROOT_SCENE_H
17 #define OHOS_ROSEN_ROOT_SCENE_H
18 
19 #include <mutex>
20 
21 #include "vsync_station.h"
22 #include "window.h"
23 #include "window_helper.h"
24 #include "ws_common.h"
25 
26 typedef struct napi_env__* napi_env;
27 typedef struct napi_value__* napi_value;
28 namespace OHOS::AppExecFwk {
29 class EventHandler;
30 class LauncherService;
31 } // namespace OHOS::AppExecFwk
32 
33 namespace OHOS::Ace {
34 class UIContent;
35 } // namespace OHOS::Ace
36 
37 namespace OHOS {
38 namespace Rosen {
39 class RSNode;
40 using GetSessionAvoidAreaByTypeCallback = std::function<AvoidArea(AvoidAreaType)>;
41 using GetStatusBarHeightCallback = std::function<uint32_t()>;
42 using UpdateRootSceneRectCallback = std::function<void(const Rect& rect)>;
43 using UpdateRootSceneAvoidAreaCallback = std::function<void()>;
44 using NotifyWatchFocusActiveChangeCallback = std::function<void(bool isFocusActive)>;
45 using UIContentResult = std::pair<Ace::UIContent*, bool>;
46 
47 class RootScene : public Window {
48 public:
49     RootScene();
50     virtual ~RootScene();
51 
52     void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage,
53         AbilityRuntime::Context* context);
54     void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
55     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
56         const std::vector<std::shared_ptr<AbilityRuntime::Context>>& ignoreWindowContexts = {});
57     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
58     void UpdateConfigurationForSpecified(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
59         const std::shared_ptr<Global::Resource::ResourceManager>& resourceManager) override;
60 
61     void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
62     int64_t GetVSyncPeriod() override;
63     void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override;
64 
65     /*
66      * Window Immersive
67      */
68     bool IsLastFrameLayoutFinished();
69     void OnFlushUIParams();
70     WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea, const Rect& rect = Rect::EMPTY_RECT,
71         int32_t apiVersion = API_VERSION_INVALID) override;
72     void RegisterGetSessionAvoidAreaByTypeCallback(GetSessionAvoidAreaByTypeCallback&& callback);
73     uint32_t GetStatusBarHeight() const override;
74     void RegisterGetStatusBarHeightCallback(GetStatusBarHeightCallback&& callback);
75     void RegisterUpdateRootSceneRectCallback(UpdateRootSceneRectCallback&& callback);
76     WMError RegisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override;
77     WMError UnregisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override;
78     void NotifyAvoidAreaChangeForRoot(const sptr<AvoidArea>& avoidArea, AvoidAreaType type,
79         const sptr<OccupiedAreaChangeInfo>& info = nullptr);
80     void RegisterUpdateRootSceneAvoidAreaCallback(UpdateRootSceneAvoidAreaCallback&& callback);
GetClassType()81     std::string GetClassType() const override { return "RootScene"; }
IsSystemWindow()82     bool IsSystemWindow() const override { return WindowHelper::IsSystemWindow(GetType()); }
IsAppWindow()83     bool IsAppWindow() const override { return WindowHelper::IsAppWindow(GetType()); }
84     void GetExtensionConfig(AAFwk::WantParams& want) const override;
85 
86     /*
87      * Keyboard Window
88      */
89     WMError RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
90     WMError UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
91     void NotifyOccupiedAreaChangeForRoot(const sptr<OccupiedAreaChangeInfo>& info);
92 
93     /*
94      * watch
95      */
96     void RegisterNotifyWatchFocusActiveChangeCallback(NotifyWatchFocusActiveChangeCallback&& callback);
97 
GetContext()98     const std::shared_ptr<AbilityRuntime::Context> GetContext() const override { return context_.lock(); }
99 
100     void OnBundleUpdated(const std::string& bundleName);
101     static void SetOnConfigurationUpdatedCallback(
102         const std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)>& callback);
103     void SetFrameLayoutFinishCallback(std::function<void()>&& callback);
104 
SetDisplayDensity(float density)105     void SetDisplayDensity(float density) { density_ = density; }
106 
SetDisplayId(DisplayId displayId)107     void SetDisplayId(DisplayId displayId) { displayId_ = displayId; }
108 
GetDisplayId()109     DisplayId GetDisplayId() const override { return displayId_; }
110 
111     void SetDisplayOrientation(int32_t orientation);
112 
GetDisplayDensity()113     float GetDisplayDensity() { return density_; }
114 
GetWindowState()115     WindowState GetWindowState() const override { return WindowState::STATE_SHOWN; }
116 
GetType()117     WindowType GetType() const override { return type_; }
118 
GetWindowName()119     const std::string& GetWindowName() const override { return name_; }
120 
GetWindowId()121     uint32_t GetWindowId() const override { return 1; } // 1 for root
122 
GetUIContent()123     Ace::UIContent* GetUIContent() const override { return uiContent_.get(); }
124 
125     UIContentResult GetUIContentByDisplayId(DisplayId displayId);
126 
127     void AddRootScene(DisplayId displayId, wptr<Window> window);
128 
129     void RemoveRootScene(DisplayId displayId);
130 
131     void SetUiDvsyncSwitch(bool dvsyncSwitch) override;
132 
133     void SetTouchEvent(int32_t touchType) override;
134 
135     /*
136      * Window Layout
137      */
138     std::shared_ptr<Rosen::RSNode> GetRSNodeByStringID(const std::string& stringId);
139     void SetTopWindowBoundaryByID(const std::string& stringId);
HasRequestedVsync()140     bool HasRequestedVsync() const { return vsyncStation_->HasRequestedVsync(); }
141 
142     /*
143      * Window Property
144      */
145     static void UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
146     void UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
147 
148     static sptr<RootScene> staticRootScene_;
149 
150     /*
151      * RS Client Multi Instance
152      */
153     std::shared_ptr<RSUIDirector> GetRSUIDirector() const override;
154     std::shared_ptr<RSUIContext> GetRSUIContext() const override;
155 
156 private:
157     void RegisterInputEventListener();
158 
159     std::unique_ptr<Ace::UIContent> uiContent_;
160     std::unordered_map<DisplayId, wptr<Window>> rootSceneMap_;
161     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
162     sptr<AppExecFwk::LauncherService> launcherService_;
163     float density_ = 1.0f;
164     DisplayId displayId_ = DISPLAY_ID_INVALID;
165     int32_t orientation_ = 0;
166     WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD;
167     std::string name_ = "EntryView";
168 
169     static std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)> configurationUpdatedCallback_;
170     std::function<void()> frameLayoutFinishCb_ = nullptr;
171     std::shared_ptr<VsyncStation> vsyncStation_ = nullptr;
172     std::weak_ptr<AbilityRuntime::Context> context_;
173     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
174 
175     /*
176      * Window Immersive
177      */
178     GetSessionAvoidAreaByTypeCallback getSessionAvoidAreaByTypeCallback_ = nullptr;
179     GetStatusBarHeightCallback getStatusBarHeightCallback_ = nullptr;
180     UpdateRootSceneRectCallback updateRootSceneRectCallback_ = nullptr;
181     UpdateRootSceneAvoidAreaCallback updateRootSceneAvoidAreaCallback_ = nullptr;
182     mutable std::mutex mutex_;
183     std::unordered_set<sptr<IAvoidAreaChangedListener>, SptrHash<IAvoidAreaChangedListener>> avoidAreaChangeListeners_;
184 
185     /*
186      * Keyboard Window
187      */
188     mutable std::mutex occupiedAreaMutex_;
189     std::unordered_set<sptr<IOccupiedAreaChangeListener>, SptrHash<IOccupiedAreaChangeListener>>
190         occupiedAreaChangeListeners_;
191 
192     /*
193      * watch
194      */
195     NotifyWatchFocusActiveChangeCallback notifyWatchFocusActiveChangeCallback_ = nullptr;
196 };
197 } // namespace Rosen
198 } // namespace OHOS
199 
200 #endif // OHOS_ROSEN_ROOT_SCENE_H
201