• 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 "ws_common.h"
24 
25 typedef struct napi_env__* napi_env;
26 typedef struct napi_value__* napi_value;
27 namespace OHOS::AppExecFwk {
28 class EventHandler;
29 class LauncherService;
30 } // namespace OHOS::AppExecFwk
31 
32 namespace OHOS::Ace {
33 class UIContent;
34 } // namespace OHOS::Ace
35 
36 namespace OHOS {
37 namespace Rosen {
38 class RSNode;
39 using GetSessionRectCallback = std::function<WSRect(AvoidAreaType)>;
40 
41 class RootScene : public Window {
42 public:
43     RootScene();
44     virtual ~RootScene();
45 
46     void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage,
47         AbilityRuntime::Context* context);
48     void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
49     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
50     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
51 
52     void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
53     int64_t GetVSyncPeriod() override;
54     void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override;
55 
56     /**
57      * Window Immersive
58      */
59     bool IsLastFrameLayoutFinished();
60     void OnFlushUIParams();
61 
GetContext()62     const std::shared_ptr<AbilityRuntime::Context> GetContext() const override { return context_.lock(); }
63 
64     void OnBundleUpdated(const std::string& bundleName);
65     static void SetOnConfigurationUpdatedCallback(
66         const std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)>& callback);
67     void SetFrameLayoutFinishCallback(std::function<void()>&& callback);
68 
SetGetSessionRectCallback(GetSessionRectCallback && callback)69     void SetGetSessionRectCallback(GetSessionRectCallback&& callback)
70     {
71         getSessionRectCallback_ = std::move(callback);
72     }
73 
SetDisplayDensity(float density)74     void SetDisplayDensity(float density)
75     {
76         density_ = density;
77     }
78 
79     void SetDisplayOrientation(int32_t orientation);
80 
GetDisplayDensity()81     float GetDisplayDensity()
82     {
83         return density_;
84     }
85 
GetWindowState()86     WindowState GetWindowState() const override
87     {
88         return WindowState::STATE_SHOWN;
89     }
90 
GetType()91     WindowType GetType() const override
92     {
93         return type_;
94     }
95 
GetWindowName()96     const std::string& GetWindowName() const override
97     {
98         return name_;
99     }
100 
GetWindowId()101     uint32_t GetWindowId() const override
102     {
103         return 1; // 1 for root
104     }
105 
GetUIContent()106     Ace::UIContent* GetUIContent() const override
107     {
108         return uiContent_.get();
109     }
110 
111     void SetUiDvsyncSwitch(bool dvsyncSwitch) override;
112 
113     /*
114      * Window Layout
115      */
116     std::shared_ptr<Rosen::RSNode> GetRSNodeByStringID(const std::string& stringId);
117     void SetTopWindowBoundaryByID(const std::string& stringId);
118 
119     WMError GetSessionRectByType(AvoidAreaType type, WSRect& rect);
120 
121 	/*
122      * Window Property
123      */
124     static void UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
125     void UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
126 
127     static sptr<RootScene> staticRootScene_;
128 
GetClassType()129     std::string GetClassType() const override { return "RootScene"; }
130 
131 private:
132     void RegisterInputEventListener();
133 
134     std::unique_ptr<Ace::UIContent> uiContent_;
135     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
136     sptr<AppExecFwk::LauncherService> launcherService_;
137     float density_ = 1.0f;
138     int32_t orientation_ = 0;
139     WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD;
140     std::string name_ = "EntryView";
141 
142     static std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)> configurationUpdatedCallback_;
143     std::function<void()> frameLayoutFinishCb_ = nullptr;
144     std::shared_ptr<VsyncStation> vsyncStation_ = nullptr;
145     std::weak_ptr<AbilityRuntime::Context> context_;
146 
147     GetSessionRectCallback getSessionRectCallback_ = nullptr;
148 };
149 } // namespace Rosen
150 } // namespace OHOS
151 
152 #endif // OHOS_ROSEN_ROOT_SCENE_H
153