• 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 "window.h"
22 typedef struct napi_env__* napi_env;
23 typedef struct napi_value__* napi_value;
24 namespace OHOS::AppExecFwk {
25 class EventHandler;
26 class LauncherService;
27 } // namespace OHOS::AppExecFwk
28 
29 namespace OHOS::Ace {
30 class UIContent;
31 } // namespace OHOS::Ace
32 
33 namespace OHOS {
34 namespace Rosen {
35 class RootScene : public Window {
36 public:
37     RootScene();
38     virtual ~RootScene();
39 
40     void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage,
41         AbilityRuntime::Context* context);
42     void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
43     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
44     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
45 
46     void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
47     int64_t GetVSyncPeriod() override;
48     void FlushFrameRate(uint32_t rate) override;
49 
50     void OnBundleUpdated(const std::string& bundleName);
51     void SetFrameLayoutFinishCallback(std::function<void()>&& callback);
52 
SetDisplayDensity(float density)53     void SetDisplayDensity(float density)
54     {
55         density_ = density;
56     }
57 
GetDisplayDensity()58     float GetDisplayDensity()
59     {
60         return density_;
61     }
62 
GetWindowState()63     WindowState GetWindowState() const override
64     {
65         return WindowState::STATE_SHOWN;
66     }
67 
GetType()68     WindowType GetType() const override
69     {
70         return type_;
71     }
72 
GetWindowName()73     const std::string& GetWindowName() const override
74     {
75         return name_;
76     }
77 
GetWindowId()78     uint32_t GetWindowId() const override
79     {
80         return 1; // 1 for root
81     }
82 
GetUIContent()83     Ace::UIContent* GetUIContent() const override
84     {
85         return uiContent_.get();
86     }
87 
88     static sptr<RootScene> staticRootScene_;
89 private:
90     void RegisterInputEventListener();
91 
92     std::mutex mutex_;
93     std::unique_ptr<Ace::UIContent> uiContent_;
94     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
95     sptr<AppExecFwk::LauncherService> launcherService_;
96     float density_ = 1.0f;
97     WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD;
98     std::string name_ = "EntryView";
99     std::function<void()> frameLayoutFinishCb_ = nullptr;
100 };
101 } // namespace Rosen
102 } // namespace OHOS
103 
104 #endif // OHOS_ROSEN_ROOT_SCENE_H
105