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 typedef struct napi_env__* napi_env; 24 typedef struct napi_value__* napi_value; 25 namespace OHOS::AppExecFwk { 26 class EventHandler; 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 ScreenScene : public Window { 36 public: 37 ScreenScene(std::string name); 38 virtual ~ScreenScene(); 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 void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override; 44 45 void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override; 46 int64_t GetVSyncPeriod() override; 47 void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override; 48 49 void OnBundleUpdated(const std::string& bundleName); 50 void SetFrameLayoutFinishCallback(std::function<void()> && callback); 51 52 void SetDisplayDensity(float density); 53 54 void SetDisplayOrientation(int32_t orientation); 55 GetWindowState()56 WindowState GetWindowState() const override 57 { 58 return WindowState::STATE_SHOWN; 59 } 60 GetType()61 WindowType GetType() const override 62 { 63 return type_; 64 } 65 GetWindowName()66 const std::string& GetWindowName() const override 67 { 68 return name_; 69 } 70 GetWindowId()71 uint32_t GetWindowId() const override 72 { 73 return 1; // 1 for root and screen 74 } 75 GetUIContent()76 Ace::UIContent* GetUIContent() const override 77 { 78 return uiContent_.get(); 79 } 80 81 WMError Destroy() override; 82 GetClassType()83 std::string GetClassType() const override { return "ScreenScene"; } 84 85 private: 86 std::mutex mutex_; 87 std::unique_ptr<Ace::UIContent> uiContent_; 88 float density_ = 1.0f; 89 int32_t orientation_; 90 WindowType type_ = WindowType::WINDOW_TYPE_SCENE_BOARD; 91 std::string name_; 92 std::function<void()> frameLayoutFinishCb_ = nullptr; 93 std::shared_ptr<VsyncStation> vsyncStation_ = nullptr; 94 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 95 }; 96 } // namespace Rosen 97 } // namespace OHOS 98 99 #endif // OHOS_ROSEN_SCREEN_SCENE_H 100