1 /*
2  * Copyright (c) 2021-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 #include "pipeline/rs_root_render_node.h"
17 
18 #ifdef NEW_RENDER_CONTEXT
19 #include "rs_render_surface.h"
20 #else
21 #include "platform/drawing/rs_surface.h"
22 #endif
23 #include "transaction/rs_transaction_proxy.h"
24 #include "visitor/rs_node_visitor.h"
25 #ifndef ROSEN_CROSS_PLATFORM
26 #include <surface.h>
27 #endif
28 
29 namespace OHOS {
30 namespace Rosen {
RSRootRenderNode(NodeId id,const std::weak_ptr<RSContext> & context,bool isTextureExportNode)31 RSRootRenderNode::RSRootRenderNode(NodeId id, const std::weak_ptr<RSContext>& context, bool isTextureExportNode)
32     : RSCanvasRenderNode(id, context, isTextureExportNode), dirtyManager_(std::make_shared<RSDirtyRegionManager>())
33 {
34 #ifndef ROSEN_ARKUI_X
35     MemoryInfo info = {sizeof(*this), ExtractPid(id), id, MEMORY_TYPE::MEM_RENDER_NODE};
36     MemoryTrack::Instance().AddNodeRecord(id, info);
37 #endif
38 }
39 
~RSRootRenderNode()40 RSRootRenderNode::~RSRootRenderNode()
41 {
42 #ifndef ROSEN_ARKUI_X
43     MemoryTrack::Instance().RemoveNodeRecord(GetId());
44 #endif
45 }
46 
AttachRSSurfaceNode(NodeId surfaceNodeId)47 void RSRootRenderNode::AttachRSSurfaceNode(NodeId surfaceNodeId)
48 {
49     surfaceNodeId_ = surfaceNodeId;
50 }
51 
GetSuggestedBufferWidth() const52 float RSRootRenderNode::GetSuggestedBufferWidth() const
53 {
54     return suggestedBufferWidth_;
55 }
56 
GetSuggestedBufferHeight() const57 float RSRootRenderNode::GetSuggestedBufferHeight() const
58 {
59     return suggestedBufferHeight_;
60 }
61 
UpdateSuggestedBufferSize(float width,float height)62 void RSRootRenderNode::UpdateSuggestedBufferSize(float width, float height)
63 {
64     suggestedBufferHeight_ = height;
65     suggestedBufferWidth_ = width;
66 }
67 #ifdef NEW_RENDER_CONTEXT
GetSurface()68 std::shared_ptr<RSRenderSurface> RSRootRenderNode::GetSurface()
69 #else
70 std::shared_ptr<RSSurface> RSRootRenderNode::GetSurface()
71 #endif
72 {
73     return rsSurface_;
74 }
75 
GetRSSurfaceNodeId()76 NodeId RSRootRenderNode::GetRSSurfaceNodeId()
77 {
78     return surfaceNodeId_;
79 }
80 
GetDirtyManager() const81 std::shared_ptr<RSDirtyRegionManager> RSRootRenderNode::GetDirtyManager() const
82 {
83     return dirtyManager_;
84 }
85 
Prepare(const std::shared_ptr<RSNodeVisitor> & visitor)86 void RSRootRenderNode::Prepare(const std::shared_ptr<RSNodeVisitor>& visitor)
87 {
88     if (!visitor) {
89         return;
90     }
91     ApplyModifiers();
92     visitor->PrepareRootRenderNode(*this);
93 }
94 
QuickPrepare(const std::shared_ptr<RSNodeVisitor> & visitor)95 void RSRootRenderNode::QuickPrepare(const std::shared_ptr<RSNodeVisitor>& visitor)
96 {
97     if (!visitor) {
98         return;
99     }
100     ApplyModifiers();
101     visitor->PrepareRootRenderNode(*this);
102 }
103 
Process(const std::shared_ptr<RSNodeVisitor> & visitor)104 void RSRootRenderNode::Process(const std::shared_ptr<RSNodeVisitor>& visitor)
105 {
106     if (!visitor) {
107         return;
108     }
109     RSRenderNode::RenderTraceDebug();
110     visitor->ProcessRootRenderNode(*this);
111 }
112 } // namespace Rosen
113 } // namespace OHOS
114