• 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/ui/rs_ui_director.h"
24 #include "vsync_receiver.h"
25 #endif
26 
27 #include "base/thread/task_executor.h"
28 #include "base/utils/macros.h"
29 #include "base/utils/noncopyable.h"
30 #include "core/common/window.h"
31 #include "core/pipeline/pipeline_context.h"
32 
33 namespace OHOS::Ace {
34 class ACE_EXPORT FormRenderWindow : public Window {
35 public:
36     using OnVsyncCallback = std::function<void(int64_t, void*)>;
37     explicit FormRenderWindow(RefPtr<TaskExecutor> taskExecutor, int32_t id);
38     FormRenderWindow() = default;
39     ~FormRenderWindow() = default;
40 
41     void RequestFrame() override;
42     void Destroy() override;
SetRootRenderNode(const RefPtr<RenderNode> & root)43     void SetRootRenderNode(const RefPtr<RenderNode>& root) override {}
44     void SetRootFrameNode(const RefPtr<NG::FrameNode>& root) override;
45 
46 #ifdef ENABLE_ROSEN_BACKEND
GetRsUIDirector()47     std::shared_ptr<OHOS::Rosen::RSUIDirector> GetRsUIDirector() const
48     {
49         return rsUIDirector_;
50     }
51 
GetRSSurfaceNode()52     std::shared_ptr<Rosen::RSSurfaceNode> GetRSSurfaceNode() const
53     {
54         return rsSurfaceNode_;
55     }
56 
FlushCustomAnimation(uint64_t timeStamp)57     bool FlushCustomAnimation(uint64_t timeStamp) override
58     {
59         return rsUIDirector_->RunningCustomAnimation(timeStamp);
60     }
61 #endif
62 
63     void OnShow() override;
64     void OnHide() override;
65     void FlushTasks() override;
66 
67 private:
68     WeakPtr<TaskExecutor> taskExecutor_ = nullptr;
69     int32_t id_ = 0;
70 #ifdef ENABLE_ROSEN_BACKEND
71     static std::mutex globalMutex_;
72     std::shared_ptr<Rosen::VSyncReceiver> receiver_ = nullptr;
73     Rosen::VSyncReceiver::FrameCallback frameCallback_;
74     OnVsyncCallback onVsyncCallback_;
75     std::shared_ptr<OHOS::Rosen::RSUIDirector> rsUIDirector_;
76     std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode_;
77 #endif
78     ACE_DISALLOW_COPY_AND_MOVE(FormRenderWindow);
79 };
80 } // namespace OHOS::Ace
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENT_FORM_FORM_RENDER_WINDOW_H
83