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