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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H 18 19 #include <memory> 20 21 #ifdef ENABLE_ROSEN_BACKEND 22 #include <mutex> 23 #include "render_service_client/core/ui/rs_frame_rate_linker.h" 24 #include "render_service_client/core/ui/rs_ui_director.h" 25 #include "vsync_receiver.h" 26 #endif 27 28 #include "base/thread/task_executor.h" 29 #include "base/utils/macros.h" 30 #include "base/utils/noncopyable.h" 31 #include "core/common/window.h" 32 #include "core/pipeline/pipeline_context.h" 33 34 namespace OHOS::Ace { 35 class ACE_EXPORT FormRenderWindow : public Window { 36 public: 37 using OnVsyncCallback = std::function<void(int64_t, int64_t, void*)>; 38 explicit FormRenderWindow(RefPtr<TaskExecutor> taskExecutor, int32_t id); 39 FormRenderWindow() = default; 40 ~FormRenderWindow() = default; 41 42 void RequestFrame() override; 43 void Destroy() override; SetRootRenderNode(const RefPtr<RenderNode> & root)44 void SetRootRenderNode(const RefPtr<RenderNode>& root) override {} 45 void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) override; 46 void FlushFrameRate(int32_t rate, int32_t animatorExpectedFrameRate, int32_t rateType) override; 47 48 #ifdef ENABLE_ROSEN_BACKEND GetRsUIDirector()49 std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRsUIDirector() const 50 { 51 return rsUIDirector_; 52 } 53 GetRSSurfaceNode()54 std::shared_ptr<Rosen::RSSurfaceNode> GetRSSurfaceNode() const 55 { 56 return rsSurfaceNode_; 57 } 58 FlushAnimation(uint64_t timeStamp)59 bool FlushAnimation(uint64_t timeStamp) override 60 { 61 return rsUIDirector_->FlushAnimation(timeStamp); 62 } 63 FlushAnimationStartTime(uint64_t timeStamp)64 void FlushAnimationStartTime(uint64_t timeStamp) override 65 { 66 rsUIDirector_->FlushAnimationStartTime(timeStamp); 67 } 68 FlushModifier()69 void FlushModifier() override 70 { 71 rsUIDirector_->FlushModifier(); 72 } 73 HasUIRunningAnimation()74 bool HasUIRunningAnimation() override 75 { 76 return rsUIDirector_->HasUIRunningAnimation(); 77 } 78 GetCurrentRefreshRateMode()79 int32_t GetCurrentRefreshRateMode() const override 80 { 81 return rsUIDirector_->GetCurrentRefreshRateMode(); 82 } 83 GetAnimateExpectedRate()84 int32_t GetAnimateExpectedRate() const override 85 { 86 return rsUIDirector_->GetAnimateExpectedRate(); 87 } 88 #endif 89 90 void OnShow() override; 91 void OnHide() override; 92 void FlushTasks() override; 93 94 private: 95 WeakPtr<TaskExecutor> taskExecutor_ = nullptr; 96 int32_t id_ = 0; 97 #ifdef ENABLE_ROSEN_BACKEND 98 std::shared_ptr<Rosen::VSyncReceiver> receiver_ = nullptr; 99 Rosen::VSyncReceiver::FrameCallback frameCallback_; 100 OnVsyncCallback onVsyncCallback_; 101 std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_; 102 std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode_; 103 std::shared_ptr<Rosen::RSFrameRateLinker> frameRateLinker_ = nullptr; 104 std::tuple<int32_t, int32_t, int32_t> frameRateData_{0, 0, 0}; 105 #endif 106 ACE_DISALLOW_COPY_AND_MOVE(FormRenderWindow); 107 }; 108 } // namespace OHOS::Ace 109 110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H 111