• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_SCREEN_SCENE_H
17 #define OHOS_ROSEN_SCREEN_SCENE_H
18 
19 #include <mutex>
20 
21 #include "vsync_station.h"
22 #include "window.h"
23 #include "window_helper.h"
24 
25 typedef struct napi_env__* napi_env;
26 typedef struct napi_value__* napi_value;
27 namespace OHOS::AppExecFwk {
28 class EventHandler;
29 } // namespace OHOS::AppExecFwk
30 
31 namespace OHOS::Ace {
32 class UIContent;
33 } // namespace OHOS::Ace
34 
35 namespace OHOS {
36 namespace Rosen {
37 class ScreenScene : public Window {
38 public:
39     ScreenScene(std::string name);
40     virtual ~ScreenScene();
41 
42     void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage,
43         AbilityRuntime::Context* context);
44     void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason);
45     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
46 
47     void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
48     int64_t GetVSyncPeriod() override;
49     void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override;
50 
51     void OnBundleUpdated(const std::string& bundleName);
52     void SetFrameLayoutFinishCallback(std::function<void()> && callback);
53 
54     void SetDisplayDensity(float density);
55 
56     void SetDisplayOrientation(int32_t orientation);
57 
58     DisplayId GetDisplayId() const override;
59     void SetDisplayId(DisplayId displayId);
60 
IsSystemWindow()61     bool IsSystemWindow() const override { return WindowHelper::IsSystemWindow(GetType()); }
IsAppWindow()62     bool IsAppWindow() const override { return WindowHelper::IsAppWindow(GetType()); }
63 
GetWindowState()64     WindowState GetWindowState() const override
65     {
66         return WindowState::STATE_SHOWN;
67     }
68 
GetType()69     WindowType GetType() const override
70     {
71         return type_;
72     }
73 
GetWindowName()74     const std::string& GetWindowName() const override
75     {
76         return name_;
77     }
78 
GetWindowId()79     uint32_t GetWindowId() const override
80     {
81         return 1; // 1 for root and screen
82     }
83 
84     Ace::UIContent* GetUIContent() const override;
85     WMError Destroy() override;
86 
GetClassType()87     std::string GetClassType() const override { return "ScreenScene"; }
88 
89 private:
90     mutable std::mutex mutex_;
91     std::unique_ptr<Ace::UIContent> uiContent_;
92     float density_ = 1.0f;
93     int32_t orientation_;
94     DisplayId displayId_;
95     WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD;
96     std::string name_;
97     std::function<void()> frameLayoutFinishCb_ = nullptr;
98     std::shared_ptr<VsyncStation> vsyncStation_ = nullptr;
99     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
100 };
101 } // namespace Rosen
102 } // namespace OHOS
103 
104 #endif // OHOS_ROSEN_SCREEN_SCENE_H
105