• 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 #include "interfaces/inner_api/ace/constants.h"
34 
35 namespace OHOS::Ace {
36 class ACE_EXPORT FormRenderWindow : public Window {
37 public:
38     using OnVsyncCallback = std::function<void(int64_t, int64_t, void*)>;
39     explicit FormRenderWindow(RefPtr<TaskExecutor> taskExecutor, int32_t id);
40     FormRenderWindow() = default;
41     ~FormRenderWindow() = default;
42 
43     void RequestFrame() override;
44     void Destroy() override;
SetRootRenderNode(const RefPtr<RenderNode> & root)45     void SetRootRenderNode(const RefPtr<RenderNode>& root) override {}
46     void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) override;
47     void FlushFrameRate(int32_t rate, int32_t animatorExpectedFrameRate, int32_t rateType) override;
48 
49 #ifdef ENABLE_ROSEN_BACKEND
GetRSUIDirector()50     std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRSUIDirector() const override
51     {
52         return rsUIDirector_;
53     }
54 
GetRSSurfaceNode()55     std::shared_ptr<Rosen::RSSurfaceNode> GetRSSurfaceNode() const
56     {
57         return rsSurfaceNode_;
58     }
59 
FlushAnimation(uint64_t timeStamp)60     bool FlushAnimation(uint64_t timeStamp) override
61     {
62         CHECK_NULL_RETURN(rsUIDirector_, false);
63         return rsUIDirector_->FlushAnimation(timeStamp);
64     }
65 
HasFirstFrameAnimation()66     bool HasFirstFrameAnimation() override
67     {
68         CHECK_NULL_RETURN(rsUIDirector_, false);
69         return rsUIDirector_->HasFirstFrameAnimation();
70     }
71 
FlushAnimationStartTime(uint64_t timeStamp)72     void FlushAnimationStartTime(uint64_t timeStamp) override
73     {
74         CHECK_NULL_VOID(rsUIDirector_);
75         rsUIDirector_->FlushAnimationStartTime(timeStamp);
76     }
77 
FlushModifier()78     void FlushModifier() override
79     {
80         CHECK_NULL_VOID(rsUIDirector_);
81         rsUIDirector_->FlushModifier();
82     }
83 
HasUIRunningAnimation()84     bool HasUIRunningAnimation() override
85     {
86         CHECK_NULL_RETURN(rsUIDirector_, false);
87         return rsUIDirector_->HasUIRunningAnimation();
88     }
89 
GetCurrentRefreshRateMode()90     int32_t GetCurrentRefreshRateMode() const override
91     {
92         CHECK_NULL_RETURN(rsUIDirector_, -1);
93         return rsUIDirector_->GetCurrentRefreshRateMode();
94     }
95 
GetAnimateExpectedRate()96     int32_t GetAnimateExpectedRate() const override
97     {
98         CHECK_NULL_RETURN(rsUIDirector_, 0);
99         return rsUIDirector_->GetAnimateExpectedRate();
100     }
101 #endif
102 
103     void OnShow() override;
104     void OnHide() override;
105     void FlushTasks(std::function<void()> callback = nullptr) override;
106 
107     void Lock() override;
108     void Unlock() override;
109     int64_t GetVSyncPeriod() const override;
110     void RecordFrameTime(uint64_t timeStamp, const std::string& name) override;
111 
112 private:
113     WeakPtr<TaskExecutor> taskExecutor_ = nullptr;
114     int32_t id_ = 0;
115     UIContentType uiContentType_ = UIContentType::UNDEFINED;
116 #ifdef ENABLE_ROSEN_BACKEND
117     void InitOnVsyncCallback();
118     static std::recursive_mutex globalMutex_;
119     std::shared_ptr<Rosen::VSyncReceiver> receiver_ = nullptr;
120     Rosen::VSyncReceiver::FrameCallback frameCallback_;
121     OnVsyncCallback onVsyncCallback_;
122     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_;
123     std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode_;
124     std::shared_ptr<Rosen::RSFrameRateLinker> frameRateLinker_ = nullptr;
125     std::tuple<int32_t, int32_t, int32_t> frameRateData_{0, 0, 0};
126 #endif
127     ACE_DISALLOW_COPY_AND_MOVE(FormRenderWindow);
128 };
129 } // namespace OHOS::Ace
130 
131 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H
132