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 using GetSessionRectCallback = std::function<WSRect(AvoidAreaType)>; 39 40 class RootScene : public Window { 41 public: 42 RootScene(); 43 virtual ~RootScene(); 44 45 void LoadContent(const std::string& contentUrl, napi_env env, napi_value storage, 46 AbilityRuntime::Context* context); 47 void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason); 48 static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 49 void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override; 50 51 void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override; 52 int64_t GetVSyncPeriod() override; 53 void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override; 54 55 void OnBundleUpdated(const std::string& bundleName); 56 static void SetOnConfigurationUpdatedCallback( 57 const std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)>& callback); 58 void SetFrameLayoutFinishCallback(std::function<void()>&& callback); 59 SetGetSessionRectCallback(GetSessionRectCallback&& callback)60 void SetGetSessionRectCallback(GetSessionRectCallback&& callback) 61 { 62 getSessionRectCallback_ = std::move(callback); 63 } 64 SetDisplayDensity(float density)65 void SetDisplayDensity(float density) 66 { 67 density_ = density; 68 } 69 70 void SetDisplayOrientation(int32_t orientation); 71 GetDisplayDensity()72 float GetDisplayDensity() 73 { 74 return density_; 75 } 76 77 WindowState GetWindowState() const override 78 { 79 return WindowState::STATE_SHOWN; 80 } 81 82 WindowType GetType() const override 83 { 84 return type_; 85 } 86 87 const std::string& GetWindowName() const override 88 { 89 return name_; 90 } 91 92 uint32_t GetWindowId() const override 93 { 94 return 1; // 1 for root 95 } 96 97 Ace::UIContent* GetUIContent() const override 98 { 99 return uiContent_.get(); 100 } 101 102 void SetUiDvsyncSwitch(bool dvsyncSwitch) override; 103 104 WMError GetSessionRectByType(AvoidAreaType type, WSRect& rect); 105 106 static sptr<RootScene> staticRootScene_; 107 108 private: 109 void RegisterInputEventListener(); 110 111 std::unique_ptr<Ace::UIContent> uiContent_; 112 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 113 sptr<AppExecFwk::LauncherService> launcherService_; 114 float density_ = 1.0f; 115 int32_t orientation_ = 0; 116 WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD; 117 std::string name_ = "EntryView"; 118 119 static std::function<void(const std::shared_ptr<AppExecFwk::Configuration>&)> configurationUpdatedCallback_; 120 std::function<void()> frameLayoutFinishCb_ = nullptr; 121 std::shared_ptr<VsyncStation> vsyncStation_ = nullptr; 122 123 GetSessionRectCallback getSessionRectCallback_ = nullptr; 124 }; 125 } // namespace Rosen 126 } // namespace OHOS 127 128 #endif // OHOS_ROSEN_ROOT_SCENE_H 129