• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/feature/hyper_graphic_manager/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         CHECK_NULL_RETURN(rsUIDirector_, false);
62         return rsUIDirector_->FlushAnimation(timeStamp);
63     }
64 
HasFirstFrameAnimation()65     bool HasFirstFrameAnimation() override
66     {
67         CHECK_NULL_RETURN(rsUIDirector_, false);
68         return rsUIDirector_->HasFirstFrameAnimation();
69     }
70 
FlushAnimationStartTime(uint64_t timeStamp)71     void FlushAnimationStartTime(uint64_t timeStamp) override
72     {
73         CHECK_NULL_VOID(rsUIDirector_);
74         rsUIDirector_->FlushAnimationStartTime(timeStamp);
75     }
76 
FlushModifier()77     void FlushModifier() override
78     {
79         CHECK_NULL_VOID(rsUIDirector_);
80         rsUIDirector_->FlushModifier();
81     }
82 
HasUIRunningAnimation()83     bool HasUIRunningAnimation() override
84     {
85         CHECK_NULL_RETURN(rsUIDirector_, false);
86         return rsUIDirector_->HasUIRunningAnimation();
87     }
88 
GetCurrentRefreshRateMode()89     int32_t GetCurrentRefreshRateMode() const override
90     {
91         CHECK_NULL_RETURN(rsUIDirector_, -1);
92         return rsUIDirector_->GetCurrentRefreshRateMode();
93     }
94 
GetAnimateExpectedRate()95     int32_t GetAnimateExpectedRate() const override
96     {
97         CHECK_NULL_RETURN(rsUIDirector_, 0);
98         return rsUIDirector_->GetAnimateExpectedRate();
99     }
100 #endif
101 
102     void OnShow() override;
103     void OnHide() override;
104     void FlushTasks() override;
105 
106     void Lock() override;
107     void Unlock() override;
108 
109 private:
110     WeakPtr<TaskExecutor> taskExecutor_ = nullptr;
111     int32_t id_ = 0;
112 #ifdef ENABLE_ROSEN_BACKEND
113     void InitOnVsyncCallback();
114     static std::recursive_mutex globalMutex_;
115     std::shared_ptr<Rosen::VSyncReceiver> receiver_ = nullptr;
116     Rosen::VSyncReceiver::FrameCallback frameCallback_;
117     OnVsyncCallback onVsyncCallback_;
118     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_;
119     std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode_;
120     std::shared_ptr<Rosen::RSFrameRateLinker> frameRateLinker_ = nullptr;
121     std::tuple<int32_t, int32_t, int32_t> frameRateData_{0, 0, 0};
122 #endif
123     ACE_DISALLOW_COPY_AND_MOVE(FormRenderWindow);
124 };
125 } // namespace OHOS::Ace
126 
127 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H
128